목록으로

Programming Notes

배운 교훈 #552: SSMS MSAL 추적에서 거의 모든 것을 알려주는 10줄


본문

In one of our support cases, a customer reported higher-than-expected connection times when connecting from SQL Server Management Studio (SSMS) to Azure SQL Database using Microsoft Entra authentication.
The behavior was also not completely consistent.
Sometimes the connection required interaction with the account selection experience. Other times, subsequent connections were noticeably faster.
At first, there were several possible areas to investigate:

  • Was Azure SQL taking too long to authenticate the user?
  • Was there a networking, proxy, or firewall issue?
  • Was access to login.microsoftonline.com being delayed or denied?
  • Was Microsoft Entra authentication itself taking the time?
  • Was Conditional Access or MFA involved?
  • Was SSMS using the expected Microsoft Entra account?
  • Was the delay happening before or after the access token was obtained?

The important question became: Where exactly was the connection time being spent?
Instead of treating the SSMS connection as a single operation, I enabled verbose MSAL tracing in SSMS and started following the authentication process.

SSMS는 Tools → Options → Azure Services 아래에 MSAL Output Window Trace Level 옵션을 제공합니다. 이 옵션 페이지에서는 Microsoft Entra authority, Azure SQL Database service principal name, 그리고 Web Account Manager 설정도 확인할 수 있습니다.

The resulting trace was large—hundreds of lines.
But while analyzing it, I realized something useful:

I didn't need to understand every line in the MSAL trace. A small number of search strings were enough to reconstruct almost the entire authentication story.

These are the 10 things I learned to look for.


1. CorrelationId — 같은 인증 요청을 추적하기 위해 먼저 확인해야 할 항목

MSAL은 여러 연관 작업을 동시에 수행합니다.

  • GetAccounts.
  • AcquireTokenSilent.
  • ReadAccountById.
  • AcquireTokenInteractive.
  • Broker operations.
  • Token cache operations.

이 작업들은 거의 같은 시점에 일어나며 반드시 같은 CorrelationId를 공유하지는 않습니다. 예를 들어, 첫 번째 시도에서는 AcquireTokenSilent이 하나의 CorrelationId를, 이어지는 인터랙티브 요청은 다른 CorrelationId를 사용했습니다.

So my first search became: CorrelationId

I learned not to calculate latency by simply subtracting two nearby timestamps.
First I identify: Operation + CorrelationId + Start / End and only then interpret the timing.

CorrelationId는 나중에 ID‑service 조사와 연계할 때도 유용합니다.


2. ApiId — SSMS가 무음(silent) 인증을 시도했는가, 인터랙티브 인증을 시도했는가?

검색어: ApiId

첫 번째 연결 시도에서는 ApiId – AcquireTokenSilent 이 나타났고, 이는 SSMS가 처음에 UI를 표시하지 않겠다는 뜻이었습니다.

하지만 같은 재현 과정에서 ApiId – AcquireTokenInteractive 도 발견되었습니다.

Flow became clearer: SSMS → AcquireTokenSilent → Silent authentication cannot continue → AcquireTokenInteractive

Lesson: SSMS Microsoft Entra 연결은 처음부터 반드시 인터랙티브하지 않을 수 있습니다. MSAL은 먼저 무음 인증을 시도하고, 필요하면 인터랙티브 방식으로 전환합니다.

MsalUiRequiredException 은 sign‑in, MFA, consent 등 사용자 상호작용이 필요할 때 발생합니다.


3. Authority — 인증 요청이 실제로 어디로 가는가?

검색어: Authority

Trace에 나타난 예시:

Authority - https://login.microsoftonline.com/<tenant-id>/

이 한 줄로 두 가지 중요한 정보를 얻습니다.

  1. https://login.microsoftonline.com/ → Microsoft Entra 테넌트(Identity authority)
  2. 특정 tenant‑id 로 연결됨

따라서 Azure SQL 를 탓하기 전에 SSMS/MSAL이 어떤 엔드포인트를 사용하고 있는지 확인할 수 있습니다.

403, 404 등 HTTP 상태 코드만 보고 “방화벽이 login.microsoftonline.com을 차단했다”고 단정짓지 말고, ErrorCode, AADSTS 코드, ResponseBody 등을 함께 살펴보세요.

MSAL은 오류를 크게 다음과 같이 구분합니다.

오류 종류 의미
MsalClientException 클라이언트/라이브러리 오류
MsalServiceException 토큰 제공자/서비스 응답 오류
MsalUiRequiredException 인터랙션 필요 상황
네트워크 실패 DNS, TLS, 프록시 등 연결 문제

4. Scopes — SSMS가 어떤 리소스에 대해 토큰을 요청했는가?

검색어: Scopes

예시:

Scopes - https://database.windows.net//.default

두 부분을 구분하면 도움이 됩니다.

  • Authority → 인증이 수행되는 위치 (login.microsoftonline.com)
  • Scope → 토큰이 사용될 대상 (database.windows.net)

SSMS는 https://database.windows.net/ 를 Azure SQL Database 서비스 프린시플 이름으로 사용합니다. 따라서 Entra 토큰 획득 문제와 Azure SQL 권한 문제를 혼동하지 않아야 합니다.


5. LoginHint — SSMS가 제안한 ID는 무엇인가?

검색어: LoginHint

예시:

LoginHint provided: True
LoginHint - [email protected]

다른 경우에는 no_account_for_login_hint 라는 MsalUiRequiredException 가 발생했습니다.

LoginHint 은 “이 ID를 찾아보라” 라는 의미이며, 이미 해결된 계정이라는 뜻은 아닙니다.

따라서 LoginHint 가 존재한다고 해서 바로 올바른 계정이 선택된 것은 아닙니다.


6. Account provided / GetAllAccounts — LoginHint와 실제 계정은 별개

검색어: GetAllAccounts 와 Account provided

예시 1:

GetAllAccounts ... found 1 accounts
LoginHint provided: True  Account provided: false

결과는 no_account_for_login_hint. 여기서 배운 점은:

계정이 존재함 ≠ LoginHint와 일치하는 계정이 존재함

예시 2:

LoginHint provided: False
Account provided: Account username: [email protected]

이 경우는 LoginHint 를 사용하지 않고 이미 해결된 계정을 직접 전달했습니다.

다른 경우에는 캐시에 아무 계정도 없고 LoginHint 만 제공되어 같은 오류가 발생했습니다.

Lesson: no_account_for_login_hint 를 단순히 “잘못된 사용자 이름”이라고 판단하지 말고, GetAllAccounts, LoginHint, Account provided 를 모두 확인하세요.


7. ErrorCode, AADSTS, StatusCode — 오류가 가리키는 다음 조사 대상

가장 빠른 검색어는 ErrorCode 와 함께 다음 항목들을 찾는 것입니다.

  • AADSTS
  • StatusCode
  • ResponseBody
  • MsalUiRequiredException
  • MsalServiceException
  • MsalClientException

예시:

MsalUiRequiredException ErrorCode: no_account_for_login_hint

이 오류는 토큰 획득/계정 해석 단계에 머물러 있음을 의미합니다. Azure SQL 권한 문제와는 별개입니다.

아래 표는 오류 타입별 조사 포인트를 정리한 것입니다.

Trace evidence First place to investigate
no_account_for_login_hint LoginHint / cached account / account resolution
MsalUiRequiredException 왜 무음 인증이 인터랙션을 요구하는가
authentication_canceled 인터랙티브 UI / broker / 사용자 취소
AADSTSxxxxx Microsoft Entra 인증 또는 정책
MsalServiceException 토큰 제공자/서비스 응답
MsalClientException 클라이언트/라이브러리 / 디바이스 측
DNS/TLS/프록시 예외 Identity 서비스 연결
Access token obtained 토큰 이후 단계로 조사 전환
— —

8. Broker, WAM, authorization_type — 실제 인증을 담당한 주체는?

검색어: Broker, WAM, RuntimeBroker, auth_flow, authorization_type

예시:

Broker is configured
Using Windows account picker
Calling SignInInteractivelyAsync
auth_flow: Broker
authorization_type: Interactive

이것은 흐름이 SSMS → MSAL → Windows Web Account Manager → Broker → Entra 라는 것을 의미합니다.

  • WAM (Web Account Manager) 은 Windows에서 MSAL이 인증 브로커로 사용할 수 있는 구성 요소이며, SSO와 계정 선택을 지원합니다.
  • 같은 SSMS 연결이라도 silent 와 interactive 경로가 교차할 수 있습니다. 계정 상태, 캐시, MFA, Conditional Access 등에 따라 경로가 달라집니다.

9. AccessToken returned — 조사 방향을 바꾸는 핵심 라인

성공적인 토큰 획득 시 나타나는 라인:

AccessToken returned: True
AccessToken Type: Bearer
=== Token Acquisition finished successfully source: Broker

이 시점부터는 Identity troubleshooting → Token acquisition 단계는 끝났으며, Azure SQL 로 토큰을 전달하고 검증하는 단계로 넘어갑니다.


10. DurationTotalInMs — 실제 연결 지연이 어디서 발생했는가

고객이 보고한 “높은 연결 시간”을 정량화하기 위해 찾은 키워드:

  • DurationTotalInMs
  • DurationInHttpInMs
  • DurationInCacheInMs
  • request_duration
  • time_in_queue_ms

MSAL 정의:

  • DurationTotalInMs – 토큰 획득 전체 소요 시간 (네트워크 + 캐시)
  • DurationInHttpInMs – Identity provider 로의 HTTP 호출 시간
  • DurationInCacheInMs – 캐시 작업 시간

예시 1 (첫 연결):

DurationTotalInMs: 2185
DurationInCacheInMs: 0
DurationInHttpInMs: 0
time_in_queue_ms: 2152
request_duration: 2183

예시 2 (두 번째 연결, 캐시 사용):

DurationTotalInMs: 13
DurationInCacheInMs: 0
DurationInHttpInMs: 0

따라서 첫 연결은 브로커 큐 대기 시간(time_in_queue_ms) 때문에 ≈2 초가 걸렸고, 두 번째 연결은 캐시된 계정 덕분에 13 ms 만에 완료되었습니다.


10가지 검색어 순서

Search for What I want to know
CorrelationId 같은 인증 흐름을 추적하고 있는가?
ApiId 무음(silent)인가, 인터랙티브인가?
Authority 어떤 Microsoft Entra 엔드포인트·테넌트를 사용했는가?
Scopes 토큰이 어떤 리소스를 대상으로 하는가?
LoginHint SSMS가 어떤 ID를 제시했는가?
Account provided / GetAllAccounts 이미 해결된 계정이 있거나 캐시된 계정이 있나?
ErrorCode / AADSTS 인증 단계에서 왜 실패했는가?
Broker / WAM / authorization_type 실제 인증을 담당한 메커니즘은?
AccessToken returned / source 토큰을 정상적으로 획득했는가? 그 출처는?
DurationTotalInMs 등 전체 인증 지연이 어디서 발생했는가?

위 10가지 검색어만으로 수백 줄에 달하는 MSAL 추적 로그도 간단히 해석할 수 있습니다.


부록 – 정제된 MSAL Trace 샘플

아래는 실제 조사에 사용된 정제·축소된 MSAL 추적 샘플입니다. 사용자 이름, 테넌트 ID, Correlation ID 등 개인 식별 정보(PII)는 모두 가명 처리했습니다.

첫 번째 연결

==== GetAccounts started ====

GetAllAccounts ... found 0 accounts
Found 0 RTs and 0 accounts in MSAL cache

=== AcquireTokenSilent Parameters ===
LoginHint provided: True
Account provided: false

Authority - https://login.microsoftonline.com/<tenant-id>/
Scopes - https://database.windows.net//.default
ApiId - AcquireTokenSilent
CorrelationId - <correlation-id-1>

=== Token Acquisition (SilentRequest) started ===

MsalUiRequiredException
ErrorCode: no_account_for_login_hint

No account was found in the token cache having this login hint.

MSAL은 이후 인터랙티브 인증으로 전환합니다.

=== InteractiveParameters Data ===

LoginHint provided: True
Prompt: select_account

Authority - https://login.microsoftonline.com/<tenant-id>/
Scopes - https://database.windows.net//.default
ApiId - AcquireTokenInteractive
LoginHint - [email protected]
CorrelationId - <correlation-id-2>

Broker is configured
Using Windows account picker
Calling SignInInteractivelyAsync

브로커가 토큰을 성공적으로 획득했습니다.

auth_flow: Broker
authorization_type: Interactive

time_in_queue_ms: 2152
request_duration: 2183

WAM response status success
Successfully retrieved token

AccessToken returned: True
AccessToken Type: Bearer

=== Token Acquisition finished successfully ===
source: Broker

DurationTotalInMs: 2185
DurationInCacheInMs: 0
DurationInHttpInMs: 0

두 번째 연결

몇 초 뒤, 캐시된 계정이 이미 존재합니다.

GetAllAccounts ... found 1 accounts
Returning 1 accounts

=== AcquireTokenSilent Parameters ===

LoginHint provided: False

Account provided:
Account username: [email protected]

Authority - https://login.microsoftonline.com/<tenant-id>/
Scopes - https://database.windows.net//.default
ApiId - AcquireTokenSilent
CorrelationId - <correlation-id-3>

이번에는 브로커가 무음으로 토큰을 반환합니다.

Acquiring token silently

authorization_type: WindowsIntegratedAuth
auth_flow: AT
request_duration: 2

WAM response status success
Successfully retrieved token

AccessToken returned: True

=== Token Acquisition finished successfully ===
source: Broker

DurationTotalInMs: 13
DurationInCacheInMs: 0
DurationInHttpInMs: 0

무엇이 바뀌었나요?

단계 첫 번째 연결 두 번째 연결
계정 상태 없음 → LoginHint → AcquireTokenSilent → no_account_for_login_hint → Interactive / WAM → Token (2185 ms) 캐시된 계정 존재 → AcquireTokenSilent → WAM → Token (13 ms)

아래는 위에서 강조한 10가지 키워드 목록입니다.

CorrelationId
ApiId
Authority
Scopes
LoginHint
Account provided / GetAllAccounts
ErrorCode / AADSTS
Broker / WAM
AccessToken returned
DurationTotalInMs