The Simplest Way to Make Azure Functions and Keycloak Work Like They Should
Teams pair azure functions and keycloak to check user logins before serverless code runs. This setup lets an external identity server control who can trigger your cloud tasks. You keep user accounts in one open source system. At the same time, you run short tasks on Microsoft cloud servers. This saves money and keeps login rules in one central place. How azure functions and keycloak share login data The workflow starts when a user logs into your app. Keycloak checks their name and password a
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 azure functions and keycloak to check user logins before serverless code runs. This setup lets an external identity server control who can trigger your cloud tasks.
You keep user accounts in one open source system. At the same time, you run short tasks on Microsoft cloud servers. This saves money and keeps login rules in one central place.
How azure functions and keycloak share login data
The workflow starts when a user logs into your app. Keycloak checks their name and password against your user list. When the check passes, the server issues a signed JSON token.
That token holds user details, group names, and app roles. Next, the client app sends a web request to your cloud function. It puts the signed token inside the request header.
Before the function runs business logic, it must check that token. Your cloud setup reads public keys from your identity server URL. It uses those keys to check the token signature and expiration time.
If the token is fake or old, the function stops right away. If the token is good, the code reads the roles inside it. Then the function knows who called it and what they can do.
Common failure modes and how to scope roles
Many teams make mistakes when they link these two tools. A common trap is using one shared service account for all calls. When every app uses one token, your logs lose user details.
You cannot tell which person or job ran a specific function. Another risk comes from tokens that have too many rights. If a token grants admin rights everywhere, one leaked key breaks everything.
Long token lifetimes also create big security gaps for your team. If a token lasts for days, you cannot block a user fast. You can fix these issues with strict role and network rules.
Keycloak + Azure RBAC: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
First, create separate client entries in your identity server for each app. Give each function its own audience tag inside the token payload. Your function should reject any token that lacks its exact audience tag.
Keep token life short so stolen keys expire in a few minutes. Next, lock down the network paths between your cloud and identity servers. Put your identity server behind a strict firewall with clear rules.
Allow token check traffic only from your known cloud outbound addresses. Finally, log every login check and role failure in a central store. Write down the user ID, the function name, and the timestamp.
Handling background tasks and database data
Not every cloud task starts from a human clicking a button. Many functions run on a timer or read from a work queue. For these jobs, your function acts as its own client app.
It asks the identity server for a machine token before it starts. This keeps background jobs inside the same rule system as human users. When your code reads database rows, watch out for private data.
Data masking rewrites matched fields in results, like emails or phone numbers. You can also mask card numbers and national IDs in query output. This step keeps raw private strings out of your function logs.
Govern statements and responses across databases and APIs
Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev runs beside each supported service as an open-source proxy, a sidecar for your database or API.
First, hoop.dev guardrails block banned queries before they run. Then hoop.dev data masking rewrites matched sensitive values in responses in memory. The audit trail records every statement and verdict per resource. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.
Frequently asked questions
Where should token checks happen in Azure?
You can check tokens inside your function code or through platform login settings. Platform checks block bad requests before your code even starts up. Code checks give you finer control over custom role rules.
How do functions handle key rotation from Keycloak?
Keycloak publishes its active public keys at a standard web endpoint. Your cloud app fetches and caches this key list on a set schedule. When keys rotate, the function pulls the new key without manual work.
Can a timer function log into Keycloak on its own?
Yes, a timer function can use a client ID and secret to log in. It trades those keys for a short-lived token before calling other internal APIs. Store that client secret in a secure cloud vault, not in code.
Related guides
In this post