keycloak

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Keycloak

Keycloak

Keycloak is an open-source Identity and Access Management solution aimed at modern applications and services. It makes it easy to secure applications and services with little to no code.
Keycloak是一款面向现代应用与服务的开源身份与访问管理(IAM)解决方案。它能让你无需编写或只需少量代码即可轻松保护应用和服务的安全。

When to Use

适用场景

  • Self-Hosted IAM: You want Auth0 features but deployed on your own infrastructure (GDPR/Compliance).
  • Enterprise Integration: Connecting to legacy LDAP/Active Directory user federations.
  • Single Sign-On (SSO): One login for your internal wiki, chat, and cloud apps.
  • 自建IAM:你需要Auth0的功能,但希望部署在自有基础设施上(符合GDPR/合规要求)。
  • 企业集成:对接传统LDAP/Active Directory用户联盟。
  • 单点登录(SSO):一次登录即可访问内部维基、聊天工具和云应用。

Quick Start (Docker)

快速开始(Docker方式)

bash
docker run -p 8080:8080 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=admin quay.io/keycloak/keycloak:latest start-dev
bash
docker run -p 8080:8080 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=admin quay.io/keycloak/keycloak:latest start-dev

Core Concepts

核心概念

Realm

Realm(领域)

A space where you manage objects (users, apps, roles). You usually create a dedicated realm for your app (e.g.,
my-app-realm
) and leave
master
for admin tasks.
用于管理对象(用户、应用、角色)的空间。通常你需要为自己的应用创建专属Realm(例如
my-app-realm
),而
master
Realm则留作管理任务使用。

Clients

客户端(Clients)

Applications (Web, Mobile, Service) that can request login.
可以发起登录请求的应用(Web、移动应用、服务)。

Identity Brokering

身份代理(Identity Brokering)

Keycloak can act as a broker: User clicks "Login with GitHub" -> Keycloak talks to GitHub -> Keycloak issues its own token to your app.
Keycloak可作为身份代理:用户点击“使用GitHub登录”→Keycloak与GitHub交互→Keycloak向你的应用颁发自己的令牌。

Best Practices (2025)

2025年最佳实践

Do:
  • Use the Operator: On Kubernetes, use the Keycloak Operator for upgrades and scaling.
  • Production Mode:
    start-dev
    is for local only. Use an external DB (Postgres) and proper HTTPS for production.
  • Theme It: Don't use the default login page. Extend the theme to match your brand.
Don't:
  • Don't Modify Core: Use the SPI (Service Provider Interface) to write plugins if you need custom logic.
  • Don't expose Admin Console: Block
    /admin
    and
    /master
    access from the public internet.
推荐做法
  • 使用Operator:在Kubernetes上,使用Keycloak Operator进行升级和扩容。
  • 生产模式
    start-dev
    仅用于本地开发。生产环境需使用外部数据库(如Postgres)并配置合法HTTPS。
  • 自定义主题:不要使用默认登录页面,扩展主题以匹配你的品牌风格。
不推荐做法
  • 不要修改核心代码:如果需要自定义逻辑,请使用SPI(服务提供者接口)编写插件。
  • 不要暴露管理控制台:阻止公网访问
    /admin
    /master
    路径。

References

参考资料