Skip to content

Commit 2f3a187

Browse files
authored
feat(aws): use region if path is full arn (#487)
1 parent 20e99e9 commit 2f3a187

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

docs/backends.md

+4
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,10 @@ documentation](https://aws.github.io/aws-sdk-go-v2/docs/configuring-sdk/#specify
241241
supplying AWS credentials. Supported credentials and the order in which they are loaded are
242242
described [here](https://aws.github.io/aws-sdk-go-v2/docs/configuring-sdk/#specifying-credentials).
243243

244+
**Note About Region**
245+
If you provide the full AWS ARN as the secret path, ex. `arn:aws:secretsmanager:us-east-1:123123123:secret:some-secret`,
246+
the region from the ARN (us-east-1) in this example, will take precedents over the AWS_REGION environment variable listed below.
247+
244248
These are the parameters for AWS:
245249
```
246250
AVP_TYPE: awssecretsmanager

pkg/backends/awssecretsmanager.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7+
"regexp"
78

89
"github.com/argoproj-labs/argocd-vault-plugin/pkg/utils"
910
"github.com/aws/aws-sdk-go-v2/aws"
@@ -40,10 +41,21 @@ func (a *AWSSecretsManager) Login() error {
4041

4142
// GetSecrets gets secrets from aws secrets manager and returns the formatted data
4243
func (a *AWSSecretsManager) GetSecrets(path string, version string, annotations map[string]string) (map[string]interface{}, error) {
44+
var opts = func(o *secretsmanager.Options) {}
45+
4346
input := &secretsmanager.GetSecretValueInput{
4447
SecretId: aws.String(path),
4548
}
4649

50+
re := regexp.MustCompile(`(?m)^(?:[^:]+:){3}([^:]+).*`)
51+
if re.MatchString(path) {
52+
parts := re.FindStringSubmatch(path)
53+
54+
opts = func(o *secretsmanager.Options) {
55+
o.Region = parts[1]
56+
}
57+
}
58+
4759
if version != "" {
4860
if version == AWS_CURRENT || version == AWS_PREVIOUS {
4961
input.VersionStage = aws.String(version)
@@ -53,7 +65,7 @@ func (a *AWSSecretsManager) GetSecrets(path string, version string, annotations
5365
}
5466

5567
utils.VerboseToStdErr("AWS Secrets Manager getting secret %s at version %s", path, version)
56-
result, err := a.Client.GetSecretValue(context.TODO(), input)
68+
result, err := a.Client.GetSecretValue(context.TODO(), input, opts)
5769
if err != nil {
5870
return nil, err
5971
}

0 commit comments

Comments
 (0)