From cddf5752f32392c4b536a18305d66889a6861e5e Mon Sep 17 00:00:00 2001 From: Marcus Feltsen Date: Wed, 8 Nov 2023 18:45:58 +0100 Subject: [PATCH] Initial commit. Move to new repo to get fresh start. Starting on v1.0.0 --- .github/workflows/container.yaml | 59 ++++++++++++++++++++++++++++++++ Dockerfile | 12 +++++++ Makefile | 3 ++ README.md | 47 ++++++++++++++++++++++++- entrypoint.sh | 29 ++++++++++++++++ 5 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/container.yaml create mode 100644 Dockerfile create mode 100644 Makefile create mode 100755 entrypoint.sh diff --git a/.github/workflows/container.yaml b/.github/workflows/container.yaml new file mode 100644 index 0000000..a735308 --- /dev/null +++ b/.github/workflows/container.yaml @@ -0,0 +1,59 @@ +name: Create and publish a container image + +on: + push: + branches: [ "main" ] + # Publish semver tags as releases. + tags: [ 'v*.*.*' ] + pull_request: + branches: [ "main" ] + +env: + REGISTRY: ghcr.io + # github.repository as / + IMAGE_NAME: ${{ github.repository }} +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + # This is used to complete the identity challenge + # with sigstore/fulcio when running outside of PRs. + id-token: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + # Set up BuildKit Docker container builder to be able to build + # multi-platform images and export cache + # https://github.com/docker/setup-buildx-action + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0 + # Login against a Docker registry except on PR + # https://github.com/docker/login-action + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + # Extract metadata (tags, labels) for Docker + # https://github.com/docker/metadata-action + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + # Build and push Docker image with Buildx (don't push on PR) + # https://github.com/docker/build-push-action + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7e4d1f1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM ubuntu:jammy + +RUN apt update && apt install -y wget curl && apt clean + +ARG HELPER_VERSION=1.1.1 +RUN set -e \ + && curl -o /usr/bin/aws_signing_helper --fail https://rolesanywhere.amazonaws.com/releases/${HELPER_VERSION}/X86_64/Linux/aws_signing_helper \ + && chmod +x /usr/bin/aws_signing_helper + +COPY entrypoint.sh /entrypoint.sh + +ENTRYPOINT /entrypoint.sh diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1fd2c44 --- /dev/null +++ b/Makefile @@ -0,0 +1,3 @@ + +build: + @podman build --platform linux/amd64 . -t aws-signing-helper diff --git a/README.md b/README.md index 9a6c0e1..a962828 100644 --- a/README.md +++ b/README.md @@ -1 +1,46 @@ -# aws-signing-helper \ No newline at end of file +# aws-signing-helper + +Inspired by [josh23french/iam-roles-anywhere-sidecar](https://github.com/josh23french/iam-roles-anywhere-sidecar) + +Uses [aws/rolesanywhere-credential-helper](https://github.com/aws/rolesanywhere-credential-helper) cli instead of building a separate http server. + +## sidecar + +Add it to your own deployment as a sidecar. + +Example: + +```yaml +spec: + containers: + - env: + - name: PRIVATE_KEY + value: /certificates/MyService.key.pem + - name: CERTIFICATE + value: /certificates/MyService.crt.pem + - name: ROLE_ARN + value: arn:aws:iam::123456789012:role/MyRole + - name: PROFILE_ARN + value: arn:aws:rolesanywhere:eu-west-1:123456789012:profile/e7acdea9-3c21-42ab-affc-c448b69eee1b + - name: TRUST_ANCHOR_ARN + value: arn:aws:rolesanywhere:eu-west-1:123456789012:trust-anchor/ee461377-7abd-428f-bc04-ff99b7538920 + - name: DEBUG + value: "false" + image: ghcr.io/ehlomarcus/aws-signin-helper:v1.0.0 + imagePullPolicy: IfNotPresent + name: iam-helper + resources: + requests: + cpu: 100m + memory: 128Mi +``` + +Next you need to add this ENV to your application container. Using this ENV will allow your application (aws-sdk) to discover credentials. + +```yaml +spec: + containers: + - env: + - name: AWS_EC2_METADATA_SERVICE_ENDPOINT + value: http://localhost:8081/ +``` \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..3bf8d10 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +set -e + +if [ -z $PORT ] +then + PORT="8081" +fi + +if [ -z $SESSION_DURATION ] +then + SESSION_DURATION="3600" +fi + +if [ -z $REGION ] +then + REGION="eu-west-1" +fi + +if [ -z $ENDPOINT ] +then + ENDPOINT="rolesanywhere.eu-west-1.amazonaws.com" +fi + +if [ -z $DEBUG ] +then + DEBUG=false +fi + +aws_signing_helper serve --port $PORT --certificate $CERTIFICATE --private-key $PRIVATE_KEY --trust-anchor-arn $TRUST_ANCHOR_ARN --profile-arn $PROFILE_ARN --role-arn $ROLE_ARN --endpoint $ENDPOINT --region $REGION --debug $DEBUG