Google 계정으로 사용자 인증

이 빠른 시작에서는 IAP (Identity-Aware Proxy) 를 사용 설정하여 App Engine 표준 또는 가변형 환경 애플리케이션을 보호하고 Google 계정으로 사용자에게 액세스 권한을 부여하는 방법을 보여줍니다.

CDN (콘텐츠 전송 네트워크)에서 리소스를 제공하려는 경우, 캐싱 권장사항 가이드 에서 중요한 정보를 확인하세요.

App Engine 애플리케이션이 여러 서비스로 구성된 경우, 서비스에 따라 다른 IAP 권한을 구성할 수 있습니다. 여기에는 일부 서비스만 공개적으로 액세스 가능하게 만들고 다른 서비스는 보호 상태를 유지하는 것이 포함됩니다.

시작하기 전에

  1. 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

  2. If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.

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

  4. App Engine에 IAP를 사용 설정하려면 App Engine 인스턴스를 설정해야 합니다. App Engine 인스턴스를 아직 설정하지 않은 경우 전체적으로 둘러보려면 App Engine에 배포를 참조하세요.

    기본적으로 IAP는 Google 관리 OAuth 클라이언트를 사용합니다. 이 클라이언트를 사용하려면 프로젝트가 조직에 속해야 하며 내부 사용자만 액세스할 수 있습니다.

필요한 역할

Google 계정으로 사용자를 인증하는 데 필요한 권한을 얻으려면 관리자에게 프로젝트의 IAP 정책 관리자 (roles/iap.policyAdmin) IAM 역할을 부여해 달라고 요청합니다. 역할 부여에 대한 자세한 내용은 프로젝트, 폴더, 조직에 대한 액세스 관리를 참조하세요.

커스텀 역할이나 다른 사전 정의된 역할을 통해 필요한 권한을 얻을 수도 있습니다.

IAP 사용 설정

콘솔

프로젝트가 조직에 속하지 않는 경우 커스텀 OAuth 사용자 인증 정보를 사용해야 합니다.

动态包含文件

如果您尚未配置项目的 OAuth 权限请求页面,系统会提示您进行配置。如需配置 OAuth 权限请求页面,请参阅设置 OAuth 权限请求页面。

设置 IAP 访问权限

  1. 转到 Identity-Aware Proxy 页面。
    转到 Identity-Aware Proxy 页面
  2. 选择要使用 IAP 保护的项目。
  3. 选中您要授予访问权限的资源旁边的复选框。
  4. 在右侧面板上,点击添加主账号。
  5. 在显示的添加主账号对话框中,输入群组或个人(应拥有项目的 IAP-secured Web App User 角色)的电子邮件地址。

    以下种类的主账号可以具有此角色:

    • Google 账号:user@gmail.com
    • Google 网站论坛:admins@googlegroups.com
    • 服务账号:server@example.
    • Google Workspace 网域:example.com

    请务必添加您有权访问的 Google 账号。

  6. 从角色下拉列表中选择 Cloud IAP > 受 IAP 保护的网页应用用户。
  7. 点击保存。

启用 IAP

  1. 在 Identity-Aware Proxy 页面上的应用下,找到您要限制访问的应用。如需为某资源开启 IAP,请
  2. 在出现的开启 IAP 窗口中,点击开启以确认您想用 IAP 保护资源。 开启 IAP 后,对于与负载均衡器的所有连接,它都要求提供登录凭证。 只有在项目中具有 IAP-Secured Web 应用 User (roles/iap.httpsResourceAccessor) 角色的主体才能获得访问权限。

gcloud

Before you set up your project and IAP, you need an up-to-date version of the gcloud CLI. For instructions on how to install the gcloud CLI, see Install the gcloud CLI.

  1. To authenticate, use the Google Cloud CLI and run the following command.
    gcloud auth login
  2. Click the URL that appears and sign in.
  3. After you sign in, copy the verification code that appears and paste it in the command line.
  4. Run the following command to specify the project that contains the applications that you want to protect with IAP.
    gcloud config set project PROJECT_ID
  5. To enable IAP, run the following command.
    gcloud iap web enable --resource-type=app-engine --versions=version
  6. Add principals who should have the IAP-secured Web App user role to the project.
    gcloud projects add-iam-policy-binding PROJECT_ID \
           --member=PRINCIPAL_IDENTIFIER \
           --role=roles/iap.httpsResourceAccessor
    • Replace PROJECT_ID with your project ID.
    • Replace PRINCIPAL_IDENTIFIER with the necessary principals. This can be a type of domain, group, serviceAccount, or user. For example, user:myemail@example.com.

After you enable IAP, you can use the gcloud CLI to modify the IAP access policy using the IAM role roles/iap.httpsResourceAccessor. Learn more about managing roles and permissions.

API

  1. Run the following command to prepare a settings.json file.

    cat << EOF > settings.json
    {
    "iap":
      {
        "enabled":true
      }
    }
    EOF
    

  2. Run the following command to enable IAP.

    curl -X PATCH \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Accept: application/json" \
    -H "Content-Type: application/json" \
    -d @settings.json \
    "https://appengine.googleapis.com/v1/apps/PROJECT_ID?updateMask=iap"
    

After you enable IAP, you can use the Google Cloud CLI to modify the IAP access policy using the IAM role roles/iap.httpsResourceAccessor. Learn more about managing roles and permissions.

프로젝트 내의 App Engine 서비스에서 IAP를 사용 설정할 수 있습니다. 일부 서비스를 공개적으로 액세스 가능하게 만들고 다른 서비스에 인증을 요구하려면 서비스 전반에서 다양한 액세스 수준을 사용하면 됩니다. 자세한 내용은 IAP로 액세스 관리를 참조하세요. 서비스를 공개적으로 액세스 가능하게 만들려면 allAuthenticatedUsers에 IAP 보안 웹 앱 사용자 역할을 부여합니다.

사용자 인증 테스트

  1. 역할이 부여되면 주 구성원은 IAP로 인증하여 앱에 액세스할 수 있습니다. IAP 보안 웹 앱 사용자(roles/iap.httpsResourceAccessor) 역할이 부여된 Google 계정에서 앱 URL에 액세스합니다.

  2. 액세스를 테스트하려면 Chrome에서 시크릿 창을 열고 앱 URL에 액세스한 후 메시지가 나타나면 로그인합니다. IAP 보안 웹 앱 사용자 (roles/iap.httpsResourceAccessor) 역할이 부여되고 인증에 성공한 사용자는 앱에 액세스할 수 있습니다. 필요한 역할이 부여되지 않았거나 인증에 실패한 사용자는 앱에 액세스할 수 없습니다.

다음 단계