Skip to content

Instantly share code, notes, and snippets.

@ralvares
Created February 6, 2023 13:17
Show Gist options
  • Save ralvares/1acb6c60c07db3b002bce6a44a477eaf to your computer and use it in GitHub Desktop.
Save ralvares/1acb6c60c07db3b002bce6a44a477eaf to your computer and use it in GitHub Desktop.
Disable all the default policies from RHACS
#!/bin/bash
if [[ -z "${ROX_ENDPOINT}" ]]; then
echo >&2 "ROX_ENDPOINT must be set"
exit 1
fi
if [[ -z "${ROX_API_TOKEN}" ]]; then
echo >&2 "ROX_API_TOKEN must be set"
exit 1
fi
ids=$(curl -k -s \
-X GET \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${ROX_API_TOKEN}" \
https://$ROX_ENDPOINT/v1/policies | jq '.policies[] | select(.disabled==false) | select(.isDefault==true)' | jq -r '.id')
for id in $(echo $ids)
do
echo "Disabling default policy ID" $id
echo '{"id": "$id","disabled": true}' | envsubst > /tmp/patch_template.json
_RETURN=$(curl -k -o /dev/null -i -sL --post302 -w "%{http_code}" \
-X PATCH \
--header "Content-Type: application/json" \
-H "Authorization: Bearer ${ROX_API_TOKEN}" \
-d @/tmp/patch_template.json \
https://$ROX_ENDPOINT/v1/policies/$id)
if [ $_RETURN == "200" ] ;
then
echo "Disabling default policy ID" $id
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment