-
Notifications
You must be signed in to change notification settings - Fork 312
/
Copy pathkeycloak.yaml
262 lines (241 loc) · 10.6 KB
/
keycloak.yaml
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
package:
name: keycloak
version: "26.1.4"
epoch: 0
description: Open Source Identity and Access Management For Modern Applications and Services
copyright:
- license: Apache-2.0
dependencies:
runtime:
- bash # Keycloak helper scripts require bash, aren't compatible with busybox.
- openjdk-21-default-jdk # TODO: Change to JRE
# Create a new major-version variable that contains only the major version
# to use in the bitnami/compat pipeline to find out the correct folder for the image.
# e.g. 25.0.2 will create a new var major-version=25
var-transforms:
- from: ${{package.version}}
match: ^(\d+).*
replace: $1
to: major-version
environment:
contents:
packages:
- bash
- build-base
- busybox
- ca-certificates-bundle
- gcc-13-default
- openjdk-21-default-jdk
- wolfi-base
- wolfi-baselayout
environment:
LANG: en_US.UTF-8
JAVA_HOME: /usr/lib/jvm/java-21-openjdk
pipeline:
- uses: git-checkout
with:
repository: https://github.com/keycloak/keycloak
tag: ${{package.version}}
expected-commit: b281b5f09d06a55c661d8df529f0020dd44942d1
- uses: maven/pombump
- runs: |
gcc napi-static-assert.c -o /tmp/preload.so -fPIC -shared -ldl
- runs: |
# Keycloak installation. Note we use the maven wrapper as configured in
# the source repo to build - ensures the correct maven version for
# building the project, preventing issues such as CI hangs.
# Build keycloak-server. Depends on `keycloak-js-adapter-jar`.
# Gross hack to work around broken NAPI ast-grep module that has
# undefined symbol: static_assert
export LD_PRELOAD=/tmp/preload.so
./mvnw clean install -DskipTests -Dmaven.test.skip=true -DskipITs -DskipProtoLock=true -Pdistribution
unset LD_PRELOAD
mkdir -p ${{targets.destdir}}/usr/share/java
unzip -d ${{targets.destdir}}/usr/share/java quarkus/dist/target/keycloak-*.zip
cp -avR ${{targets.destdir}}/usr/share/java/keycloak-* ${{targets.destdir}}/usr/share/java/keycloak
# Create an empty data directory for keycloak. Required by the UI to store some data.
mkdir -p ${{targets.destdir}}/usr/share/java/keycloak/data
mkdir -p ${{targets.destdir}}/usr/bin
for i in kc.sh kcadm.sh kcreg.sh; do
ln -sf /usr/share/java/keycloak/bin/$i ${{targets.destdir}}/usr/bin/$i
done
# images like keycloak-operator may need it as they expect it to find keycloak in /opt/keycloak
# For ref: https://github.com/keycloak/keycloak/blob/4b194d00bed51458acb3d125eba9a0ba654c930a/operator/Dockerfile#L11
subpackages:
- name: keycloak-compat
pipeline:
- runs: |
mkdir -p "${{targets.subpkgdir}}"/opt
ln -s /usr/share/java/keycloak "${{targets.subpkgdir}}"/opt/
# https://github.com/bitnami/containers/tree/main/bitnami/keycloak/24/debian-12
- name: ${{package.name}}-bitnami-compat
description: "compat package with bitnami/keycloak image"
dependencies:
runtime:
- coreutils # Keycloak Helm Chart scripts require coreutils, aren't compatible with busybox. (i.e., `cp` with `--preserve` option)
- krb5
- libaio
- procps
- zlib
- wait-for-port
- net-tools
- posix-libc-utils
- su-exec
pipeline:
- uses: bitnami/compat
with:
image: keycloak
version-path: ${{vars.major-version}}/debian-12
- runs: |
mkdir -p ${{targets.contextdir}}/bitnami/keycloak
mkdir -p ${{targets.contextdir}}/opt/bitnami/keycloak
mkdir -p ${{targets.contextdir}}/docker-entrypoint-initdb.d
for dir in bin conf conf.default lib providers themes; do
mkdir -p ${{targets.contextdir}}/opt/bitnami/keycloak/$dir
done
chmod g+rwX ${{targets.contextdir}}/opt/bitnami
# Copy keycloak files to /opt/bitnami/keycloak for compatibility with
# their Helm Chart, which copies the directories into an emptyDir in
# an initContainer
cp -r ${{targets.destdir}}/usr/share/java/keycloak/* ${{targets.contextdir}}/opt/bitnami/keycloak
# Replace the incorrect Java paths in the Bitnami scripts
sed -i 's/JAVA_HOME="\/opt\/bitnami\/java"/JAVA_HOME="\/usr\/lib\/jvm\/java-21-openjdk"/g' ${{targets.contextdir}}/opt/bitnami/scripts/keycloak-env.sh
sed -i 's/\/opt\/bitnami\/java\/lib\/security/\/usr\/lib\/jvm\/java-21-openjdk\/conf\/security/g' ${{targets.contextdir}}/opt/bitnami/scripts/java/postunpack.sh
# Disable some commands used in Bitnami scripts. These commands more likely fail in this since this image take non root approach
sed -i 's/chown -R "$KEYCLOAK_DAEMON_USER" "$dir"/# chown -R "$KEYCLOAK_DAEMON_USER" "$dir"/g' ${{targets.contextdir}}/opt/bitnami/scripts/keycloak/postunpack.sh
sed -i 's/ensure_user_exists/# ensure_user_exists/g' ${{targets.contextdir}}/opt/bitnami/scripts/keycloak/postunpack.sh
sed -i 's/am_i_root/# am_i_root/g' ${{targets.contextdir}}/opt/bitnami/scripts/keycloak/setup.sh
sed -i 's/hostname --fqdn/hostname -f/g' ${{targets.contextdir}}/opt/bitnami/scripts/keycloak-env.sh
# The `--userspec`` flag belongs to GNU's chroot, whereas we are use BusyBox's. As a workaround, use `su-exec` instead.
sed -i 's|exec chroot --userspec="$userspec" /|exec chroot / su-exec "$userspec"|' ${{targets.contextdir}}/opt/bitnami/scripts/libos.sh
sed -i 's|chroot --userspec="$userspec" /|chroot / su-exec "$userspec"|' ${{targets.contextdir}}/opt/bitnami/scripts/libos.sh
# Use package path while unpacking
find . -iname "*.sh" -exec sed 's#/opt/bitnami#${{targets.contextdir}}/opt/bitnami#g' -i {} \;
${{targets.contextdir}}/opt/bitnami/scripts/keycloak/postunpack.sh || true
# Restore path
find ${{targets.contextdir}}/opt/bitnami -type f -exec sed 's#${{targets.contextdir}}##g' -i {} \;
# Link binaries used by Bitnami config
ln -sf /opt/bitnami/scripts/keycloak/entrypoint.sh ${{targets.contextdir}}/entrypoint.sh
ln -sf /opt/bitnami/scripts/keycloak/run.sh ${{targets.contextdir}}/run.sh
scriptlets:
post-install: |
#!/bin/sh
# Copy required provider files.
cp -avR /usr/share/java/keycloak/providers/* ${{targets.contextdir}}/opt/bitnami/keycloak/providers/
test:
environment:
contents:
packages:
- curl
- postgresql
- postgresql-client
- shadow
- sudo-rs
- jq
- keycloak
- keycloak-compat
- keycloak-bitnami-compat
accounts:
groups:
- groupname: nonroot
gid: 65532
users:
- username: nonroot
gid: 65532
uid: 65532
run-as: 0
environment:
PGDATA: /tmp/test_db
PGUSER: bn_keycloak
PGDB: bitnami_keycloak
ALLOW_EMPTY_PASSWORD: yes
JAVA_HOME: /usr/lib/jvm/default-jvm
pipeline:
- name: "version and help tests"
runs: |
/opt/bitnami/keycloak/bin/kc.sh --version
/opt/bitnami/keycloak/bin/kc.sh --help
/opt/bitnami/keycloak/bin/kcadm.sh --help
/opt/bitnami/keycloak/bin/kcreg.sh --help
- working-directory: /tmp
pipeline:
- name: "Test database creation"
with:
setup: echo "127.0.0.1 postgresql" >> /etc/hosts
runs: |
useradd $PGUSER
sudo -u $PGUSER initdb -D ${PGDATA}
sudo -u $PGUSER pg_ctl -D ${PGDATA} -l /tmp/logfile start
sudo -u $PGUSER createdb ${PGDB}
sudo -u $PGUSER psql -lqt | cut -d \| -f 1 | grep -qw ${PGDB}
- name: "start daemon on localhost"
uses: test/daemon-check-output
with:
setup: |
#!/bin/sh -e
echo "127.0.0.1 postgresql" >> /etc/hosts
echo "$(hostname) postgresql" >> /etc/hosts
start: |
env "BITNAMI_APP_NAME=keycloak" \
"APP_VERSION=${{package.version}}" \
"PATH=/opt/bitnami/keycloak/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" \
"KEYCLOAK_ENABLE_HEALTH_ENDPOINTS=true" \
/opt/bitnami/scripts/keycloak/entrypoint.sh \
/opt/bitnami/scripts/keycloak/run.sh
timeout: 60
expected_output: |
Welcome to the Bitnami keycloak container
keycloak setup finished!
server listening on
Keycloak ${{package.version}}
Profile dev activated.
post: |
#!/bin/sh -e
url=http://localhost:9000/health/ready
response=$(curl -fsS --connect-timeout 5 --max-time 10 --retry 5 --retry-delay 0 --retry-max-time 40 "$url") || {
echo "curl ${url} failed $?"
exit 1
}
echo "$response" | jq .status | grep -q UP || {
echo "response from $url did not contain \"UP\""
echo "response: $response"
exit 1
}
echo "$url had expected output: $response"
test:
pipeline:
- name: "start daemon on localhost"
uses: test/daemon-check-output
with:
start: "kc.sh start --hostname=localhost --https-key-store-password=MYPASSWORD"
timeout: 60
expected_output: |
Listening on
Keycloak ${{package.version}}
Profile prod activated
setup: |
#!/bin/sh -ex
echo "127.0.0.1 $(hostname)" >> /etc/hosts
kspath=/usr/share/java/keycloak/conf/server.keystore
keytool -v \
-keystore $kspath \
-alias localhost \
-genkeypair -sigalg SHA512withRSA -keyalg RSA -dname CN=localhost \
-storepass MYPASSWORD || {
echo "failed [$?] to create keystore with keytool at $kspath"
exit 1
}
- name: "version and help tests"
runs: |
kc.sh --version
kc.sh --help
kcadm.sh --help
kcreg.sh --help
update:
# The upstream repos releases contains a 'nightly' release. Which we want to
# exclude from discovery.
ignore-regex-patterns:
- ".*nightly.*"
enabled: true
github:
identifier: keycloak/keycloak