OpenID Connect 인증 예제

본 섹션에서는 Driverless AI에서 OpenID Connect 인증을 활성화하는 방법에 관해 설명합니다. 두 가지 예제가 제공됩니다. 첫 번째는 OpenID 연결을 활성화하고 Driverless AI UI에 로그인하는 방법에 관해 설명합니다. 두 번째는 Driverless AI Python client를 실행할 수 있는 추가 토큰 기반 인증 설정에 관해 설명합니다(토큰 기반 인증은 Driverless AI R 클라이언트에서 아직 지원되지 않습니다). 본 섹션에서는 사용자가 OpenID Connect 에 관해 이해하고 있다고 가정합니다.

OpenID Connect 프로토콜

OpenID Connect는 인증 프로세스 중에 고유 프로토콜을 따릅니다.

  1. 클라이언트(RP)에서 OpenID 공급자(OP)로 요청이 전송됩니다.

  2. OP는 최종 사용자를 인증하고 권한을 획득합니다.

  3. OP는 ID 토큰을 사용해서 응답합니다(보통 액세스 토큰도 제공됩니다).

  4. Relying Party(RP)는 액세스 토큰을 포함한 요청을 UserInfo 엔드포인트에 전송할 수 있습니다.

  5. UserInfo 엔드포인트는 최종 사용자에 대한 클레임을 반환합니다.

자세한 정보는 OpenID Connect 기본 클라이언트 Implementer 가이드를 참조하십시오. https://openid.net/specs/openid-connect-basic-1_0.html

잘 알려진 엔드포인트 이해

OpenID 기반 인증을 위한 Driverless AI 구성 프로세스 시작을 위해서는 최종 사용자가 well-known endpoint 에서 정보를 요청하여 인증 서버에 관한 OpenID Connect 메타 데이터를 검색해야 합니다. 이 정보는 나중에 공급자와의 추가 상호 작용 구성에 사용됩니다.

잘 알려진 엔드포인트는 일반적으로 다음과 같이 구성됩니다.

https://yourOpenIDProviderHostname/.well-known/openid-configuration

구성 옵션

OpenID 구성 옵션

config.toml 파일의 다음 옵션은 OpenID 기반 인증을 활성화하는 데 사용됩니다. 이러한 옵션을 설정하면 OpenID를 사용하여 Driverless AI UI에 로그인이 가능합니다.

# The OpenID server URL. (Ex: https://oidp.ourdomain.com) Do not end with a "/"
auth_openid_provider_base_uri= "https://yourOpenIDProviderHostname"

# The uri to pull OpenID config data from. (You can extract most of required OpenID config from this URL.)
# Usually located at: /auth/realms/master/.well-known/openid-configuration

# Quote method from urllib.parse used to encode payload dict in Authentication Request
auth_openid_urlencode_quote_via="quote"

# These endpoints are made available by the well-known endpoint of the OpenID provider
# All endpoints should start with a "/"
auth_openid_auth_uri=""
auth_openid_token_uri=""
auth_openid_userinfo_uri=""
auth_openid_logout_uri=""

# In most cases, these values are usually 'code' and 'authorization_code' (as shown below)
# Supported values for response_type and grant_type are listed in the response of well-known endpoint
auth_openid_response_type="code"
auth_openid_grant_type="authorization_code"

# Scope values—supported values are available in the response from the well-known endpoint
# 'openid' is required
# Additional scopes may be necessary if the response to the userinfo request
# does not include enough information to use for authentication
# Separate additional scopes with a blank space.
# See https://openid.net/specs/openid-connect-basic-1_0.html#Scopes for more info
auth_openid_scope="openid"

# The OpenID client details that are available from the provider
# A new client for Driverless AI in your OpenID provider must be created if one does not already exist
auth_openid_client_id=""
auth_openid_client_secret=""

# Sample redirect value: http[s]://driverlessai-server-address:port/openid/callback
# Ensure that the client configuration in the OpenID provider (see previous step) includes
# this exact URL as one of the possible redirect URLs for the client
# If these do not match, the OpenID connection will fail
auth_openid_redirect_uri=""

# Token endpoint response key configs
auth_openid_access_token_expiry_key="expires_in"
auth_openid_refresh_token_expiry_key="refresh_expires_in"

# UserInfo response key configs for all users who log in to Driverless AI
# The userinfo_auth_key and userinfi_auth_value are
# a key value combination in the userinfo response that remain static for everyone
# If this key value pair does not exist in the user_info response,
# then the Authentication is considered failed
auth_openid_userinfo_auth_key=""
auth_openid_userinfo_auth_value=""

# Key that specifies username in user_info json (we will use value of this key as username in Driverless AI)
auth_openid_userinfo_username_key=""

# Enable advanced matching for OpenID authentication
# When enabled, the ObjectPath expression is used to evaluate the user's identity
# Disabled by default
# For more information, refer to http://objectpath.org/
auth_openid_use_objectpath_match=false

# Set the ObjectPath expression
# Used to evaluate whether a user is allowed to login to Driverless AI
# The user is allowed to log in when the expression evaluates to True
# Examples:
# $.our_claim is "our_value" (simple claim equality)
# "expected_role" in @.roles (list of claims contains required value)
auth_openid_use_objectpath_expression=""

토큰 기반 인증 구성 옵션

config.toml 파일의 다음 추가 옵션은 토큰 기반 인증을 활성화하는 데 사용됩니다. 토큰 기반 인증을 사용하면 각각의 요청에 대해 토큰을 제공하여 클라이언트가 Driverless AI 서버를 통해 인증할 수 있습니다. 이것은 OpenID Connect 인증을 사용하는 환경을 대상으로 하지만, 이에 국한되지는 않습니다. 이러한 옵션을 설정하지 않으면 OpenID Connect가 인증 방법으로 구성되어 있을 때 클라이언트가 서버를 통한 인증을 할 수 없습니다.

# Sets token introspection URL for OpenID Connect authentication.(needs to be an absolute URL)
auth_openid_token_introspection_url = ""

# Enables option to use Bearer token for authentication with the RPC endpoint.
api_token_introspection_enabled = false

# Sets the method that is used to introspect the bearer token.
# OAUTH2_TOKEN_INTROSPECTION: Uses  OAuth 2.0 Token Introspection (RPC 7662)
# endpoint to introspect the bearer token.
# This useful when 'openid' is used as the authentication method.
# Uses 'auth_openid_client_id' and 'auth_openid_client_secret' and to
# authenticate with the authorization server and
# `auth_openid_token_introspection_url` to perform the introspection.
#
api_token_introspection_method = "OAUTH2_TOKEN_INTROSPECTION"

# Sets the minimun of the scopes that the access token needs to have
# in order to pass the introspection. Space separated./
# This is passed to the introspection endpoint and also verified after response
# for the servers that don't enforce scopes.
# Keeping this empty turns any the verification off.
#
api_token_oauth2_scopes = ""

# Which field of the response returned by the token introspection endpoint should be used as a username.
api_token_oauth2_username_field_name = "username"

# Enables the option to initiate a PKCE flow from the UI in order to obtain tokens usable with Driverless clients
oauth2_client_tokens_enabled = false

# Sets up client id that will be used in the OAuth 2.0 Authorization Code Flow to obtain the tokens. Client needs to be public and be able to use PKCE with S256 code challenge.
oauth2_client_tokens_client_id = ""

# Sets up the absolute url to the authorize endpoint.
oauth2_client_tokens_authorize_url = ""

# Sets up the absolute url to the token endpoint.
oauth2_client_tokens_token_url = ""

# Sets up the absolute url to the token introspection endpoint.It's displayed in the UI so that clients can inspect the token expiration.
oauth2_client_tokens_introspection_url = ""

# Sets up the absolute to the redirect url where Driverless handles the redirect part of the Authorization Code Flow. this <Driverless base url>/oauth2/client_token
oauth2_client_tokens_redirect_url = ""

# Sets up the scope for the requested tokens. Space seprated list.
oauth2_client_tokens_scope = "openid profile ai.h2o.storage"

예제 1: OpenID Connect 활성화

이 예제에서는 OpenID 구성 후, Docker 이미지 및 Native 설치에서 Driverless AI를 시작하는 방법에 관해 설명합니다. 해당 예제는 토큰을 활성화하지 않기 때문에 Driverless AI Python client는 해당 설치와 호환되지 않습니다.

  1. 구성 옵션 섹션에 설명된 대로 config.toml 파일에서 OpenID 구성 옵션을 편집하십시오.

  2. 편집된 config.toml 파일을 Docker 컨테이너에 마운트하십시오.

  nvidia-docker run \
    --net=openid-network \
    --name="dai-with-openid" \
    --pid=host \
    --init \
    --rm \
    --shm-size=256m \
    -u `id -u`:`id -g` \
    -p 12345:12345 \
    -v "`pwd`/DAI_DATA/data":/data \
    -v "`pwd`/DAI_DATA/log":/log \
    -v "`pwd`/DAI_DATA/license":/license \
    -v "`pwd`/DAI_DATA/tmp":/tmp \
    -v "`pwd`/DAI_DATA/config":/config \
    -e DRIVERLESS_AI_CONFIG_FILE="/config/config.toml" \
    h2oai/dai-centos7-x86_64:1.10.1-cuda11.2.2.xx

다음 단계는 Driverless AI 시작 및 로그인입니다. Driverless AI에 로그인 을 참조하십시오.

예제 2: OpenID Connect를 사용한 토큰 기반 인증 활성화

예제 1과 비슷하게 이 예제에서는 OpenID 구성 후, Docker 이미지 및 Native 설치에서 Driverless AI의 시작 방법에 관해 설명합니다. 또한 Driverless AI Python client와의 호환성을 위해 토큰을 활성화합니다.

  1. 구성 옵션 섹션에 설명된 것처럼 config.toml 파일에서 OpenID 구성 옵션을 수정하십시오. 토큰 기반 인증 구성 옵션 옵션 섹션에 설명된 토큰 기반 인증 옵션도 활성화하십시오.

  2. 편집된 config.toml 파일을 Docker 컨테이너에 마운트하십시오.

  nvidia-docker run \
    --net=openid-network \
    --name="dai-with-openid" \
    --pid=host \
    --init \
    --rm \
    --shm-size=256m \
    -u `id -u`:`id -g` \
    -p 12345:12345 \
    -v "`pwd`/DAI_DATA/data":/data \
    -v "`pwd`/DAI_DATA/log":/log \
    -v "`pwd`/DAI_DATA/license":/license \
    -v "`pwd`/DAI_DATA/tmp":/tmp \
    -v "`pwd`/DAI_DATA/config":/config \
    -e DRIVERLESS_AI_CONFIG_FILE="/config/config.toml" \
    h2oai/dai-centos7-x86_64:1.10.1-cuda11.2.2.xx

다음 단계는 Driverless AI 시작 및 로그인입니다. Driverless AI에 로그인 을 참조하십시오.

Driverless AI에 로그인

브라우저를 열고 Driverless AI를 시작하십시오. OpenID로 로그인하라는 메시지가 나타납니다.

_images/auth_openid_launchdai.png