Skip to content

Instantly share code, notes, and snippets.

@craigmdennis
Created September 26, 2023 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save craigmdennis/f75deadeedc2626eea79e2d003bd974a to your computer and use it in GitHub Desktop.
Save craigmdennis/f75deadeedc2626eea79e2d003bd974a to your computer and use it in GitHub Desktop.
Update Cloudflare Access Group IP address based on current public IP address from the requestor
ACCOUNT_ID="YOUR_ACCOUNT_ID"
GROUP_ID="YOUR_ACCESS_GROUP_ID"
GROUP_NAME="YOUR_ACCESS_GROUP_NAME"
API_TOKEN="YOUR_CLOUDFLARE_API_KEY"
IP_ADDRESS=$(curl -s https://api.ipify.org)
curl --request PUT \
--url https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/access/groups/$GROUP_ID \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $API_TOKEN" \
--data '{
"include": [
{
"ip": {
"ip": "'"$IP_ADDRESS"'"
}
}
],
"name": "$GROUP_NAME"
}'
echo "Updated $GROUP_NAME to include $IP_ADDRESS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment