惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Hacker News: Ask HN
Hacker News: Ask HN
N
News and Events Feed by Topic
Forbes - Security
Forbes - Security
The Last Watchdog
The Last Watchdog
TaoSecurity Blog
TaoSecurity Blog
Schneier on Security
Schneier on Security
SecWiki News
SecWiki News
V
Vulnerabilities – Threatpost
Project Zero
Project Zero
O
OpenAI News
W
WeLiveSecurity
Security Archives - TechRepublic
Security Archives - TechRepublic
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
H
Hacker News: Front Page
Cisco Talos Blog
Cisco Talos Blog
Spread Privacy
Spread Privacy
Help Net Security
Help Net Security
P
Privacy & Cybersecurity Law Blog
K
Kaspersky official blog
S
Security @ Cisco Blogs
Latest news
Latest news
AWS News Blog
AWS News Blog
U
Unit 42
Martin Fowler
Martin Fowler
阮一峰的网络日志
阮一峰的网络日志
S
Secure Thoughts
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Know Your Adversary
Know Your Adversary
Scott Helme
Scott Helme
博客园 - 司徒正美
B
Blog RSS Feed
C
Check Point Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
D
Docker
Google Online Security Blog
Google Online Security Blog
Jina AI
Jina AI
aimingoo的专栏
aimingoo的专栏
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Last Week in AI
Last Week in AI
月光博客
月光博客
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
SegmentFault 最新的问题
NISL@THU
NISL@THU
T
The Blog of Author Tim Ferriss
C
Cisco Blogs
Attack and Defense Labs
Attack and Defense Labs
小众软件
小众软件

カレーうどん屋

パソコンをアップグレードした 我再也不能不假思索 Soundcore C30i 耳机 日本之行-第二站-奈良 23 年对我影响最大的硬件与软件 旅行与军粮 被我整坏的路由器和服务器 日本之行-第一站-大阪 深圳-香港三日行 My Second Attempt To ARM Servers 修复 UEFI 引导的 GRUB 使用 Docker Compose 部署音乐服务器 Navidrome 寻梦穿越机 - 入门浅谈 使用再生龙 Clonezilla 备份操作系统 BETAFPV 高频头固件编译 AttributeError DIY 显示器音箱 迁移 Hexo 渲染环境至 GitHub Actions DELL 灵越 15 5547 拆解与更换硅脂 Virmach Japan
使用 Docker Compose 部署 Keycloak 20
Kare Udon · 2023-01-22 · via カレーうどん屋

部署方式

采用 Docker Compose 部署,使用 Postgres 作为数据库,使用 Nginx 作为反向代理。

Docker Compose 配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
version: '3'

services:
keycloak:
image: quay.io/keycloak/keycloak:latest
environment:
KC_DB: postgres
KC_DB_URL: jdbc:postgresql://db:5432/keycloak
KC_DB_USERNAME: keycloak
KC_DB_PASSWORD: keycloak
KC_HTTP_ENABLED: true # 开启 HTTP
KC_HOSTNAME_STRICT: false
KC_HOSTNAME_STRICT_HTTPS: false
KC_HTTP_RELATIVE_PATH: '/' # Keycloak 应用的相对路径
KC_HTTP_PORT: 8080 # HTTP 端口
KEYCLOAK_ADMIN: MY_USERNAME # 管理员账号,仅初始化时使用
KEYCLOAK_ADMIN_PASSWORD: MY_PASSWORD # 管理员密码,仅初始化时使用
PROXY_ADDRESS_FORWARDING: true # 使用反向代理必须开启
KC_PROXY: edge # 反向代理模式,详见文档
entrypoint: /opt/keycloak/bin/kc.sh start # 第一次运行后可以加上 --optimized 参数,加快二次启动速度
ports:
- 127.0.0.1:18080:8080 # Keycloak 应用端口
restart: unless-stopped
db:
image: postgres:14
restart: unless-stopped
environment:
- POSTGRES_USER=keycloak
- POSTGRES_PASSWORD=keycloak
- POSTGRES_DB=keycloak
volumes:
- ./postgres-data:/var/lib/postgresql/data # 数据库数据保存位置

使用命令 docker compose up -d 启动服务。

Nginx 配置

我建议使用 DigitalOcean 的 Nginx 配置生产工具,示例配置如下:

示例配置

也可参考下述配置,此为 DigitalOcean 生成配置的简化版:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name auth.example.com;

# SSL
ssl_certificate /etc/letsencrypt/live/auth.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/auth.example.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/auth.example.com/chain.pem;

# logging
access_log /var/log/nginx/access.log combined buffer=512k flush=1m;
error_log /var/log/nginx/error.log warn;

# reverse proxy
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Auth-Request-Redirect $request_uri;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_pass http://127.0.0.1:18080;
}

location /auth/realms {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Auth-Request-Redirect $request_uri;
proxy_pass http://127.0.0.1:18080;
}

location /auth/resources {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Auth-Request-Redirect $request_uri;
proxy_pass http://127.0.0.1:18080;
}

location /auth/js {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Auth-Request-Redirect $request_uri;
proxy_pass http://127.0.0.1:18080;
}
}

# subdomains redirect
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name *.auth.example.com;

# SSL
ssl_certificate /etc/letsencrypt/live/auth.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/auth.example.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/auth.example.com/chain.pem;
return 301 https://auth.example.com$request_uri;
}

配置 Keycloak

创建 Realm

打开 Keycloak 地址,界面如下。

Keycloak 界面

选择 Administration Console,进入管理界面。

管理界面

选择箭头指向的下拉菜单,选择 Add realm,创建一个新的 Realm。

创建 Realm

填写 Realm 名称,点击 Create

创建 Client

管理界面

选择 Clients

Client 管理界面

点击 Create client

创建 Client

填写 Client 相关信息,点击 Next

配置 Client

按需求选择 Client 的配置,点击 Save

Client 创建完成

至此,Keycloak 配置完成,且创建了第一个测试用 Client。

测试 Client

可根据 官方教程 测试该 Client。

尾声

上述便是使用 Docker Compose 部署 Keycloak 20 的方法,我们顺利创建了第一个测试用 Client,接下来可以根据自己的需求进行配置。