Skip to content

Commit a49ace0

Browse files
committed
Restrict site access to OWID staff via Cloudflare Access
1 parent 57580cc commit a49ace0

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

.github/workflows/publish.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,53 @@ jobs:
9595
else
9696
echo "Record exists. Skipping."
9797
fi
98+
99+
- name: Restrict Access to OWID Staff
100+
env:
101+
CLOUDFLARE_API_TOKEN: ${{ secrets.WEBSITE_STARTER_CLOUDFLARE_API_TOKEN }}
102+
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
103+
DOMAIN: "${{ steps.meta.outputs.NAME }}.apps.owid.io"
104+
run: |
105+
# Check if an Access application already exists for this domain
106+
EXISTING_APP=$(curl -s -X GET \
107+
"https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/access/apps" \
108+
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
109+
-H "Content-Type: application/json" \
110+
| jq -r --arg domain "$DOMAIN" '.result[] | select(.domain == $domain) | .id')
111+
112+
if [ -n "$EXISTING_APP" ]; then
113+
echo "Access application already exists for $DOMAIN (ID: $EXISTING_APP). Skipping."
114+
exit 0
115+
fi
116+
117+
echo "Creating Access application for $DOMAIN..."
118+
APP_RESPONSE=$(curl -f -s -X POST \
119+
"https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/access/apps" \
120+
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
121+
-H "Content-Type: application/json" \
122+
--data "{
123+
\"name\": \"$DOMAIN\",
124+
\"domain\": \"$DOMAIN\",
125+
\"type\": \"self_hosted\",
126+
\"session_duration\": \"24h\"
127+
}")
128+
129+
APP_ID=$(echo "$APP_RESPONSE" | jq -r '.result.id')
130+
echo "Created Access application: $APP_ID"
131+
132+
echo "Adding policy to allow @ourworldindata.org emails..."
133+
curl -f -s -X POST \
134+
"https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/access/apps/$APP_ID/policies" \
135+
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
136+
-H "Content-Type: application/json" \
137+
--data "{
138+
\"name\": \"Allow OWID Staff\",
139+
\"decision\": \"allow\",
140+
\"include\": [{
141+
\"email_domain\": {
142+
\"domain\": \"ourworldindata.org\"
143+
}
144+
}]
145+
}"
146+
147+
echo "Access restriction enabled for $DOMAIN"

0 commit comments

Comments
 (0)