Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify NSQ TLS cert handling. #601

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/metal-api/internal/eventbus/nsq.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (n *NSQClient) WaitForPublisher() {
}

func (n *NSQClient) CreateEndpoints(lookupds ...string) error {
c, err := bus.NewConsumer(n.logger, n.config.TLS, lookupds...)
c, err := bus.NewConsumer(n.logger, n.config.NSQ, lookupds...)
if err != nil {
return fmt.Errorf("cannot create consumer for endpoints: %w", err)
}
Expand Down
40 changes: 21 additions & 19 deletions cmd/metal-api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import (
"github.com/metal-stack/metal-lib/auditing"
"github.com/metal-stack/metal-lib/rest"

nsq2 "github.com/nsqio/go-nsq"

"github.com/metal-stack/metal-lib/jwt/grp"
"github.com/metal-stack/metal-lib/jwt/sec"
"github.com/metal-stack/metal-lib/pkg/pointer"
Expand Down Expand Up @@ -75,12 +73,12 @@ const (
var (
logger *slog.Logger

ds *datastore.RethinkStore
ipamer ipam.IPAMer
publisherTLSConfig *bus.TLSConfig
nsqer *eventbus.NSQClient
mdc mdm.Client
headscaleClient *headscale.HeadscaleClient
ds *datastore.RethinkStore
ipamer ipam.IPAMer
nsqer *eventbus.NSQClient
publisherCfg *bus.PublisherConfig
mdc mdm.Client
headscaleClient *headscale.HeadscaleClient
)

var rootCmd = &cobra.Command{
Expand Down Expand Up @@ -257,6 +255,7 @@ func init() {
rootCmd.Flags().StringP("nsqd-http-endpoint", "", "nsqd:4151", "the address of the nsqd http endpoint")
rootCmd.Flags().StringP("nsqd-ca-cert-file", "", "", "the CA certificate file to verify nsqd certificate")
rootCmd.Flags().StringP("nsqd-client-cert-file", "", "", "the client certificate file to access nsqd")
rootCmd.Flags().StringP("nsqd-client-cert-key-file", "", "", "the client certificate key file to access nsqd")
rootCmd.Flags().StringP("nsqd-write-timeout", "", "10s", "the write timeout for nsqd")
rootCmd.Flags().StringP("nsqlookupd-addr", "", "", "the http addresses of the nsqlookupd as a commalist")

Expand Down Expand Up @@ -415,19 +414,22 @@ func initEventBus() {
if err != nil {
writeTimeout = 0
}
caCertFile := viper.GetString("nsqd-ca-cert-file")
clientCertFile := viper.GetString("nsqd-client-cert-file")
if caCertFile != "" && clientCertFile != "" {
publisherTLSConfig = &bus.TLSConfig{
CACertFile: caCertFile,
ClientCertFile: clientCertFile,
}

var (
caCertFile = viper.GetString("nsqd-ca-cert-file")
clientCertFile = viper.GetString("nsqd-client-cert-file")
clientCertKeyFile = viper.GetString("nsqd-client-cert-key-file")
)

cfg, err := bus.CreateNSQConfig(caCertFile, clientCertFile, clientCertKeyFile)
if err != nil {
panic(err)
}
publisherCfg := &bus.PublisherConfig{

publisherCfg = &bus.PublisherConfig{
TCPAddress: viper.GetString("nsqd-tcp-addr"),
HTTPEndpoint: viper.GetString("nsqd-http-endpoint"),
TLS: publisherTLSConfig,
NSQ: nsq2.NewConfig(),
NSQ: cfg,
}
publisherCfg.NSQ.WriteTimeout = writeTimeout

Expand Down Expand Up @@ -969,7 +971,7 @@ func run() error {
p = nsqer.Publisher
}

c, err := bus.NewConsumer(logger, publisherTLSConfig, viper.GetString("nsqlookupd-addr"))
c, err := bus.NewConsumer(logger, publisherCfg.NSQ, viper.GetString("nsqlookupd-addr"))
if err != nil {
log.Fatalf("cannot connect to NSQ: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/looplab/fsm v1.0.2
github.com/metal-stack/go-ipam v1.14.7
github.com/metal-stack/masterdata-api v0.11.5
github.com/metal-stack/metal-lib v0.19.0
github.com/metal-stack/metal-lib v0.19.1-0.20250115130857-14ae17045094
github.com/metal-stack/security v0.9.0
github.com/metal-stack/v v1.0.3
github.com/nsqio/go-nsq v1.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ github.com/metal-stack/go-ipam v1.14.7 h1:DA+uP72rAqGechwDJ3EzjI/snaMc77lGqoQYsy
github.com/metal-stack/go-ipam v1.14.7/go.mod h1:YxQhPVl9cXFSs3/DpyYa4qVsYT+aDIlwfCFLt4znTqI=
github.com/metal-stack/masterdata-api v0.11.5 h1:r7bYdhdVgOjCk6k7K/SCLlHALH23ZuMGY8E4udk4wXQ=
github.com/metal-stack/masterdata-api v0.11.5/go.mod h1:Xk8kqxAp3NkAc2BX8yTIWgSlD77T897QSdRSluWvP4w=
github.com/metal-stack/metal-lib v0.19.0 h1:4yBnp/jPGgX9KeCje3A4MFL2oDjgjOjgsIK391LltRI=
github.com/metal-stack/metal-lib v0.19.0/go.mod h1:fCMaWwVGA/xAoGvBk72/nfzqBkHly0iOzrWpc55Fau4=
github.com/metal-stack/metal-lib v0.19.1-0.20250115130857-14ae17045094 h1:yS5fwvmhwg0GwldOfXHX0Ql09eauM+Al7CTEIig6bRI=
github.com/metal-stack/metal-lib v0.19.1-0.20250115130857-14ae17045094/go.mod h1:fCMaWwVGA/xAoGvBk72/nfzqBkHly0iOzrWpc55Fau4=
github.com/metal-stack/security v0.9.0 h1:FYBXJfNJwUw2E0HBa+jay37XF7b6EikEuf4Mw8u04EY=
github.com/metal-stack/security v0.9.0/go.mod h1:6pQhJ4Kdu4BKnjB4zyzfK9skiHymqfrqt63Y+UmZBKA=
github.com/metal-stack/v v1.0.3 h1:Sh2oBlnxrCUD+mVpzfC8HiqL045YWkxs0gpTvkjppqs=
Expand Down
Loading