Skip to content

Commit

Permalink
fix: redact service account key in config in RedactSecrets method
Browse files Browse the repository at this point in the history
Include the previously missing service account key field in the redaction.

Signed-off-by: Utku Ozdemir <utku.ozdemir@siderolabs.com>
  • Loading branch information
utkuozdemir committed Dec 15, 2022
1 parent b3aebfa commit 873bd38
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/machinery/config/types/v1alpha1/v1alpha1_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ func (c *Config) Bytes() ([]byte, error) {
}

// RedactSecrets implements the config.Provider interface.
//
//nolint:gocyclo
func (c *Config) RedactSecrets(replacement string) config.Provider {
if c == nil {
return nil
Expand Down Expand Up @@ -135,6 +137,10 @@ func (c *Config) RedactSecrets(replacement string) config.Provider {
clone.ClusterConfig.ClusterAESCBCEncryptionSecret = redactStr(clone.ClusterConfig.ClusterAESCBCEncryptionSecret)
clone.ClusterConfig.ClusterSecretboxEncryptionSecret = redactStr(clone.ClusterConfig.ClusterSecretboxEncryptionSecret)

if clone.ClusterConfig.ClusterServiceAccount != nil {
clone.ClusterConfig.ClusterServiceAccount.Key = redactBytes(clone.ClusterConfig.ClusterServiceAccount.Key)
}

if clone.ClusterConfig.ClusterCA != nil {
clone.ClusterConfig.ClusterCA.Key = redactBytes(clone.ClusterConfig.ClusterCA.Key)
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/machinery/config/types/v1alpha1/v1alpha1_redact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func TestRedactSecrets(t *testing.T) {
require.NotEmpty(t, config.ClusterConfig.ClusterSecretboxEncryptionSecret)
require.NotEmpty(t, config.ClusterConfig.ClusterCA.Key)
require.NotEmpty(t, config.ClusterConfig.EtcdConfig.RootCA.Key)
require.NotEmpty(t, config.ClusterConfig.ClusterServiceAccount.Key)

replacement := "**.***"

Expand All @@ -55,4 +56,5 @@ func TestRedactSecrets(t *testing.T) {
require.Equal(t, replacement, redacted.Cluster().SecretboxEncryptionSecret())
require.Equal(t, replacement, string(redacted.Cluster().CA().Key))
require.Equal(t, replacement, string(redacted.Cluster().Etcd().CA().Key))
require.Equal(t, replacement, string(redacted.Cluster().ServiceAccount().Key))
}

0 comments on commit 873bd38

Please sign in to comment.