Skip to content

Commit

Permalink
Use OIDC to login to AWS
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacome committed Apr 11, 2023
1 parent 76a6ffe commit 4b70c87
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 22 deletions.
48 changes: 29 additions & 19 deletions .github/workflows/build-oss.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ defaults:
jobs:
build:
runs-on: ubuntu-22.04
permissions:
contents: read # for docker/build-push-action to read repo content
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
id-token: write # for OIDC login to AWS ECR
packages: write # for docker/build-push-action to push to GHCR
outputs:
version: ${{ steps.meta.outputs.version }}
image_digest: ${{ steps.build-push.outputs.digest }}
Expand Down Expand Up @@ -63,12 +68,17 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}
if: github.event_name != 'pull_request'

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@e1e17a757e536f70e52b5a12b2e8d1d1c60e04ef # v2.0.0
with:
aws-region: us-east-1
role-to-assume: ${{ secrets.AWS_ROLE_PUBLIC_ECR }}
if: github.event_name != 'pull_request'

- name: Login to Public ECR
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # v2.1.0
with:
registry: public.ecr.aws
username: ${{ secrets.AWS_ACCESS_KEY_ID }}
password: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
if: github.event_name != 'pull_request'

- name: Login to Quay.io
Expand Down Expand Up @@ -123,7 +133,7 @@ jobs:
id: build-push
with:
file: build/Dockerfile
context: '.'
context: "."
cache-from: type=gha,scope=${{ inputs.image }}
cache-to: type=gha,scope=${{ inputs.image }},mode=max
target: goreleaser
Expand All @@ -145,32 +155,32 @@ jobs:
continue-on-error: true
with:
image-ref: nginx/nginx-ingress:${{ steps.meta.outputs.version }}
format: 'sarif'
output: 'trivy-results-${{ inputs.image }}.sarif'
ignore-unfixed: 'true'
format: "sarif"
output: "trivy-results-${{ inputs.image }}.sarif"
ignore-unfixed: "true"

- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@d186a2a36cc67bfa1b860e6170d37fb9634742c7 # v2.2.11
continue-on-error: true
with:
sarif_file: 'trivy-results-${{ inputs.image }}.sarif'
sarif_file: "trivy-results-${{ inputs.image }}.sarif"

- name: Upload Scan Results
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
continue-on-error: true
with:
name: 'trivy-results-${{ inputs.image }}.sarif'
path: 'trivy-results-${{ inputs.image }}.sarif'
name: "trivy-results-${{ inputs.image }}.sarif"
path: "trivy-results-${{ inputs.image }}.sarif"
if: always()

send-notification:
name: Send Notification
needs: build
uses: ./.github/workflows/updates-notification.yml
with:
sha_long: ${{ inputs.sha_long }}
tag: ${{ inputs.tag }}
version: ${{ needs.build.outputs.version }}
image_digest: ${{ needs.build.outputs.image_digest }}
secrets: inherit
if: ${{ inputs.tag != '' }}
name: Send Notification
needs: build
uses: ./.github/workflows/updates-notification.yml
with:
sha_long: ${{ inputs.sha_long }}
tag: ${{ inputs.tag }}
version: ${{ needs.build.outputs.version }}
image_digest: ${{ needs.build.outputs.image_digest }}
secrets: inherit
if: ${{ inputs.tag != '' }}
12 changes: 9 additions & 3 deletions .github/workflows/build-plus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
permissions:
contents: read # for docker/build-push-action to read repo content
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
id-token: write # for OIDC login to AWS
runs-on: ubuntu-22.04
steps:
- name: Checkout Repository
Expand Down Expand Up @@ -58,13 +59,18 @@ jobs:
password: ${{ secrets.GCR_JSON_KEY }}
if: github.event_name != 'pull_request'

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@e1e17a757e536f70e52b5a12b2e8d1d1c60e04ef # v2.0.0
with:
aws-region: us-east-1
role-to-assume: ${{ secrets.AWS_ROLE_MARKETPLACE }}
if: startsWith(github.ref, 'refs/tags/') && contains(inputs.target, 'aws')

- name: Login to ECR
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # v2.1.0
with:
registry: 709825985650.dkr.ecr.us-east-1.amazonaws.com
username: ${{ secrets.AWS_ACCESS_KEY_ID }}
password: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
if: startsWith(github.ref, 'refs/tags/')
if: startsWith(github.ref, 'refs/tags/') && contains(inputs.target, 'aws')

- name: Docker meta
id: meta
Expand Down

0 comments on commit 4b70c87

Please sign in to comment.