Need
You use the Semarchy Data Platform (SDP) Workload for Microsoft Fabric with SDP Self-Hosted, and you authenticate the Workload against SDP with OAuth 2 client credentials (a client id and a client secret). The Workload cannot authenticate: the browser reports a Cross-Origin Request Blocked (CORS) error when the Workload calls the Keycloak token endpoint.
This only applies to authentication with client credentials. Authentication with an API key does not require this procedure.
Summarized Solution
The Keycloak client used by the Workload (type Service Account, with Client authentication enabled) has no Web Origins configured, and this field is not displayed in the Keycloak admin console for this type of client. Keycloak then does not return the Access-Control-Allow-Origin header on successful token responses, and the browser blocks the call.
To fix it, add https://fabric.semarchy.net to the Web Origins of the client by calling the Keycloak Admin API (3 calls, for example with cURL), as described below.
Detailed Solution
Prerequisites
- The SDP API is served over https (http is not supported by the Workload).
- The system property
-PcorsAllowOrigins=https://fabric.semarchy.netis set at startup on all the Data Management nodes that expose the REST API and can be called by the Workload. - You have the credentials of a Keycloak administrator of the
masterrealm. An SDP administrator account is not sufficient. See step 1 to retrieve these credentials on a Kubernetes deployment. curlandjqare available on the machine running the commands, and, for step 1,kubectlwith read access to the SDP namespace.- You know the client id configured in the Source SDP connection step of the Semarchy Data Product item in Fabric.
In the commands below, replace <sdp-host> with the base URL of your SDP server (including the /auth context path if your installation uses one), <realm> with the realm used by your SDP instance, <client-id> with the client id, and ADMIN_USER / ADMIN_PASS with the credentials of the Keycloak master realm administrator.
1. Retrieve the Keycloak administrator credentials
The administrator of the master realm is stored in a Kubernetes secret of your SDP deployment. Replace <namespace-sdp> with the namespace where SDP is installed:
NS=<namespace-sdp>
kubectl get secret keycloak-provider -n $NS -o jsonpath='{.data.username}' | base64 -d; echo
kubectl get secret keycloak-provider -n $NS -o jsonpath='{.data.password}' | base64 -d; echoThe first command returns the username (ADMIN_USER) and the second the password (ADMIN_PASS).
2. Get an administrator token
TOKEN=$(curl -s -X POST \ "https://<sdp-host>/auth/realms/master/protocol/openid-connect/token" \ -d "grant_type=password&client_id=admin-cli&username=ADMIN_USER&password=ADMIN_PASS" \ | jq -r .access_token)
3. Retrieve the internal UUID of the client
CLIENT_UUID=$(curl -s -H "Authorization: Bearer $TOKEN" \ "https://<sdp-host>/auth/admin/realms/<realm>/clients?clientId=<client-id>" \ | jq -r '.[0].id')
4. Update the Web Origins of the client
curl -s -X PUT \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
"https://<sdp-host>/auth/admin/realms/<realm>/clients/$CLIENT_UUID" \
-d '{"webOrigins": ["https://fabric.semarchy.net", "+"]}'5. (Optional) Verify the result
curl -s -H "Authorization: Bearer $TOKEN" \
"https://<keycloak-host>/auth/admin/realms/<realm>/clients/$CLIENT_UUID" \
| jq '{clientId: .clientId, webOrigins: .webOrigins}'The output must list https://fabric.semarchy.net in webOrigins. You can then retry the connection from the Workload.
To check the CORS headers yourself, send the request from the real application origin: curl -si -X POST -H "Origin: https://fabric.semarchy.net" -H "Content-Type: application/x-www-form-urlencoded" -d "grant_type=client_credentials&client_id=<client-id>&client_secret=<client-secret>" "https://<keycloak-host>/auth/realms/<realm>/protocol/openid-connect/token" | head -15. The access-control-allow-origin header must be present on the 200 response. Testing from the browser console on about:blank sends Origin: null and gives misleading results.Keep your Keycloak administrator credentials private: never paste them in a support ticket. If you need help with this procedure, open a ticket with the Semarchy Support team and describe the step where you are blocked.