Amazon Cognito 보안 인증 풀을 사용하여 사용자에게 AWS 서비스에 대한 액세스 권한을 부여하려면 어떻게 해야 합니까?

3분 분량
0

Amazon Cognito 사용자 풀을 사용하여 사용자에게 AWS 리소스에 대한 액세스 권한을 부여하고 싶습니다.

해결 방법

Amazon Cognito 자격 증명 풀을 Amazon Cognito 사용자 풀과 통합하여 AWS 리소스에 액세스하기 위한 임시 보안 인증을 발급할 수 있습니다. 사용자 풀로 자격 증명 풀을 구성하여 인증 공급자를 설정합니다. 사용자 풀을 통해 사용자를 인증한 후 인증 흐름과 사용자 ID 토큰을 사용하여 자격 증명 풀에서 임시 보안 인증을 검색합니다. 임시 보안 인증을 검색하기 위한 기본 인증 흐름과 향상된 인증 흐름이 있습니다.

중요: 다음 예제 AWS Command Line Interface(AWS CLI) 명령에서 예제 문자열의 모든 인스턴스를 사용자 값으로 변경합니다. (예를 들어, **"example_identity_pool_id"**를 자격 증명 풀 ID로, 또는 **"abcdef"**를 AWS 리전의 자격 증명 ID로 변경합니다.)

기본 흐름

참고: AWS Command Line Interface(AWS CLI) 명령을 실행할 때 오류가 발생할 경우 AWS CLI의 최신 버전을 사용하고 있는지 확인하세요.

기본 인증 흐름을 사용하여 임시 AWS 보안 인증을 검색하려면 다음 단계를 수행합니다.

1.    이전 Amazon Cognito 콘솔에서 ID 풀 관리를 선택합니다. 업데이트하려는 Amazon Cognito ID 풀의 이름을 선택한 다음 ID 풀 편집을 선택합니다. 인증 흐름 설정에서 기본 (클래식) 흐름 허용을 선택한 다음 변경 사항을 저장합니다.

2.    자격 증명 풀에서 사용자 ID를 생성 또는 검색하려면 GetId API를 호출합니다.

get-id 명령의 예는 다음과 같습니다.

aws cognito-identity get-id --identity-pool-id "example_identity_pool_id" --logins cognito-idp.example_region.amazonaws.com/example_cognito_user_pool_id=example_cognito_user_id_token

출력 예시:

{
    "IdentityId": "region:abcdef"
}

3.    오픈 ID 토큰을 검색하려면 2단계의 결과를 사용하여 GetOpenIdToken API를 호출합니다.

get-open-id-token 명령의 예:

aws cognito-identity get-open-id-token --identity-id "region:abcdef" --logins cognito-idp.example_region.amazonaws.com/example_user_pool_id=example_cognito_user_id_token

출력 예시:

{
    "IdentityId": "region:abcdef",
    "Token": "HIJKLMN"
}

4.    인증된 역할의 임시 보안 인증을 검색하려면 3단계의 토큰을 사용하여 AssumeRoleWithWebIdentity API를 호출합니다.

assume-role-with-web-identity 명령의 예시:

aws sts assume-role-with-web-identity --role-arn "example_auth_role_arn_of_the_identity_pool" --web-identity-token "HIJKLMN" --role-session-name "example_session_name"

출력 예시:

{
    "Credentials": {
        AccessKeyId": "xxxxxxxxxxxx",
        SecretAccessKey": "xxxxxxxxxxxx",
        SessionToken": "xxxxxxxxxxxx",
        Expiration": ""
    },
    "SubjectFromWebIdentityToken": "",
    "AssumedRoleUser": {
        "AssumedRoleId": "",
        "Arn": ""
    },
    "Provider": "cognito-identity.amazonaws.com",
    "Audience": ""
}

향상된 흐름

향상된 인증 흐름을 사용하여 임시 AWS 보안 인증을 검색하려면 다음 단계를 수행합니다.

1.    Amazon Cognito 자격 증명 풀에서 사용자 ID를 생성 또는 검색하려면 GetId API를 호출합니다.

get-id 명령의 예는 다음과 같습니다.

aws cognito-identity get-id --identity-pool-id "example_identity_pool_id" --logins cognito-idp.example_region.amazonaws.com/example_cognito_user_pool_id=example_cognito_user_id_token

출력 예시:

{
    "IdentityId": "region:abcdef"
}

2.    자격 증명 풀에서 임시 보안 인증을 검색하려면 GetCredentialsForIdentity API를 호출합니다.

get-credentials-for-identity 명령의 예시:

aws cognito-identity get-credentials-for-identity --identity-id region:abcdef --logins cognito-idp.example_region.amazonaws.com/example_cognito_user_pool_id = example_cognito_user_id_token

출력 예시:

{
    "IdentityId": "region:abcdef",
    "Credentials": {
        "AccessKeyId": "xxxxxxxxxx",
        "SecretKey": "xxxxxxxxxx",
        "SessionToken": "xxxxxxxxxx",
        "Expiration": ""
    }
}

복합 역할 기반 액세스 제어와 속성 기반 액세스 제어에 대해 자세히 알아보려면 Amazon Cognito 자격 증명 풀을 사용한 세분화된 액세스 제어를 참조하십시오.


관련 정보

자격 증명 풀(연동 자격 증명) 인증 흐름

AWS 공식
AWS 공식업데이트됨 일 년 전
댓글 없음