auth
azure_bootstrap.auth
¶
Webhook + API-key authentication helpers.
Modules:
| Name | Description |
|---|---|
api_key |
API-key header verification helper. |
hmac |
HMAC signature verification for webhooks. |
webhook |
Microsoft-Graph-style webhook authentication helpers. |
Classes:
| Name | Description |
|---|---|
WebhookDedup |
In-process dedup keyed on caller-supplied tuples. |
Functions:
| Name | Description |
|---|---|
verify_api_key_header |
FastAPI dependency. Raises |
verify_hmac_signature |
Constant-time HMAC-SHA256 verify (GitHub/Sumo |
install_graph_webhook_route |
Register a Graph-flavored webhook route on the FastAPI app. |
validation_token_handshake |
Graph subscription-validation handshake — echo the token, or None. |
verify_webhook_client_state |
Constant-time comparison of received clientState against the configured value. |
WebhookDedup
¶
WebhookDedup(*, ttl_seconds: float = _DEFAULT_DEDUP_TTL_SECONDS, max_entries: int = _DEFAULT_DEDUP_MAX_ENTRIES)
In-process dedup keyed on caller-supplied tuples.
Thread-safe (single threading.Lock). Entries older than ttl_seconds
are GC'd on every check; total entries capped at max_entries.
Methods:
| Name | Description |
|---|---|
reset |
Test-only. Refuses unless AZURE_BOOTSTRAP_ALLOW_RESET=1. |
Source code in azure_bootstrap/auth/webhook.py
reset
¶
Test-only. Refuses unless AZURE_BOOTSTRAP_ALLOW_RESET=1.
Source code in azure_bootstrap/auth/webhook.py
verify_api_key_header
async
¶
verify_api_key_header(x_api_key: str | None, *, env_var: str = 'API_KEY', fail_open_when_unset: bool = True) -> None
FastAPI dependency. Raises HTTPException(401) on mismatch.
When fail_open_when_unset is True (default) and the env var is unset
or empty, the check passes — matches the v1 reference behavior. Strict
mode (env required) is opt-in via fail_open_when_unset=False.
Imports FastAPI lazily so this module is importable without the fastapi
extra; only callers that actually invoke the function pay the dep.
Source code in azure_bootstrap/security/__init__.py
verify_hmac_signature
¶
verify_hmac_signature(secret: str, raw_body: bytes, header_value: str, *, prefix: str = 'sha256=') -> bool
Constant-time HMAC-SHA256 verify (GitHub/Sumo sha256=… style).
Parameters¶
secret:
Shared signing secret.
raw_body:
Raw request body bytes (must not be re-serialized JSON).
header_value:
Value of the signature header (may include sha256= prefix).
prefix:
Expected algorithm prefix in the header value.
Source code in azure_bootstrap/auth/hmac.py
install_graph_webhook_route
¶
install_graph_webhook_route(app: Any, path: str, *, background_handler: Callable[[str], None], rate_limit_bucket: Any | None = None, dedup: WebhookDedup | None = None, counter_namespace: str = 'webhook') -> None
Register a Graph-flavored webhook route on the FastAPI app.
Pipeline order: validation token → rate limit → JSON parse → per-entry clientState → dedup → background dispatch → 202 Accepted.
Source code in azure_bootstrap/auth/webhook.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | |
validation_token_handshake
¶
Graph subscription-validation handshake — echo the token, or None.
Source code in azure_bootstrap/auth/webhook.py
verify_webhook_client_state
¶
verify_webhook_client_state(received_client_state: str | None, *, env_var: str = 'GRAPH_WEBHOOK_CLIENT_STATE') -> bool
Constant-time comparison of received clientState against the configured value.
Raises :class:ConfigurationError when env_var is unset — the webhook
endpoint MUST be configured before accepting any requests.