vincbeck commented on code in PR #77743:
URL: https://github.com/apache/airflow/pull/77743#discussion_r4741936852


##########
providers/keycloak/docs/auth-manager/setup/env.rst:
##########
@@ -28,6 +28,11 @@ If you don't have a Keycloak environment set up, please 
refer to the `official K
 Setup and run Keycloak with Breeze (local development)
 ------------------------------------------------------
 
-Setting up and running a Keycloak environment with Breeze for local 
development is straightforward.
-Simply run ``breeze start-airflow --integration keycloak``. Breeze will handle 
starting Keycloak in a separate container.
-The Keycloak admin console will be available at http://localhost:48080/.
+Run ``breeze start-airflow --backend postgres --auth-manager 
KeycloakAuthManager``. Breeze starts Keycloak in a
+separate container, creates an ``airflow`` realm and client in it, and 
configures Airflow to use the Keycloak auth
+manager with them. The Keycloak admin console is available at 
http://localhost:48080/.
+
+Breeze does not create the Airflow permissions or any user. Run ``airflow 
keycloak-auth-manager create-all`` inside
+Breeze to create the permissions, see :doc:`/auth-manager/manage/permissions`, 
then create a user in the realm.
+See the `Breeze Keycloak guide 
<https://github.com/apache/airflow/blob/main/contributing-docs/21_keycloak_client_settings.rst>`__

Review Comment:
   nit: `create-all` needs `--username` and `--password` here too, like in the 
contributing guide: `airflow keycloak-auth-manager create-all --username admin 
--password admin`



##########
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:
   If the client needs `AFFIRMATIVE` for the `create-all` permissions to work, 
shouldn't `create-all` set it on the resource server? Otherwise users outside 
Breeze who follow `manage/login.rst` keep the `UNANIMOUS` default and hit the 
same problem.



##########
dev/breeze/src/airflow_breeze/params/shell_params.py:
##########
@@ -905,19 +920,37 @@ def _generate_env_for_docker_compose_file_if_needed(env: 
dict[str, str]):
                 "\n".join([f"{k}=${{{k}}}" for k in sorted(env.keys())])
             )
 
+    def get_selected_integrations(self) -> list[str] | None:

Review Comment:
   nit: should be private, it is only used inside `ShellParams`



-- 
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]

Reply via email to