OAuth 2.0 authentication
OAuth 2.0 authentication (OAuth 2.0 인증)
OAuth 2.0을 사용해 Web UI와 JDBC 드라이버가 HTTPS로 인증하도록 Trino를 구성하는 방법이에요. Trino는 Authorization Code 흐름을 사용해 인가 코드를 토큰으로 교환해요.
출처: 문서
본문
Trino는 Web UI와 JDBC 드라이버에 대해 HTTPS로 OAuth 2.0 인증을 활성화하도록 구성할 수 있어요. Trino는 Authorization Code를 토큰으로 교환하는 Authorization Code 흐름을 사용해요. 높은 수준에서 이 흐름은 다음 단계를 포함해요:
- Trino 코디네이터가 사용자의 브라우저를 Authorization Server로 리다이렉트해요.
- 사용자가 Authorization Server로 인증하고 Trino의 권한 요청을 승인해요.
- 사용자의 브라우저가 인가 코드와 함께 Trino 코디네이터로 리다이렉트돼요.
- Trino 코디네이터가 인가 코드를 토큰으로 교환해요.
Trino에서 OAuth 2.0 인증을 활성화하려면 Trino 코디네이터에 구성 변경을 해요. 워커 구성은 변경할 필요가 없어요. 오직 클라이언트에서 코디네이터로의 통신만 인증돼요.
OpenID Connect(OIDC) 제공자 같은 OAuth 2.0 인가 서버를 구성할 때 콜백/리다이렉트 URL을 https://<trino-coordinator-domain-name>/oauth2/callback으로 설정하세요.
Web UI가 활성화되어 있다면 OpenID Connect(OIDC) 제공자 같은 OAuth 2.0 인증 서버를 구성할 때 로그아웃 후 콜백 URL을 https://<trino-coordinator-domain-name>/ui/logout/logout.html로 설정하세요.
OAuth 2.0 인증에는 TLS 사용과 구성된 공유 시크릿(shared secret)이 필요해요.
OpenID Connect Discovery
Trino는 OIDC 제공자 구성 메타데이터 문서에서 Authorization Server 구성을 읽는 것을 지원해요. 코디네이터 시작 시 Trino는 문서를 가져와 제공된 값을 사용해 해당 OAuth2 인증 구성 속성을 설정해요:
authorization_endpoint->http-server.authentication.oauth2.auth-urltoken_endpoint->http-server.authentication.oauth2.token-urljwks_uri->http-server.authentication.oauth2.jwks-urluserinfo_endpoint->http-server.authentication.oauth2.userinfo-urlaccess_token_issuer->http-server.authentication.oauth2.access-token-issuerend_session_endpoint->http-server.authentication.oauth2.end-session-url
Warning
인가 서버가 JSON 웹 토큰(JWT)을 발급하고 메타데이터 문서에 userinfo_endpoint가 있다면, Trino는 이 엔드포인트를 사용해 OAuth2 액세스 토큰의 유효성을 확인해요. JWT는 로컬에서 검사할 수 있으므로, 이를 userinfo_endpoint에 사용하면 인증 실패가 발생할 수 있어요. 이 경우 http-server.authentication.oauth2.oidc.use-userinfo-endpoint 구성 속성을 false로 설정하세요(http-server.authentication.oauth2.oidc.use-userinfo-endpoint=false). 이렇게 하면 Trino가 userinfo_endpoint를 무시하고 토큰을 로컬에서 검사하도록 지시해요.
이 기능은 기본적으로 활성화되어 있지만 http-server.authentication.oauth2.oidc.discovery=false로 끌 수 있어요.
Trino 서버 구성 (Trino server configuration)
OAuth2 인증을 사용하려면 Trino 코디네이터가 TLS로 보호되어야 해요.
다음은 코디네이터의 config.properties 파일에 추가해야 하는 필수 속성의 예시예요:
http-server.authentication.type=oauth2
http-server.https.port=8443
http-server.https.enabled=true
http-server.authentication.oauth2.issuer=https://authorization-server.com
http-server.authentication.oauth2.client-id=CLIENT_ID
http-server.authentication.oauth2.client-secret=CLIENT_SECRET
Web UI에 OAuth 2.0 인증을 활성화하려면 다음 속성을 추가해야 해요:
web-ui.authentication.type=oauth2
다음 구성 속성을 사용할 수 있어요:
OAuth2 구성 속성 (OAuth2 configuration properties)
| Property | Description |
|---|---|
http-server.authentication.type |
사용할 인증 타입. Trino 코디네이터의 OAuth2 인증을 활성화하려면 oauth2로 설정해야 해요. |
http-server.authentication.oauth2.issuer |
IdP의 issuer URL. 발급된 모든 토큰은 iss 필드에 이 값을 가져야 해요. |
http-server.authentication.oauth2.access-token-issuer |
액세스 토큰용 IdP의 issuer URL(다른 경우). 발급된 모든 액세스 토큰은 iss 필드에 이 값을 가져야 해요. OIDC discovery가 활성화된 동안 이 값을 제공하면 OpenID 제공자 메타데이터 문서의 값을 재정의해요. 기본값은 http-server.authentication.oauth2.issuer의 값. |
http-server.authentication.oauth2.auth-url |
인가 URL. OAuth 2.0 인가 프로세스를 시작하기 위해 사용자 브라우저가 리다이렉트될 URL이에요. OIDC discovery가 활성화된 동안 이 값을 제공하면 OpenID 제공자 메타데이터 문서의 값을 재정의해요. |
http-server.authentication.oauth2.domain-hint |
SSO 계정 선택을 특정 도메인으로 제한하는 도메인 힌트. 설정하면 인가 URL에 domain_hint 파라미터와 함께 prompt=select_account로 포함되는데, 일부 IdP(예: Azure AD)가 로그인 중 사용자에게 보여주는 계정 선택기를 필터링하는 데 사용해요. |
http-server.authentication.oauth2.token-url |
Trino가 액세스 토큰을 얻기 위해 사용하는 인가 서버의 엔드포인트 URL. OIDC discovery가 활성화된 동안 이 값을 제공하면 OpenID 제공자 메타데이터 문서의 값을 재정의해요. |
http-server.authentication.oauth2.jwks-url |
인가 서버의 JSON Web Key Set(JWKS) 엔드포인트 URL. 인가 서버의 JSON 웹 토큰(JWT)을 검증할 공개 키를 담은 키 집합을 Trino에 제공해요. OIDC discovery가 활성화된 동안 이 값을 제공하면 OpenID 제공자 메타데이터 문서의 값을 재정의해요. |
http-server.authentication.oauth2.userinfo-url |
IdP의 /userinfo 엔드포인트 URL. 제공되면 이 URL로 OAuth 액세스 토큰을 검증하고 관련 클레임을 검색해요. IdP가 불투명(opaque) 토큰을 발급하면 필수예요. OIDC discovery가 활성화된 동안 이 값을 제공하면 OpenID 제공자 메타데이터 문서의 값을 재정의해요. |
http-server.authentication.oauth2.client-id |
Trino 클라이언트의 공개 식별자. |
http-server.authentication.oauth2.client-secret |
Trino 클라이언트를 인가 서버에 인가하는 데 사용하는 시크릿. |
http-server.authentication.oauth2.additional-audiences |
항상 신뢰되는 대상인 클라이언트 ID 외에 추가로 신뢰할 대상. |
http-server.authentication.oauth2.scopes |
인가 도전 중 서버가 요청하는 스코프. 참고: https://tools.ietf.org/html/rfc6749#section-3.3 |
http-server.authentication.oauth2.challenge-timeout |
인가 도전의 최대 지속 시간. 기본값은 15m. |
http-server.authentication.oauth2.state-key |
인가 요청이 위조되지 않았는지 보장하기 위해 state 파라미터에 서명하는 SHA-256 HMAC 알고리즘에 사용하는 시크릿 키. 기본값은 코디네이터 시작 시 생성되는 무작위 문자열. |
http-server.authentication.oauth2.user-mapping.pattern |
사용자와 대조할 정규식. 일치하면 사용자 이름이 첫 번째 정규식 그룹으로 대체되고, 일치하지 않으면 인증이 거부돼요. 기본값은 (.*)로 모든 사용자 이름을 허용해요. |
http-server.authentication.oauth2.user-mapping.file |
사용자 매핑 규칙을 담은 파일. 자세한 내용은 User mapping 참고. |
http-server.authentication.oauth2.principal-field |
Trino 사용자 프린시펄에 사용하는 액세스 토큰의 필드. 기본값은 sub. 다른 자주 쓰이는 필드로는 sAMAccountName, name, upn, email이 있어요. |
http-server.authentication.oauth2.oidc.discovery |
OIDC 제공자 메타데이터 읽기 활성화. 기본값은 true. |
http-server.authentication.oauth2.oidc.discovery.timeout |
OpenID 제공자 메타데이터를 읽을 때의 시간 제한. 기본값은 30s. |
http-server.authentication.oauth2.oidc.use-userinfo-endpoint |
제공자 메타데이터에서 userinfo_endpoint 값을 사용. userinfo_endpoint 값이 제공되면 이 URL로 OAuth 2.0 액세스 토큰을 검증하고 관련 클레임을 검색해요. 이 플래그로 메타데이터 문서에서 제공된 값을 무시할 수 있어요. 기본값은 true. |
http-server.authentication.oauth2.end-session-url |
Trino에서 로그아웃할 때 End-User가 인증 서버에서도 로그아웃되도록 사용자 브라우저가 리다이렉트되는 인증 서버의 엔드포인트 URL. |
리프레시 토큰 (Refresh tokens)
리프레시 토큰을 사용하면 애플리케이션 안에서 사용자 세션의 길이를 안전하게 제어할 수 있어요. 리프레시 토큰은 더 긴 수명(TTL)을 가지며 수명이 짧은 액세스 토큰을 새로고침하는 데 사용돼요. 리프레시 토큰을 액세스 토큰과 함께 사용하면 사용자는 또 다른 로그인 요청으로 중단되지 않고 연장된 기간 동안 로그인 상태를 유지할 수 있어요.
리프레시 토큰 흐름에는 서로 다른 만료 시간을 가진 세 개의 토큰이 있어요:
- access token(액세스 토큰)
- refresh token(리프레시 토큰)
- 액세스와 리프레시 토큰의 조합인 Trino-암호화 토큰. 암호화 토큰은
http-server.authentication.oauth2.refresh-tokens.issued-token.timeout속성으로 설정한 timeout 값으로 세션 수명을 관리해요.
다음 시나리오에서 IdP가 발급한 토큰의 수명은:
- access token 5m
- refresh token 24h
액세스 토큰 수명이 5분뿐이므로 Trino는 수명이 더 긴 리프레시 토큰을 사용해 5분마다 사용자를 대신해 다른 액세스 토큰을 요청해요. 이 경우 최대 http-server.authentication.oauth2.refresh-tokens.issued-token.timeout은 24시간이에요.
리프레시 토큰 흐름을 사용하려면 코디네이터 구성에서 다음 속성을 활성화해야 해요:
http-server.authentication.oauth2.refresh-tokens=true
IdP 구성에 따라 오프라인 접근용 추가 스코프가 필요할 수 있어요.
http-server.authentication.oauth2.scopes=openid,offline_access [or offline]
다음 구성 속성을 사용할 수 있어요:
리프레시 흐름용 OAuth2 구성 속성 (OAuth2 configuration properties for refresh flow)
| Property | Description |
|---|---|
http-server.authentication.oauth2.refresh-tokens.issued-token.timeout |
발급 토큰(액세스 토큰과 리프레시 토큰을 담은 Trino-암호화 토큰)의 만료 시간. timeout 값은 IdP가 발급한 리프레시 토큰 만료 기간보다 작거나 같아야 해요. 기본값은 1h. 이 timeout 값은 리프레시 토큰이 활성화된 OAuth2 인증 클라이언트의 최대 세션 시간이에요. 자세한 내용은 Troubleshooting을 참고하세요. |
http-server.authentication.oauth2.refresh-tokens.issued-token.issuer |
발급 토큰에서 참조되는 코디네이터 인스턴스를 나타내는 issuer. 기본값은 Trino_coordinator. 현재 Trino 버전이 값에 추가돼요. 주로 디버깅 목적으로 사용돼요. |
http-server.authentication.oauth2.refresh-tokens.issued-token.audience |
발급 토큰에서 사용되는 이 코디네이터 인스턴스를 나타내는 audience. 기본값은 Trino_coordinator. |
http-server.authentication.oauth2.refresh-tokens.secret-key |
생성된 토큰을 암호화하는 데 사용하는 Base64 인코딩 시크릿 키. 기본적으로 시작 시 생성돼요. |
문제 해결 (Troubleshooting)
문제를 디버깅하려면 OAuth 2.0 인증기의 로그 수준을 변경하세요:
io.trino.server.security.oauth2=DEBUG
Web UI와 함께 OAuth 2.0 인증 이슈를 디버깅하려면 다음 구성 속성을 설정하세요:
io.trino.server.ui.OAuth2WebUiAuthenticationFilter=DEBUG
이것은 Trino server configuration에 설명된 대로 Web UI의 OAuth 2.0 인증이 활성화되어 있다고 가정해요.
만료된 리프레시 토큰에 대한 로그 디버그 오류는 Tokens refresh challenge has failed예요.
Warning
리프레시 토큰이 만료되면 사용자 세션이 중단되고 사용자는 다시 로그인해 재인증해야 해요. http-server.authentication.oauth2.refresh-tokens.issued-token.timeout 값을 IdP가 발급한 리프레시 토큰 만료 기간보다 작거나 같게 설정하세요. 이상적으로는 세션이 원활하게 끝나도록 timeout을 IdP 리프레시 토큰 수명보다 약간 작게 설정하세요.
더 알아보기 (Learn more)
OAuth2를 사용할 때 JWT는 자동으로 처리되므로 별도 JWT 인증은 필요 없어요. JWT authentication 문서도 참고해 보세요.