This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
setup_credentials.sh
executable file
·46 lines (37 loc) · 1.74 KB
/
setup_credentials.sh
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
#!/bin/bash
if [ -z "$email" ]; then
echo "Please set the env: email"
exit 1
fi
if [ -z "$username" ]; then
echo "Please set the env: username"
exit 1
fi
if [ -z "$password" ]; then
echo "Please set the env: password"
exit 1
fi
DISTRIBUTION_PATH="./distribution"
OAUTH2_PROXY_SECRET=${DISTRIBUTION_PATH}/oidc-auth/oauth2-proxy-secret.yaml
DEX_CONFIG_SECRET=${DISTRIBUTION_PATH}/oidc-auth/dex-config-secret.yaml
DEX_CONFIG_TEMPLATE=${DISTRIBUTION_PATH}/oidc-auth/dex-config-template.yaml
COOKIE_SECRET=$(python3 -c 'import os, base64; print(base64.urlsafe_b64encode(os.urandom(16)).decode())')
OIDC_CLIENT_ID=$(python3 -c 'import secrets; print(secrets.token_hex(16))')
OIDC_CLIENT_SECRET=$(python3 -c 'import secrets; print(secrets.token_hex(32))')
ADMIN_PASS_DEX=$(python3 -c "from passlib.hash import bcrypt; print(bcrypt.using(rounds=12, ident='2y').hash(\"${password}\"))")
kubectl create secret generic -n auth oauth2-proxy \
--from-literal=client-id=${OIDC_CLIENT_ID} \
--from-literal=client-secret=${OIDC_CLIENT_SECRET} \
--from-literal=cookie-secret=${COOKIE_SECRET} \
--dry-run=client -o yaml | kubeseal | yq eval -P \
> ${OAUTH2_PROXY_SECRET}
# yq eval -i ".data.ADMIN = \"${email}\"" ${DISTRIBUTION_PATH}/kubeflow/notebooks/profile-controller_access-management/patch-admin.yaml
yq eval ".staticClients[0].id = \"${OIDC_CLIENT_ID}\" | \
.staticClients[0].secret = \"${OIDC_CLIENT_SECRET}\" | \
.staticPasswords[0].hash = \"${ADMIN_PASS_DEX}\" | \
.staticPasswords[0].email = \"${email}\" | \
.staticPasswords[0].username = \"${username}\"" \
${DEX_CONFIG_TEMPLATE} | \
kubectl create secret generic -n auth dex-config --dry-run=client --from-file=config.yaml=/dev/stdin -o yaml | \
kubeseal | yq eval -P \
> ${DEX_CONFIG_SECRET}