인증되지 않은 ID에 대한 액세스 해제

8942 단어 AWSCognitotech

이거 뭐야?

  • Cognito IdentityPool의 설정 중 하나인'인증되지 않은 ID에 대한 액세스 활성화'는 무엇을 대체적으로 요약한 것인가.
  • 서비스 규격으로 방문객에게 내용을 제공하지 않으면 설정을 무효로 하십시오.
  • 예비 지식


    이른바 IdentityPool

  • IdentityProvider(이하 IDP)와 협업하여 사용자에게 AWS 자원에 접근할 수 있는 권한을 부여하는 서비스.
  • IDP는 사용자 인증과 관리를 담당하는 서비스를 간단히 설명하는 것으로 IdentityPool에서 같은 AWS 시리즈의 Cognito UserPool을 비롯해 Google+와 트위터 등 다양한 서비스를 지원한다.
  • 발행 가능한 일시적 신용장은 인증 사용자와 방문객 사용자를 대상으로 하는 두 가지가 있는데 STS는 뒷면의 구조로 사용된다.

  • Fig1: identity Pool의 역할

    메시지


    인증된 ID 및 인증되지 않은 ID

  • IdentityPool에서 일시적인 신용 발행 대상인 사용자 단위 지급 ID는 해당 발행의 ID를 관리하는 역할도 한다.
  • 관리되는 ID는 2가지로 인증된 ID와 인증되지 않은 ID가 있습니다.
  • 인증 ID

  • 사용자가 IDP를 로그인 처리한 후 액세스 권한을 요청할 때 발행됩니다.
  • 액세스 권한이 요청되면 IDP에서 받은 사용자 식별자(UserPool의 경우 ID 토큰)를 IdentityPool로 보냅니다.
  • 승인된 액세스 권한은 인증 사용자를 위한 IAM 스크롤에 해당합니다.
    image
    Fig2: 인증된 ID의 발행과 일시적인 신용 취득
  • 인증되지 않은 ID

  • 사용자가 IDP에 로그인하지 않고 identityPool에 접근 권한을 요청할 때 발행한다.
  • 액세스 권한은 방문자 사용자를 위한 IAM 스크롤에 해당합니다.

    Fig3: 인증되지 않은 ID의 발행과 일시적인 신용 취득
  • 인증되지 않은 ID를 사용하여 신용 증명 취득

  • 인증되지 않은 ID의 발행 및 일시적인 신용장 취득에 필요한 API는 그 성격상 Public API로 제공된다.
  • 따라서 AWS신용장은 필요 없고 알면identityPoolId 누구나 발행할 수 있다.
  • # 認証されていないIDの発行
    $aws cognito-identity get-id --identity-pool-id ${IDENTITY_POOL_ID} --query "IdentityId" --output text
    
    us-east-1:xxx-xxxx-xxxx-xxx-xxx
    
    # 一時クレデンシャルの取得
    $aws cognito-identity get-credentials-for-identity --identity-id us-east-1:xxx-xxxx-xxxx-xxx-xxx
    
    {
        "IdentityId": "us-east-1:xxx-xxxx-xxxx-xxx-xxx",
        "Credentials": {
            "AccessKeyId": "xxxx",
            "SecretKey": "xxxx",
            "SessionToken": "xxxx",
            "Expiration": "2021-05-05T12:15:31+09:00"
        }
    }
    

    인증되지 않은 ID에 대한 액세스 해제

  • 서비스 규격으로 인증 사용자/방문자 사용자로 구분되어 있으며, AWS 자원에 대한 접근을 각각 제어하려면 방문을 사용해도 문제가 없다.
  • 하지만 그렇지 않은 경우 방문이 활성화되면 IAM 정책의 내용에 따라 예상치 못한 방문이 발생할 수 있다.
  • 따라서 방문객에게 신용장을 지불하지 않기 위해 마지막으로 이 설정을 무효화하는 방법을 총괄했다.
  • 콘솔 상태

  • IDプールの編集認証されていない ID に対してアクセスを有効にする의 체크 상자를 뜯어내세요.
  • AWS CLI 시


    $aws cognito-identity update-identity-pool --identity-pool-id ${IDENTITY_POOL_ID} --identity-pool-name ${IDENTITY_POOL_NAME} --no-allow-unauthenticated-identities
    

    AWS CDK의 경우

  • allowUnauthenticatedIdentities의 값을 가짜로 설정하고 디자인하면 반영할 수 있다.
  • import { CfnIdentityPool } from '@aws-cdk/aws-cognito';
    import { Construct, Stack, StackProps } from '@aws-cdk/core';
    
    export class SampleCdkStack extends Stack {
      constructor(scope: Construct, id: string, props?: StackProps) {
        super(scope, id, props);
    
        const identityPool = new CfnIdentityPool(this, 'myIdentityPool', {
          // ここの値です。
          allowUnauthenticatedIdentities: false, 
        });
      }
    }
    

    결과를 반영하다

  • 액세스가 잘못된 상태에서 인증되지 않은 ID를 발행하도록 요청하는 중 오류가 발생했습니다.
  • $aws cognito-identity get-id --identity-pool-id ${IDENTITY_POOL_ID} --query "IdentityId" --output text
    
    An error occurred (NotAuthorizedException) when calling the GetId operation: Unauthenticated access is not supported for this identity pool.
    

    참고물


    https://docs.aws.amazon.com/ja_jp/cognito/latest/developerguide/identity-pools.html
    https://docs.aws.amazon.com/ja_jp/cognito/latest/developerguide/authentication-flow.html
    https://docs.aws.amazon.com/cognitoidentity/latest/APIReference/API_GetId.html
    https://docs.aws.amazon.com/cognitoidentity/latest/APIReference/API_GetCredentialsForIdentity.html
    https://docs.aws.amazon.com/cli/latest/reference/cognito-identity/update-identity-pool.html
    https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/aws-resource-cognito-identitypool.html

    좋은 웹페이지 즐겨찾기