Skip to content

Commit

Permalink
Merge pull request #6 from shinitiandrei/session-tokens
Browse files Browse the repository at this point in the history
update: adding session tokens for temporary credentials for AWS S3
  • Loading branch information
peter-evans authored May 9, 2022
2 parents e5ff6b5 + df86c38 commit 4f39c7d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM minio/mc:RELEASE.2020-10-03T02-54-56Z
FROM minio/mc:RELEASE.2022-05-04T06-07-55Z

LABEL maintainer="Peter Evans <[email protected]>"
LABEL repository="https://github.com/peter-evans/s3-backup"
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ The following variables may be passed to the action as secrets or environment va
- `ACCESS_KEY_ID` (**required**) - The storage service access key id.
- `SECRET_ACCESS_KEY` (**required**) - The storage service secret access key.
- `MIRROR_TARGET` (**required**) - The target bucket, and optionally, the key within the bucket.
- `AWS_SESSION_TOKEN` - When using temporary credentials (Amazon S3)
- `AWS_REGION` (required with AWS_SESSION_TOKEN) - the region where the s3 bucket is located for Amazon S3. **Mandatory** when using SESSION_TOKEN.
- `MIRROR_SOURCE` - The source defaults to the repository root. If required a path relative to the root can be set.
- `STORAGE_SERVICE_URL` - The URL to the object storage service. Defaults to `https://s3.amazonaws.com` for Amazon S3.
- `STORAGE_SERVICE_ALIAS` - Defaults to `s3`. See [MinIO Client](https://github.com/minio/mc) for other options such as S3 compatible `minio`, and `gcs` for Google Cloud Storage.
Expand Down
8 changes: 7 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ set -euo pipefail

STORAGE_SERVICE_ALIAS=${STORAGE_SERVICE_ALIAS:="s3"}
STORAGE_SERVICE_URL=${STORAGE_SERVICE_URL:="https://s3.amazonaws.com"}
AWS_SESSION_TOKEN=${AWS_SESSION_TOKEN:=""}
MIRROR_SOURCE=${MIRROR_SOURCE:="."}
AWS_REGION=${AWS_REGION:=""}

# Set mc configuration
mc alias set "$STORAGE_SERVICE_ALIAS" "$STORAGE_SERVICE_URL" "$ACCESS_KEY_ID" "$SECRET_ACCESS_KEY"
if [ -z "$AWS_SESSION_TOKEN" ]; then
mc alias set "$STORAGE_SERVICE_ALIAS" "$STORAGE_SERVICE_URL" "$ACCESS_KEY_ID" "$SECRET_ACCESS_KEY"
else
export MC_HOST_${STORAGE_SERVICE_ALIAS}=https://${ACCESS_KEY_ID}:${SECRET_ACCESS_KEY}:${AWS_SESSION_TOKEN}@s3.${AWS_REGION}.amazonaws.com
fi

# Execute mc mirror
mc mirror $* "$MIRROR_SOURCE" "$STORAGE_SERVICE_ALIAS/$MIRROR_TARGET"

0 comments on commit 4f39c7d

Please sign in to comment.