Skip to content

Commit

Permalink
sops/keyservice: properly fallback to default
Browse files Browse the repository at this point in the history
Signed-off-by: Hidde Beydals <[email protected]>
  • Loading branch information
hiddeco committed Mar 25, 2022
1 parent 5d8bcf9 commit 770bffe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
22 changes: 12 additions & 10 deletions controllers/kustomization_decryptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,6 @@ func (kd *KustomizeDecryptor) ImportKeys(ctx context.Context) error {
var ageIdentities []string
var vaultToken string
for name, value := range secret.Data {
if name == DecryptionAzureAuthFile {
azureConf := azkv.AADConfig{}
if err = azkv.LoadAADConfigFromBytes(value, &azureConf); err != nil {
return err
}
kd.azureAADConfig = &azureConf
continue
}
switch filepath.Ext(name) {
case ".asc":
keyPath, err := securejoin.SecureJoin(tmpDir, name)
Expand All @@ -182,13 +174,23 @@ func (kd *KustomizeDecryptor) ImportKeys(ctx context.Context) error {
}
case ".agekey":
ageIdentities = append(ageIdentities, string(value))
case ".vault-token":
// Make sure we have the absolute file name
case filepath.Ext(DecryptionVaultTokenFileName):
// Make sure we have the absolute name
if name == DecryptionVaultTokenFileName {
token := string(value)
token = strings.Trim(strings.TrimSpace(token), "\n")
vaultToken = token
}
case filepath.Ext(DecryptionAzureAuthFile):
// Make sure we have the absolute name
if name == DecryptionAzureAuthFile {
azureConf := azkv.AADConfig{}
if err = azkv.LoadAADConfigFromBytes(value, &azureConf); err != nil {
return err
}
kd.azureAADConfig = &azureConf
continue
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions internal/sops/keyservice/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (ks Server) Encrypt(ctx context.Context,
// Fallback to default server if no custom settings are configured
// to ensure backwards compatibility with global configurations
if ks.AzureAADConfig == nil {
return ks.Encrypt(ctx, req)
return ks.DefaultServer.Encrypt(ctx, req)
}
ciphertext, err := ks.encryptWithAzureKeyvault(k.AzureKeyvaultKey, req.Plaintext)
if err != nil {
Expand Down Expand Up @@ -252,7 +252,7 @@ func (ks Server) Decrypt(ctx context.Context,
// Fallback to default server if no custom settings are configured
// to ensure backwards compatibility with global configurations
if ks.AzureAADConfig == nil {
return ks.Decrypt(ctx, req)
return ks.DefaultServer.Decrypt(ctx, req)
}
plaintext, err := ks.decryptWithAzureKeyvault(k.AzureKeyvaultKey, req.Ciphertext)
if err != nil {
Expand Down

0 comments on commit 770bffe

Please sign in to comment.