The Simplest Way to Make Cloud Functions and Microsoft Entra ID Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

Teams pair cloud functions and microsoft entra id to verify users and run serverless jobs. This setup lets apps check user tokens before running backend tasks or reading databases. In production, a client app signs in through the directory first. The directory issues a signed token with user claims and group details. The client sends this token with an HTTP request to the serverless function. The function checks the token signature and reads the user role before running logic. How cloud funct

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

Teams pair cloud functions and microsoft entra id to verify users and run serverless jobs. This setup lets apps check user tokens before running backend tasks or reading databases.

In production, a client app signs in through the directory first. The directory issues a signed token with user claims and group details. The client sends this token with an HTTP request to the serverless function. The function checks the token signature and reads the user role before running logic.

How cloud functions and microsoft entra id exchange tokens and roles

The link between cloud functions and microsoft entra id relies on standard web tokens. You register the serverless app inside your directory tenant to start. This registration gives the function a unique app ID and a set of rules.

You can also define custom app roles inside the directory for different team needs. Users or client services get assigned to these roles based on their job. When a user logs in, the directory puts their assigned roles inside the token.

The serverless function reads the incoming request header to find this token. The function fetches public keys from the directory to check the token signature. It also checks that the token matches the right app ID and tenant ID. If the checks pass, the function runs its code using those role permissions.

Sometimes the function must call another API or database on its own. In that case, the function uses a federated identity instead of a saved secret. The cloud platform trades its local identity token for a directory token at runtime. This flow avoids putting static client secrets inside your function settings.

Common failure modes and how to scope roles

Many teams make mistakes when they link serverless code to an identity directory. A common flaw is using one shared service account for every function. When every function shares one identity, you cannot tell which job ran a query. If an attacker steals that shared key, they gain broad reach across your systems.

Microsoft Entra ID (Azure AD) + Cloud Functions IAM: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Another common issue is granting broad directory permissions to a single function. Teams often give read and write rights across the whole tenant to save time. Instead, you should scope each function to the exact resource it needs to do its job. Give each function its own distinct identity and limit its role assignments.

Long-lived client secrets stored in function settings also create high risk for teams. People forget to rotate these keys, or they leak them in build logs. Workload identity federation fixes this by removing static secrets from the setup. The directory trusts the cloud provider token and issues a short token on demand.

Unlogged database queries and API calls create another blind spot during security audits. A function might check the user token at the start of the request. Then it connects to a database using a single shared database user name. At that point, the database log only shows the shared function account name.

To fix this, pass user identity claims into your audit logs for every step. You should also restrict network paths between the serverless runtime and your backend stores. Place functions inside a private virtual network whenever they talk to internal data stores. Use strict firewall rules so only specific function identities can reach sensitive ports.

When Functions process personal data, masking rewrites matched fields like emails or card numbers. Masking also rewrites phone numbers and national IDs in query results to protect privacy. Combining narrow network paths, distinct roles, and clear logs keeps serverless workflows safe.

Add runtime guardrails and masking beside your databases and APIs

Login rules, role grants, and CI checks govern who connects to your stack. Yet any allowed script, engineer, or AI agent still runs commands with the full scope of its role. For workloads on Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes, SSH, or internal HTTP services, hoop.dev sits beside the service as an open-source proxy, a sidecar for your database or API.

Before a query runs, hoop.dev guardrails check the statement against your rules. An AI Analyzer you configure can score intent or hold risky calls for human review. Next, hoop.dev data masking rewrites sensitive fields in responses, and each verdict is logged per listener. Explore the MIT-licensed project on GitHub.

Frequently asked questions

How does a cloud function check a Microsoft Entra ID token?

The function reads the bearer token from the request header and checks its signature. It uses public keys from the directory and verifies the audience and issuer claims.

Can cloud functions talk to Microsoft Entra ID without storing client secrets?

Yes, you can set up workload identity federation between your cloud provider and the directory. The function trades its native cloud token for a directory token at runtime.

Why should each function have its own app registration or managed identity?

Separate identities let you grant minimal permissions for each task and track activity clearly. If one function fails or gets compromised, other workloads stay isolated and safe.

The query runs. The emails stay hidden.