A Caller keyword tests the identity making the request¶
Context and Problem Statement¶
Azure Policy can test who makes a request, not just what it asks for, through requestContext().identity (Learn: using request context identity, updated 2026-07-08; Tech Community, 2026-11-05). A claim is read with tryGet(requestContext().identity, '<claim>'), in a value condition:
{ "value": "[tryGet(requestContext().identity, 'appid')]", "notIn": "[parameters('allowedClientAppIds')]" }
Learn lists these claims, "at a high level", so not necessarily all of them:
| Claim | Meaning |
|---|---|
idtyp |
The caller's type: app, user, or null |
appid |
The client application's ID |
acrs |
Authentication context class references, comma-separated (such as p1 for a step-up policy) |
http://schemas.microsoft.com/identity/claims/objectidentifier |
The caller's object ID, a user or service principal |
Learn's other points:
- Enforcement at request time applies to
deny,modifyanddeployIfNotExists. The blog also usesdenyAction. - Compliance scans of such a policy are marked
NotApplicable. - Claims can be missing, which is why
tryGetis used. It then returns null. - Neither page says whether the feature is in preview or generally available.
Bylaw can already write this, since Arm can be piped to Must (ADR-0025):
Arm "[tryGet(requestContext().identity, 'appid')]" | Must -BeIn (Param AllowedClientAppIds)
That compiles to Learn's example exactly (checked 2026-11-28). But the expression and the object ID claim's URI are hard to read, and two behaviours are easy to get wrong without help from the compiler:
- A missing claim. In a
Require,Must -BeInis inverted tonotIn, which is true for null, so a request without the claim is denied. That is usually the safe outcome, but nothing in the source says so, unlike a missing field, where the author chooses with-IfPresent(ADR-0003, ADR-0004). - Effects and compliance. Under
AuditorAuditIfNotExiststhe policy never reports anything, and its compliance state is alwaysNotApplicable.
Should Bylaw have a keyword for the caller's identity, and how should a missing claim behave?
Decision Drivers¶
- Reads like the rest of the language:
Caller AppId | Must -BeIn (Param AllowedClientAppIds). - A missing claim behaves as the author intends, and the source shows it.
- The checks Azure can't do at authoring time are done at build time.
- Claims Learn doesn't list yet can still be used.
ConvertTo-Bylawcan write the keyword back from the JSON (ADR-0039).
Considered Options¶
- A
Callervalue keyword, with named claims and-Claimfor others - Document the
Armpattern only - A
Callerblock that holds the identity conditions, likeWhen
Proposed Outcome¶
Proposed option: "A Caller value keyword, with named claims and -Claim for others", to be revisited and accepted before work starts.
Resource *
Require 'Only approved apps write resources' {
Caller AppId | Must -BeIn (Param AllowedClientAppIds)
}
Effect Deny
Caller Type,Caller AppIdandCaller ObjectIdemit[tryGet(requestContext().identity, '<claim>')]with the claim's name.Caller AuthContextis a list,[split(tryGet(requestContext().identity, 'acrs'), ',')], tested withMust -Contain 'p1'.Caller -Claim '<name>'covers other claims.- It works in
RequireandWhen, likeResourceGroupTag(ADR-0025). - Questions to settle before accepting:
- Missing claims. Should a missing claim be a violation by default, as for a strict field, with
-IfPresentto allow requests without it? Or the other way round? What doessplitdo with a nullacrs? That needs checking in a sandbox, like ADR-0004's truth table. - Effects. Error or warning for
Audit,AuditIfNotExists,ManualandAppend? IsdenyActionreally supported (Learn's list doesn't include it; the blog uses it)? - Compliance. Should every policy that uses
Callerget a warning that its compliance state will beNotApplicable, or should that be documented only? - Values. Should
Caller Typetake onlyuserandapp? - Preview. Is the feature in preview? If so, warn, as for Modify on array elements (BYL3075).
- Out of scope:
resourceSelectors,overrides,enforcementModeand identity-based exemptions, which belong to assignments and exemptions, not definitions. Bylaw doesn't write those; EPAC does.
Consequences¶
- Good, because identity rules read as plainly as resource rules, and their pitfalls are caught at build time.
- Neutral, because the
Armform keeps working, andConvertTo-Bylawcan turn it intoCaller. - Bad, because the claim list may change, and the keyword has to keep up.
Confirmation¶
Unit and golden tests for each claim, the missing-claim behaviour and the effect checks. A sandbox run to confirm the missing-claim and split behaviour, recorded in this ADR.
Pros and Cons of the Options¶
Document the Arm pattern only¶
- Good, because it needs no new language.
- Bad, because the missing-claim behaviour stays implicit, and nothing warns about effects or compliance.
A Caller block that holds the identity conditions, like When¶
- Good, because it groups identity conditions visibly.
- Bad, because identity conditions belong in
RequireandWhenalongside resource conditions, as Learn's examples combine them, and a block of its own would need its own inversion rules.
More Information¶
- ADR-0025 (value conditions), ADR-0003 and ADR-0004 (missing fields), ADR-0017 (DenyAction), ADR-0039 (ConvertTo-Bylaw)