Enforcing security profiles with Keycloak client policies

Client policies let you apply security requirements such as PKCE, confidential client rules, PAR, DPoP or signed requests to groups of Keycloak clients at once. This page explains how the feature works, how to configure it, and what to confirm before you rely on it.

On this page

Why enforce security profiles with Keycloak client policies instead of client by client

A Keycloak realm with many clients usually drifts. Each client was created at a different time, by a different person, with different redirect URIs, PKCE settings and client authentication methods, so the security posture of the realm is only as good as its weakest client. Keycloak client policies let you define a security rule once and have it apply to every client that matches. Teams need them as soon as the number of clients makes manual review unreliable, or when a new requirement, such as mandatory PKCE or confidential client authentication, must reach existing applications without editing each one.

The Keycloak server administration guide separates two parts of the feature. A client profile is a named set of executors, where each executor is a single rule, such as requiring PKCE or enforcing a client authentication method. A client policy holds conditions that decide which clients a profile applies to, such as the client's role, its access type or the client scope it requests. Profiles say what must be true, and policies say to whom. Keep this split in mind when you design the realm, because a profile that no policy references does nothing, and a broad condition can pull in clients you did not intend to change.

You configure client policies in the admin console, and you can also manage them as configuration so that changes are reviewed and version controlled. The available executors and their options depend on the Keycloak version you run, and some behavior has changed between releases, so confirm the executor list and each option against the documentation for your exact version before you write the design. Before any policy goes live, test it against a copy of your realm and list the clients it will affect. Expect some existing applications to fail their next login, because a policy that requires PKCE or a stronger client authentication method will reject flows the application currently uses.

Which profile or executor fits which client group

This table compares the security requirements teams most often enforce through client policies, against the client types they usually fit and what each one changes for developers. Read each row as a candidate rule for a client group, then confirm the exact executor or profile name in your installed Keycloak version before building the policy.

RequirementWhat it protects againstUsual client typesWhat changes for developers and what to confirm
PKCE for authorization code flowInterception of the authorization code by another app on the same device or a malicious redirect handler, so the code cannot be exchanged without the original verifier.Public browser apps, single-page apps, mobile and native appsApps must send a code challenge and verifier. Confirm in the admin console whether the PKCE requirement is set through a client policy and which code challenge methods the version accepts.
Confidential client authenticationToken issuance to a caller that cannot prove it holds the client credential, which limits misuse of a leaked client identifier.Confidential server-side web apps, backend services, machine-to-machine clientsDevelopers keep the client secret or switch to a stronger method on the server. Confirm which client authenticator types are allowed for the group in your version's administration guide.
Pushed authorization requests (PAR)Exposure of authorization request parameters in browser URLs and logs, and request tampering between the front channel and Keycloak.Confidential web apps and high-assurance browser clientsApps first post the request to the PAR endpoint and then redirect with a request URI. Confirm that PAR can be required per client or through a policy, and that the client library in use supports it.
DPoP sender-constrained tokensReuse of a stolen bearer access token by an attacker who does not hold the client's private key.Public clients calling APIs, confidential clients calling sensitive APIsApps must generate a key pair and send a proof with each request, and resource servers must validate it. Confirm the DPoP token binding setting and the supported signing algorithms in the server administration guide.
Signed request objects (JAR)Tampering with or forging authorization request parameters, such as scopes, redirect URIs or claims, that travel through the browser.High-assurance confidential clients, financial and public sector profilesApps sign the request as a JWT with a registered key. Confirm the request object setting, whether unsigned requests are rejected, and the key registration method for each client in your version.
Redirect URI and web origin rulesOpen redirects and code theft when wildcard or overly broad redirect URIs let an attacker receive the authorization response.All browser-based clients, including single-page and mobile appsTeams must register exact redirect URIs and cannot rely on broad patterns. Confirm which redirect URI checks the policy enforces and whether an existing client already breaks them.
Client secret rulesLong-lived shared secrets that are copied, leaked or never rotated, which widens the impact of any single exposure.Confidential server-side apps and backend servicesOperations teams schedule secret rotation and move to signed JWT or mutual TLS where supported. Confirm which client authenticator methods and secret strength checks exist in the installed release and how they are applied to a group.
Restricted response types and grant typesUse of legacy or implicit flows and password grants that expose tokens or credentials to the browser or client code.Single-page apps, mobile apps and any client that should use only the authorization code flowApps using implicit or direct access grants must move to the authorization code flow with PKCE. Confirm which grant types the policy can block and list every client that currently depends on a blocked grant.

How a client policy decides which profile applies at token request time

The diagram starts when a client sends an authorization or token request to the Keycloak realm. Keycloak checks each client policy in turn against the client's ID, type, roles or scopes, and any other conditions the policy sets. Every profile attached to a matching policy runs its executors, which can accept the request or reject it with an error. A client that matches no policy keeps its own per-client settings. Check which policies match each client before you rely on a profile to protect it, because an unmatched client gets no added rules.

Client policy matching decides which profile executors run for a token request.

How profiles and policies interact with existing client settings

A client policy layers enforcement on top of each client's own configuration, so a profile requirement can override or conflict with settings the client already has. The practical question for each profile is what happens when a client does not meet it. For example, if a profile requires PKCE and a client was registered without PKCE, the authorization request is refused by Keycloak for that client, and the application sees an error returned through the redirect or the token endpoint rather than a login page. Confirm the exact error code and where it surfaces for your Keycloak version in the server administration guide, because the application's error handling and logs depend on it. Treat each conflict as one of three outcomes: the client is fixed, the client is moved to a different policy scope, or the application is changed. Decide which one before rollout, not during an incident.

A policy that works in a test realm can still break an application because the test client was not the one that uses the unusual method. Clients that authenticate differently, such as a backend service using client credentials, a single-page app using a public client, or a mobile app with a custom redirect scheme, each hit a different requirement. A profile that requires confidential clients will not affect a public single-page app in the same way it affects a server-side web app, and a signed request requirement only matters to clients that send request objects. Check which grant types, client authentication methods and token endpoint calls each real application uses, and compare them with the profile's conditions. Any mismatch found in this review should be resolved in the client or the policy scope before the profile is switched on for production.

Test each profile against one representative client of each type before wider rollout: a confidential web app, a public single-page app, a native mobile app, a service account and any client that uses a non-standard flow. For each one, run a full login, token refresh, logout and API call, and record the request that failed, the status or error returned and the owner of the fix. Keep the test clients in a realm that mirrors production policy settings, so that differences in scope or defaults surface early. Repeat the test after any change to the policy, the profile or the Keycloak version, since the upgrade notes for each release should be checked against your profile list. Only widen the scope once every representative client passes and each exception has a documented owner and a retirement date.

Which client groups to put under which security rules

Client policies work best when each rule set maps to a group of clients that are built the same way. Group boundaries should follow how applications actually authenticate, not how teams are organized, so inventory existing clients before writing any condition.

Browser single-page apps

Public clients with no secret that run the Authorization Code flow in the browser. Apply a profile that requires PKCE with the S256 method, disables the implicit flow and direct access grants, and restricts redirect URIs to exact values. The main compatibility risk is older SPA builds that still use an implicit or password flow, which will fail at sign-in after the policy takes effect. Identify them by client type and the public-client setting before enforcing.

Keycloak docs

Native mobile apps

Public clients that run on phones or desktops and receive authorization codes through custom schemes or loopback redirects. Require PKCE for every authorization request and review whether the group should also be covered by PAR so authorization parameters never travel through the browser URL. The compatibility risk is that some mobile SDKs or older libraries send no code challenge, and a broad condition can block them. Match on a naming convention or a scope assigned only to mobile clients.

Server-side web apps

Confidential clients that hold a client secret on a backend server. Require confidential client authentication and, where your policy calls for it, signed JWT or mTLS client authentication instead of shared secrets. The risk is that legacy apps may authenticate with a secret method the policy forbids, so test each application's token request before switching the policy from report-only to enforced. Identify the group by the client authenticator setting.

Service-to-service clients

Machine clients that use the client credentials grant to call APIs without a user present. Apply the strictest client authentication requirement and limit them to the scopes and audiences they need. The main compatibility risk is that background jobs and scheduled services often share one client across several systems, so splitting them can break deployments that depend on the shared identity. Find them by the service account setting and by which clients have no login flow enabled.

Clients in a regulated business line

Applications that handle payments, health records or other regulated data and that your compliance team has agreed must meet a stricter profile. Require sender-constrained tokens such as DPoP where the application and its resource servers support them, and enforce PAR and signed request objects if the business line's assurance standard calls for them. The risk is that resource servers and gateways may not yet validate DPoP proofs, which blocks traffic after enforcement. Group these by an assigned role or a client scope that the business line owns, and confirm the requirement with the control owner.

How to set up a client policy in a test realm first

This sequence builds one client policy in a non-production realm, proves that a compliant client signs in and a deliberately non-compliant client is rejected, and leaves evidence you can review before anything reaches production.

  1. Inventory clients and their current settings

    In a non-production realm that mirrors production, list every client in the admin console under Clients and record its client authentication setting, PKCE behavior, redirect URIs, and token settings for the group you plan to govern. Export the realm with the realm export option so you have a baseline file to compare against later. Done when you have a written list showing which clients already meet the target rules and which do not, and the export file is stored with the change record.

  2. Define one profile per security rule set

    Under Realm settings, open Client policies and create a client profile for each rule set you need, such as one profile that requires PKCE and one that requires confidential client authentication. Add the executors each profile needs, for example the PKCE enforcer or the secure client authenticator, and set their configuration fields. Done when each profile appears in the Profiles tab with its executors listed, and the same definitions can be read back in the realm export under the client policies section.

  3. Create a policy with conditions for one client group

    In the Policies tab, create a client policy and add a condition that selects only the clients in the group under test, using the condition type that matches your naming or grouping approach, such as a client role, a client ID pattern, or a set of client IDs. Attach the profile from the previous step to this policy and keep the policy enabled. Done when the policy lists the attached profile and the condition, and the test realm shows no change for clients outside the condition.

  4. Sign in with a compliant representative client

    Choose one client from the governed group that already meets the rules and run a full authorization code sign-in through it, then exchange the code for tokens at the token endpoint. Confirm the request carries the required parameters, such as a code challenge when PKCE is enforced. Done when the sign-in completes and the token response is returned, and you can see a matching LOGIN and CODE_TO_TOKEN event in the Events section of the admin console for that client.

  5. Confirm a non-compliant test client is rejected

    Create a deliberately non-compliant test client in the same group, for example one with PKCE turned off or with a client authentication method the profile forbids, and attempt the same sign-in. The request should fail at the enforced step. Done when the flow returns an error and the Events section shows a failed event for that client ID with an error reason that matches the rule you enforced. Record the error text so the rejection is reproducible.

  6. Check the policy against your existing clients

    Review the policy's effect on every other client in the realm, not only the two you tested. Confirm that clients outside the condition still sign in as before and that clients inside it that fail the rules are listed in your inventory with a remediation owner. Use the admin event log and a sample of sign-ins to check. Done when you have a list of affected clients, each marked compliant or scheduled for change, and no unexpected failures appear in the event log.

  7. Keep the test evidence for promotion

    Export the realm again after the policy works, then diff it against the baseline export to confirm that only the intended profiles, policies, and client settings changed. Save the event log entries, the rejection error text, and the export diff with the change request. Done when the diff contains only the approved changes and the evidence bundle is attached to the record that will be used to promote the policy to production.

How the setup changes for public, confidential and machine clients

Public clients are single-page applications and native mobile or desktop apps. They cannot keep a client secret, so the policy has to rely on the authorization code flow with PKCE and on controls around redirects and token storage. A client policy that requires PKCE and blocks the implicit flow is usually the first rule a team applies to this group.

  • PKCE parameters: The app must send a code_challenge and code_challenge_method on the authorization request and the matching code_verifier on the token request. Older SPA libraries or hand-written login code often omit them.
  • Redirect handling: Mobile apps must use the platform's supported redirect mechanism, and the redirect URI in the client must match it exactly.
  • Token storage: Keep tokens out of local storage where your threat model rejects it, and confirm the library's refresh behavior after the policy change.
  • Public client ban on direct grants: Resource owner password grants and other legacy flows should be disabled for this group.

Before rollout, test sign-in on every browser and device family you support, including silent renewal and logout. Confirm that a login attempt without PKCE is rejected with an error the app can display, and that the app's own error handling does not loop the user.

Security risks to address when enforcing client policies

Client policies apply rules to many clients at once, which makes them efficient and also means one mistake reaches many applications. The cards below cover the failure modes teams most often miss, with the mitigation for each and the records to keep so reviewers can confirm the policy is in force.

Broad conditions reach internal clients

A condition that matches clients by a broad attribute can pull in the admin console, internal service accounts or management clients and apply PKCE, sender constraints or authentication rules they were never designed for. Map every condition to a named list of clients before enabling it, and check which built-in clients the condition matches in a test realm. Record the exported client policy JSON and a list of matched clients for each condition.

Keycloak docs

Profiles weakened during upgrades

Keycloak releases change built-in profiles and executors, and a minor release can alter defaults. A profile you customized may be replaced, reduced or left pointing at an executor that no longer enforces what you expect. Compare exported profiles before and after every upgrade and rerun your client authentication tests. Keep the upgrade change record with the profile diff and the test output.

Release updates

Untested requirements cause sign-in outages

Requiring a sender-constrained token, signed request or pushed authorization request for a client that a partner or mobile build does not yet support will break sign-in for that application. Test each requirement against every client it covers, including older app versions and integration partners, in a staging realm first. Keep the test matrix and the results from each run so the go-live decision has evidence behind it.

Keycloak docs

Policy changes outside change control

Client policies can be edited in the admin console by any administrator with realm rights, so a quick change can weaken a profile or add an exemption without review. Restrict who can edit policies, route changes through versioned configuration, and require approval for each change. Record the change history, the approver and the exported configuration that was applied.

Clients missed by the policy

A client created before the policy, or one created by a team outside the policy's condition, keeps its old settings and never receives the new requirements. Periodically list all clients and compare each one against the policy conditions, and treat any client that matches no policy as a finding. Keep the client inventory export with the date and the list of exceptions and their owners.

Evidence that the policy is in force

Auditors and security reviewers ask how you know the policy applies, not only what it says. A policy definition alone does not show it is active, that it covers the intended clients, or that a non-compliant request is rejected. Keep the exported policy and profile configuration, the matched client list, and test results showing a rejected request. Retain these records with each release.

What to confirm about client policies in your Keycloak version

Before you build a client policy baseline, confirm which executors your installed Keycloak release actually provides. Client policies are assembled from profiles and conditions, and the executors that enforce PKCE, client authentication, PAR, DPoP or signed requests vary by release. Read the server administration guide for the version you plan to run, and list each executor you need against that version's documentation. Do not assume an executor from an earlier release or from a blog post still applies. The current release is 26.8.1, so start there and then compare against the version you will actually deploy.

Next, check whether each profile applies to the protocols and client types in your inventory. OIDC and SAML do not share the same controls, so a rule that enforces PKCE or PAR for OpenID Connect clients does nothing for a SAML service provider. Build a table of every client, its protocol, whether it is confidential or public, and which profile you expect to govern it. Then test a sample client from each group to confirm the policy changes the behavior you expect, including how a client that fails the policy is reported. Ask whether the policy evaluation is documented as applying to the flows your applications use, such as the authorization code flow for single-page apps and the token endpoint for service clients.

Finally, confirm how policies are represented in exported realm configuration and whether that export is part of your promotion process. If you move realm configuration from a test environment to production through exports or configuration as code, verify that the client policy objects are included, that IDs or references do not break on import, and that a secret or policy setting is not silently dropped. Also confirm whether the Red Hat build of Keycloak exposes the same executors and profile options as the upstream release, since the supported distribution can lag or differ in version. Read the Keycloak upgrade notes for every version change, because policy behavior and defaults can change between releases. A DeployOpen engagement would confirm these points against your chosen version and client inventory rather than assume them.

What client policy enforcement costs and what it takes from your team

What drives the effort of a client policy rollout?

The effort scales with how many clients the realm holds, how many distinct client types those clients represent, how complete your current inventory is, and how many applications need code or configuration changes before a stricter profile can be enforced. A realm with a few clients that are all standard browser apps is a small job. A realm with dozens of clients spanning single-page apps, mobile apps, server-side web apps and machine-to-machine services usually needs separate profiles, more test cases and more coordination with application teams. The configuration itself is rarely the largest part. Ask any partner to show how they will count clients, classify them and record which ones break under each requirement before quoting.

Can an internal team enforce client policies without outside help?

Yes, if the team already administers Keycloak, understands OAuth 2.0 and OpenID Connect flows, and has access to a non-production realm where changes can be tested safely. Client policies are configured in the admin console and through the Admin REST API, so the platform work is within reach of a platform or identity team. Outside help is most useful for the inventory, for judging which clients can move to PKCE, confidential or sender-constrained settings without breaking, and for building the test plan and evidence. Many organizations split the work: their own team makes the configuration changes, and a partner reviews the design and tests the results.

How long does a client policy rollout take, and what sets the pace?

The pace is set mainly by testing and application release cycles, not by the Keycloak configuration. Each affected application team has to confirm that its login, token refresh and logout flows still work under the new profile, then ship a change if one is needed, then wait for that change to reach production. Teams with frequent release trains move faster than teams that deploy quarterly. Confirm the duration with your partner against your own release calendar, change freeze dates and the number of application owners who must sign off. Do not plan around a generic figure.

What does the work need from our team?

The work needs named owners, a place to test, and a clear approval path. Each application should have an owner who can answer questions about its redirect URIs, client type, token use and release schedule. A non-production test realm with copies of the relevant clients lets you try a profile before it reaches users. A change approval process, usually through your existing change board, records which profile applies to which client and why. Without these three things, the rollout tends to stall at the first client that fails, because no one can decide whether to fix the app or relax the policy.

What should a quote for client policy enforcement include?

A quote should follow from a written scope and list each piece of work separately so you can see what you are paying for. Ask for:

  • A client inventory, with client type, protocol, redirect URIs, current settings and owner for each client
  • A profile design that maps each client group to required settings such as PKCE, confidential client authentication, PAR, DPoP or signed requests
  • A test plan covering login, token refresh, logout and failure paths in a non-production realm
  • Application support for teams that must change code or configuration
  • Evidence that records the settings, test results and approvals for your auditors

For each item, ask what is one-time and what recurs, and which parts depend on your application teams' release dates.

What recurs after a client policy rollout goes live?

Three things recur. First, new clients must be reviewed against the profiles before they reach production, because a new application that skips the policy will not be covered by it unless your process checks for it. Second, Keycloak version upgrades can change client policy behavior or add new settings, so each upgrade needs a regression check of the profiles. Third, retests of the enforced settings should happen on a schedule and after significant application changes. Ask your partner whether these are covered by a retainer or by a separate review, and confirm what the retest evidence will contain.

How DeployOpen scopes and delivers Keycloak client policy work

DeployOpen plans and implements client policies in Keycloak inside infrastructure you control, starting from an inventory of which clients need which security profile. Each engagement is fixed-scope, with the policy design, the client changes and the evidence agreed in writing before work begins.

How we scope

  • Inventory every client, its type, flow and redirect pattern, and whether it can hold a secret.
  • Map each client group to a target profile such as PKCE, confidential clients, PAR, DPoP or signed requests.
  • Agree in writing which realms, clients and policy conditions are in scope, and which applications need a planned migration window.

How we build

  • Create client policies and client profiles in a non-production realm, then promote them through your change process.
  • Apply conditions so policies target client groups by role or attribute rather than by individual client name.
  • Test each application's sign-in, token refresh and logout against the new policy, and record the results for every client group.

How we hand over

  • Deliver the policy definitions as exported configuration with a document describing each profile and its owner.
  • Provide a verification checklist that your team can rerun after upgrades or when new clients are created.
  • Walk through the rollback steps and the list of applications that needed changes, so your team can operate the policies alone.

How we support

  • Support is available as a retainer for policy changes, Keycloak upgrades and continuous testing of client configuration.
  • Review new client registrations against the policy set when your teams add applications or change flows.
  • Confirm with Keycloak release notes and your vendor support terms how policy behavior changes between releases before you upgrade.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.