Most identity misconfigurations look correct at a glance: the token is signed, the policy requires MFA, the role trusts a known identity provider, and the flaw sits in one missing line. These ten short exercises train the eye for that line. Each shows a fictional token validation rule, Conditional Access design or cloud trust policy, asks you to find the weakness, and then explains the flaw and the fix with the source that sets the rule. They cover JWT audience, issuer, algorithm and type checks, Conditional Access exclusions, and wildcard or over-broad principals in AWS, Google Cloud and Microsoft Azure federation. The page is for IAM and platform engineers, reviewers and learners; the protocol background is in the OAuth 2.0 and OpenID Connect Guide, which this page does not repeat.
Key takeaways
- A valid signature is not a valid token. RFC 8725 requires the relying party to check that the signing keys belong to the issuer and that the audience is its own, and to reject the token otherwise.
- Every Conditional Access exclusion is a hole. Microsoft limits its baseline MFA exclusions to emergency access, directory sync and service accounts, and any account excluded is not covered by the policy.
- Federated trust needs a subject, not just an issuer. Public CI issuers such as GitHub serve every customer from one issuer URL, so a trust that checks only the issuer trusts strangers.
- Wildcards belong in the narrowest field possible. AWS warns against a wildcard principal in role trust policies; Google Cloud requires an attribute condition for GitHub; Microsoft Entra federated credentials match subjects exactly.
- Prefer immutable identifiers. Google Cloud recommends numeric GitHub owner and repository IDs over names, which can be re-registered.
How to use these exercises
Read each snippet and write down the flaw before opening the answer. Every snippet is fictional, uses placeholder domains and account numbers, and is deliberately short; real policies hide the same mistakes inside longer files. The cloud examples are listed alphabetically by provider (AWS, Google Cloud, Microsoft Azure), and order is not a ranking.
| Exercise | Area | Skill tested | Difficulty |
|---|---|---|---|
| 1 | JWT validation | Audience check | Starter |
| 2 | JWT validation | Algorithm allowlist | Starter |
| 3 | JWT validation | Issuer to key binding in multi-tenant apps | Intermediate |
| 4 | JWT validation | Token type confusion | Intermediate |
| 5 | Conditional Access | Exclusion sprawl | Starter |
| 6 | Conditional Access | Service accounts and workload identities | Intermediate |
| 7 | Conditional Access | Trusted location bypass | Intermediate |
| 8 | AWS trust policy | Wildcard principal and broad subject | Starter |
| 9 | Google Cloud workload identity federation | Attribute condition and principalSet scope | Intermediate |
| 10 | Microsoft Azure federated credential | Subject choice for production | Intermediate |
For teams: run the set as a 45-minute review exercise, then take one real policy of each type from your own estate and review it the same way. Score the session by how many flaws each person found unaided, and track the real findings as tickets. For team leads, the useful measures are the share of reviewers who catch exercises 3, 6 and 9 (the least obvious), the number of real exclusions and wildcards removed after the session, and the time from finding to fix.
Exercises: tokens and claims
Exercise 1. An orders API accepts bearer tokens from the corporate identity provider, which also issues tokens for twenty other internal APIs.
1 Sample only, based on the public documentation cited. Assess it independently against the current official documentation, test outside production and back up first.
validate(token):
verify_signature(token, jwks_from("https://login.example.com/.well-known/jwks.json"))
require token.iss == "https://login.example.com"
require token.exp > now()
acceptExercise 2. A service validates tokens with a library call configured as follows.
decode(token,
key = public_key,
algorithms = token.header.alg) # use whatever the token declaresExercise 3. A multi-tenant SaaS app lets any customer organisation sign in through a shared identity platform endpoint whose signing keys are common to all tenants.
validate(token):
verify_signature(token, jwks_from("https://idp.example.net/common/keys"))
require token.aud == "api://saas-app"
require token.exp > now()
tenant = token.tid # trusted for data access
acceptExercise 4. A mobile back end checks tokens like this. The same identity provider issues both ID tokens and access tokens for the app, signed with the same key.
validate(token):
verify_signature(token, idp_keys)
require token.iss == "https://login.example.com"
require token.aud == "mobile-app-client-id"
require token.exp > now()
accept as API accessExercises: conditional access
Exercise 5. A tenant's baseline policy, as documented by the identity team.
Policy: Require MFA for all users
Users: Include All users
Exclude group "CA-Exclusions" (43 members: 2 break-glass,
1 sync account, 6 executives, 34 "app owners")
Resources: All resources
Grant: Require authentication strength: Multifactor authentication
State: OnExercise 6. A design note on non-human accounts.
Service accounts are excluded from the MFA policy.
Service principals used by automation are covered because the
MFA policy targets All resources.Exercise 7. An MFA policy with a network exception.
Network: Include Any network or location
Exclude All trusted networks and locations
Trusted named location "Corporate":
head-office range, plus the full public egress range of the
shared cloud region used by the company's VDI and partner VPNExercises: cloud trust policies
Exercise 8 (AWS). A deployment role in account 111122223333.
{
"Version": "2012-10-17",
"Statement": [
{ "Effect": "Allow",
"Principal": { "AWS": "*" },
"Action": "sts:AssumeRole" },
{ "Effect": "Allow",
"Principal": { "Federated": "arn:aws:iam::111122223333:oidc-provider/token.actions.githubusercontent.com" },
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": { "token.actions.githubusercontent.com:aud": "sts.amazonaws.com" },
"StringLike": { "token.actions.githubusercontent.com:sub": "repo:example-org/*" } } }
]
}Exercise 9 (Google Cloud). A workload identity pool provider for GitHub Actions and the binding that lets it impersonate a deployer service account.
Provider: issuer https://token.actions.githubusercontent.com
attribute mapping: google.subject=assertion.sub,
attribute.repository=assertion.repository
attribute condition: assertion.repository.startsWith("example-org/")
Binding: roles/iam.workloadIdentityUser on projects/PROJECT/serviceAccounts/deployer
member principalSet://iam.googleapis.com/projects/PROJECT_NUMBER/
locations/global/workloadIdentityPools/ci-pool/*Exercise 10 (Microsoft Azure). A federated identity credential on the app registration that deploys to production.
{
"name": "github-prod",
"issuer": "https://token.actions.githubusercontent.com",
"subject": "repo:example-org/payments-api:pull-request",
"audiences": ["api://AzureADTokenExchange"]
}Answers and explanations
| Exercise | Flaw | Fix | Rule source |
|---|---|---|---|
| 1 | No audience check | Require aud to equal the orders API identifier | RFC 8725 s3.9; RFC 9700 s2.3; ASVS V9.2.3 |
| 2 | Algorithm taken from the token | Fixed allowlist per key | RFC 8725 s3.1, s3.2; ASVS V9.1.2 |
| 3 | Issuer and tenant not bound to the token | Validate iss per tenant against an allowlist and bind tid to it | RFC 8725 s3.8 |
| 4 | ID token accepted as access token | Separate audiences and explicit type checks | RFC 8725 s3.11, s3.12; ASVS V9.2.2 |
| 5 | Exclusion group used as a bypass list | Exclude only break-glass and sync accounts; fix the rest | Microsoft Learn baseline MFA policy |
| 6 | Assumes user policies cover service principals | Conditional Access for workload identities; managed identities | Microsoft Learn baseline MFA policy |
| 7 | Trusted location covers shared egress | Trust only addresses you exclusively control | Microsoft Learn baseline MFA policy (network exception) |
| 8 | Wildcard principal; org-wide subject | Remove the wildcard statement; pin the subject | AWS IAM principal and OIDC role docs |
| 9 | Name-based condition; whole-pool binding | Numeric owner ID condition; bind a specific attribute set | Google Cloud workload identity federation docs |
| 10 | Pull request subject unlocks production | Protected environment subject | Microsoft Learn federated credential docs |
Token answers
- Exercise 1: the API checks issuer, signature and expiry but not audience, so any token the corporate identity provider issued for any of the other twenty APIs is accepted here. RFC 8725 section 3.9 says the relying party "MUST validate the audience value" and must reject the token if the audience is missing or not its own. RFC 9700 section 2.3 adds that access tokens should be audience-restricted and that every resource server must check, on every request, that the token was meant for it. Fix:
require token.aud == "api://orders". See the JWT Security Guide. - Exercise 2: the accepted algorithm comes from the token header, which the sender controls. RFC 8725 section 3.1 says libraries should let callers specify supported algorithms and reject all others, with each key bound to one algorithm, and section 3.2 limits
noneto tokens protected by other means. Fix:algorithms = ["RS256"](or the one algorithm that key uses), configured in code, never read from the token. - Exercise 3: the common key set signs tokens for every tenant, so a valid signature proves only that some tenant's user signed in. The app then trusts
tidfor data access without checking that the issuer is an approved tenant. RFC 8725 section 3.8 requires the application to confirm the keys belong to the issuer in the token and to reject it otherwise. Fix: maintain an allowlist of onboarded tenant issuers, validateissagainst it, check thattidmatches the issuer, and map users to tenants server-side. - Exercise 4: the ID token's audience is the client ID, and so is the audience being checked, so an ID token (meant to tell the app who signed in) is accepted as API authorisation. RFC 8725 section 3.12 requires validation rules for different token kinds from one issuer to be mutually exclusive, using distinct
typ, audience, claims or keys, and section 3.11 recommends explicit typing. Fix: issue access tokens for an API audience distinct from the client ID, and check token type (for example atypheader or a scope claim that only access tokens carry). See the JWT Validation Errors Troubleshooting Guide.
Conditional Access answers
- Exercise 5: Microsoft's baseline "require MFA for all users" policy recommends excluding only emergency access accounts, directory synchronisation accounts and service accounts (with guests optional where a separate guest policy exists), and an excluded account is not covered by the policy. Executives and app owners are high-value targets, not exceptions. Fix: shrink the group to break-glass and sync accounts, alert on any membership change, and solve the app owners' underlying problem (often a legacy client or shared account). See the Break-Glass Account Guide.
- Exercise 6: the same Microsoft page states that user-scoped Conditional Access policies do not block service principal calls; they need Conditional Access for workload identities. It also suggests replacing service accounts used by scripts with managed identities. Fix: inventory excluded service accounts, move them to managed identities or workload identities, and apply location or risk policies to those. See Conditional Access for Workload Identities.
- Exercise 7: the network exception is a documented option, but this trusted location includes a shared cloud region's egress range, which other tenants of that cloud also use, plus a partner VPN. Anyone signing in from those addresses skips MFA. Fix: mark as trusted only address ranges your organisation exclusively controls, prefer device or authentication strength conditions to network ones, and review named locations in the same change process as policies. Test any change in report-only mode first, as Microsoft advises for new policies. See the Conditional Access Guide.
Trust policy answers
- Exercise 8 (AWS): two flaws. The first statement lets any AWS principal call
sts:AssumeRole; AWS documentation strongly recommends against a wildcard principal in role trust policies "because they allow other principals to become a principal in your account" and adds "Do not leave your role accessible to everyone!". The second statement allows every repository in the organisation, including test and personal-fork style repositories, to deploy. AWS recommendsStringEqualswith a specificsubwherever possible and keepingStringLikepatterns as narrow as you can. Fix: delete the wildcard statement (or replace it with a named account principal plus conditions) and pin the subject, for examplerepo:example-org/payments-api:environment:production. See the AWS IAM Policies and Roles Guide and How to review AWS cross-account trust policies for confused deputy. - Exercise 9 (Google Cloud): Google Cloud requires an attribute condition restricting tokens to your GitHub organisation, because GitHub uses a single issuer for all organisations. This condition exists but relies on the repository name, and Google warns that name-based claims increase the chance of cybersquatting and typosquatting, recommending the numeric
*_idclaims, which cannot be reused. The binding also uses the/*principalSet, so every identity in the pool can impersonate the deployer. Fix: map and condition onassertion.repository_owner_id(and the ref where relevant), and bindroles/iam.workloadIdentityUserto a specificattribute.principalSet for the one repository that deploys. See the Google Cloud IAM and Service Accounts Guide. - Exercise 10 (Microsoft Azure): Microsoft Entra matches the issuer, subject and audience exactly, with one credential per branch or tag, which makes the subject the main control. The
pull-requestsubject matches workflows running on pull requests, which typically run code that has not yet been reviewed, so it should not unlock a production deployer. Fix: use an environment subject such asrepo:example-org/payments-api:environment:Production, protect that environment with required reviewers and deployment branch rules, and give pull request workflows a separate, read-only identity. See the Azure RBAC and Service Principals Guide and the GitHub Actions OIDC Federation Hardening Guide.
Detection and framework mapping
Each flaw has a matching signal: tokens accepted with an unexpected aud or typ (log both claims at the API gateway); Conditional Access exclusion group membership changes and sign-ins evaluated as "not applied"; AssumeRole or AssumeRoleWithWebIdentity events in AWS CloudTrail from unfamiliar accounts or subjects; Google Cloud STS token exchanges from unexpected subjects in Cloud Audit Logs; and Entra service principal sign-ins through federated credentials from unexpected subjects. Abuse of these flaws typically shows up as use of valid cloud accounts (ATT&CK T1078.004) or application access tokens (T1550.001).
| Framework | Reference | Exercises |
|---|---|---|
| OWASP ASVS 5.0 | V9.1.1, V9.1.2, V9.2.2, V9.2.3, V10.3.1 | 1 to 4 |
| NIST SP 800-53 Rev. 5 | IA-2, AC-3 | 1 to 7 |
| NIST SP 800-53 Rev. 5 | AC-6 Least Privilege | 5, 8, 9, 10 |
| NIST CSF 2.0 | PR.AA-01, PR.AA-05 | All |
| MITRE ATT&CK | T1078.004 Cloud Accounts; T1550.001 Application Access Token | 3, 4, 8 to 10 |
Practitioner checklist
- Check every API's token validation for issuer, audience, algorithm allowlist, expiry and token type, in code review and in automated tests that present wrong-audience and wrong-type tokens.
- In multi-tenant apps, validate the issuer against an allowlist of onboarded tenants and bind tenant IDs server-side.
- List every Conditional Access exclusion, its owner and reason; keep only break-glass and sync accounts in baseline exclusions and alert on changes.
- Cover service principals with Conditional Access for workload identities or move them to managed identities.
- Mark as trusted only network ranges you exclusively control, and test policy changes in report-only mode.
- Search role trust policies for
"AWS": "*"and forStringLikesubjects ending in/*. - Require attribute conditions on immutable numeric IDs in Google Cloud workload identity providers and avoid whole-pool principalSet bindings.
- Use protected environment subjects for production federated credentials and separate identities for pull request workflows.
Standards and references
- IETF: RFC 8725 JSON Web Token Best Current Practices
- IETF: RFC 9700 Best Current Practice for OAuth 2.0 Security
- AWS: IAM JSON policy elements: Principal
- AWS: Create a role for OpenID Connect federation
- Google Cloud: Configure Workload Identity Federation with deployment pipelines
- Microsoft Learn: Require MFA for all users with Conditional Access
- Microsoft Learn: Configure an app to trust an external identity provider
- Microsoft Learn: Workload identity federation
Related NHI Mgmt Group resources: OAuth 2.0 and OpenID Connect Guide · OAuth 2.0 Security Best Current Practice (RFC 9700) Guide · JWT Security Guide · Cross-cloud workload identity federation