Skip to content

Commit

Permalink
Merge pull request #2477 from SanjalKatiyar/fix_key_rotation
Browse files Browse the repository at this point in the history
allow disabling key rotation
  • Loading branch information
openshift-merge-bot[bot] authored Feb 22, 2024
2 parents f8a0c2c + 5626e03 commit 5c83893
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 22 deletions.
3 changes: 1 addition & 2 deletions api/v1/storagecluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,7 @@ type EncryptionSpec struct {
type KeyRotationSpec struct {
// Enable represents whether the key rotation is enabled.
// +optional
// +kubebuilder:default=false
Enable bool `json:"enable,omitempty"`
Enable *bool `json:"enable,omitempty"`
// Schedule represents the cron schedule for key rotation.
// +optional
// +kubebuilder:default="@weekly"
Expand Down
9 changes: 7 additions & 2 deletions api/v1/zz_generated.deepcopy.go

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

1 change: 0 additions & 1 deletion config/crd/bases/ocs.openshift.io_storageclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,6 @@ spec:
description: KeyRotation defines options for Key Rotation.
properties:
enable:
default: false
description: Enable represents whether the key rotation is
enabled.
type: boolean
Expand Down
9 changes: 5 additions & 4 deletions controllers/storagecluster/cephcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,6 @@ func (obj *ocsCephCluster) ensureCreated(r *StorageClusterReconciler, sc *ocsv1.
return reconcile.Result{}, err
}
}

isEnabled, rotationSchedule := util.GetKeyRotationSpec(sc)
cephCluster.Spec.Security.KeyRotation.Enabled = isEnabled
cephCluster.Spec.Security.KeyRotation.Schedule = rotationSchedule
}

// Set StorageCluster instance as the owner and controller
Expand Down Expand Up @@ -558,6 +554,11 @@ func newCephCluster(sc *ocsv1.StorageCluster, cephImage string, serverVersion *v
}
cephCluster.Spec.Security.KeyManagementService.ConnectionDetails = kmsConfigMap.Data
}

isEnabled, rotationSchedule := util.GetKeyRotationSpec(sc)
cephCluster.Spec.Security.KeyRotation.Enabled = isEnabled
cephCluster.Spec.Security.KeyRotation.Schedule = rotationSchedule

return cephCluster, nil
}

Expand Down
18 changes: 11 additions & 7 deletions controllers/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@ func DetectDuplicateInStringSlice(slice []string) bool {

func GetKeyRotationSpec(sc *ocsv1.StorageCluster) (bool, string) {
schedule := sc.Spec.Encryption.KeyRotation.Schedule
if (sc.Spec.Encryption.Enable || sc.Spec.Encryption.ClusterWide) && !sc.Spec.Encryption.KeyManagementService.Enable {
if schedule == "" {
// default schedule
schedule = "@weekly"
if schedule == "" {
// default schedule
schedule = "@weekly"
}

if sc.Spec.Encryption.KeyRotation.Enable == nil {
if (sc.Spec.Encryption.Enable || sc.Spec.Encryption.ClusterWide) && !sc.Spec.Encryption.KeyManagementService.Enable {
// use key-rotation by default if cluster-wide encryption is opted without KMS & "enable" spec is missing
return true, schedule
}
// use key-rotation by default if cluster-wide encryption is opted without KMS
return true, schedule
return false, schedule
}
return sc.Spec.Encryption.KeyRotation.Enable, schedule
return *sc.Spec.Encryption.KeyRotation.Enable, schedule
}
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,6 @@ spec:
description: KeyRotation defines options for Key Rotation.
properties:
enable:
default: false
description: Enable represents whether the key rotation is
enabled.
type: boolean
Expand Down
1 change: 0 additions & 1 deletion deploy/ocs-operator/manifests/storagecluster.crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,6 @@ spec:
description: KeyRotation defines options for Key Rotation.
properties:
enable:
default: false
description: Enable represents whether the key rotation is
enabled.
type: boolean
Expand Down

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

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

0 comments on commit 5c83893

Please sign in to comment.