Skip to content

Commit

Permalink
fix encryption config ID backward compatibility (#244)
Browse files Browse the repository at this point in the history
* fix encryption config ID backward compatibility

* revert database encryption key secret path
  • Loading branch information
kobzonega authored Aug 28, 2024
1 parent 52154b3 commit ada0a42
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions api/v1alpha1/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ const (
ConfigDir = "/opt/ydb/cfg"
ConfigFileName = "config.yaml"

DatabaseEncryptionKeySecretDir = "encryption"
DatabaseEncryptionKeySecretFile = "key.pem"
DatabaseEncryptionKeySecretDir = "database_encryption"
DatabaseEncryptionKeySecretFile = "key"
DatabaseEncryptionKeyConfigFile = "key.txt"

BinariesDir = "/opt/ydb/bin"
Expand Down
4 changes: 2 additions & 2 deletions deploy/ydb-operator/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.5.24
version: 0.5.25

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "0.5.24"
appVersion: "0.5.25"
2 changes: 1 addition & 1 deletion internal/controllers/storage/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ var _ = Describe("Storage controller medium tests", func() {
}, &foundStorage)).Should(Succeed())

foundConfigurationChecksumAnnotation := false
if podAnnotations[annotations.ConfigurationChecksum] == resources.GetConfigurationChecksum(foundStorage.Spec.Configuration) {
if podAnnotations[annotations.ConfigurationChecksum] == resources.SHAChecksum(foundStorage.Spec.Configuration) {
foundConfigurationChecksumAnnotation = true
}
Expect(foundConfigurationChecksumAnnotation).To(BeTrue())
Expand Down
4 changes: 2 additions & 2 deletions internal/resources/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (b *DatabaseBuilder) GetResourceBuilders(restConfig *rest.Config) []Resourc
statefulSetLabels.Merge(map[string]string{labels.StatefulsetComponent: b.Name})

statefulSetAnnotations := CopyDict(b.Spec.AdditionalAnnotations)
statefulSetAnnotations[annotations.ConfigurationChecksum] = GetConfigurationChecksum(b.Spec.Configuration)
statefulSetAnnotations[annotations.ConfigurationChecksum] = SHAChecksum(b.Spec.Configuration)

grpcServiceLabels := databaseLabels.Copy()
grpcServiceLabels.Merge(b.Spec.Service.GRPC.AdditionalLabels)
Expand Down Expand Up @@ -123,7 +123,7 @@ func (b *DatabaseBuilder) GetResourceBuilders(restConfig *rest.Config) []Resourc
api.DatabaseEncryptionKeySecretDir,
api.DatabaseEncryptionKeySecretFile,
),
ID: b.Name,
ID: SHAChecksum(b.Spec.StorageClusterRef.Name),
Pin: b.Spec.Encryption.Pin,
Version: 1,
},
Expand Down
2 changes: 1 addition & 1 deletion internal/resources/databasenodeset.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (b *DatabaseNodeSetResource) GetResourceBuilders(restConfig *rest.Config) [
}

statefulSetAnnotations := CopyDict(b.Spec.AdditionalAnnotations)
statefulSetAnnotations[annotations.ConfigurationChecksum] = GetConfigurationChecksum(b.Spec.Configuration)
statefulSetAnnotations[annotations.ConfigurationChecksum] = SHAChecksum(b.Spec.Configuration)

var resourceBuilders []ResourceBuilder
resourceBuilders = append(resourceBuilders,
Expand Down
4 changes: 2 additions & 2 deletions internal/resources/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,9 +564,9 @@ func buildCAStorePatchingCommandArgs(
return command, args
}

func GetConfigurationChecksum(configuration string) string {
func SHAChecksum(text string) string {
hasher := sha256.New()
hasher.Write([]byte(configuration))
hasher.Write([]byte(text))
return hex.EncodeToString(hasher.Sum(nil))
}

Expand Down
2 changes: 1 addition & 1 deletion internal/resources/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (b *StorageClusterBuilder) GetResourceBuilders(restConfig *rest.Config) []R
statefulSetLabels.Merge(map[string]string{labels.StatefulsetComponent: b.Name})

statefulSetAnnotations := CopyDict(b.Spec.AdditionalAnnotations)
statefulSetAnnotations[annotations.ConfigurationChecksum] = GetConfigurationChecksum(b.Spec.Configuration)
statefulSetAnnotations[annotations.ConfigurationChecksum] = SHAChecksum(b.Spec.Configuration)

grpcServiceLabels := storageLabels.Copy()
grpcServiceLabels.Merge(b.Spec.Service.GRPC.AdditionalLabels)
Expand Down
2 changes: 1 addition & 1 deletion internal/resources/storage_init_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func GetInitJobBuilder(storage *api.Storage) ResourceBuilder {
}
if storage.Spec.InitJob.AdditionalAnnotations != nil {
jobAnnotations = CopyDict(storage.Spec.InitJob.AdditionalAnnotations)
jobAnnotations[annotations.ConfigurationChecksum] = GetConfigurationChecksum(storage.Spec.Configuration)
jobAnnotations[annotations.ConfigurationChecksum] = SHAChecksum(storage.Spec.Configuration)
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/resources/storagenodeset.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (b *StorageNodeSetResource) GetResourceBuilders(restConfig *rest.Config) []
}

statefulSetAnnotations := CopyDict(b.Spec.AdditionalAnnotations)
statefulSetAnnotations[annotations.ConfigurationChecksum] = GetConfigurationChecksum(b.Spec.Configuration)
statefulSetAnnotations[annotations.ConfigurationChecksum] = SHAChecksum(b.Spec.Configuration)

var resourceBuilders []ResourceBuilder
resourceBuilders = append(
Expand Down

0 comments on commit ada0a42

Please sign in to comment.