인바운드 SAML SSO API 설정하기

이 페이지에서는 SAML 프로필을 관리하거나 싱글 사인온(SSO) 할당을 구성하기 전에 Cloud ID 인바운드 SAML SSO 프로필(inboundSamlSsoProfiles) 및 인바운드 SSO 할당(inboundSsoAssignments) API를 설정하는 방법을 설명합니다.

시작하기 전에

Inbound SAML SSO API를 사용하려면 먼저 도메인에 Cloud ID 또는 Google Workspace를 설정해야 합니다. 자세한 내용은 Cloud ID 설정을 참조하세요.

Python 클라이언트 라이브러리 설치

Python 클라이언트 라이브러리와 Google 인증 라이브러리를 설치하려면 다음 명령어를 실행합니다.

pip install --upgrade google-api-python-client google-auth \
  google-auth-oauthlib google-auth-httplib2

Python 개발 환경 설정에 관한 자세한 내용은 Python 개발 환경 설정 가이드를 참조하세요.

API 사용 설정 및 사용자 인증 정보 설정

  1. Google Cloud 계정에 로그인합니다. Google Cloud를 처음 사용하는 경우 계정을 만들고 Google 제품의 실제 성능을 평가해 보세요. 신규 고객에게는 워크로드를 실행, 테스트, 배포하는 데 사용할 수 있는 $300의 무료 크레딧이 제공됩니다.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Enable the Cloud Identity API, if it is not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the API

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  6. Verify that billing is enabled for your Google Cloud project.

  7. Enable the Cloud Identity API, if it is not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the API

인바운드 SAML SSO API로 인증

인바운드 SAML SSO 프로필 및 인바운드 SSO 할당 API는 도메인 수준 인증 설정을 관리합니다. 다음 방법 중 하나를 사용하여 호출을 인증할 수 있습니다.

  • 도메인 전체 위임이 있는 서비스 계정(자동화된 워크플로 및 백엔드 서비스에 권장): 서비스 계정이 Google Workspace 또는 Cloud ID 최고 관리자를 가장하여 API를 호출합니다.
  • 관리자 OAuth 2.0 사용자 인증 정보(대화형 도구 및 CLI 스크립트에 권장): 관리자 사용자가 OAuth 2.0 웹 흐름 또는 로컬 동의 흐름을 통해 직접 인증합니다.

OAuth 범위

인바운드 SAML SSO 프로필 및 인바운드 SSO 할당 API는 다음 OAuth 범위를 지원합니다.

범위 설명
https://www.googleapis.com/auth/cloud-identity.inboundsso 인바운드 SSO 프로필 및 할당을 생성, 업데이트, 삭제, 가져오기, 나열할 수 있는 전체 읽기 및 쓰기 액세스 권한입니다.
https://www.googleapis.com/auth/cloud-identity.inboundsso.readonly 인바운드 SSO 프로필 및 할당을 가져오고 나열할 수 있는 읽기 전용 액세스 권한입니다.
https://www.googleapis.com/auth/cloud-identity 모든 Cloud ID API 리소스에 대한 전체 액세스 권한입니다.
https://www.googleapis.com/auth/cloud-platform 모든 Google Cloud 리소스 및 API에 대한 전체 액세스 권한입니다.

도메인 전체 위임을 사용하여 서비스 계정으로 인증

서비스 계정에서 인바운드 SAML SSO API를 호출하려면 Google 관리 콘솔에서 서비스 계정에 도메인 전체 위임을 부여해야 합니다. 도메인 전체 위임을 사용하면 서비스 계정에서 관리자 사용자를 가장할 수 있으므로 서비스 계정 작업이 가장된 관리자가 수행한 것으로 감사 로그에 표시됩니다.

1단계: 서비스 계정에 도메인 전체 권한 위임하기

  1. Google Cloud 콘솔의 서비스 계정 페이지에서 서비스 계정의 OAuth 2 클라이언트 ID(클라이언트 ID 숫자 문자열)를 복사합니다.
  2. Google 관리 콘솔을 엽니다.
  3. 기본 메뉴 > 보안 > 액세스 및 데이터 컨트롤 > API 컨트롤로 이동합니다.
  4. 도메인 전체 위임 창에서 도메인 전체 위임 관리를 클릭합니다.
  5. 새로 추가를 클릭합니다.
  6. 클라이언트 ID 필드에 서비스 계정의 클라이언트 ID를 입력합니다.
  7. OAuth 범위 필드에 필요한 범위를 쉼표로 구분된 목록으로 입력합니다.
    • 읽기 및 쓰기 액세스: https://www.googleapis.com/auth/cloud-identity.inboundsso
    • 읽기 전용 액세스: https://www.googleapis.com/auth/cloud-identity.inboundsso.readonly
  8. 승인을 클릭합니다.

자세한 내용은 도메인 전체 위임으로 API 액세스 제어하기를 참고하세요.

2단계: 애플리케이션 코드에서 사용자 인증 정보 초기화

애플리케이션에서 위임된 사용자 인증 정보를 초기화할 때 subject 매개변수를 사용하여 도메인 관리자의 이메일 주소를 지정합니다.

Python

from google.auth import iam
from google.auth.transport import requests
import google.auth
from google.oauth2 import service_account
from googleapiclient.discovery import build

# OAuth scope authorized for domain-wide delegation in the Admin console
SCOPES = ['https://www.googleapis.com/auth/cloud-identity.inboundsso']

# Administrator email address to impersonate
ADMIN_EMAIL = 'admin@example.com'

# Option A: Using a service account JSON key file
# credentials = service_account.Credentials.from_service_account_file(
#     'SERVICE_ACCOUNT_KEY_FILE.json',
#     scopes=SCOPES,
#     subject=ADMIN_EMAIL
# )

# Option B: Using Application Default Credentials (ADC) with IAM Signer
base_credentials, _ = google.auth.default(
    scopes=['https://www.googleapis.com/auth/iam']
)
request = requests.Request()
base_credentials.refresh(request)

signer = iam.Signer(
    request,
    base_credentials,
    base_credentials.service_account_email
)
delegated_credentials = service_account.Credentials(
    signer=signer,
    service_account_email=base_credentials.service_account_email,
    token_uri='https://accounts.google.com/o/oauth2/token',
    scopes=SCOPES,
    subject=ADMIN_EMAIL
)

# Build the Cloud Identity API client
service = build('cloudidentity', 'v1', credentials=delegated_credentials)

3단계: 서비스 계정 가장과 함께 gcloud CLI 사용

애플리케이션 기본 사용자 인증 정보(ADC) 및 서비스 계정 가장과 함께 gcloud CLI를 사용하여 인바운드 SAML SSO API를 테스트하거나 호출하려면 다음 명령어를 실행합니다.

gcloud auth application-default login \
  --impersonate-service-account=SERVICE_ACCOUNT_EMAIL \
  --scopes=https://www.googleapis.com/auth/iam,https://www.googleapis.com/auth/cloud-identity.inboundsso

다음을 바꿉니다.

  • SERVICE_ACCOUNT_EMAIL: 도메인 전체 위임이 구성된 서비스 계정의 이메일 주소입니다.

OAuth 2.0을 사용하여 관리자로 인증

서비스 계정 없이 대화형 애플리케이션 또는 스크립트를 최고 관리자로 직접 인증하려면 표준 OAuth 2.0 사용자 인증 정보를 사용하세요.

웹 또는 데스크톱 애플리케이션의 OAuth 2.0 사용자 인증 정보를 가져오는 방법에 대한 자세한 내용은 OAuth 2.0을 사용하여 Google API에 액세스를 참조하세요.

다음 단계