Skip to content

feat(awssecrets): add support for binary #500

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions docs/backends.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,24 @@ stringData:
type: Opaque
```

###### Retrieving of binary data

Since there is no way to set a key for binary type in AWS Secret Manager, set the `<key>` part to `SecretBinary` to retrieve binary data:

```yaml
apiVersion: v1
kind: Secret
metadata:
name: aws-example
stringData:
sample-secret: <path:arn:aws:secretsmanager:<REGION>:<ACCOUNT_NUMBER>:<SECRET_ID>#SecretBinary>
type: Opaque
```

**NOTE**
For cross account access there is the need to configure the correct permissions between accounts, please check:
https://aws.amazon.com/premiumsupport/knowledge-center/secrets-manager-share-between-accounts
https://docs.aws.amazon.com/secretsmanager/latest/userguide/auth-and-access_examples_cross.html
https://aws.amazon.com/premiumsupport/knowledge-center/secrets-manager-share-between-accounts
https://docs.aws.amazon.com/secretsmanager/latest/userguide/auth-and-access_examples_cross.html

### GCP Secret Manager

Expand Down
5 changes: 5 additions & 0 deletions pkg/backends/awssecretsmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ func (a *AWSSecretsManager) GetSecrets(path string, version string, annotations
if err != nil {
return nil, err
}
} else if result.SecretBinary != nil {
utils.VerboseToStdErr("Get binary value for %v", path)
dat = make(map[string]interface{})
dat["SecretBinary"] = result.SecretBinary
return dat, nil
} else {
return nil, fmt.Errorf("Could not find secret %s", path)
}
Expand Down
17 changes: 17 additions & 0 deletions pkg/backends/awssecretsmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ func (m *mockSecretsManagerClient) GetSecretValue(ctx context.Context, input *se
string := "{\"test-secret\":\"previous-value\"}"
data.SecretString = &string
}
case "test-binary":
data.SecretBinary = []byte("binary-data")
}

return data, nil
Expand Down Expand Up @@ -75,6 +77,21 @@ func TestAWSSecretManagerGetSecrets(t *testing.T) {
t.Errorf("expected: %s, got: %s.", expected, data)
}
})

t.Run("Get binary secret", func(t *testing.T) {
data, err := sm.GetSecrets("test-binary", "", map[string]string{})
if err != nil {
t.Fatalf("expected 0 errors but got: %s", err)
}

expected := map[string]interface{}{
"SecretBinary": []byte("binary-data"),
}

if !reflect.DeepEqual(expected, data) {
t.Errorf("expected: %v, got: %v.", expected, data)
}
})
}

func TestAWSSecretManagerEmptyIfNoSecret(t *testing.T) {
Expand Down