Google OAuth 인증 구성

Google OAuth 인증 구성 (Configure Google OAuth authentication)

Google OAuth를 활성화하려면 애플리케이션을 Google에 등록해야 해요. Google이 클라이언트 ID와 시크릿 키를 생성해 줘요. Grafana는 UI, Terraform provider, Grafana 구성 파일로 Google OAuth 클라이언트를 구성할 수 있어요.

출처: 문서

본문

Note Google과 다른 인증 공급자에서 같은 이메일 주소를 쓰면 사용자가 올바르게 매칭되도록 추가 구성이 필요해요.

Google OAuth 키 만들기

  1. https://console.developers.google.com/apis/credentials로 이동.
  2. 프로젝트가 없으면 새로 만들어요. OAuth consent screen에서 External User Type 선택. 요청된 정보를 Grafana Cloud 인스턴스 URL로 채워요.
  3. Create Credentials 클릭 후 드롭다운에서 OAuth Client ID 선택.
  4. 다음을 입력: Application Type: Web application, Name: Grafana, Authorized JavaScript origins: https://<YOUR_GRAFANA_URL>, Authorized redirect URIs: https://<YOUR_GRAFANA_URL>/login/google. <YOUR_GRAFANA_URL>을 Grafana 인스턴스 홈페이지 URL로 바꿔요 (Grafana Cloud 포털 URL이 아님).
  5. Create 클릭.
  6. OAuth Client 모달에서 Client ID와 Client Secret을 복사.

Grafana UI로 클라이언트 구성

Grafana Admin으로 Administration > Authentication > Google 페이지에서 양식을 채워 구성할 수 있어요. Save 후 성공하면 적용돼요. Reset으로 기본값으로 되돌릴 수 있어요.

Terraform provider로 클라이언트 구성

resource "grafana_sso_settings" "google_sso_settings" {
  provider_name = "google"
  oauth2_settings {
    name            = "Google"
    client_id       = "CLIENT_ID"
    client_secret   = "CLIENT_SECRET"
    allow_sign_up   = true
    auto_login      = false
    scopes          = "openid email profile"
    allowed_domains = "mycompany.com mycompany.org"
    hosted_domain   = "mycompany.com"
    use_pkce        = true
  }
}

Grafana 구성 파일로 클라이언트 구성

Grafana에서 Google OAuth 활성화

구성 파일에 Client ID와 Secret을 지정해요:

[auth.google]
enabled = true
allow_sign_up = true
auto_login = false
client_id = CLIENT_ID
client_secret = CLIENT_SECRET
scopes = openid email profile
auth_url = https://accounts.google.com/o/oauth2/v2/auth
token_url = https://oauth2.googleapis.com/token
api_url = https://openidconnect.googleapis.com/v1/userinfo
allowed_domains = mycompany.com mycompany.org
hosted_domain = mycompany.com
use_pkce = true

프록시 뒤에서 서빙한다면 [server]root_url을 설정해야 할 수 있어요. Grafana 백엔드를 재시작하면 로그인 페이지에 Google 로그인 버튼이 보여요. allow_sign_uptrue로 하면 Google 인증으로 가입을 허용할 수 있어요.

Note Grafana 10.3.0부터 Google ID 토큰에서 가져온 hd 파라미터로 사용자의 hosted domain을 결정해요. allowed_domains가 설정되면 ID 토큰의 hd 파라미터가 일치해야 하고, 일치하지 않으면 접근이 거부돼요. Google Workspace에 속하지 않은 계정은 hd 클레임이 없어요. 이 검증은 기본 활성화이며 꺼려면 validate_hdfalse로 설정.

PKCE

RFC 7636의 PKCE는 인가 코드 가로채기 공격의 일부 형태에 대한 추가 보호를 제공하며 OAuth 2.1에서 요구될 예정이에요. [auth.google]에서 use_pkcefalse로 설정해 비활성화할 수 있어요.

refresh token 구성

기본적으로 Grafana는 인가 요청에 access_type=offline 파라미터를 포함해 refresh token을 요청해요. Grafana v10.1.0부터 기본 활성화. 끄려면 use_refresh_tokenfalse로 설정.

JWT ID 토큰 검증 구성

  • [auth.google]에서 validate_id_tokentrue로 설정.
  • jwk_set_url을 Google JWKS 엔드포인트 https://www.googleapis.com/oauth2/v3/certs로 설정.
[auth.google]
enabled = true
validate_id_token = true
jwk_set_url = https://www.googleapis.com/oauth2/v3/certs
client_id = <client id>
client_secret = <client secret>
scopes = openid email profile

Caution validate_id_tokentruejwk_set_url을 반드시 구성해야 해요. 없거나 서명 검증에 실패하면 인증이 실패해요.

자동 로그인

auto_login = true

팀 동기화 구성

Note Grafana Enterprise와 Grafana Cloud에서 사용 가능.

Google 그룹으로 사용자를 팀에 추가할 수 있어요.

  • 조직 대시보드에서 Google Cloud Identity API를 활성화.
  • [auth.google] 구성에 https://www.googleapis.com/auth/cloud-identity.groups.readonly 스코프를 추가:
[auth.google]
# ..
scopes = openid email profile https://www.googleapis.com/auth/cloud-identity.groups.readonly
  • Grafana 팀의 External group sync 탭에서 팀 동기화 구성. Google 그룹의 외부 그룹 ID는 그룹 이메일 주소(예: [email protected])예요.

allowed groups 구성

한 개 이상 그룹의 멤버로 접근을 제한하려면 allowed_groups를 그룹 목록으로 설정해요. Google 그룹은 그룹 이메일 키(예: [email protected])로 참조해요. 그룹을 가져오려면 cloud-identity.groups.readonly 스코프를 추가해야 해요.

역할 매핑 구성

skip_org_role_sync가 활성화되지 않았다면 사용자 역할은 Google에서 매핑된 역할로 설정돼요. role_attribute_path의 JMESPath 표현식으로 가져와요. 서버 관리자 역할은 allow_assign_grafana_admin으로 매핑. 유효한 역할이 없으면 auto_assign_org_role이 지정한 역할을 할당하고, role_attribute_strict = true로 기본 할당을 비활성화. (기본적으로 skip_org_role_sync가 활성화되지만 Grafana v10.3.0 이상에서는 기본값이 false로 바뀜.)

Org roles 매핑 예제:

org_mapping = group-1:org_foo:Viewer group-2:org_bar:Editor *:org_baz:Editor

OAuth 토큰 사용자 정보로 역할 매핑:

role_attribute_path = email=='[email protected]' && 'Admin' || 'Viewer'
skip_org_role_sync = false

그룹으로 역할 매핑:

role_attribute_path = contains(groups[*], '[email protected]') && 'Editor' || 'Viewer'
skip_org_role_sync = false

서버 관리자 역할 매핑:

allow_assign_grafana_admin = true
skip_org_role_sync = false
role_attribute_path = email=='[email protected]' && 'GrafanaAdmin' || 'Viewer'

모든 사용자에게 한 역할 매핑:

role_attribute_path = "'Viewer'"
skip_org_role_sync = false

주요 구성 옵션

설정 필수 설명 기본값
enabled 아니요 Google 인증 활성화 false
client_id / client_secret 앱의 클라이언트 ID/시크릿
auth_url Google OAuth 인가 엔드포인트 https://accounts.google.com/o/oauth2/v2/auth
token_url 액세스 토큰을 얻는 엔드포인트 https://oauth2.googleapis.com/token
api_url 사용자 정보 엔드포인트 https://openidconnect.googleapis.com/v1/userinfo
scopes 아니요 OAuth2 스코프 목록 openid email profile
allow_sign_up 아니요 Google 로그인으로 사용자 생성 제어 true
auto_login 아니요 자동 로그인 false
hosted_domain 아니요 특정 도메인 사용자로 접근 제한. hd 파라미터로 전송
validate_hd 아니요 Google ID 토큰의 hd 파라미터 검증 비활성화 여부 true
role_attribute_strict 아니요 역할 추출 실패 시 로그인 거부 false
allow_assign_grafana_admin 아니요 서버 관리자 역할 자동 동기화 false
skip_org_role_sync 아니요 사용자 역할 자동 동기화 중지 false
allowed_groups 아니요 허용 그룹 목록
allowed_domains 아니요 허용 도메인 목록
use_pkce 아니요 PKCE 사용 true
use_refresh_token 아니요 refresh token 사용 true
validate_id_token 아니요 JWKS로 ID 토큰 JWT 서명 검증 false
jwk_set_url 아니요 JWT 서명 검증용 JWKS 엔드포인트

더 알아보기 (Learn more)