Skip to content

Commit

Permalink
Added support for reusing the webhook TLS certificate across differen…
Browse files Browse the repository at this point in the history
…t deployments to prevent cases where operator takes too long to start up (#180)
  • Loading branch information
omris94 authored Feb 17, 2025
1 parent d182a14 commit f126b1c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
11 changes: 11 additions & 0 deletions src/operator/config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ rules:
- patch
- update
- watch
- apiGroups:
- ""
resourceNames:
- credentials-operator-webhook-cert
resources:
- secrets
verbs:
- get
- list
- update
- watch
- apiGroups:
- ""
resources:
Expand Down
2 changes: 1 addition & 1 deletion src/operator/go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/operator/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 18 additions & 2 deletions src/operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,25 @@ func main() {
// setup webhook
if viper.GetBool(operatorconfig.SelfSignedCertKey) {
logrus.Infoln("Creating self signing certs")
certBundle, err := operatorwebhooks.GenerateSelfSignedCertificate("credentials-operator-webhook-service", podNamespace)
secretName := viper.GetString(operatorconfig.WebhookCertSecretNameKey)
certBundle, ok, err := operatorwebhooks.ReadCertBundleFromSecret(signalHandlerCtx, directClient, secretName, podNamespace)
if err != nil {
logrus.WithError(err).Panic("unable to create self signed certs for webhook")
logrus.WithError(err).Warn("unable to read existing certs from secret, generating new ones")
}
if !ok {
logrus.Info("webhook certs uninitialized, generating new certs")
}
if !ok || err != nil {
certBundleNew, err :=
operatorwebhooks.GenerateSelfSignedCertificate("intents-operator-webhook-service", podNamespace)
if err != nil {
logrus.WithError(err).Panic("unable to create self signed certs for webhook")
}
err = operatorwebhooks.PersistCertBundleToSecret(signalHandlerCtx, directClient, secretName, podNamespace, certBundleNew)
if err != nil {
logrus.WithError(err).Panic("unable to persist certs to secret")
}
certBundle = certBundleNew
}
err = operatorwebhooks.WriteCertToFiles(certBundle)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions src/operator/operatorconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ const (
EnableSecretRotationDefault = false
DatabasePasswordRotationIntervalKey = "database-password-rotation-interval"
DatabasePasswordRotationIntervalDefault = time.Hour * 8
WebhookCertSecretNameKey = "webhook-cert-secret-name"
WebhookCertSecretNameDefault = "credentials-operator-webhook-cert"
)

const (
Expand Down Expand Up @@ -86,6 +88,7 @@ func init() {
viper.SetDefault(AWSUseSoftDeleteStrategyKey, AWSUseSoftDeleteStrategyDefault)
viper.SetDefault(EnableSecretRotationKey, EnableSecretRotationDefault)
viper.SetDefault(DebugKey, DebugDefault)
viper.SetDefault(WebhookCertSecretNameKey, WebhookCertSecretNameDefault)
viper.SetEnvPrefix(EnvPrefix)
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
viper.AutomaticEnv()
Expand Down

0 comments on commit f126b1c

Please sign in to comment.