|
|
@@ -98,13 +98,17 @@ fix_ownership "${VOLUME_PATH}/mas"
|
|
|
|
|
|
|
|
|
|
|
|
log_info "Linking Synapse and MAS via OIDC..."
|
|
|
|
log_info "Linking Synapse and MAS via OIDC..."
|
|
|
|
|
|
|
|
|
|
|
|
CLIENT_ID="synapse-client"
|
|
|
|
CLIENT_ID="0000000000000000000SYNAPSE"
|
|
|
|
CLIENT_SECRET=$(openssl rand -hex 32)
|
|
|
|
CLIENT_SECRET=$(openssl rand -hex 32)
|
|
|
|
|
|
|
|
ADMIN_SECRET=$(openssl rand -hex 32)
|
|
|
|
|
|
|
|
MATRIX_SECRET=$(openssl rand -hex 32)
|
|
|
|
|
|
|
|
MATRIX_ENDPOINT="http://synapse:8008"
|
|
|
|
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
|
|
|
|
CLIENT_OBJ="{
|
|
|
|
CLIENT_OBJ="{
|
|
|
|
\"client_id\": \"${CLIENT_ID}\",
|
|
|
|
\"client_id\": \"${CLIENT_ID}\",
|
|
|
|
|
|
|
|
\"client_auth_method\": \"client_secret_basic\",
|
|
|
|
\"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\"],
|
|
|
|
\"grant_types\": [\"authorization_code\", \"refresh_token\"],
|
|
|
|
\"grant_types\": [\"authorization_code\", \"refresh_token\"],
|
|
|
@@ -112,12 +116,22 @@ if [[ -z "$EXISTING_CLIENT" ]]; then
|
|
|
|
\"scopes\": [\"openid\", \"profile\", \"email\"],
|
|
|
|
\"scopes\": [\"openid\", \"profile\", \"email\"],
|
|
|
|
\"application_type\": \"web\"
|
|
|
|
\"application_type\": \"web\"
|
|
|
|
}"
|
|
|
|
}"
|
|
|
|
yq -y -i ".clients += [$CLIENT_OBJ]" "$SYNAPSE_CFG" || { log_error "Failed to register Synapse client in MAS"; exit 1; }
|
|
|
|
yq -y -i ".clients += [$CLIENT_OBJ]" "$MAS_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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Ensure the matrix section exists
|
|
|
|
|
|
|
|
if ! yq '.matrix' "$MAS_CFG" > /dev/null 2>&1; then
|
|
|
|
|
|
|
|
yq -y -i '.matrix = {}' "$MAS_CFG"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
yq -y -i ".matrix.homeserver = \"${HOMESERVER_FQDN}\"" "$MAS_CFG"
|
|
|
|
|
|
|
|
yq -y -i ".matrix.secret = \"${MATRIX_SECRET}\"" "$MAS_CFG"
|
|
|
|
|
|
|
|
yq -y -i ".matrix.endpoint = \"${MATRIX_ENDPOINT}\"" "$MAS_CFG"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ISSUER_URL="https://${MAS_FQDN}"
|
|
|
|
ISSUER_URL="https://${MAS_FQDN}"
|
|
|
|
fix_ownership "$SYNAPSE_CFG"
|
|
|
|
fix_ownership "$SYNAPSE_CFG"
|
|
|
|
|
|
|
|
|
|
|
@@ -129,6 +143,7 @@ if ! yq '.oidc_providers' "$SYNAPSE_CFG" 2>/dev/null | grep -q "idp_id"; then
|
|
|
|
\"issuer\": \"${ISSUER_URL}\",
|
|
|
|
\"issuer\": \"${ISSUER_URL}\",
|
|
|
|
\"client_id\": \"${CLIENT_ID}\",
|
|
|
|
\"client_id\": \"${CLIENT_ID}\",
|
|
|
|
\"client_secret\": \"${CLIENT_SECRET}\",
|
|
|
|
\"client_secret\": \"${CLIENT_SECRET}\",
|
|
|
|
|
|
|
|
\"shared_secret\": \"${MATRIX_SECRET}\",
|
|
|
|
\"scopes\": [\"openid\", \"profile\"],
|
|
|
|
\"scopes\": [\"openid\", \"profile\"],
|
|
|
|
\"skip_verification\": false
|
|
|
|
\"skip_verification\": false
|
|
|
|
}]" "$SYNAPSE_CFG" || { log_error "Failed to inject OIDC config"; exit 1; }
|
|
|
|
}]" "$SYNAPSE_CFG" || { log_error "Failed to inject OIDC config"; exit 1; }
|
|
|
|