Skip to content

Commit 7833a26

Browse files
authored
Limit GLB to allowed IPs, automatically update if needed (#54242)
1 parent 12d6749 commit 7833a26

File tree

4 files changed

+63
-7
lines changed

4 files changed

+63
-7
lines changed

.github/workflows/alert-changed-branch-protections.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
branch_protection_rule:
55
workflow_dispatch:
66
schedule:
7-
- cron: '20 16 * * 3' # Run every Wednesday at 16:30 UTC / 8:30 PST
7+
- cron: '20 16 * * 3' # Run every Wednesday at 16:20 UTC / 8:20 PST
88

99
permissions:
1010
contents: read
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Update Moda allowed IPs
2+
3+
# **What it does**: Make sure that the allowed IPs in Moda are up to date.
4+
# **Why we have it**: The IP ranges from Fastly can change.
5+
# **Who does it impact**: Docs engineering.
6+
7+
on:
8+
schedule:
9+
- cron: '20 16 * * 4' # Run every Thursday at 16:20 UTC / 8:20 PST
10+
workflow_dispatch:
11+
12+
permissions:
13+
contents: write
14+
pull-requests: write
15+
16+
jobs:
17+
update-moda-allowed-ips:
18+
if: github.repository == 'github/docs-internal'
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Check out the repository
22+
uses: actions/checkout@v4
23+
24+
- name: Update list of allowed IPs
25+
run: |
26+
echo "Getting a list of Fastly IP addresses...."
27+
ips=$( \
28+
curl -s https://api.fastly.com/public-ip-list \
29+
| jq -r '.addresses | join(",")' \
30+
)
31+
echo "Got a list of Fastly IP addresses: $ips"
32+
33+
echo "Updating the list of allowed IPs in Moda config..."
34+
yq -i ".metadata.annotations[\"moda.github.net/allowed-ips\"] = \"$ips\"" \
35+
config/kubernetes/production/services/webapp.yaml
36+
echo "Updated the list of allowed IPs in Moda config"
37+
38+
echo "Checking if there is a change to make..."
39+
if git diff --quiet; then
40+
echo "No changes to the allowed IPs"
41+
exit 0
42+
fi
43+
44+
echo "Change found; making a pull request..."
45+
branchname=update-allowed-ips-$(date +%s)
46+
git checkout -b $branchname
47+
git commit -am "Update list of allowed IPs"
48+
git push
49+
gh pr create \
50+
--title "Update list of allowed IPs" \
51+
--body 'This PR updates the list of allowed IPs in Moda. It is automatically generated.' \
52+
--head=$branchname
53+
echo "Pull request created"
54+
55+
- uses: ./.github/actions/slack-alert
56+
if: ${{ failure() }}
57+
with:
58+
slack_channel_id: ${{ secrets.DOCS_ALERTS_SLACK_CHANNEL_ID }}
59+
slack_token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }}

config/kubernetes/production/services/webapp.yaml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@ metadata:
77
annotations:
88
moda.github.net/domain-name: 'docs-internal.github.com'
99
moda.github.net/dns-registration-enabled: 'false'
10-
moda.github.net/load-balancer-type:
11-
public-external-http
12-
# moda.github.net/allowed-ips: '23.235.32.0/20,43.249.72.0/22,103.244.50.0/24,103.245.222.0/23,103.245.224.0/24,104.156.80.0/20,140.248.64.0/18,140.248.128.0/17,146.75.0.0/17,151.101.0.0/16,157.52.64.0/18,167.82.0.0/17,167.82.128.0/20,167.82.160.0/20,167.82.224.0/20,172.111.64.0/18,185.31.16.0/22,199.27.72.0/21,199.232.0.0/1'
13-
# ipv6 addresses not included
14-
# curl -i "https://api.fastly.com/public-ip-list"
10+
moda.github.net/load-balancer-type: public-external-http
11+
moda.github.net/allowed-ips: 23.235.32.0/20,43.249.72.0/22,103.244.50.0/24,103.245.222.0/23,103.245.224.0/24,104.156.80.0/20,140.248.64.0/18,140.248.128.0/17,146.75.0.0/17,151.101.0.0/16,157.52.64.0/18,167.82.0.0/17,167.82.128.0/20,167.82.160.0/20,167.82.224.0/20,172.111.64.0/18,185.31.16.0/22,199.27.72.0/21,199.232.0.0/16
1512
spec:
1613
ports:
1714
- name: http

src/workflows/tests/actions-workflows.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { chain, get } from 'lodash-es'
1010
const githubOwnedActionsRegex =
1111
/^(actions\/(cache|checkout|download-artifact|upload-artifact)@v\d+(\.\d+)*)$/
1212
const actionHashRegexp = /^[A-Za-z0-9-/]+@[0-9a-f]{40}$/
13-
const checkoutRegexp = /^[actions/checkout]+@[0-9a-f]{40}$/
13+
const checkoutRegexp = /^[actions/checkout]+@(v\d+(\.\d+)*|[0-9a-f]{40})$/
1414
const permissionsRegexp = /(read|write)/
1515

1616
type WorkflowMeta = {

0 commit comments

Comments
 (0)