first working version!

This commit is contained in:
2026-05-21 09:54:07 +00:00
parent 75089cd2e9
commit 56e97b9ead
2 changed files with 16 additions and 43 deletions
+8 -35
View File
@@ -82,13 +82,13 @@ docker run -it --rm --network matrix_network \
ghcr.io/element-hq/matrix-authentication-service:latest config generate \ ghcr.io/element-hq/matrix-authentication-service:latest config generate \
| grep -v '^[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}' > "${VOLUME_PATH}/mas/config.yaml" || { log_error "Mas config generation failed"; exit 1; } | grep -v '^[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}' > "${VOLUME_PATH}/mas/config.yaml" || { log_error "Mas config generation failed"; exit 1; }
MAS_CFG="${VOLUME_PATH}/mas/config.json" MAS_CFG="${VOLUME_PATH}/mas/config.yaml"
if ! yq '.clients' "$MAS_CFG" > /dev/null 2>&1; then if ! yq '.clients' "$MAS_CFG" > /dev/null 2>&1; then
yq -i '.clients = []' "$MAS_CFG" yq -y -i '.clients = []' "$MAS_CFG"
fi fi
yq -i ".public_base_url = \"https://${MAS_FQDN}\"" "$MAS_CFG" yq -y -i ".public_base_url = \"https://${MAS_FQDN}\"" "$MAS_CFG"
yq -i ".http.listen = \"0.0.0.0:8000\"" "$MAS_CFG" yq -y -i ".http.listen = \"0.0.0.0:8000\"" "$MAS_CFG"
yq -i ".database.uri = \"postgres://${PG_USER_MAS}:${PG_PASSWORD_MAS}@matrix-db:5432/auth?sslmode=prefer\"" "$MAS_CFG" yq -y -i ".database.uri = \"postgres://${PG_USER_MAS}:${PG_PASSWORD_MAS}@matrix-db:5432/auth?sslmode=prefer\"" "$MAS_CFG"
fix_ownership "${VOLUME_PATH}/mas" fix_ownership "${VOLUME_PATH}/mas"
@@ -100,32 +100,10 @@ log_info "Linking Synapse and MAS via OIDC..."
CLIENT_ID="synapse-client" CLIENT_ID="synapse-client"
CLIENT_SECRET=$(openssl rand -hex 32) CLIENT_SECRET=$(openssl rand -hex 32)
#TEMP_FILTER=$(mktemp)
#trap "rm -f $TEMP_FILTER" EXIT
#cat > "$TEMP_FILTER" <<EOF
#clients:
# - client_id: "${CLIENT_ID}"
# client_secret: "${CLIENT_SECRET}"
# redirect_uris:
# - "https://${HOMESERVER_FQDN}/_synapse/client/oidc/callback"
# grant_types:
# - "authorization_code"
# - "refresh_token"
# response_types:
# - "code"
# scopes:
# - "openid"
# - "profile"
# - "email"
# application_type: "web"
#EOF
EXISTING_CLIENT=$(yq '.clients[] | select(.client_id == "'"${CLIENT_ID}"'")' "$MAS_CFG" 2>/dev/null || echo "") EXISTING_CLIENT=$(yq '.clients[] | select(.client_id == "'"${CLIENT_ID}"'")' "$MAS_CFG" 2>/dev/null || echo "")
if [[ -z "$EXISTING_CLIENT" ]]; then if [[ -z "$EXISTING_CLIENT" ]]; then
yq -y -i ".clients += [{ CLIENT_OBJ="{
\"client_id\": \"${CLIENT_ID}\", \"client_id\": \"${CLIENT_ID}\",
\"client_secret\": \"${CLIENT_SECRET}\", \"client_secret\": \"${CLIENT_SECRET}\",
\"redirect_uris\": [\"https://${HOMESERVER_FQDN}/_synapse/client/oidc/callback\"], \"redirect_uris\": [\"https://${HOMESERVER_FQDN}/_synapse/client/oidc/callback\"],
@@ -133,22 +111,17 @@ if [[ -z "$EXISTING_CLIENT" ]]; then
\"response_types\": [\"code\"], \"response_types\": [\"code\"],
\"scopes\": [\"openid\", \"profile\", \"email\"], \"scopes\": [\"openid\", \"profile\", \"email\"],
\"application_type\": \"web\" \"application_type\": \"web\"
}]" "$MAS_CFG" || { log_error "Failed to register Synapse client in MAS"; exit 1; } }"
yq -y -i ".clients += [$CLIENT_OBJ]" "$SYNAPSE_CFG" || { log_error "Failed to register Synapse client in MAS"; exit 1; }
log_info " -> Registered Synapse as OIDC client in MAS" log_info " -> Registered Synapse as OIDC client in MAS"
else else
log_info " -> Synapse client already registered in MAS, skipping" log_info " -> Synapse client already registered in MAS, skipping"
fi fi
ISSUER_URL="https://${MAS_FQDN}" ISSUER_URL="https://${MAS_FQDN}"
fix_ownership "$SYNAPSE_CFG" fix_ownership "$SYNAPSE_CFG"
#cat > "$TEMP_FILTER" <<EOF
#.oidc_providers += [{"idp_id": "mas", "idp_name": "Matrix Authentication Service", "idp_brand": "mas", "issuer": "${ISSUER_URL}", "client_id": "${CLIENT_ID}", "client_secret": "${CLIENT_SECRET}", "scopes": ["openid", "profile"], "skip_verification": false}]
#EOF
if ! yq '.oidc_providers' "$SYNAPSE_CFG" 2>/dev/null | grep -q "idp_id"; then if ! yq '.oidc_providers' "$SYNAPSE_CFG" 2>/dev/null | grep -q "idp_id"; then
# # yq -y -i "$(cat "$TEMP_FILTER")" "$SYNAPSE_CFG" || { log_error "Failed to inject OIDC config"; exit 1; }
yq -y -i ".oidc_providers += [{ yq -y -i ".oidc_providers += [{
\"idp_id\": \"mas\", \"idp_id\": \"mas\",
\"idp_name\": \"Matrix Authentication Service\", \"idp_name\": \"Matrix Authentication Service\",
+1 -1
View File
@@ -77,7 +77,7 @@ services:
- "traefik.http.routers.auth.rule=Host(`${MAS_FQDN}`)" - "traefik.http.routers.auth.rule=Host(`${MAS_FQDN}`)"
- "traefik.http.routers.auth.entrypoints=websecure" - "traefik.http.routers.auth.entrypoints=websecure"
- "traefik.http.routers.auth.tls.certresolver=myresolver" - "traefik.http.routers.auth.tls.certresolver=myresolver"
- "traefik.http.services.auth.loadbalancer.server.port=8000" - "traefik.http.services.auth.loadbalancer.server.port=8080"
# [TRAEFIK_LABELS_END] # [TRAEFIK_LABELS_END]
# --- OPTIONAL: LIVEKIT RTC STACK --- # --- OPTIONAL: LIVEKIT RTC STACK ---