vincbeck commented on code in PR #77743:
URL: https://github.com/apache/airflow/pull/77743#discussion_r4745971311
##########
scripts/ci/docker-compose/keycloak/keycloak-entrypoint.sh:
##########
@@ -34,11 +34,73 @@ done
sleep 3
echo "Keycloak is running (probably...)"
+# Exiting on a failed call makes `restart: always` retry the setup instead of
leaving Keycloak
+# running half set up.
+fail() {
+ echo "ERROR: $1"
+ exit 1
+}
+
# The below commands are used to disable the ssl requirement to use the admin
panel of keycloak
echo "Configuring admin console access without ssl/https"
# Get credentials to make the below update to the realm settings
-./kcadm.sh config credentials --server http://localhost:"$http_port" --realm
master --user admin --password admin
-./kcadm.sh update realms/master -s sslRequired=NONE --server
http://localhost:"$http_port"
+./kcadm.sh config credentials --server http://localhost:"$http_port" --realm
master --user admin --password admin \
+ || fail "Could not log in to the Keycloak admin API"
+./kcadm.sh update realms/master -s sslRequired=NONE --server
http://localhost:"$http_port" \
+ || fail "Could not turn off the SSL requirement of the master realm"
+
+# The realm and client live in the Breeze Postgres database, so they are only
created on the first
+# start after the database volume is created. They are checked separately so
that a start which
+# created the realm but not the client is completed on the next start.
+realms=$(./kcadm.sh get realms --fields realm) || fail "Could not list the
Keycloak realms"
+if grep -qF "\"${AIRFLOW_REALM}\"" <<< "${realms}"; then
+ echo "Realm ${AIRFLOW_REALM} already exists, leaving it unchanged"
+else
+ echo "Creating realm ${AIRFLOW_REALM}"
+ ./kcadm.sh create realms -s realm="${AIRFLOW_REALM}" -s enabled=true -s
sslRequired=NONE \
+ || fail "Could not create realm ${AIRFLOW_REALM}"
+fi
+
+clients=$(./kcadm.sh get clients -r "${AIRFLOW_REALM}" -q
clientId="${AIRFLOW_CLIENT_ID}" --fields clientId) \
+ || fail "Could not list the clients of realm ${AIRFLOW_REALM}"
+if grep -qF "\"${AIRFLOW_CLIENT_ID}\"" <<< "${clients}"; then
+ echo "Client ${AIRFLOW_CLIENT_ID} already exists, leaving it unchanged"
+else
+ echo "Creating client ${AIRFLOW_CLIENT_ID} in realm ${AIRFLOW_REALM}"
+ airflow_url="http://localhost:${AIRFLOW_HOST_PORT}"
+ # The loopback redirect URIs are for the browser login of command-line
clients, see
+ # providers/keycloak/docs/auth-manager/token.rst. The permissions of
+ # ``airflow keycloak-auth-manager create-all`` overlap (for example ReadOnly
and User both cover
+ # Dags), so a role only gets access when one of them grants it: AFFIRMATIVE,
not the
+ # UNANIMOUS default.
+ ./kcadm.sh create clients -r "${AIRFLOW_REALM}" -f - <<EOF || fail "Could
not create client ${AIRFLOW_CLIENT_ID}"
+{
+ "clientId": "${AIRFLOW_CLIENT_ID}",
+ "protocol": "openid-connect",
+ "publicClient": false,
+ "secret": "${AIRFLOW_CLIENT_SECRET}",
+ "standardFlowEnabled": true,
+ "directAccessGrantsEnabled": true,
+ "implicitFlowEnabled": false,
+ "serviceAccountsEnabled": true,
+ "authorizationServicesEnabled": true,
+ "frontchannelLogout": true,
+ "rootUrl": "${airflow_url}",
+ "baseUrl": "${airflow_url}",
+ "redirectUris": ["${airflow_url}/*", "http://127.0.0.1/callback",
"http://[::1]/callback"],
+ "webOrigins": ["${airflow_url}"],
+ "attributes": {
+ "post.logout.redirect.uris": "${airflow_url}/*",
+ "oauth2.device.authorization.grant.enabled": "true"
+ },
+ "authorizationSettings": {
+ "allowRemoteResourceManagement": true,
+ "policyEnforcementMode": "ENFORCING",
+ "decisionStrategy": "AFFIRMATIVE"
Review Comment:
I do not think we are far from merging
https://github.com/apache/airflow/pull/74371 so let's go with that first. If we
notice it stales for some days, you can create a new PR just for the decision
strategy
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]