Skip to content
Merged
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
14 changes: 11 additions & 3 deletions libs/go/sia/aws/lambda/lambda.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/AthenZ/athenz/libs/go/sia/util"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/credentials/stscreds"
"github.com/aws/aws-sdk-go-v2/service/acm"
acmtypes "github.com/aws/aws-sdk-go-v2/service/acm/types"
"github.com/aws/aws-sdk-go-v2/service/secretsmanager"
Expand Down Expand Up @@ -125,7 +126,7 @@ func getInternalAthenzIdentity(athenzDomain, athenzService, athenzProvider, ztsU
//
// The secret specified by the name must be pre-created
func StoreAthenzIdentityInSecretManager(athenzDomain, athenzService, secretName string, siaCertData *util.SiaCertData, isRoleCertificate bool) error {
return StoreAthenzIdentityInSecretManagerCustomFormat(athenzDomain, athenzService, secretName, siaCertData, nil, isRoleCertificate)
return StoreAthenzIdentityInSecretManagerCustomFormat(athenzDomain, athenzService, secretName, siaCertData, nil, isRoleCertificate, "")
}

// StoreAthenzIdentityInSecretManagerCustomFormat store the retrieved athenz identity in the
Expand All @@ -144,8 +145,10 @@ func StoreAthenzIdentityInSecretManager(athenzDomain, athenzService, secretName
//
// { "certPem":"<x509-cert-pem>, "keyPem":"<pkey-pem> }
//
// The secret specified by the name must be pre-created
func StoreAthenzIdentityInSecretManagerCustomFormat(athenzDomain, athenzService, secretName string, siaCertData *util.SiaCertData, jsonFieldMapper map[string]string, isRoleCertificate bool) error {
// The secret specified by the name must be pre-created. If the targetRoleArn is specified, the function
// will assume the role and use the temporary credentials to access the secret manager, otherwise it
// will use the default credentials from environment.
func StoreAthenzIdentityInSecretManagerCustomFormat(athenzDomain, athenzService, secretName string, siaCertData *util.SiaCertData, jsonFieldMapper map[string]string, isRoleCertificate bool, targetRoleArn string) error {
Comment thread
havetisyan marked this conversation as resolved.

var keyCertJson []byte
var err error
Expand All @@ -162,6 +165,11 @@ func StoreAthenzIdentityInSecretManagerCustomFormat(athenzDomain, athenzService,
if err != nil {
return err
}
if targetRoleArn != "" {
stsClient := sts.NewFromConfig(cfg)
provider := stscreds.NewAssumeRoleProvider(stsClient, targetRoleArn)
cfg.Credentials = aws.NewCredentialsCache(provider)
}
svc := secretsmanager.NewFromConfig(cfg)
input := &secretsmanager.PutSecretValueInput{
SecretId: aws.String(secretName),
Expand Down
Loading