Skip to content

Commit ab182e1

Browse files
authored
Create self-signed certificates by default when webhook is enabled (#186)
1 parent 251a000 commit ab182e1

File tree

2 files changed

+33
-31
lines changed

2 files changed

+33
-31
lines changed

Diff for: src/mapper/cmd/main.go

+29-27
Original file line numberDiff line numberDiff line change
@@ -93,32 +93,6 @@ func main() {
9393
os.Exit(1)
9494
}
9595

96-
if viper.GetBool(config.CreateWebhookCertificateKey) {
97-
// create webhook server certificate
98-
logrus.Infoln("Creating self signing certs")
99-
podNamespace, err := kubeutils.GetCurrentNamespace()
100-
101-
if err != nil {
102-
logrus.WithError(err).Panic("unable to get pod namespace")
103-
}
104-
105-
certBundle, err :=
106-
operatorwebhooks.GenerateSelfSignedCertificate("otterize-network-mapper-webhook-service", podNamespace)
107-
if err != nil {
108-
logrus.WithError(err).Panic("unable to create self signed certs for webhook")
109-
}
110-
err = operatorwebhooks.WriteCertToFiles(certBundle)
111-
if err != nil {
112-
logrus.WithError(err).Panic("failed writing certs to file system")
113-
}
114-
115-
err = operatorwebhooks.UpdateMutationWebHookCA(context.Background(),
116-
"otterize-aws-visibility-mutating-webhook-configuration", certBundle.CertPem)
117-
if err != nil {
118-
logrus.WithError(err).Panic("updating validation webhook certificate failed")
119-
}
120-
}
121-
12296
errgrp.Go(func() error {
12397
defer errorreporter.AutoNotify()
12498

@@ -162,7 +136,9 @@ func main() {
162136
defer cancelFn()
163137
mgr.GetCache().WaitForCacheSync(initCtx) // needed to let the manager initialize before used in intentsHolder
164138

165-
if viper.GetBool(config.EnableAWSVisibilityKeyWebHook) {
139+
if viper.GetBool(config.EnableAWSVisibilityWebHookKey) {
140+
logrus.Infoln("Registering AWS visibility mutating webhook")
141+
166142
webhookHandler, err := pod_webhook.NewInjectDNSConfigToPodWebhook(
167143
mgr.GetClient(),
168144
admission.NewDecoder(mgr.GetScheme()),
@@ -178,6 +154,32 @@ func main() {
178154
Handler: webhookHandler,
179155
},
180156
)
157+
158+
if viper.GetBool(config.CreateWebhookCertificateKey) {
159+
// create webhook server certificate
160+
logrus.Infoln("Creating self signing certs for webhook")
161+
podNamespace, err := kubeutils.GetCurrentNamespace()
162+
163+
if err != nil {
164+
logrus.WithError(err).Panic("unable to get pod namespace")
165+
}
166+
167+
certBundle, err :=
168+
operatorwebhooks.GenerateSelfSignedCertificate("otterize-network-mapper-webhook-service", podNamespace)
169+
if err != nil {
170+
logrus.WithError(err).Panic("unable to create self signed certs for webhook")
171+
}
172+
err = operatorwebhooks.WriteCertToFiles(certBundle)
173+
if err != nil {
174+
logrus.WithError(err).Panic("failed writing certs to file system")
175+
}
176+
177+
err = operatorwebhooks.UpdateMutationWebHookCA(context.Background(),
178+
"otterize-aws-visibility-mutating-webhook-configuration", certBundle.CertPem)
179+
if err != nil {
180+
logrus.WithError(err).Panic("updating validation webhook certificate failed")
181+
}
182+
}
181183
}
182184

183185
intentsHolder := intentsstore.NewIntentsHolder()

Diff for: src/mapper/pkg/config/config.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ const (
2424
ExternalTrafficCaptureEnabledKey = "capture-external-traffic-enabled"
2525
ExternalTrafficCaptureEnabledDefault = false
2626
CreateWebhookCertificateKey = "create-webhook-certificate"
27-
CreateWebhookCertificateDefault = false
28-
EnableAWSVisibilityKeyWebHook = "enable-aws-visibility-webhook"
29-
EnableAWSVisibilityDefaultWebHook = false
27+
CreateWebhookCertificateDefault = true
28+
EnableAWSVisibilityWebHookKey = "enable-aws-visibility-webhook"
29+
EnableAWSVisibilityWebHookDefault = false
3030
)
3131

3232
var excludedNamespaces *goset.Set[string]
@@ -45,6 +45,6 @@ func init() {
4545
viper.SetDefault(OTelMetricKey, OTelMetricDefault)
4646
viper.SetDefault(ExternalTrafficCaptureEnabledKey, ExternalTrafficCaptureEnabledDefault)
4747
viper.SetDefault(CreateWebhookCertificateKey, CreateWebhookCertificateDefault)
48-
viper.SetDefault(EnableAWSVisibilityKeyWebHook, EnableAWSVisibilityDefaultWebHook)
48+
viper.SetDefault(EnableAWSVisibilityWebHookKey, EnableAWSVisibilityWebHookDefault)
4949
excludedNamespaces = goset.FromSlice(viper.GetStringSlice(ExcludedNamespacesKey))
5050
}

0 commit comments

Comments
 (0)