This repository has been archived by the owner on Jan 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
configure-keycloak
executable file
·75 lines (59 loc) · 2.67 KB
/
configure-keycloak
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
#!/bin/bash -e
source `dirname $? | xargs readlink -f`/config
oc login -u system:admin
oc project default
echo "Waiting for Keycloak to start"
#get pod name
SLEEP=5
for i in `seq 10`; do
KEYCLOAK_READY=`oc get pod --no-headers=true -l application=keycloak -o custom-columns=STATUS:.status.containerStatuses[0].ready`
if [ "$KEYCLOAK_READY" = "true" ]; then
KEYCLOAK_POD=`oc get pod -l application=keycloak -o name | sed 's/pod\///'`
break
else
sleep $SLEEP
((SLEEP+=5))
fi
done
if [ -z "$KEYCLOAK_POD" ]; then
echo "Failed to get pod, or pod never became ready"
exit 1
else
echo "Keycloack POD: $KEYCLOAK_POD"
fi
echo "Configuring Keycloak"
oc rsh $KEYCLOAK_POD ./keycloak/bin/kcadm.sh config credentials \
--config /tmp/.kcadm.config \
--server http://localhost:8080/auth --realm master \
--user admin --password admin
echo "Creating clients"
echo "Creating web console client"
cat $DIR/kc-client-openshift-web-console.json | oc rsh $KEYCLOAK_POD ./keycloak/bin/kcadm.sh create clients \
--config /tmp/.kcadm.config \
-f -\
-s "redirectUris=[\"https://$OC_PUBLIC_IP:8443/console/*\",\"https://localhost:9000/*\"]" \
-s baseUrl=https://$OC_PUBLIC_IP:8443/ \
-s adminUrl=https://$OC_PUBLIC_IP:8443/
echo "Creating temporary token client"
cat $DIR/kc-client-openshift-cli.json | oc rsh $KEYCLOAK_POD ./keycloak/bin/kcadm.sh create clients \
--config /tmp/.kcadm.config \
-f -
echo "Creating oc client"
FLOW_ID=$(oc rsh $KEYCLOAK_POD ./keycloak/bin/kcadm.sh get realms/master/authentication/flows --config /tmp/.kcadm.config -r master | jq -c '.[] | select(.alias | contains("http challenge")) | .id' | sed 's/"//g')
cat $DIR/kc-client-openshift-challenging-client.json | oc rsh $KEYCLOAK_POD ./keycloak/bin/kcadm.sh create clients \
--config /tmp/.kcadm.config \
-s "authenticationFlowBindingOverrides={\"browser\": \"$FLOW_ID\"}"\
-s "redirectUris=[\"$KEYCLOAK_URL/realms/master/oauth/token/implicit\"]" \
-f -
echo "Creating token review client"
oc rsh $KEYCLOAK_POD ./keycloak/bin/kcadm.sh create clients \
--config /tmp/.kcadm.config -r master \
-s clientId=token-review \
-s enabled=true \
-s publicClient=false \
-s "redirectUris=[\"*\"]" \
-s "attributes={\"x509.subjectdn\": \"CN=keycloak-client\"}" \
-s clientAuthenticatorType=client-x509
echo "Creating Openshift Client Storage"
oc login --username=admin --password=admin
cat kc-client-openshift-storage.json | sed "s/_access_token/$(oc whoami -t)/g" | sed "s/_openshift_public_uri/https:\/\/$OC_PUBLIC_IP:8443/g" | oc rsh $KEYCLOAK_POD ./keycloak/bin/kcadm.sh create components --config /tmp/.kcadm.config -f -