azure-containerapps-execute-as-via-exec
Exec into a running replica + the app runs as an MI => execute as that MI (read the identity endpoint from the shell).
match
A conjunctive graph pattern. Variables (?x) bind node ids; every clause must hold.
where
node_type(?app) in [
ContainerService, BatchJob]
?mi.privilege_level > ?principal.privilege_level # strict escalation only (equal-privilege lateral excluded)
?mi reachable from the exec'd container/job execution (identitySettings.lifecycle in [All, Main] or unset)
optional
Present → upgrade the emitted state; absent → downgrade (not a hard requirement).
{'principal': None}
CanTrigger {'app': None}
emit
| source type | Identity |
|---|---|
| target type | Identity |
| source | <principal> |
| target | <managed identity> |
| permissions | Microsoft.App/containerApps/exec/action |
| state logic | if ?app has a running replica: ACTIVE elif matched(optional[0]): ACTIVE # attacker can trigger scale-up else: CONDITIONAL(service_state) |
Narrative
{principal.name} can shell into a running replica of {app.name} (exec/action) and mint the token of its identity {mi.name} from $IDENTITY_ENDPOINT, executing as {mi.name}.
Raw rule rules/derived/azure/containerapps.yaml
id: azure-containerapps-execute-as-via-exec
emits: CanExecuteAs
description: Exec into a running replica + the app runs as an MI => execute as that MI (read the identity
endpoint from the shell).
match:
- - principal: null
- CanExecuteCommand
- app: null
- - app: null
- ExecutesAs
- mi: null
where:
- node_type(?app) in [ContainerService, BatchJob]
- '?mi.privilege_level > ?principal.privilege_level # strict escalation only (equal-privilege lateral
excluded)'
- ?mi reachable from the exec'd container/job execution (identitySettings.lifecycle in [All, Main] or
unset)
optional:
- - principal: null
- CanTrigger
- app: null
emit:
source_type: Identity
target_type: Identity
source: <principal>
target: <managed identity>
state_logic: 'if ?app has a running replica: ACTIVE
elif matched(optional[0]): ACTIVE # attacker can trigger scale-up
else: CONDITIONAL(service_state)
'
conditions_from:
- app: null
- mi: null
permissions:
- Microsoft.App/containerApps/exec/action
derived_from:
- <CanExecuteCommand edge_id>
- <ExecutesAs edge_id>
false_positive_note: Requires the exec DATA ACTION (not Contributor) AND a running replica; scaled-to-zero
-> CONDITIONAL(service_state). Escalation only if the MI out-privileges the caller and is reachable
from the container.
narrative: '{principal.name} can shell into a running replica of {app.name} (exec/action) and mint the
token of its identity {mi.name} from $IDENTITY_ENDPOINT, executing as {mi.name}.'