> 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="/files/yvwUQ3eDGt7Ufj3u7KFR" 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="/files/C9108PJFNrCGKmX67uBh" 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="/files/vx0F4sL0HGsIRmKhBXqU" 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
