Skip to content

Commit

Permalink
Remove the option to disable automated CA rotation
Browse files Browse the repository at this point in the history
This option was only added to disable the feature in 4.3 and is not
necessary for a release that enables automated rotation.
  • Loading branch information
marun committed Feb 6, 2020
1 parent 66ea5b7 commit 95afe0e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 31 deletions.
24 changes: 6 additions & 18 deletions pkg/operator/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,19 @@ import (
type unsupportedServiceCAConfig struct {
CAConfig caConfig `json:"caConfig"`

TimeBasedRotation timeBasedRotationConfig `json:"timeBasedRotation"`

ForceRotation forceRotationConfig `json:"forceRotation"`
}

type caConfig struct {
// validityDurationForTesting determines how long a new signing CA
// will be valid for from the time that it is generated. It should
// only be used for testing purposes and is not intended for
// production use. If unspecified or 0, the CA will be valid for 1
// year.
// production use. If unspecified or 0, the CA will be valid for 26
// months.
// +optional
ValidityDurationForTesting time.Duration `json:"validityDurationForTesting"`
}

type timeBasedRotationConfig struct {
// enabled determines whether automatic rotation will occur when the signing CA
// has less than a minimum validity duration.
// +optional
Enabled bool `json:"enabled"`
}

type forceRotationConfig struct {
// reason indicates why a rotation of the signing CA should be forced. If the
// reason is not empty and has not been recorded as an annotation on the signing
Expand All @@ -48,17 +39,14 @@ func loadUnsupportedServiceCAConfig(raw []byte) (unsupportedServiceCAConfig, err
return serviceCAConfig, err
}

// RawUnsupportedServiceCAConfig returns the raw value of the operator field
// UnsupportedConfigOverrides for whether time-based rotation is enabled and the
// given force rotation reason.
func RawUnsupportedServiceCAConfig(enabled bool, reason string, duration time.Duration) ([]byte, error) {
// RawUnsupportedServiceCAConfig returns the raw value of the operator
// field UnsupportedConfigOverrides for the given force rotation
// reason.
func RawUnsupportedServiceCAConfig(reason string, duration time.Duration) ([]byte, error) {
config := &unsupportedServiceCAConfig{
CAConfig: caConfig{
ValidityDurationForTesting: duration,
},
TimeBasedRotation: timeBasedRotationConfig{
Enabled: enabled,
},
ForceRotation: forceRotationConfig{
Reason: reason,
},
Expand Down
7 changes: 2 additions & 5 deletions pkg/operator/rotate.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,8 @@ func maybeRotateSigningSecret(secret *corev1.Secret, currentCACert *x509.Certifi
reason := serviceCAConfig.ForceRotation.Reason
forcedRotation := forcedRotationRequired(secret, reason)

timeBasedRotation := false
if serviceCAConfig.TimeBasedRotation.Enabled {
minimumExpiry := time.Now().Add(minimumTrustDuration)
timeBasedRotation = currentCACert.NotAfter.Before(minimumExpiry)
}
minimumExpiry := time.Now().Add(minimumTrustDuration)
timeBasedRotation := currentCACert.NotAfter.Before(minimumExpiry)

if !(forcedRotation || timeBasedRotation) {
return "", nil
Expand Down
11 changes: 3 additions & 8 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,11 +410,6 @@ func triggerTimeBasedRotation(t *testing.T, client *kubernetes.Clientset, config
Key: currentCAKey,
}

// Enable time-based rotation by updating the operator config.
timeBasedRotationEnabled := true
forceRotationReason := ""
setUnsupportedServiceCAConfig(t, config, timeBasedRotationEnabled, forceRotationReason, 0)

// Trigger rotation by renewing the current ca with an expiry that
// is sooner than the minimum required duration.
renewedCAConfig, err := operator.RenewSelfSignedCertificate(currentCAConfig, 1*time.Hour, true)
Expand Down Expand Up @@ -465,7 +460,7 @@ func triggerForcedRotation(t *testing.T, client *kubernetes.Clientset, config *r

// Trigger a forced rotation by updating the operator config
// with a reason.
setUnsupportedServiceCAConfig(t, config, false, "42", customDuration)
setUnsupportedServiceCAConfig(t, config, "42", customDuration)

signingSecret := pollForCARotation(t, client, caCertPEM, caKeyPEM)

Expand All @@ -480,7 +475,7 @@ func triggerForcedRotation(t *testing.T, client *kubernetes.Clientset, config *r
}
}

func setUnsupportedServiceCAConfig(t *testing.T, config *rest.Config, timeBasedRotationEnabled bool, forceRotationReason string, validityDuration time.Duration) {
func setUnsupportedServiceCAConfig(t *testing.T, config *rest.Config, forceRotationReason string, validityDuration time.Duration) {
operatorClient, err := operatorv1client.NewForConfig(config)
if err != nil {
t.Fatalf("error creating operator client: %v", err)
Expand All @@ -489,7 +484,7 @@ func setUnsupportedServiceCAConfig(t *testing.T, config *rest.Config, timeBasedR
if err != nil {
t.Fatalf("error retrieving operator config: %v", err)
}
rawUnsupportedServiceCAConfig, err := operator.RawUnsupportedServiceCAConfig(timeBasedRotationEnabled, forceRotationReason, validityDuration)
rawUnsupportedServiceCAConfig, err := operator.RawUnsupportedServiceCAConfig(forceRotationReason, validityDuration)
if err != nil {
t.Fatalf("failed to create raw unsupported config overrides: %v", err)
}
Expand Down

0 comments on commit 95afe0e

Please sign in to comment.