Kontakt os

Easy Auth Ate My Events: excludedPaths for Event Grid Delivery

My mail pipeline was humming along: Graph notifications through an Event Grid partner topic, into an Azure Function, alerts armed in case anything dead-lettered. Then I did something completely reasonable: I turned on App Service Authentication - Easy Auth - on the function app, because it also hosts HTTP endpoints that should require a signed-in user.

The mail stopped.

Not with a bang, either. The functions were healthy, the topic was receiving events, and delivery was quietly failing with 401s. My own early-warning alert didn’t fire, because the handler was never invoked - the requests died at the front door. Event Grid, to its credit, kept retrying. That 24-hour retry window was now a 24-hour countdown to dead-letters.

Easy Auth Guards Every Door, Including Event Grid’s

Easy Auth doesn’t run inside your app. It’s middleware in front of the entire app: every incoming request gets checked against globalValidation, and with “require authentication” on, anything without a valid identity is rejected before your code, or even the Functions host, gets a look.

That “everything” includes the runtime’s own webhook endpoints. An Event Grid trigger isn’t magic; under the hood, the Event Grid subscription delivers events as HTTPS POSTs to:

https://<function-app>.azurewebsites.net/runtime/webhooks/eventgrid?functionName=MailEventHandler&code=<system-key>

Event Grid authenticates itself with that code query parameter, a system key the Functions host validates. But Easy Auth checks for a user or app identity token, which Event Grid doesn’t have and won’t send. 401, before the system key is ever considered.

The two auth systems don’t compose. Easy Auth wins, and your events lose.

The Fix: excludedPaths in authsettingsV2

Easy Auth supports excluding specific paths from globalValidation - requests to those paths skip the identity check and flow through to the app. Exactly one path needs it: the Event Grid webhook endpoint.

The catch: excludedPaths isn’t in the portal UI. It lives in the authsettingsV2 configuration, which you edit over the ARM API. Four commands:

SITE="/subscriptions/<subscription-id>/resourceGroups/rg-my-app/providers/Microsoft.Web/sites/func-mail-handler"

# 1. Read the current auth settings
az rest --method GET \
  --url "https://management.azure.com$SITE/config/authsettingsV2/list?api-version=2022-03-01" > auth.json

# 2. Add the excluded path
jq '.properties.globalValidation.excludedPaths = ["/runtime/webhooks/eventgrid"]' auth.json > auth-new.json

# 3. Write the settings back
az rest --method PUT \
  --url "https://management.azure.com$SITE/config/authsettingsV2?api-version=2022-03-01" \
  --body @auth-new.json

And verify it stuck:

az rest --method GET \
  --url "https://management.azure.com$SITE/config/authsettingsV2/list?api-version=2022-03-01" \
  | jq '.properties.globalValidation'

What’s happening here?

  1. authsettingsV2 is the full Easy Auth configuration as an ARM sub-resource of the site. The /list endpoint returns the whole document, secrets and all - that’s why reading it is its own endpoint.
  2. The jq line is the entire change: one array with one path on globalValidation.excludedPaths. Everything else in the document goes back exactly as it came, which is why the read-modify-write shape matters. Don’t hand-craft a partial body; you’ll clobber settings you didn’t mean to touch.
  3. The PUT replaces the auth configuration with your edited copy. It takes effect on new requests without a restart.
  4. The verify step should show your path in excludedPaths. If you had failing deliveries piling up, watch them recover on the next retry - Event Grid was retrying the whole time, so the backlog delivers itself once the door opens.

If you edit excludedPaths again later, mind that jq assignment: it overwrites the array. Append with += ["/new/path"] instead when there’s already something in it.

Wait, Did I Just Disable Auth on My Webhook?

No, and this is the part worth being precise about. Excluding the path from Easy Auth doesn’t make it anonymous; it hands authentication back to the layer that was designed for it. The Functions host still requires the Event Grid system key in the code query parameter, and requests without a valid key get rejected by the host itself. The key was minted when the event subscription was created and is validated on every single delivery.

So the security model after the fix is: every route on the app goes through Easy Auth, except one path that requires a per-app secret key instead of an identity token. That’s not a hole, that’s two locks on two doors instead of one lock covering a door it was never meant to fit.

What you should not do is get frustrated and exclude broad paths like /api/* or /runtime/* to make errors go away. Every excluded path is a path where Easy Auth no longer protects anything, and anything under it had better carry its own auth. One precise path, no wildcards you can’t justify.

Gotchas

  • This failure is silent from inside the app. No function invocation, no exception, no Application Insights trace - the request never reaches the host. If your monitoring only watches the handler, add the event subscription’s delivery metrics to the list. My failure alert saw nothing; the delivery-failure count on the subscription saw everything.
  • Event Grid’s retries buy you a day. Deliveries that failed with 401 retry for ~24 hours, so if you catch the mistake in time, no events are lost. The moment the fix lands, the backlog drains on its own. This saved me.
  • The portal won’t show you excludedPaths. Toggling Easy Auth settings in the portal can also rewrite authsettingsV2 - re-run the verify command after portal changes to confirm your exclusion survived.
  • Local development is unaffected. Easy Auth only exists in Azure; localhost:7071 has no front door. Which also means this bug is invisible locally and only appears after deploy. The staging slot earns its keep here.

Wrapping Up

Easy Auth guards the whole app, including the /runtime/webhooks/eventgrid endpoint that Event Grid delivers to, and Event Grid can’t do identity tokens - so deliveries 401 until you exclude that one path via authsettingsV2. The path stays locked by its own system key. Rule of thumb: when two auth layers stack, make sure each endpoint is judged by the lock that fits it, and punch exclusions one precise path at a time.

If you’re earlier in this than debugging a 401, What Is Azure Event Grid (and Why I Don’t Poll) covers why the events are arriving at a Function at all.

Pinksky bruger cookies for at forbedre funktionaliteten på denne hjemmeside. Du bestemmer selv hvad vi må bruge. Læs mere i vores cookiepolitik.