Skip to content
LumenaryAcademy
Practice 90 min

Cloud security and identity

In the cloud, identity is the perimeter — who may do what to which resource, under which conditions, with which keys, and how to notice when the answer is wrong.

Code tested · 5AI-draftedAwaiting review by a cloud engineer

Your guides: Chloe · The Computer Scientist, Margaret · The Experimenter, Gideon · The Verifier

MotivationH

Identity is the perimeter

In a traditional data centre, security began at the door: a guarded building, a firewall at the edge of the network, and inside it a trusted zone. A cloud has no such door. Every resource — every virtual machine, bucket, database, key and backup — is created, changed and deleted through an API that answers on the internet, and anyone who presents valid credentials with the right permissions can do whatever the API allows. In practice this means that identity is the perimeter: who you are, what you are allowed to do, and under which conditions.

That changes where breaches come from. Year after year, published analyses of real incidents, such as Verizon's annual Data Breach Investigations Report, find stolen or misused credentials among the commonest ways in, and misconfiguration — a bucket readable by anyone, a role that can do everything, a forgotten key — among the commonest causes of exposure. Exotic exploits of the provider's own systems are rare. As the first lesson put it in the shared-responsibility model, your data, who may reach it and your configuration choices stay yours in every service model.

This lesson applies Lumenary CS's security lesson (threat models, authentication and authorisation, least privilege, defence in depth) and its applied cryptography to cloud platforms: how access is decided and kept small, how secrets and keys are handled, how networks are trusted (or not), and how to find mistakes before someone else does. It is written for defenders, about systems you own or are authorised to manage; probing systems you do not own is illegal in most countries, and the security lesson explains how to report a problem responsibly.

DefinitionsH

Principals, credentials and policies

Definition— Principal

Any identity that can make a request: a human user, a group, a workload identity (a role or service account used by a program), or a federated identity vouched for by an outside identity provider.

Authentication proves which principal is calling. For people, the professional pattern is single sign-on through one identity provider, so that leaving the organisation disables everything at once, with phishing-resistant multi-factor authentication (passkeys or hardware keys). For programs, it is short-lived credentials: a workload proves what it is (its machine, its pod's service account, the signed token a CI system issues for one run) and receives a token that expires within an hour or so. Long-lived access keys, which work from anywhere until revoked, are the credential most often leaked.

Authorisation is decided by policies. Whatever the provider's syntax, a policy statement says:

Definition— Policy statement

An effect (allow or deny) for a set of principals, actions (such as storage:GetObject) and resources (such as bucket/reports/*), optionally restricted by conditions on the request's context: the source network, whether multi-factor authentication was used, the time, or tags on the principal and the resource.

Two styles coexist. Role-based access control (RBAC) bundles permissions into roles and assigns roles to principals: "analysts can read reports". Attribute-based access control (ABAC) writes rules over attributes: "anyone may write objects whose team tag matches their own" — one rule instead of one role per team. Policies attach at several levels: to identities, to resources (a bucket's own policy), and as guardrails over a whole organisation, which cap what any policy below them can grant. The names differ by platform; the table is a map as of 2026.

Amazon Web ServicesMicrosoft AzureGoogle CloudAlibaba Cloud
People and sign-inIAM Identity CenterMicrosoft Entra IDCloud Identity, workforce identity federationRAM users and SSO
PermissionsIAM policies (JSON)Azure RBAC role assignments, with conditionsIAM allow policies (role bindings), IAM ConditionsRAM policies (JSON)
Workload identityIAM roles for instances, functions and podsmanaged identitiesservice accountsRAM roles
Organisation guardrailsservice control policiesAzure Policy and management groupsOrganization Policy, IAM deny policiesResource Directory control policies
Audit log of API callsCloudTrailActivity Log, Entra audit logsCloud Audit LogsActionTrail

Open-source systems use the same ideas: Kubernetes has its own RBAC (allow-only: there are no deny rules), Keycloak is a widely used open-source identity provider, and policy engines such as Open Policy Agent and Cedar let applications evaluate policies of their own.

ComputationC

A policy evaluator you can read

Every provider's documentation spells out how its evaluator combines statements, and the details differ — which policy types apply, how sessions and boundaries narrow them. The core, though, is shared by AWS IAM, Google Cloud's deny policies, Alibaba Cloud's RAM and Azure's deny assignments: an explicit deny always wins; otherwise an explicit allow is needed; otherwise the answer is no.

Requestwho, action, resourceAny matching deny?guardrails, resource, identityAny matching allow?only if no deny matchedALLOWDENY (explicit)DENY (default)noyesyesno
The core of cloud policy evaluation. Every statement that applies — guardrails, resource policies, identity policies — is gathered first; then a matching deny wins, an allow is needed, and the default is to deny.

The evaluator below implements that core for a small policy language of our own, with wildcard matching, three kinds of condition (multi-factor authentication, source network, and an attribute-based "same tag" rule) and a reason for every decision. The documentation range 203.0.113.0/24 stands in for an outside address.

python
import ipaddress
from fnmatch import fnmatchcase

# A small policy language in the spirit of the providers' (not any one provider's syntax).
POLICIES = [
    {"id": "analysts-read-reports", "effect": "allow", "principals": ["group:analysts"],
     "actions": ["storage:Get*", "storage:List*"], "resources": ["bucket/reports/*"]},
    {"id": "payroll-team", "effect": "allow", "principals": ["group:payroll"],
     "actions": ["storage:GetObject", "storage:PutObject"], "resources": ["bucket/payroll/*"],
     "conditions": {"mfa": True}},
    {"id": "payroll-only-from-office", "effect": "deny", "principals": ["*"],
     "actions": ["storage:*"], "resources": ["bucket/payroll/*"],
     "conditions": {"source_ip_not_in": "10.20.0.0/16"}},
    {"id": "teams-own-prefix", "effect": "allow", "principals": ["*"],      # attribute-based:
     "actions": ["storage:*"], "resources": ["bucket/teams/*"],             # your team tag must
     "conditions": {"same_tag": "team"}},                                   # match the object's
    {"id": "ops-admin", "effect": "allow", "principals": ["role:ops-admin"],
     "actions": ["*"], "resources": ["*"]},
    {"id": "nobody-deletes-audit-logs", "effect": "deny", "principals": ["*"],
     "actions": ["storage:Delete*"], "resources": ["bucket/audit/*"]},
]

def condition_holds(name, value, req):
    ctx = req.get("context", {})
    if name == "mfa":
        return ctx.get("mfa") is value                       # a missing key is not "True"
    if name == "source_ip_not_in":
        if "source_ip" not in ctx:
            return True                                      # unknown origin: treat as outside
        return ipaddress.ip_address(ctx["source_ip"]) not in ipaddress.ip_network(value)
    if name == "same_tag":
        mine, theirs = req["principal_tags"].get(value), req["resource_tags"].get(value)
        return mine is not None and mine == theirs
    raise ValueError(f"unknown condition {name!r}")          # never ignore what we don't understand

def matches(st, req):
    identities = [req["principal"], *req.get("groups", [])]
    return (any(fnmatchcase(i, p) for p in st["principals"] for i in identities)
            and any(fnmatchcase(req["action"], a) for a in st["actions"])
            and any(fnmatchcase(req["resource"], r) for r in st["resources"])
            and all(condition_holds(k, v, req) for k, v in st.get("conditions", {}).items()))

def evaluate(policies, req):
    hits = [st for st in policies if matches(st, req)]
    for st in hits:
        if st["effect"] == "deny":
            return "DENY", f"explicit deny: {st['id']}"
    for st in hits:
        if st["effect"] == "allow":
            return "ALLOW", f"allowed by {st['id']}"
    return "DENY", "implicit deny: nothing allows it"

def request(who, groups, action, resource, ptags=None, rtags=None, **context):
    return {"principal": who, "groups": groups, "action": action, "resource": resource,
            "principal_tags": ptags or {}, "resource_tags": rtags or {}, "context": context}

office, cafe = "10.20.4.7", "203.0.113.50"      # 203.0.113.0/24 is reserved for documentation
requests = [
    request("user:amara", ["group:analysts"], "storage:GetObject", "bucket/reports/2026-q3.csv", source_ip=office),
    request("user:amara", ["group:analysts"], "storage:DeleteObject", "bucket/reports/2026-q3.csv", source_ip=office),
    request("user:kenji", ["group:payroll"], "storage:GetObject", "bucket/payroll/nov.pdf", source_ip=office, mfa=True),
    request("user:kenji", ["group:payroll"], "storage:GetObject", "bucket/payroll/nov.pdf", source_ip=cafe, mfa=True),
    request("user:kenji", ["group:payroll"], "storage:GetObject", "bucket/payroll/nov.pdf", source_ip=office),
    request("user:kenji", ["group:payroll"], "storage:GetObject", "bucket/payroll/nov.pdf", mfa=True),
    request("user:leila", [], "storage:PutObject", "bucket/teams/maps/tiles.bin", {"team": "maps"}, {"team": "maps"}),
    request("user:leila", [], "storage:GetObject", "bucket/teams/search/index", {"team": "maps"}, {"team": "search"}),
    request("role:ops-admin", [], "storage:PutObject", "bucket/audit/2026-11.log"),
    request("role:ops-admin", [], "storage:DeleteObject", "bucket/audit/2026-11.log"),
]
PLACES = {office: "office", cafe: "café"}
for r in requests:
    decision, why = evaluate(POLICIES, r)
    ctx = r["context"]
    where = PLACES.get(ctx.get("source_ip"), "no IP") + (" +MFA" if ctx.get("mfa") else "")
    print(f"{r['principal'].split(':')[1]:9s} {r['action'].split(':')[1]:12s} "
          f"{r['resource'].removeprefix('bucket/'):21s} {where:12s} {decision:5s} {why}")
Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.

Amara can read reports but not delete them: nothing allows deletion, and the default is deny. Kenji can read payroll from the office with MFA; from a café the explicit deny beats his team's allow; without MFA his allow's condition fails. One attribute-based statement lets Leila write to her own team's prefix but not read another team's. And even ops-admin cannot delete audit logs: a deny written once protects them from every allow, present or future.

Theorem— Deny-overrides evaluation

Let M(P,q)M(P, q) be the set of statements in a policy set PP that match request qq, and let the decision be DENY if M(P,q)M(P,q) contains a deny statement, ALLOW if it contains only allow statements and is non-empty, and DENY if it is empty. Then (1) the decision depends only on the set M(P,q)M(P,q), not on the order in which statements are written or evaluated; and (2) if some deny statement in PP matches qq, then for every policy set P′⊇PP' \supseteq P the decision for qq is DENY.

Proof

(1) The decision is defined by two questions about the set M(P,q)M(P,q) — does it contain a deny? does it contain an allow? — and neither answer changes when the statements are reordered, because membership in a set does not depend on order. (2) Whether a statement matches qq depends only on that statement and qq, so every statement that matches qq in PP still matches it in P′P': M(P,q)⊆M(P′,q)M(P,q) \subseteq M(P',q). A deny in M(P,q)M(P,q) is therefore also in M(P′,q)M(P',q), and the decision for P′P' is DENY.

∎

Part (2) is why guardrails work: an organisation-wide deny on deleting audit logs cannot be undone by any team adding allows later. Precise semantics also make policies analysable over every possible request — "can anyone outside the organisation read this bucket?" — by translating them into logic for a solver, as AWS has described doing with SMT solvers (see the references); access analysers such as Google Cloud's Policy Analyzer and Azure's check access answer "who can do what" across all policies.

Two more traps hide in the matching. Wildcards match more than they seem to: bucket/reports* also matches bucket/reports-salaries/, so end prefixes with a slash. And * in an action list grants actions that do not exist yet — every new action the provider adds next year.

ComputationC

Least privilege in practice

Least privilege, from Lumenary CS's security lesson, becomes a set of concrete habits in the cloud:

  • One identity per workload, with only what it needs. A role shared by twelve services can never be small.
  • No long-lived keys where federation exists. A CI pipeline can exchange the signed OpenID Connect token its platform issues for each run for a short-lived cloud credential, scoped to one repository and branch, so there is no stored key to steal. All four providers document this: AWS, Azure, Google Cloud and Alibaba Cloud. Across clouds and data centres, the open-source SPIFFE standard and its SPIRE implementation issue workloads short-lived, verifiable identities.
  • Small standing access for people. Engineers hold read-only roles day to day and request elevated ones for a limited time, with a reason and an audit trail (Microsoft Entra's Privileged Identity Management is one such service; other platforms and identity providers offer similar just-in-time access). One or two break-glass accounts, with hardware keys in a safe and loud alerts on use, cover the day the identity provider is down.
  • Right-size from evidence. Every platform records API calls in an audit log, so granted permissions can be compared with used ones. AWS IAM Access Analyzer and Google Cloud's role recommendations do this as a service; the same analysis can be run on Azure's activity logs and Alibaba Cloud's ActionTrail.

The program below does that analysis on 90 days of synthetic audit events for four roles, of the kind every organisation accumulates.

python
import random
from collections import Counter
from fnmatch import fnmatchcase

CATALOGUE = {          # every action each (made-up) service offers
    "storage": ["GetObject", "PutObject", "DeleteObject", "ListBucket", "GetBucketPolicy", "PutBucketPolicy"],
    "queue":   ["Send", "Receive", "Delete", "Purge", "CreateQueue", "DeleteQueue"],
    "kms":     ["Encrypt", "Decrypt", "GenerateDataKey", "DisableKey", "ScheduleKeyDeletion"],
    "db":      ["Connect", "Query", "CreateSnapshot", "RestoreSnapshot", "DeleteInstance"],
    "iam":     ["CreateRole", "AttachPolicy", "PassRole", "CreateAccessKey"],
}
ALL = [f"{svc}:{a}" for svc, acts in CATALOGUE.items() for a in acts]
DANGEROUS = {"storage:PutBucketPolicy", "queue:Purge", "kms:DisableKey", "kms:ScheduleKeyDeletion",
             "db:DeleteInstance", "iam:CreateRole", "iam:AttachPolicy", "iam:PassRole", "iam:CreateAccessKey"}

GRANTS = {             # what each workload's role is allowed, as written by busy people
    "invoice-worker": ["storage:*", "queue:*", "kms:*"],
    "reporting":      ["db:*", "storage:Get*", "storage:List*"],
    "ci-deployer":    ["*"],
    "old-migration":  ["db:*", "storage:*"],
}
NEEDS = {              # what each workload actually calls (unknown to the analysis)
    "invoice-worker": ["queue:Receive", "queue:Delete", "storage:GetObject", "storage:PutObject",
                       "kms:Decrypt", "kms:GenerateDataKey"],
    "reporting":      ["db:Connect", "db:Query", "storage:GetObject", "storage:ListBucket"],
    "ci-deployer":    ["storage:PutObject", "storage:GetObject", "iam:PassRole", "db:Connect"],
    "old-migration":  [],
}

# 90 days of synthetic audit-log events: (day, role, action).
rng = random.Random(11)
log = [(day, role, rng.choice(acts)) for day in range(90) for role, acts in NEEDS.items()
       if acts for _ in range(rng.randint(20, 60))]

def expand(patterns):
    return {a for a in ALL if any(fnmatchcase(a, p) for p in patterns)}

used = {role: Counter(a for _, r, a in log if r == role) for role in GRANTS}
print(f"{len(log):,} audit events over 90 days\n")
print(f"{'role':15s} {'granted':>7s} {'used':>5s} {'unused':>6s}  dangerous ones among the unused")
for role, patterns in GRANTS.items():
    granted = expand(patterns)
    unused = granted - set(used[role])
    risky = sorted(unused & DANGEROUS)
    print(f"{role:15s} {len(granted):7d} {len(used[role]):5d} {len(unused):6d}  "
          + f"{len(risky)}: " + ", ".join(a.split(":")[1] for a in risky[:3]) + (", ..." if len(risky) > 3 else ""))

granted_total = sum(len(expand(p)) for p in GRANTS.values())
needed_total = sum(len(u) for u in used.values())
print(f"\nall roles: {granted_total} grants, {needed_total} used; "
      f"right-sizing removes {1 - needed_total / granted_total:.0%} of them")
print("suggested policy for invoice-worker:", sorted(used["invoice-worker"]))
print("old-migration: no calls in 90 days -> candidate for deletion, after asking its owner")
Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.

More than three quarters of the granted permissions were never used, and among them are the dangerous ones — disabling encryption keys, purging queues, rewriting bucket policies, creating new access keys. None of that was needed by the work, and all of it would have been available to whoever stole the role's credentials.

On Kubernetes the same habit is a namespaced Role that grants a workload exactly the verbs and objects it uses, bound to that workload's service account (not run here):

yaml
# Not run here: Kubernetes RBAC. The invoice worker may read one ConfigMap, nothing else.
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: invoice-worker
  namespace: billing
rules:
  - apiGroups: [""]
    resources: ["configmaps"]
    resourceNames: ["invoice-settings"]
    verbs: ["get", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: invoice-worker
  namespace: billing
subjects:
  - kind: ServiceAccount
    name: invoice-worker
    namespace: billing
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: invoice-worker
ExplanationH

Secrets management

A secret is anything that grants access by being known: a database password, an API token, a private key, a webhook signing key. The rules are short. Never put secrets in source code, container images, infrastructure code, or logs; they are copied, cached and shared far more widely than anyone intends, and a secret pushed to a public repository can be found by automated scanners within minutes. Keep them in a secrets manager — AWS Secrets Manager, Azure Key Vault, Google Cloud Secret Manager, the secrets feature of Alibaba Cloud's Key Management Service, or open-source OpenBao and HashiCorp's Vault (now under a source-available licence) — and let workloads fetch them at run time with their own identity, so access to each secret is a policy and every read is logged. For configuration kept in Git, tools such as SOPS encrypt the secret values with a key held in a key management service. How Kubernetes Secrets fit in — and why base64 is not encryption — is in the Kubernetes lesson.

Better still is needing fewer secrets. Workload identity removes cloud keys altogether; dynamic secrets go further, with the secrets manager creating a short-lived database account for each workload on request. What remains should be rotated automatically, since a rotation that takes a person a weekend never happens, and repositories scanned for leaks with tools such as gitleaks.

When a secret does leak, the order matters: revoke or rotate it first, then investigate. Deleting the commit does not help, since copies already exist. After rotation, read the audit logs for every use of the old credential since it was exposed, and treat what it could reach as possibly compromised.

IntuitionH

Encryption in transit and at rest

In transit, use TLS for every connection — including between your own services inside a private network, since an attacker who reaches one machine inside it may be able to read whatever crosses it unencrypted. TLS 1.3 (RFC 8446) is the current version. Within a cluster, mutual TLS (mTLS), in which both sides present certificates, gives every connection authenticated identities as well as encryption; service meshes such as Istio and Linkerd provide it without changing application code. Certificates expire, so their issue and renewal must be automated, through the providers' certificate services or with cert-manager and the ACME protocol used by Let's Encrypt. As of 2026, a large share of TLS connections on the public internet — from current browsers, and to many cloud endpoints — already negotiate a hybrid post-quantum key exchange based on ML-KEM (FIPS 203), so that traffic recorded today cannot be decrypted by a future quantum computer.

At rest, the large providers encrypt data in most storage and database services by default, or with one account-wide setting, using keys they manage. That protects against a lost disk, not against a stolen credential: the service decrypts transparently for anyone it authorises. The control that matters is therefore who may use the key. With customer-managed keys in a key management service — AWS KMS, Azure Key Vault and its Managed HSM, Google Cloud KMS, Alibaba Cloud KMS — key use is a separate permission, logged on every call, held by different people from those who administer the data, and revocable: disabling the key makes the data unreadable everywhere at once.

Key management services use envelope encryption, because sending terabytes to a key service would be slow and the key must never leave it.

objectdata keyfresh, per objectciphertextkey management servicekey-encryption key(in a hardware module;never leaves)checks permission,logs every usestored togetherciphertext + wrapped keyencryptdata key, to be wrappedwrapped key
Envelope encryption. Each object is encrypted locally with its own data key; the data key is encrypted (wrapped) by a key-encryption key that never leaves the key management service, and the wrapped copy is stored beside the data.

To read an object, the wrapped data key goes back to the key service, which checks permission, logs the call and returns the data key for local decryption. The hierarchy pays off at rotation: key services keep old versions of a key-encryption key to unwrap old data keys, and re-wrapping, when required, touches only the small data keys, never the data. Keys live in hardware security modules validated to FIPS 140-3 or similar schemes; NIST's SP 800-57 is the standard reference for key lifetimes and roles. Where the threat includes the provider itself, or a government with power over it, options run from importing your own key material, to external key managers in which the key never enters the provider at all, to confidential computing; these are taken up in Edge, multi-cloud and sovereignty and Sustainable and confidential cloud.

ExplanationH

Network security and zero trust

Network controls remain essential; Cloud networking describes private subnets, security groups that admit only what each tier needs, and private endpoints that reach managed services without an internet route. Add two habits: control egress too, so a compromised server cannot freely send data out, and never expose administration ports, reaching machines instead through identity-aware services that authenticate and record each session, such as AWS Systems Manager Session Manager, Azure Bastion, Google Cloud's Identity-Aware Proxy and Alibaba Cloud's Bastionhost.

Zero trust is the name for not relying on the network at all. NIST's SP 800-207 sets out its principles; Google's BeyondCorp papers describe one of the first large deployments. In our words: no request is trusted because of where it comes from; every request is authenticated and authorised, as a person or as a workload, on its own; access is granted per resource and per session, with the least privilege that does the job; decisions use all available signals — identity, device health, location, behaviour — and are re-evaluated continuously; and everything is logged, on the assumption that some part of the network is already compromised.

In a cloud, zero trust is less a product than the sum of this lesson: identity for every person and workload, policy on every call, mTLS between services, and private networks as one layer of defence in depth rather than the boundary of trust.

ComputationC

The commonest misconfigurations, and how to find them

Most cloud exposures come from a short list of configuration mistakes. Each has a reliable way to detect it and a known fix.

  1. Storage readable by anyone, often set up once for a quick share. Detect by listing every bucket's effective access; prevent with each provider's account- or organisation-wide setting — S3 Block Public Access, Azure Storage's setting to disallow anonymous access, Google Cloud Storage's public access prevention, Alibaba Cloud OSS's Block Public Access — and share files with expiring signed URLs instead.
  2. Over-broad roles: every action on every resource, built-in owner and editor roles granted for convenience, or unconditional trust in another organisation's accounts. Detect by analysing policies for wildcards and external trust; fix by right-sizing.
  3. Old or unprotected credentials: years-old access keys, password-only sign-ins, accounts of people who left. Detect from credential reports and sign-in logs; fix with federation, phishing-resistant MFA and automatic deprovisioning.
  4. Administration and database ports open to the internet: SSH (22), RDP (3389) or a database port allowed from 0.0.0.0/0 or ::/0. Detect by scanning firewall rules for the whole-internet source; fix with identity-aware access and private endpoints.
  5. Snapshots and images shared publicly, carrying whole disks. Detect by listing sharing permissions; fix by unsharing, encrypting snapshots by default, and checking who read them.
  6. An unprotected instance metadata service. A server-side request forgery bug can make a web server fetch its own credentials from it. Fix by requiring the session-token mode where offered (AWS's IMDSv2, Alibaba Cloud's security hardening mode); Azure and Google Cloud require a special request header on every metadata call.
  7. Incomplete logging: audit logs missing in some regions, or deletable by the people they watch. Fix by logging every region to a separate, locked-down account.

The scanner below applies these checks to a synthetic inventory, the kind of list a posture tool builds through the providers' read-only APIs, and prints each finding with its fix.

python
import ipaddress

# A synthetic inventory, as a posture tool would collect it through the providers' read-only APIs.
INVENTORY = [
    {"kind": "bucket", "name": "press-kit", "public_read": True, "approved_public": True},
    {"kind": "bucket", "name": "customer-exports", "public_read": True},
    {"kind": "bucket", "name": "invoices", "public_read": False, "encrypted": True, "versioning": True},
    {"kind": "bucket", "name": "ml-training-data", "public_read": False, "encrypted": True, "versioning": False},
    {"kind": "role", "name": "ci-deployer", "actions": ["*"], "resources": ["*"]},
    {"kind": "role", "name": "vendor-support", "actions": ["storage:*"], "resources": ["*"],
     "trusts_external_account": True, "requires_external_id": False},
    {"kind": "role", "name": "reporting", "actions": ["db:Query", "storage:GetObject"], "resources": ["bucket/reports/*"]},
    {"kind": "user", "name": "svc-backup", "key_age_days": 812, "key_last_used_days": 2, "mfa": False},
    {"kind": "user", "name": "admin-break-glass", "console": True, "mfa": False},
    {"kind": "user", "name": "ana.souza", "console": True, "mfa": True},
    {"kind": "firewall", "name": "allow-ssh", "source": "0.0.0.0/0", "ports": (22, 22)},
    {"kind": "firewall", "name": "web", "source": "0.0.0.0/0", "ports": (443, 443)},
    {"kind": "firewall", "name": "db-debug", "source": "::/0", "ports": (5432, 5432)},
    {"kind": "firewall", "name": "office-rdp", "source": "10.20.0.0/16", "ports": (3389, 3389)},
    {"kind": "snapshot", "name": "orders-db-2026-10-01", "encrypted": False, "shared_publicly": True},
    {"kind": "vm", "name": "web-7", "metadata_tokens_required": False},
    {"kind": "audit_log", "name": "org-trail", "enabled": True, "all_regions": False},
]

def everyone(source):
    return ipaddress.ip_network(source).prefixlen == 0       # 0.0.0.0/0 or ::/0

def check(r):
    """Yield (severity, finding, fix) for one resource."""
    k = r["kind"]
    if k == "bucket" and r["public_read"]:
        if r.get("approved_public"):
            yield "INFO", "public by design", "serve it through a CDN; keep it free of anything private"
        else:
            yield "CRITICAL", "anyone on the internet can read it", "block public access account-wide; share with expiring signed URLs"
    if k == "bucket" and not r.get("versioning", True):
        yield "MEDIUM", "no versioning: deletions and overwrites are final", "turn on versioning and object lock for important data"
    if k == "role" and "*" in r["actions"] and "*" in r["resources"]:
        yield "HIGH", "allowed every action on every resource", "grant only what its audit log shows it uses"
    if k == "role" and r.get("trusts_external_account") and not r.get("requires_external_id"):
        yield "HIGH", "another organisation can assume it with no extra check", "trust one named identity, with a condition such as an agreed external ID"
    if k == "user" and r.get("key_age_days", 0) > 90:
        yield "HIGH", f"access key is {r['key_age_days']} days old", "replace with a role or workload identity; rotate meanwhile"
    if k == "user" and r.get("console") and not r["mfa"]:
        yield "CRITICAL", "can sign in with a password alone", "require phishing-resistant MFA (hardware key or passkey)"
    if k == "firewall" and everyone(r["source"]):
        lo, hi = r["ports"]
        if lo <= 22 <= hi or lo <= 3389 <= hi:
            yield "HIGH", f"remote administration open to the internet ({r['source']})", "close it; use an identity-aware access service"
        elif (lo, hi) not in [(80, 80), (443, 443)]:
            yield "HIGH", f"port {lo} open to the internet ({r['source']})", "keep databases on private addresses only"
    if k == "snapshot" and r["shared_publicly"]:
        yield "CRITICAL", "disk snapshot shared with every account", "unshare it now; check access logs; encrypt snapshots by default"
    if k == "vm" and not r["metadata_tokens_required"]:
        yield "MEDIUM", "metadata service answers without a session token", "require the token-based (hardened) metadata mode"
    if k == "audit_log" and not r["all_regions"]:
        yield "MEDIUM", "audit log misses some regions", "log every region, to a separate, locked-down account"

ORDER = ["CRITICAL", "HIGH", "MEDIUM", "INFO"]
findings = sorted(((sev, r["kind"], r["name"], what, fix) for r in INVENTORY for sev, what, fix in check(r)),
                  key=lambda f: ORDER.index(f[0]))
for sev, kind, name, what, fix in findings:
    print(f"{sev:8s} {kind:9s} {name:21s} {what}\n{'':40s}-> {fix}")
counts = {s: sum(f[0] == s for f in findings) for s in ORDER}
print("\n" + ", ".join(f"{n} {s.lower()}" for s, n in counts.items()), f"across {len(INVENTORY)} resources")
Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.

Real tools do this continuously and at scale. Every large provider runs a posture service — AWS Security Hub, Microsoft Defender for Cloud, Google Cloud's Security Command Center and Alibaba Cloud's Security Center — and open-source tools such as Prowler, Cloud Custodian and Trivy check one or several clouds against baselines such as the CIS Benchmarks. Two practices make findings rarer: organisation-wide guardrails that make the worst settings impossible, and policy as code, in which tools such as Checkov or Open Policy Agent reject a dangerous change in its pull request — the natural partner of infrastructure as code. Note the INFO line: some buckets are public on purpose, and a good process records the exception and its owner.

ExplanationH

Compliance in outline

Compliance means showing customers, auditors and regulators that the controls you claim are real, and in the cloud it is shared like everything else. Providers are independently audited against standards such as ISO/IEC 27001 and SOC 2, the payment industry's PCI DSS, and national schemes such as FedRAMP in the United States, C5 in Germany, ISMAP in Japan and the Multi-Level Protection Scheme in China, and they publish the reports for customers to inspect. Those attestations cover the provider's layers; your application inherits them only for those layers, and must still show its own controls for the rest.

Privacy and data-protection laws — the EU's GDPR, Brazil's LGPD, India's Digital Personal Data Protection Act, China's Personal Information Protection Law, Kenya's Data Protection Act and many others — add duties about what personal data is collected, where it may be stored and moved, how long it is kept and how breaches are reported. Frameworks such as the Cloud Security Alliance's Cloud Controls Matrix map one set of controls to many of these standards. For engineers, the useful fact is that the evidence auditors ask for — who had access, what changed and when, whether data was encrypted and backed up — is what good identity management, audit logging, infrastructure as code and posture checks produce anyway. Compliance built on them is a by-product; compliance bolted on before an audit is a fire drill. Where data may live, and under whose law, is the subject of Edge, multi-cloud and sovereignty.

Common misconceptionsH

Common misconceptions

Misconception

"The provider is responsible for security." The provider secures its layers. Who may access your data, how your services are configured and what you expose are yours in every service model.

Misconception

"Our data is encrypted at rest, so a leaked access key is harmless." Storage services decrypt transparently for any authorised caller, and a leaked key is an authorised caller. Encryption at rest protects lost disks; identity and key-use policies protect against stolen credentials.

Misconception

"An explicit deny always protects us." It wins whenever it matches. A deny with a condition on a key that a request does not carry may not match at all, and a deny on bucket/reports* may cover more than intended. Test denies against the requests they are meant to stop.

Misconception

"MFA for every person means we are safe." Workloads, CI pipelines and integrations make most API calls, and their credentials cannot do MFA. They need short-lived credentials, narrow permissions and monitoring of their own.

Exercises

Exercises

1. Cloud security and identity

Warm-upHuman

A storage bucket's policy contains, in this order: (1) allow role:auditor every storage:Get* action on bucket/finance/*; (2) deny every principal every action on bucket/finance/* unless the request comes from the organisation's network. An auditor sends storage:GetObject for bucket/finance/ledger.csv from a hotel's Wi-Fi, outside the organisation's network. Under deny-overrides evaluation, what happens?

Choose one

2. Cloud security and identity

CoreHuman

A policy allows the payroll team to read bucket/payroll/*, and adds a deny on bucket/payroll/* with the condition "the request's source IP is not in 10.20.0.0/16". The evaluator treats a condition on a key the request does not carry as false. A request from a payroll team member arrives through an internal reporting service that does not forward the original source IP, so the request has no source-IP key. What is the decision?

Choose one

3. Cloud security and identity

CoreComputational

The starter's evaluate(policies, request) lets the first matching statement decide, so reordering a policy changes its meaning. Rewrite it with deny-overrides semantics: "DENY" if any matching statement is a deny; otherwise "ALLOW" if any matching statement is an allow; otherwise "DENY". Use the matches helper, which is already correct.

Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.

4. Cloud security and identity

CoreComputational

Write exposed_admin_rules(rules), a detection check for your own organisation's firewall rules. It returns the sorted names of rules that let the whole internet — IPv4 0.0.0.0/0 or IPv6 ::/0 — reach SSH (port 22) or RDP (port 3389). Each rule has name, source (a network in CIDR notation), from_port and to_port (an inclusive range). The starter misses several cases.

Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.

5. Cloud security and identity

CoreHuman

A data lake stores 5 million objects, 200 TB in all, each encrypted with its own 256-bit data key, and the data keys are wrapped by one key-encryption key. After the key-encryption key is replaced, every data key is re-wrapped with the new one. How many megabytes (10⁶ bytes) of key material are re-encrypted?

6. Cloud security and identity

CoreHuman

Your organisation wants to make sure none of its storage buckets is ever readable by anyone on the internet, except a few deliberately public ones. Which measures help? Select all that apply.

Choose all that apply

7. Cloud security and identity

Warm-upHuman

Which statement best captures zero trust?

Choose one

Further reading and resources