azure-appsvc-execute-as-via-deploy

Code/config modification on a site + the site runs as an MI => execute as that MI (via the MSI token endpoint).

derived azure emits CanExecuteAs

match

A conjunctive graph pattern. Variables (?x) bind node ids; every clause must hold.

{'principal': None} CanModifyCode {'site': None} {'site': None} ExecutesAs {'mi': None}

where

node_type(?site) == ApplicationPlatform ?mi.privilege_level >= ?principal.privilege_level # escalation only

optional

Present → upgrade the emitted state; absent → downgrade (not a hard requirement).

{'principal': None} CanStart {'site': None}

emit

source typeIdentity
target typeIdentity
source<principal>
target<managed identity>
permissionsMicrosoft.Web/sites/publish/action | config/write | extensions/write | sourcecontrols/write | functions/write
state logicif ?site running: ACTIVE elif matched(optional[0]): ACTIVE # attacker can start/restart it else: CONDITIONAL(service_state)

Narrative

{principal.name} can deploy/modify code on {site.name} and mint the token of its identity {mi.name} from the App Service MSI endpoint, executing as {mi.name}.

Raw rule rules/derived/azure/appservice.yaml

id: azure-appsvc-execute-as-via-deploy
emits: CanExecuteAs
description: Code/config modification on a site + the site runs as an MI => execute as that MI (via the
  MSI token endpoint).
match:
- - principal: null
  - CanModifyCode
  - site: null
- - site: null
  - ExecutesAs
  - mi: null
where:
- node_type(?site) == ApplicationPlatform
- '?mi.privilege_level >= ?principal.privilege_level   # escalation only'
optional:
- - principal: null
  - CanStart
  - site: null
emit:
  source_type: Identity
  target_type: Identity
  source: <principal>
  target: <managed identity>
  state_logic: 'if ?site running: ACTIVE

    elif matched(optional[0]): ACTIVE   # attacker can start/restart it

    else: CONDITIONAL(service_state)

    '
  conditions_from:
  - site: null
  - mi: null
  permissions:
  - Microsoft.Web/sites/publish/action | config/write | extensions/write | sourcecontrols/write | functions/write
  derived_from:
  - <CanModifyCode edge_id>
  - <ExecutesAs edge_id>
  false_positive_note: Emit only when the site has a managed identity and that MI out-privileges the caller.
    On a stopped app without CanStart -> CONDITIONAL(service_state). CanModifyConfiguration (startup command)
    also satisfies this via the same fixpoint.
  narrative: '{principal.name} can deploy/modify code on {site.name} and mint the token of its identity
    {mi.name} from the App Service MSI endpoint, executing as {mi.name}.'
move · open · esc close