The Simplest Way to Make Keycloak and Step Functions Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

You link keycloak and step functions to run cloud jobs with real user identities. Keycloak checks who the user is, and Step Functions runs the multi-step cloud workflow. Teams use this setup to start background jobs from web apps or internal tools. A user logs in once, and that identity carries into the cloud workflow run. You get clear logs of who started each job and why it ran. You also avoid hardcoding cloud keys inside your client apps or frontend code. How identity flows between keycloa

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.

You link keycloak and step functions to run cloud jobs with real user identities. Keycloak checks who the user is, and Step Functions runs the multi-step cloud workflow.

Teams use this setup to start background jobs from web apps or internal tools. A user logs in once, and that identity carries into the cloud workflow run. You get clear logs of who started each job and why it ran. You also avoid hardcoding cloud keys inside your client apps or frontend code.

How identity flows between keycloak and step functions

The flow starts when a user or service logs in to your Keycloak realm. Keycloak checks the credentials and returns a signed token with user roles and groups. This token proves the user identity and holds claims about what they can do.

Step Functions runs on AWS and uses AWS IAM to check every call. Because of this, you must map your Keycloak token to an AWS IAM role. You set up Keycloak as an OpenID Connect provider inside your AWS account. When a user sends a token, AWS checks the signature against your Keycloak keys. If the check passes, AWS gives out temporary credentials for a matching IAM role.

Your app then uses those temporary credentials to start the Step Functions state machine. You can also pass user details like email or group into the job input. Each step in the workflow can read those details to make clear routing choices. For example, a high-cost step can pause and wait for a manager approval.

Common failure modes and how to scope roles

Many teams make the mistake of using one shared service account for all runs. Every user logs in to Keycloak, but the backend uses one static AWS key. When a workflow changes data, the cloud logs only show the shared backend account. You lose the trail back to the human who actually asked for the job.

Broad tokens and wide IAM roles cause another common problem in production systems. If one IAM role can start any state machine, any user can trigger sensitive jobs. You should split your IAM roles by team or by job risk level. Use token claims from Keycloak to pick the exact IAM role a user gets. A support user should only trigger support workflows, not billing or database cleanup jobs.

Keycloak + Cloud Functions IAM: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Long token lifetimes also create risk when jobs run for hours or days. Keep your Keycloak access tokens short so stolen tokens expire fast. Let the state machine use its own scoped execution role for the inner steps. That execution role should only touch the exact queues and functions the job needs.

Keeping workflow data and logs clean

State machines pass JSON payloads from one step to the next during a run. AWS records these payloads in the execution history so teams can debug failed runs. If you pass raw user data into the input, that data sits in logs.

Be careful when workflows handle emails, phone numbers, card numbers, or national IDs. Pass only the record ID when you can, and fetch sensitive fields inside steps. If a step must return personal data, use masking to rewrite matched fields in results. This keeps your state machine history clean while engineers fix broken workflow steps.

You should also check network paths between your cloud steps and your Keycloak server. If a task step calls Keycloak to verify a user state, use private networking. Put your compute tasks in private subnets and limit outbound calls with security groups.

Check database and API queries on the wire

Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev runs beside those services as an open-source proxy, a sidecar for your Postgres or API. It inspects requests coming in and results going back on the wire.

Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run. On responses, hoop.dev data masking rewrites matched sensitive values in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.

Frequently asked questions

Can Step Functions call Keycloak directly during a workflow run?

Yes, a state machine can make HTTPS calls or run a task to query Keycloak. Teams do this to check if a user account is still active before finishing.

How do we know which Keycloak user started a state machine?

Pass the Keycloak user ID as the role session name when getting AWS credentials. You can also include the user email inside the state machine input payload.

What happens if a Keycloak token expires while a workflow is waiting?

Once the state machine starts, it runs under its own AWS IAM execution role. An expired user token will not stop a workflow that is already running.

The query runs. The emails stay hidden.