> For the complete documentation index, see [llms.txt](https://docs.openg2p.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.openg2p.org/operations/deployment/deployment-guide/keycloak/keycloak-advanced-security.md).

# Keycloak Advanced Security

Keycloak can manage user authentication for web and mobile apps. Users can self-register, and admins can add them. It also supports custom attributes beyond the default ones, like name and email.

This guide covers enabling advanced security features on Keycloak and configuring self-registration.

Please note that all of the following operations are made on the selected realm. Be mindful of which realm is being modified.

## Password strength policy

* Navigate to Keycloak Admin Console -> Authentication Menu -> Policies Section.
* Add the following policies.

  <figure><img src="https://3034178245-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJZcdob2emEcLMvLyIxqT%2Fuploads%2Fbb4i0c0Fn0jRNngWgbPP%2Fimage.png?alt=media&amp;token=76fb4824-87b9-473f-81af-85b4f3e7808a" alt=""><figcaption></figcaption></figure>

## Password expiry & history policy

TODO

## Account lockout

* Navigate to Keycloak Admin Console -> Realm Settings -> Security defenses.
* Under "Brute force detection", configure Account lock out option after 3 wrong password attempts.

  <figure><img src="https://3034178245-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJZcdob2emEcLMvLyIxqT%2Fuploads%2Fu8CpPhyTtT4p3p2eWmS6%2Fimage.png?alt=media&amp;token=d5ae4504-a474-428b-bcba-7450ea2ed3a1" alt=""><figcaption></figcaption></figure>

## MFA setup

* Navigate to Keycloak Admin Console -> Authentication Menu -> Flows Section.
* Click on **Browser** flow, make a copy of the Browser as **Browser with 2Fa** and bind it to Browser flow.

  <figure><img src="https://3034178245-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJZcdob2emEcLMvLyIxqT%2Fuploads%2FbXcQspO2Sj2Ql6fzU1an%2Fimage.png?alt=media&amp;token=32d3aff2-708a-4240-9670-ea0ea620f5ff" alt=""><figcaption></figcaption></figure>

  1. Look for the Browser - Conditional OTP option which by default is set to `Alternative`. Change this to `Required`.
  2. That's it. KeyCloak is now configured for 2FA.

## Self-Registration

Refer to [Keycloak User self-registration](/operations/deployment/deployment-guide/keycloak/enabling-keycloak-user-self-registration.md) guide.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.openg2p.org/operations/deployment/deployment-guide/keycloak/keycloak-advanced-security.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
