Best practice for handling credential switching within Concourse tasks (cross-account AWS example) #9351
-
|
Context: Current Approach (Task-Based): - task: copy-backup
params:
source_bucket: account-a-backups
dest_bucket: account-b-backups
target_role_arn: arn:aws:iam::111222333444:role/worker-role
config:
run:
path: bash
args:
- -c
- |
# Download with Account A creds
aws s3 cp s3://${source_bucket}/backup /tmp/backup --recursive
# Assume Account B role
creds=$(aws sts assume-role --role-arn "${target_role_arn}" ...)
export AWS_ACCESS_KEY_ID=$(...)
# Upload with Account B creds
aws s3 cp /tmp/backup s3://${dest_bucket}/backup --recursiveAlternative Approach (Resource-Based): resources:
- name: source-backup
type: s3 # or s3-dir
source:
aws_assume_role_arn: arn:aws:iam::999888777666:role/worker-role-a
bucket: account-a-backups
bucket_region: us-east-1
- name: dest-backup
type: s3
source:
aws_assume_role_arn: arn:aws:iam::111222333444:role/worker-role-b
bucket: account-b-backups
bucket_region: us-east-1
jobs:
- name: copy-backup
plan:
- get: source-backup
- put: dest-backup
params:
file: source-backup/*Question: Should we refactor to use the resource-based approach? Pros I see:
Cons I see:
Specific Challenges:
- task: get-latest-backup
outputs: [backup-info]
- load_var: backup-folder
file: backup-info/folder-name.txtCan we use
- task: invoke-lambda-backup
# Backup doesn't exist yet...
- get: source-backup # Will this fail/retry automatically?
- put: dest-backup
params:
file: source-backup/*
sse: aws:kms
sse_kms_key_id: arn:aws:kms:us-east-1:111222333444:key/abc-123Does the S3 resource support this?
SOURCE_COUNT=$(aws s3 ls s3://source/backup/ --recursive | wc -l)
DEST_COUNT=$(aws s3 ls s3://dest/backup/ --recursive | wc -l)How would we do this with resources? Is there a hybrid approach? Maybe use resources for the actual copy, but tasks for orchestration: - task: invoke-lambda-backup
- task: wait-for-backup-ready
# Polls until backup exists
- get: source-backup
passed: [wait-for-backup-ready]
- put: dest-backup
- task: verify-file-countsWhat's the recommended pattern for:
Environment:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Hi Tobi! Hope you're doing well 😊 This whole thing looks LLM generated. I think you guys made this after I left, but what the LLM is suggesting would work and is how I would have tried to write it. You can read the S3 resource's docs here: https://github.com/concourse/s3-resource The latest version of the s3-resource does support using the IAM role on the worker. You need to either:
resource_types:
- name: s3
type: registry-image
source:
repository: concourse/s3-resource
tag: 2.4.0The version of Concourse you are on, 7.11.2, comes with v1.3.0 of the S3 resource: https://github.com/concourse/concourse/releases/tag/v7.11.2 |
Beta Was this translation helpful? Give feedback.
Hi Tobi! Hope you're doing well 😊
This whole thing looks LLM generated. I think you guys made this after I left, but what the LLM is suggesting would work and is how I would have tried to write it. You can read the S3 resource's docs here: https://github.com/concourse/s3-resource
The latest version of the s3-resource does support using the IAM role on the worker. You need to either:
Add this to your pipeline:
resource_…