Skip to content

Commit 0f5814e

Browse files
authored
Merge pull request #39 from linuxfoundation/jme/LFXV2-1094
support cross-account role assumption in dynamodb-stream-consumer
2 parents a22eaca + ff2a1d4 commit 0f5814e

File tree

5 files changed

+26
-9
lines changed

5 files changed

+26
-9
lines changed

charts/lfx-v1-sync-helper/values.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,10 @@ dynamodbStreamConsumer:
239239
# AWS_REGION is the AWS region for DynamoDB
240240
AWS_REGION:
241241
value: us-west-2
242+
# AWS_ASSUME_ROLE_ARN is an optional IAM role ARN to assume via STS for cross-account
243+
# DynamoDB access. Example: "arn:aws:iam::123456789012:role/dynamodb-streams-reader"
244+
AWS_ASSUME_ROLE_ARN:
245+
value: ""
242246
# DYNAMODB_TABLES is a comma-separated list of DynamoDB table names to consume.
243247
# Defaults to the full set of tables used by the tap-dynamodb Meltano extractor.
244248
DYNAMODB_TABLES:

cmd/dynamodb-stream-consumer/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ All configuration is via environment variables.
122122
|---|---|---|
123123
| `DYNAMODB_TABLES` | *(required)* | Comma-separated list of DynamoDB table names |
124124
| `AWS_REGION` | `us-west-2` | AWS region |
125+
| `AWS_ASSUME_ROLE_ARN` | *(unset)* | IAM role ARN to assume via STS for cross-account DynamoDB access |
125126
| `NATS_URL` | `nats://localhost:4222` | NATS server URL |
126127
| `NATS_STREAM_NAME` | `dynamodb_streams` | JetStream stream name |
127128
| `NATS_SUBJECT_PREFIX` | `dynamodb_streams` | Subject prefix |
@@ -133,8 +134,9 @@ All configuration is via environment variables.
133134
| `BIND` | `*` | Interface to bind the health check server on |
134135
| `DEBUG` | `false` | Enable debug logging |
135136

136-
AWS credentials are resolved via the standard AWS credential chain (environment
137-
variables, `~/.aws/credentials`, EC2/ECS instance profile, etc.).
137+
AWS credentials are resolved via the standard AWS credential chain. When
138+
`AWS_ASSUME_ROLE_ARN` is set, those credentials are used to assume the specified
139+
role via STS, enabling cross-account DynamoDB access.
138140

139141
## Health checks
140142

cmd/dynamodb-stream-consumer/config.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ type Config struct {
2626
CheckpointBucket string
2727

2828
// AWS configuration
29-
AWSRegion string
29+
AWSRegion string
30+
AssumeRoleARN string // Optional: IAM role ARN to assume via STS for cross-account access
3031

3132
// DynamoDB tables to consume (comma-separated)
3233
Tables []string
@@ -76,6 +77,7 @@ func LoadConfig() (*Config, error) {
7677
NATSSubjectPrefix: os.Getenv("NATS_SUBJECT_PREFIX"),
7778
CheckpointBucket: os.Getenv("CHECKPOINT_BUCKET"),
7879
AWSRegion: os.Getenv("AWS_REGION"),
80+
AssumeRoleARN: os.Getenv("AWS_ASSUME_ROLE_ARN"),
7981
Tables: tables,
8082
StartFromLatest: parseBooleanEnv("START_FROM_LATEST"),
8183
PollInterval: time.Duration(pollIntervalMS) * time.Millisecond,

cmd/dynamodb-stream-consumer/main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ import (
4141
"time"
4242

4343
awsconfig "github.com/aws/aws-sdk-go-v2/config"
44+
"github.com/aws/aws-sdk-go-v2/credentials/stscreds"
4445
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
4546
"github.com/aws/aws-sdk-go-v2/service/dynamodbstreams"
47+
"github.com/aws/aws-sdk-go-v2/service/sts"
4648
nats "github.com/nats-io/nats.go"
4749
"github.com/nats-io/nats.go/jetstream"
4850
)
@@ -183,6 +185,13 @@ func main() {
183185
os.Exit(1)
184186
}
185187

188+
// If a role ARN is configured, assume it via STS for cross-account DynamoDB access.
189+
if cfg.AssumeRoleARN != "" {
190+
logger.With("role_arn", cfg.AssumeRoleARN).Info("assuming IAM role for DynamoDB access")
191+
stsClient := sts.NewFromConfig(awsCfg)
192+
awsCfg.Credentials = stscreds.NewAssumeRoleProvider(stsClient, cfg.AssumeRoleARN)
193+
}
194+
186195
dynClient := dynamodb.NewFromConfig(awsCfg)
187196
streamsClient := dynamodbstreams.NewFromConfig(awsCfg)
188197

go.mod

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ go 1.25.6
77
require (
88
github.com/akamensky/base58 v0.0.0-20210829145138-ce8bf8802e8f
99
github.com/auth0/go-auth0 v1.32.1
10+
github.com/aws/aws-sdk-go-v2 v1.41.1
11+
github.com/aws/aws-sdk-go-v2/config v1.32.9
12+
github.com/aws/aws-sdk-go-v2/credentials v1.19.9
13+
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.55.0
14+
github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.32.10
15+
github.com/aws/aws-sdk-go-v2/service/sts v1.41.6
1016
github.com/golang-jwt/jwt/v5 v5.3.0
1117
github.com/google/uuid v1.6.0
1218
github.com/linuxfoundation/lfx-v2-committee-service v0.2.19
@@ -22,22 +28,16 @@ require (
2228

2329
require (
2430
github.com/PuerkitoBio/rehttp v1.4.0 // indirect
25-
github.com/aws/aws-sdk-go-v2 v1.41.1 // indirect
26-
github.com/aws/aws-sdk-go-v2/config v1.32.9 // indirect
27-
github.com/aws/aws-sdk-go-v2/credentials v1.19.9 // indirect
2831
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.17 // indirect
2932
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.17 // indirect
3033
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.17 // indirect
3134
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4 // indirect
32-
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.55.0 // indirect
33-
github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.32.10 // indirect
3435
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.4 // indirect
3536
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.11.17 // indirect
3637
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.17 // indirect
3738
github.com/aws/aws-sdk-go-v2/service/signin v1.0.5 // indirect
3839
github.com/aws/aws-sdk-go-v2/service/sso v1.30.10 // indirect
3940
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.14 // indirect
40-
github.com/aws/aws-sdk-go-v2/service/sts v1.41.6 // indirect
4141
github.com/aws/smithy-go v1.24.0 // indirect
4242
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
4343
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 // indirect

0 commit comments

Comments
 (0)