Skip to content

Commit edc6027

Browse files
committed
debug
1 parent 5b74b60 commit edc6027

File tree

2 files changed

+47
-8
lines changed

2 files changed

+47
-8
lines changed

.github/workflows/token-federation-test.yml

+32-6
Original file line numberDiff line numberDiff line change
@@ -214,19 +214,26 @@ jobs:
214214
215215
# Create a properly URL-encoded request
216216
echo "Creating token exchange request..."
217+
curl_data=$(cat << 'EOF'
218+
client_id=$IDENTITY_FEDERATION_CLIENT_ID&\
219+
subject_token=$OIDC_TOKEN&\
220+
subject_token_type=urn:ietf:params:oauth:token-type:jwt&\
221+
grant_type=urn:ietf:params:oauth:grant-type:token-exchange&\
222+
scope=sql
223+
EOF
224+
)
225+
226+
# Substitute environment variables in the curl data
227+
curl_data=$(eval echo "$curl_data")
217228
218229
# Print request details (except the token)
219230
echo "Request URL: https://$DATABRICKS_HOST_FOR_TF/oidc/v1/token"
220-
echo "Request data: client_id=$IDENTITY_FEDERATION_CLIENT_ID&subject_token=REDACTED&subject_token_type=urn:ietf:params:oauth:token-type:jwt&grant_type=urn:ietf:params:oauth:grant-type:token-exchange&scope=sql"
231+
echo "Request data: $(echo "$curl_data" | sed 's/subject_token=.*&/subject_token=REDACTED&/')"
221232
222233
# Make the request with detailed info
223234
echo "Sending request..."
224235
response=$(curl -v -s -X POST "https://$DATABRICKS_HOST_FOR_TF/oidc/v1/token" \
225-
--data-urlencode "client_id=$IDENTITY_FEDERATION_CLIENT_ID" \
226-
--data-urlencode "subject_token=$OIDC_TOKEN" \
227-
--data-urlencode "subject_token_type=urn:ietf:params:oauth:token-type:jwt" \
228-
--data-urlencode "grant_type=urn:ietf:params:oauth:grant-type:token-exchange" \
229-
--data-urlencode "scope=sql" \
236+
--data-raw "$curl_data" \
230237
-H "Content-Type: application/x-www-form-urlencoded" \
231238
-H "Accept: application/json" \
232239
2>&1)
@@ -239,6 +246,13 @@ jobs:
239246
status_code=$(echo "$response" | grep -o "< HTTP/[0-9.]* [0-9]*" | grep -o "[0-9]*$" || echo "unknown")
240247
echo "HTTP Status Code: $status_code"
241248
249+
# Try to extract and pretty-print the JSON response body if present
250+
response_body=$(echo "$response" | sed -n -e '/^{/,/^}/p' || echo "")
251+
if [ ! -z "$response_body" ]; then
252+
echo "Response body (formatted):"
253+
echo "$response_body" | python3 -m json.tool || echo "$response_body"
254+
fi
255+
242256
# Don't fail the workflow if curl fails
243257
exit 0
244258
@@ -315,6 +329,18 @@ jobs:
315329
print(f"Expected: {audience}")
316330
print(f"Actual: {claims.get('aud')}")
317331
332+
# Enable more verbose HTTP debugging
333+
import http.client as http_client
334+
http_client.HTTPConnection.debuglevel = 1
335+
336+
# Log requests library debug info
337+
import logging
338+
logging.basicConfig()
339+
logging.getLogger().setLevel(logging.DEBUG)
340+
requests_log = logging.getLogger("requests.packages.urllib3")
341+
requests_log.setLevel(logging.DEBUG)
342+
requests_log.propagate = True
343+
318344
response = requests.post(url, data=data, headers=headers)
319345
320346
print(f"Status code: {response.status_code}")

src/databricks/sql/auth/token_federation.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,25 @@ def _init_oidc_discovery(self):
153153

154154
# Fallback to default token endpoint if discovery fails
155155
if not self.token_endpoint:
156-
self.token_endpoint = f"{self.hostname}oidc/v1/token"
156+
# Make sure hostname has proper format with https:// prefix and trailing slash
157+
hostname = self.hostname
158+
if not hostname.startswith('https://'):
159+
hostname = f'https://{hostname}'
160+
if not hostname.endswith('/'):
161+
hostname = f'{hostname}/'
162+
self.token_endpoint = f"{hostname}oidc/v1/token"
157163
logger.info(f"Using default token endpoint: {self.token_endpoint}")
158164

159165
except Exception as e:
160166
logger.warning(f"OIDC discovery failed: {str(e)}. Using default token endpoint.")
161-
self.token_endpoint = f"{self.hostname}oidc/v1/token"
167+
# Make sure hostname has proper format with https:// prefix and trailing slash
168+
hostname = self.hostname
169+
if not hostname.startswith('https://'):
170+
hostname = f'https://{hostname}'
171+
if not hostname.endswith('/'):
172+
hostname = f'{hostname}/'
173+
self.token_endpoint = f"{hostname}oidc/v1/token"
174+
logger.info(f"Using default token endpoint after error: {self.token_endpoint}")
162175

163176
def _extract_token_info_from_header(self, headers: Dict[str, str]) -> Tuple[str, str]:
164177
"""Extract token type and token value from authorization header."""

0 commit comments

Comments
 (0)