Identity and Access Management: Policies, Wildcards and “Deny Wins”
Control who can do what in the cloud: write JSON access policies with allow and deny statements, wildcards and conditions, understand that anything not allowed is denied and an explicit deny always wins, and test a policy engine against a table of expected decisions in two languages.
In this lesson you will
- Read an access policy
- Explain implicit and explicit deny
- Use wildcards and conditions safely
- Test a policy against expected decisions
About 28 minutes
The intern who could delete the customer data
At Wren’s company, everybody started with the administrator account, because it was quick. Then a new intern, trying to clear out test files, deleted a storage folder with real ticket data. Identity and access management, IAM, is the part of a cloud platform that decides who may do what to which resource, and getting it right is the single most effective security measure. The vocabulary is similar everywhere. A principal is who is asking: a person, a program or a role. An action is what they want to do, such as reading or deleting an object. A resource is what it applies to, named by a path. A policy is a list of statements, each either Allow or Deny, for sets of actions and resources, optionally with conditions such as the source network or the time.
Three rules decide the outcome. First, everything is denied by default: if no statement allows a request, it fails. This implicit deny is why a new user can do nothing until given something. Second, an explicit Deny statement beats any Allow, whatever the order, which makes Deny the right tool for guardrails such as “nobody may delete this bucket”. Third, wildcards match patterns: an action pattern such as storage:Get* matches storage:GetObject and storage:GetBucket, and a resource pattern ending in an asterisk matches everything under a path. Wildcards are powerful and dangerous: a policy that allows * on * is the administrator, and a careless wildcard in a resource path can open far more than intended. The principle of least privilege says to start with nothing and add exactly what a role needs, then check the result with tests, as this lesson does.
| Concept | Meaning | Example |
|---|---|---|
| Principal | Who is asking | intern, a program, a role |
| Action | What is requested | storage:DeleteObject |
| Resource | What it applies to | bucket/tickets/* |
| Effect | Allow or Deny | Deny wins |
| Condition | Extra requirement | source network, time |
import json, fnmatch, ipaddress, sys
policy = json.loads(sys.argv[1])
def match(patterns, value): return any(fnmatch.fnmatchcase(value, p) for p in patterns)
def decide(action, resource, ctx=None):
ctx = ctx or {}; allowed = False
for s in policy["statements"]:
if not (match(s["actions"], action) and match(s["resources"], resource)): continue
c = s.get("condition")
if c and not (ctx.get("ip") and ipaddress.ip_address(ctx["ip"]) in ipaddress.ip_network(c["sourceNet"])): continue
if s["effect"] == "Deny": return "DENY (explicit)"
allowed = True
return "ALLOW" if allowed else "DENY (implicit)"
cases = [("storage:GetObject", "bucket/tickets/2024/a.csv", None), ("storage:ListBucket", "bucket/tickets/", None), ("storage:GetObject", "bucket/uploads/x", None),
("storage:PutObject", "bucket/uploads/x", {"ip": "10.1.2.3"}), ("storage:PutObject", "bucket/uploads/x", {"ip": "203.0.113.9"}), ("storage:PutObject", "bucket/uploads/x", None),
("storage:PutObject", "bucket/tickets/new.csv", {"ip": "10.1.2.3"}), ("storage:DeleteObject", "bucket/tickets/a.csv", None), ("storage:DeleteObject", "bucket/uploads/x", {"ip": "10.1.2.3"}),
("storage:DeleteBucket", "bucket/tickets", None), ("compute:DescribeInstances", "vm/42", None), ("compute:StartInstance", "vm/42", None), ("storage:GetObject", "bucket/TICKETS/a.csv", None), ("iam:CreateUser", "*", None)]
out = []
for a, r, c in cases: d = decide(a, r, c); out.append([a, r, c and c["ip"], d]); print((a + " on " + r).ljust(52), (str(c["ip"]) if c else "-").ljust(12), d)
print("DATA " + json.dumps(out))
storage:GetObject on bucket/tickets/2024/a.csv - ALLOW
storage:ListBucket on bucket/tickets/ - ALLOW
storage:GetObject on bucket/uploads/x - DENY (implicit)
storage:PutObject on bucket/uploads/x 10.1.2.3 ALLOW
storage:PutObject on bucket/uploads/x 203.0.113.9 DENY (implicit)
storage:PutObject on bucket/uploads/x - DENY (implicit)
storage:PutObject on bucket/tickets/new.csv 10.1.2.3 DENY (implicit)
storage:DeleteObject on bucket/tickets/a.csv - DENY (explicit)
storage:DeleteObject on bucket/uploads/x 10.1.2.3 DENY (explicit)
storage:DeleteBucket on bucket/tickets - DENY (explicit)
compute:DescribeInstances on vm/42 - ALLOW
compute:StartInstance on vm/42 - DENY (implicit)
storage:GetObject on bucket/TICKETS/a.csv - DENY (implicit)
iam:CreateUser on * - DENY (implicit)
{
"statements": [
{
"effect": "Allow",
"actions": [
"storage:Get*",
"storage:List*"
],
"resources": [
"bucket/tickets/*"
]
},
{
"effect": "Allow",
"actions": [
"storage:PutObject"
],
"resources": [
"bucket/uploads/*"
],
"condition": {
"sourceNet": "10.0.0.0/8"
}
},
{
"effect": "Deny",
"actions": [
"storage:Delete*"
],
"resources": [
"bucket/*"
]
},
{
"effect": "Allow",
"actions": [
"compute:Describe*"
],
"resources": [
"*"
]
}
]
}
Fourteen requests were checked against the policy, and the table in the output block is the engine’s decision for each. The policy says four things. People may read and list objects under bucket/tickets. Uploads are allowed under bucket/uploads only from the internal network 10.0.0.0/8, which is a condition. Deleting anything in any bucket is denied. And describing computers is allowed on all resources. The results follow: reading the ticket files and listing the folder are allowed, reading the uploads folder is denied implicitly because no statement allows it, and an upload is allowed from the internal address, refused from the outside address, and refused when no address is given, since the condition cannot be met. An upload into the tickets folder is denied implicitly, because the upload permission covers only the uploads path.
The interesting cases are the explicit denials. Deleting an object under tickets is denied by the delete rule, and so is deleting an object in the uploads folder from the internal network, although the upload statement matched there: there is no statement that allows deletion, and in any case the explicit Deny would win over an Allow. That is exactly the guardrail that would have saved the ticket data. The request to delete the bucket itself matches the Deny pattern storage:Delete*, and describing a computer is allowed while starting one is denied implicitly. Two details deserve notice: the path with TICKETS in capitals is denied, since matching is case sensitive, and a request for creating users, which no statement mentions, is denied implicitly. Anything not written is forbidden, which is the right default.
Independent check: the same policy and the same fourteen requests were evaluated by a separate engine written in JavaScript, with its own pattern matcher, built from regular expressions, and its own network test using bit arithmetic on the address, and its fourteen decisions are identical to the Python engine’s, which uses the standard library’s fnmatch and the ipaddress module. The expected decisions were also written down in advance, from reading the policy, and both engines match them. A table of expected results for every statement, including the edge cases, is the best test of a policy, and should be rerun whenever the policy changes.
Check by hand with the fourth request: PutObject on bucket/uploads/x from 10.1.2.3 matches the second statement, which allows uploads, and its condition, since 10.1.2.3 is inside 10.0.0.0/8. No Deny matches, because storage:Delete* does not match PutObject, so the result is Allow. The same request from 203.0.113.9 fails the condition, the statement does not apply, nothing else allows it, and the result is implicit deny.
A policy that allows every action on every resource is the administrator. Give people and programs only the actions and resources they need, and review wide permissions regularly.
A table of requests and expected decisions, run after every change, catches the wildcard that opens too much and the typo that closes too much.
No cloud account is needed for this course. The cloud services in these lessons are small simulations that run on your own computer, in Python 3.13 or Node.js 22, because the ideas, such as access policies, queues, autoscaling and templates, are the same at every provider. Prices and names are invented or generic, and each provider’s services and prices change often, so check the current documentation of the provider you use. Every result was checked a second way. Real providers’ policy languages have more features, such as roles, groups, boundaries and tags. The evaluation logic of default deny, explicit deny and matching is the same.
Practice
Add a statement that lets an auditor read everything but nothing else, and write five test requests. Add a condition on the time of day. Find a request that the policy allows that you did not intend, by thinking about wildcards.
Check what you learned
Five quick questions. Pick an answer and you will see straight away whether it is right and why.
What is the default decision when no statement matches?
- Deny
- Allow
- Ask
- Log only
Implicit deny.
What wins when an Allow and a Deny both match?
- The Allow
- The first one
- The last one
- The Deny
Explicit deny.
What does storage:Get* match?
- Only storage:Get
- All storage actions
- Nothing
- Actions starting with storage:Get
The asterisk matches the rest.
Why is a wildcard on all actions and resources risky?
- It is slow
- It is invalid
- It is the administrator
- It encrypts data
Least privilege.
Why test policies with expected results?
- To make them longer
- Providers require it
- To catch wildcards and typos that open or close too much
- To compress them
Run after every change.
Summary
- Principals, actions, resources and effects make up policies.
- Default is deny; an explicit deny always wins.
- Wildcards and conditions need care.
- Test policies against expected decisions in two implementations.
Questions
What is least privilege?
Giving each person and program only the permissions they need for their task, and nothing more, and removing them when no longer needed.
What is a role?
A set of permissions that a person or program can take on temporarily, instead of a permanent account with a password. Roles reduce the risk from lost credentials.
Should I use the root account?
Almost never. Protect it with multi-factor authentication, and create separate users and roles for daily work.
