Guardrails: SCPs, Azure Policy and Organization Policy
Permissions say what a person may do. Guardrails say what nobody may do, whatever their permissions: "no resources outside the EU", "no public storage buckets", "no service account keys". All three clouds have them, attached high in the hierarchy and inherited down. They differ in what they check and in how levels combine, and that second difference changes how you design them.
On AWS this is… service control policies (SCPs) and resource control policies (RCPs) on OUs and accounts, plus AWS Config rules for detection. See the SCP row in IAM Policies and CloudTrail and AWS Config.
Side by side
| AWS SCPs | Azure Policy | Google Cloud Organization Policy | |
|---|---|---|---|
| Checks | API actions a principal may call | resource properties on create/update (and existing resources) | constraints: named, service-defined rules ("restrict resource locations"), plus custom constraints |
| Attached to | root, OUs, accounts | management groups, subscriptions, resource groups | organization, folders, projects |
| Effects | deny (an action not allowed at every level is denied) | deny, audit, modify, append, deployIfNotExists, auditIfNotExists, denyAction, disabled … |
enforce (boolean constraint), allow/deny lists (list constraint), custom CEL conditions |
| Existing resources | not affected | evaluated and reported as non-compliant; deployIfNotExists/modify can remediate |
generally not changed; enforced on new operations |
| Exceptions | restructure OUs or edit the SCP | exemptions at a scope | set a different policy lower in the tree (if allowed) |
| Dry run | none built in (test in a sandbox OU) | audit effect, or enforcement mode DoNotEnforce |
dry-run policies |
Azure Policy also detects and fixes, which on AWS is AWS Config's job: one policy can deny new public storage accounts and report the old ones and deploy diagnostic settings to every VM that lacks them.
How levels combine
- AWS SCPs: an action is possible only if an SCP allows it at every level from root to account, and no SCP denies it. Lower levels can only restrict further.
- Azure Policy: every assignment that applies is evaluated; any
denyblocks the request. More assignments only make it stricter. Exemptions are the explicit escape hatch. - Google Cloud Organization Policy: by default a policy set on a folder or project replaces the inherited one for that subtree. A list policy can instead set
inheritFromParent: trueto merge with the parent. So a lower level can loosen a guardrail, if someone there holds the Organization Policy Administrator role. Keep that role at the organization level only.
Model: allowed regions three ways
Each level of the tree states the regions it allows. The function computes what a project or account at the bottom ends up with:
tree = [ # from the top down
("root / org", {"westeurope", "northeurope", "swedencentral", "eastus"}),
("prod folder", {"westeurope", "northeurope"}),
("shop project", {"westeurope", "eastus"}), # the team asks for eastus too
]
def aws_scp(levels): # allow must be present at every level: intersection
allowed = None
for _, regions in levels:
allowed = regions if allowed is None else allowed & regions
return allowed
def azure_policy(levels): # each assignment denies what it doesn't list: also intersection
allowed = set.union(*(r for _, r in levels))
for _, regions in levels:
allowed = {r for r in allowed if r in regions}
return allowed
def gcp_org_policy(levels, inherit_from_parent):
allowed = set()
for _, regions in levels:
allowed = (allowed | regions) if inherit_from_parent else set(regions)
return allowed
print("AWS SCPs: ", sorted(aws_scp(tree)))
print("Azure Policy: ", sorted(azure_policy(tree)))
print("GCP org policy (replace): ", sorted(gcp_org_policy(tree, False)))
print("GCP org policy (inherit): ", sorted(gcp_org_policy(tree, True)))AWS SCPs: ['westeurope']
Azure Policy: ['westeurope']
GCP org policy (replace): ['eastus', 'westeurope']
GCP org policy (inherit): ['eastus', 'northeurope', 'swedencentral', 'westeurope']
Same intent, different results. On AWS and Azure, the team's request for eastus is silently overruled by the folder above. On Google Cloud, whoever can set the project's policy wins for that project, and with inheritFromParent the lists are unioned, which can be looser than intended. (Real GCP location policies use value groups such as in:eu-locations rather than single region names, but the combination rules are the same.)
Real definitions
Azure: assign the built-in Allowed locations policy to a management group (sample session):
az policy assignment create \
--name allowed-locations-prod \
--display-name "Allowed locations (prod)" \
--scope /providers/Microsoft.Management/managementGroups/mg-prod \
--policy e56962a6-4747-49cd-b67b-bf8b01975c4c \
--params '{"listOfAllowedLocations": {"value": ["westeurope", "northeurope"]}}'
az policy state summarize --management-group mg-prod # compliance summaryA custom Azure Policy definition is JSON with an if condition on resource properties and a then effect. This one denies storage accounts that allow public blob access:
{
"mode": "Indexed",
"policyRule": {
"if": {
"allOf": [
{ "field": "type", "equals": "Microsoft.Storage/storageAccounts" },
{ "field": "Microsoft.Storage/storageAccounts/allowBlobPublicAccess", "notEquals": "false" }
]
},
"then": { "effect": "deny" }
}
}Google Cloud: restrict locations on a folder with a policy file (sample session):
# policy.yaml
name: folders/345678901234/policies/gcp.resourceLocations
spec:
rules:
- values:
allowedValues:
- in:eu-locationsgcloud org-policies set-policy policy.yaml
gcloud org-policies describe gcp.resourceLocations --folder=345678901234 --effectiveBoolean constraints are one line of intent each. Useful ones to know: iam.disableServiceAccountKeyCreation (no downloadable keys), storage.publicAccessPrevention, compute.vmExternalIpAccess (a list constraint: which VMs may have public IPs), iam.allowedPolicyMemberDomains (only identities from your own domains). Google enforces several of these by default on newly created organizations; check which are on before you fight them.
Design advice
- Start in audit/dry-run mode, look at what would have been blocked for a week, then enforce.
- Put the few non-negotiables (regions, no public storage, no long-lived keys, required tags) at the top; keep the rest close to the teams.
- On Google Cloud, decide who may set policy at lower levels. On Azure, decide who may create exemptions. Those people effectively own the guardrails.
- Guardrails are code too: Azure Policy definitions and assignments and Google Cloud org policies are all Terraform resources (
azurerm_policy_definition,azurerm_management_group_policy_assignment,google_org_policy_policy).
Test yourself
A Google Cloud folder restricts locations to the EU. A project below it sets its own location policy without inheritFromParent. What applies to the project?
- The intersection of both
- The folder's policy
- The project's own policy, which replaces the inherited one
- Neither
What can Azure Policy do that AWS SCPs cannot?
- Deny API calls
- Evaluate resource properties and report or remediate existing non-compliant resources
- Apply to an OU
- Block the root user
Which effect lets you roll out an Azure Policy without blocking anyone?
- deny
- audit
- denyAction
- append