Skip to content

feat: use region if path is full arn #487

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 3 commits into from
Jun 18, 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
4 changes: 4 additions & 0 deletions docs/backends.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ documentation](https://aws.github.io/aws-sdk-go-v2/docs/configuring-sdk/#specify
supplying AWS credentials. Supported credentials and the order in which they are loaded are
described [here](https://aws.github.io/aws-sdk-go-v2/docs/configuring-sdk/#specifying-credentials).

**Note About Region**
If you provide the full AWS ARN as the secret path, ex. `arn:aws:secretsmanager:us-east-1:123123123:secret:some-secret`,
the region from the ARN (us-east-1) in this example, will take precedents over the AWS_REGION environment variable listed below.

These are the parameters for AWS:
```
AVP_TYPE: awssecretsmanager
Expand Down
14 changes: 13 additions & 1 deletion pkg/backends/awssecretsmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"regexp"

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

// GetSecrets gets secrets from aws secrets manager and returns the formatted data
func (a *AWSSecretsManager) GetSecrets(path string, version string, annotations map[string]string) (map[string]interface{}, error) {
var opts = func(o *secretsmanager.Options) {}

input := &secretsmanager.GetSecretValueInput{
SecretId: aws.String(path),
}

re := regexp.MustCompile(`(?m)^(?:[^:]+:){3}([^:]+).*`)
if re.MatchString(path) {
parts := re.FindStringSubmatch(path)

opts = func(o *secretsmanager.Options) {
o.Region = parts[1]
}
}

if version != "" {
if version == AWS_CURRENT || version == AWS_PREVIOUS {
input.VersionStage = aws.String(version)
Expand All @@ -53,7 +65,7 @@ func (a *AWSSecretsManager) GetSecrets(path string, version string, annotations
}

utils.VerboseToStdErr("AWS Secrets Manager getting secret %s at version %s", path, version)
result, err := a.Client.GetSecretValue(context.TODO(), input)
result, err := a.Client.GetSecretValue(context.TODO(), input, opts)
if err != nil {
return nil, err
}
Expand Down