azure-func-execute-as-via-code
Code modification on a Function app + the app runs as an MI => execute as that MI (via the identity endpoint).
match
A conjunctive graph pattern. Variables (?x) bind node ids; every clause must hold.
where
node_type(?app) in [
ServerlessFunction, ApplicationPlatform]
?mi.privilege_level >= ?principal.privilege_level # escalation only
optional
Present → upgrade the emitted state; absent → downgrade (not a hard requirement).
{'principal': None}
CanInvoke {'app': None}
emit
| source type | Identity |
|---|---|
| target type | Identity |
| source | <principal> |
| target | <managed identity> |
| permissions | Microsoft.Web/sites/functions/write | extensions/write | sourcecontrols/Write |
| state logic | if matched(optional[0]) or trigger_exists(?app): ACTIVE else: CONDITIONAL(trigger_exists) |
Narrative
{principal.name} can overwrite code on {app.name} and, on trigger/invoke, mint the token of its identity {mi.name} from the App Service identity endpoint, executing as {mi.name}.
Raw rule rules/derived/azure/functions.yaml
id: azure-func-execute-as-via-code
emits: CanExecuteAs
description: Code modification on a Function app + the app runs as an MI => execute as that MI (via the
identity endpoint).
match:
- - principal: null
- CanModifyCode
- app: null
- - app: null
- ExecutesAs
- mi: null
where:
- node_type(?app) in [ServerlessFunction, ApplicationPlatform]
- '?mi.privilege_level >= ?principal.privilege_level # escalation only'
optional:
- - principal: null
- CanInvoke
- app: null
emit:
source_type: Identity
target_type: Identity
source: <principal>
target: <managed identity>
state_logic: 'if matched(optional[0]) or trigger_exists(?app): ACTIVE
else: CONDITIONAL(trigger_exists)
'
conditions_from:
- app: null
- mi: null
permissions:
- Microsoft.Web/sites/functions/write | extensions/write | sourcecontrols/Write
derived_from:
- <CanModifyCode edge_id>
- <ExecutesAs edge_id>
false_positive_note: Emit only when the app has a managed identity and that MI out-privileges the caller.
No trigger and no CanInvoke -> CONDITIONAL(trigger_exists). Stopped app w/o CanStart -> CONDITIONAL(service_state).
narrative: '{principal.name} can overwrite code on {app.name} and, on trigger/invoke, mint the token
of its identity {mi.name} from the App Service identity endpoint, executing as {mi.name}.'