Skip to content

Commit 8b84752

Browse files
authored
Merge pull request #294 from OvertureMaps/306-devops-create-omf-ruleset-for-all-public-repos
[SECURITY] Harden GitHub workflows
2 parents 1c9ed10 + 820f97a commit 8b84752

3 files changed

Lines changed: 69 additions & 23 deletions

File tree

.github/dependabot.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ updates:
1313
commit-message:
1414
prefix: "[CHORE](deps)"
1515
include: "scope"
16+
cooldown:
17+
default-days: 7

.github/workflows/deploy-gh-pages.yml

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
---
2-
# This workflow builds and deploys to GitHub Pages
2+
# Production Deployment Workflow
3+
#
4+
# Triggered on: push to main
5+
# Jobs:
6+
# - build: Installs dependencies, runs tests, builds the site, and uploads a Pages artifact
7+
# - deploy: Deploys the artifact to GitHub Pages via OIDC
38

49
name: Production Deployment
510
run-name: Publish prod site
@@ -10,8 +15,6 @@ on:
1015

1116
permissions:
1217
contents: read # required to checkout the code from the repo
13-
pages: write # required to deploy to GitHub Pages
14-
id-token: write # required to use OIDC authentication
1518

1619
concurrency:
1720
group: "pages"
@@ -21,13 +24,17 @@ jobs:
2124
build:
2225
name: Build
2326
runs-on: ubuntu-latest
27+
permissions:
28+
contents: read
2429

2530
steps:
2631
- name: Checkout
27-
uses: actions/checkout@v6
32+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
33+
with:
34+
persist-credentials: false
2835

2936
- name: Set up Node.js
30-
uses: actions/setup-node@v6
37+
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
3138
with:
3239
node-version-file: package.json
3340

@@ -46,22 +53,25 @@ jobs:
4653
run: npm run build
4754

4855
- name: Setup Pages
49-
uses: actions/configure-pages@v6
56+
uses: actions/configure-pages@45bfe0192ca1faeb007ade9deae92b16b8254a0d # v6.0.0
5057

5158
- name: Upload artifact
52-
uses: actions/upload-pages-artifact@v4
59+
uses: actions/upload-pages-artifact@7b1f4a764d45c48632c6b24a0339c27f5614fb0b # v4.0.0
5360
with:
5461
path: out
5562

5663
deploy:
5764
name: Deploy to GitHub Pages
5865
runs-on: ubuntu-slim
5966
needs: build
67+
permissions:
68+
pages: write # required to deploy to GitHub Pages
69+
id-token: write # required to use OIDC authentication
6070
environment:
6171
name: github-pages
6272
url: ${{ steps.deployment.outputs.page_url }}
6373

6474
steps:
6575
- name: Deploy to GitHub Pages
6676
id: deployment
67-
uses: actions/deploy-pages@v5
77+
uses: actions/deploy-pages@cd2ce8fcbc39b97be8ca5fce6e763baed58fa128 # v5.0.0

.github/workflows/deploy-staging.yml

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
---
2-
# This workflow will do a clean install of node dependencies and deploy to AWS.
2+
# Staging Deploy Workflow
3+
#
4+
# Triggered on: pull requests targeting main
5+
# Jobs:
6+
# - test: Lints and runs unit tests
7+
# - build: Builds the site with a PR-specific base URL and uploads artifacts
8+
# - a11y: Runs accessibility tests against the root build
9+
# - deploy: Syncs build to S3, invalidates CloudFront cache, and comments the staging URL on the PR
310

411
name: Staging Deploy
512
run-name: Publish staging site
@@ -9,21 +16,27 @@ on:
916
branches: [ main ]
1017

1118
permissions:
12-
id-token: write # required to use OIDC authentication
1319
contents: read # required to checkout the code from the repo
14-
pull-requests: write # required to comment on the PR with the staging URL
20+
21+
concurrency:
22+
group: staging-${{ github.event.pull_request.number }}
23+
cancel-in-progress: true
1524

1625
jobs:
1726
test:
1827
name: Test
1928
runs-on: ubuntu-latest
29+
permissions:
30+
contents: read
2031

2132
steps:
2233
- name: Checkout
23-
uses: actions/checkout@v6
34+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
35+
with:
36+
persist-credentials: false
2437

2538
- name: Set up Node.js
26-
uses: actions/setup-node@v6
39+
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
2740
with:
2841
node-version-file: package.json
2942

@@ -42,13 +55,17 @@ jobs:
4255
build:
4356
name: Build
4457
runs-on: ubuntu-latest
58+
permissions:
59+
contents: read
4560

4661
steps:
4762
- name: Checkout
48-
uses: actions/checkout@v6
63+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
64+
with:
65+
persist-credentials: false
4966

5067
- name: Set up Node.js
51-
uses: actions/setup-node@v6
68+
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
5269
with:
5370
node-version-file: package.json
5471

@@ -67,7 +84,7 @@ jobs:
6784
BASEURL: ${{ github.event.repository.name }}/pr/${{ github.event.number }}
6885

6986
- name: Upload artifacts
70-
uses: actions/upload-artifact@v7
87+
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
7188
with:
7289
name: build-artifact
7390
path: out
@@ -76,15 +93,19 @@ jobs:
7693
a11y:
7794
name: Accessibility
7895
runs-on: ubuntu-latest
96+
permissions:
97+
contents: read
7998
# No basePath — built at root so the local test server can resolve assets
8099
# The deployment build (with BASEURL) is tested separately via the build job
81100

82101
steps:
83102
- name: Checkout
84-
uses: actions/checkout@v6
103+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
104+
with:
105+
persist-credentials: false
85106

86107
- name: Set up Node.js
87-
uses: actions/setup-node@v6
108+
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
88109
with:
89110
node-version-file: package.json
90111

@@ -107,33 +128,46 @@ jobs:
107128
name: Deploy
108129
runs-on: ubuntu-slim
109130
needs: [test, build, a11y]
131+
permissions:
132+
id-token: write # required to use OIDC authentication
133+
contents: read
134+
pull-requests: write # required to comment on the PR with the staging URL
110135
environment:
111136
name: staging
112137
url: ${{ steps.deploy_url.outputs.url }}
113138

114139
steps:
115140
- name: Set deploy URL
116141
id: deploy_url
117-
run: echo "url=https://staging.overturemaps.org/${{ github.event.repository.name }}/pr/${{ github.event.number }}/index.html" >> $GITHUB_OUTPUT
142+
run: echo "url=https://staging.overturemaps.org/${GITHUB_EVENT_REPOSITORY_NAME}/pr/${PR_NUMBER}/index.html" >> $GITHUB_OUTPUT
143+
env:
144+
GITHUB_EVENT_REPOSITORY_NAME: ${{ github.event.repository.name }}
145+
PR_NUMBER: ${{ github.event.number }}
118146

119147
- name: Configure AWS credentials
120-
uses: aws-actions/configure-aws-credentials@v6
148+
uses: aws-actions/configure-aws-credentials@ec61189d14ec14c8efccab744f656cffd0e33f37 # v6.1.0
121149
with:
122150
role-to-assume: arn:aws:iam::763944545891:role/pages-staging-oidc-overturemaps
123151
aws-region: us-west-2
124152

125153
- name: Download artifacts
126-
uses: actions/download-artifact@v8
154+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
127155
with:
128156
name: build-artifact
129157
path: build
130158

131159
- name: Copy to S3
132160
run: |
133-
aws s3 sync --delete build s3://overture-managed-staging-usw2/gh-pages/${{ github.event.repository.name }}/pr/${{ github.event.number }}/
161+
aws s3 sync --delete build s3://overture-managed-staging-usw2/gh-pages/${GITHUB_EVENT_REPOSITORY_NAME}/pr/${PR_NUMBER}/
162+
env:
163+
GITHUB_EVENT_REPOSITORY_NAME: ${{ github.event.repository.name }}
164+
PR_NUMBER: ${{ github.event.number }}
134165

135166
- name: Bust the Cache
136-
run: aws cloudfront create-invalidation --distribution-id E1KP2IN0H2RGGT --paths "/${{ github.event.repository.name }}/pr/${{ github.event.number }}/*"
167+
run: aws cloudfront create-invalidation --distribution-id E1KP2IN0H2RGGT --paths "/${GITHUB_EVENT_REPOSITORY_NAME}/pr/${PR_NUMBER}/*"
168+
env:
169+
GITHUB_EVENT_REPOSITORY_NAME: ${{ github.event.repository.name }}
170+
PR_NUMBER: ${{ github.event.number }}
137171

138172
- name: Get deploy timestamp
139173
id: timestamp

0 commit comments

Comments
 (0)