Skip to content

Commit 9bb0a73

Browse files
github: Use IAM Roles to push files on AWS S3
For security reasons long lived credentials are not considered secure. To overcome this issue we can configure Github Workflows to use AWS OpenID Connect instead: For further details: https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect
1 parent d3d2d59 commit 9bb0a73

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

Diff for: .github/workflows/publish-go-nightly-task.yml

+12-9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ env:
88
DIST_DIR: dist
99
# The project's folder on Arduino's download server for uploading builds
1010
AWS_PLUGIN_TARGET: /arduino-lint/
11+
AWS_REGION: "us-east-1"
1112
ARTIFACT_PREFIX: dist-
1213

1314
# See: https://docs.github.com/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows
@@ -183,8 +184,10 @@ jobs:
183184

184185
publish-nightly:
185186
runs-on: ubuntu-latest
187+
environment: production
186188
needs: notarize-macos
187-
permissions: {}
189+
permissions:
190+
id-token: write # This is required for requesting the JWT
188191

189192
steps:
190193
- name: Download artifact
@@ -200,15 +203,15 @@ jobs:
200203
TAG="nightly-$(date -u +"%Y%m%d")"
201204
sha256sum ${{ env.PROJECT_NAME }}_${TAG}* > ${TAG}-checksums.txt
202205
206+
- name: configure aws credentials
207+
uses: aws-actions/configure-aws-credentials@v4
208+
with:
209+
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
210+
role-session-name: "github_${{ env.PROJECT_NAME }}"
211+
aws-region: ${{ env.AWS_REGION }}
212+
203213
- name: Upload release files on Arduino downloads servers
204-
uses: docker://plugins/s3
205-
env:
206-
PLUGIN_SOURCE: "${{ env.DIST_DIR }}/*"
207-
PLUGIN_TARGET: "${{ env.AWS_PLUGIN_TARGET }}nightly"
208-
PLUGIN_STRIP_PREFIX: "${{ env.DIST_DIR }}/"
209-
PLUGIN_BUCKET: ${{ secrets.DOWNLOADS_BUCKET }}
210-
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
211-
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
214+
run: aws s3 sync ${{ env.DIST_DIR }} s3://${{ secrets.DOWNLOADS_BUCKET }}${{ env.AWS_PLUGIN_TARGET }}nightly
212215

213216
report:
214217
runs-on: ubuntu-latest

Diff for: .github/workflows/release-go-task.yml

+11-8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ env:
88
DIST_DIR: dist
99
# The project's folder on Arduino's download server for uploading builds
1010
AWS_PLUGIN_TARGET: /arduino-lint/
11+
AWS_REGION: "us-east-1"
1112
ARTIFACT_PREFIX: dist-
1213

1314
on:
@@ -189,9 +190,11 @@ jobs:
189190

190191
create-release:
191192
runs-on: ubuntu-latest
193+
environment: production
192194
needs: notarize-macos
193195
permissions:
194196
contents: write
197+
id-token: write # This is required for requesting the JWT
195198

196199
steps:
197200
- name: Download artifact
@@ -235,12 +238,12 @@ jobs:
235238
# (all the files we need are in the DIST_DIR root)
236239
artifacts: ${{ env.DIST_DIR }}/*
237240

241+
- name: configure aws credentials
242+
uses: aws-actions/configure-aws-credentials@v4
243+
with:
244+
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
245+
role-session-name: "github_${{ env.PROJECT_NAME }}"
246+
aws-region: ${{ env.AWS_REGION }}
247+
238248
- name: Upload release files on Arduino downloads servers
239-
uses: docker://plugins/s3
240-
env:
241-
PLUGIN_SOURCE: "${{ env.DIST_DIR }}/*"
242-
PLUGIN_TARGET: ${{ env.AWS_PLUGIN_TARGET }}
243-
PLUGIN_STRIP_PREFIX: "${{ env.DIST_DIR }}/"
244-
PLUGIN_BUCKET: ${{ secrets.DOWNLOADS_BUCKET }}
245-
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
246-
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
249+
run: aws s3 sync ${{ env.DIST_DIR }} s3://${{ secrets.DOWNLOADS_BUCKET }}${{ env.AWS_PLUGIN_TARGET }}

0 commit comments

Comments
 (0)