IAM 권한 액세스 거부됨 또는 승인되지 않음 오류를 해결하는 데 도움이 되는 데이터를 어떻게 얻을 수 있습니까?

5분 분량
0

AWS 리소스에 액세스할 때 "액세스 거부됨" 또는 "승인되지 않음" 오류 메시지가 나타납니다. 이러한 AWS Identity and Access Management(IAM) API 호출 실패 오류를 해결하는 데 도움이 되는 데이터가 필요합니다.

간략한 설명

Amazon Athena 쿼리 또는 AWS Command Line Interface(AWS CLI)를 사용하여 IAM API 호출 실패에 대한 오류 로그를 가져올 수 있습니다. 그런 다음 지침에 따라 IAM 정책을 적용할 때 액세스 거부 또는 승인되지 않은 작업 오류를 해결합니다.

해결 방법

참고: AWS CLI 명령을 실행할 때 오류가 발생하면 최신 AWS CLI 버전을 사용하고 있는지 확인하십시오.

Athena 쿼리를 사용해 CloudTrail 로그를 검색하여 IAM API 호출 실패 문제 해결

참고: 시작하기 전에 Amazon Simple Storage Service(Amazon S3) 버킷에 로깅할 트레일을 생성해야 합니다. 이는 Athena가 해당 트레일에 대한 Amazon S3 버킷으로 전송되는 AWS CloudTrail 로그 파일에 기록된 이벤트를 사용하기 때문입니다.

1.    Athena에서 테이블을 자동으로 생성하여 AWS CloudTrail 로그를 검색하려면 어떻게 해야 합니까?Athena 테이블 생성 섹션의 단계를 따릅니다.

참고: 자동으로 생성되는 Athena 테이블은 Amazon S3 버킷과 동일한 AWS 리전에 있습니다.

2.    Athena 콘솔을 연 다음 더하기 기호 **"+"**를 선택하여 새 쿼리를 생성합니다.

3.    다음 예시 쿼리를 입력한 다음 실행을 선택합니다.

이 예시 쿼리의 시간 형식은 UTC의 Z 변수와 함께 ISO 8601 기본 형식을 사용합니다.

참고: your-arn을 리소스의 IAM Amazon 리소스 이름(ARN)으로, your-table은 테이블 이름으로 바꾸십시오.

SELECT from_iso8601_timestamp(eventTime) AS "Time", useridentity.arn AS "Identity ARN", eventID AS "Event ID",
         eventsource AS "Service", eventname AS "Action", errorCode AS "Error", errorMessage AS "Message"
FROM your-table
WHERE from_iso8601_timestamp(eventtime) >= from_iso8601_timestamp('2019-10-29T06:40:00Z')
        AND from_iso8601_timestamp(eventtime) < from_iso8601_timestamp('2019-10-29T06:55:00Z')
        AND userIdentity.arn = 'your-arn'
        AND eventType = 'AwsApiCall'
        AND errorCode is not null
        AND (lower(errorCode) LIKE '%accessdenied%' OR lower(errorCode) LIKE '%unauthorized%')
ORDER BY eventTime desc

4.    이 예시 테이블 출력에는 ID ARN에 대한 권한 오류가 나열되어 있습니다.

| Time                        | Event ID                             | Service                  | Action       | Error        | Message                                                                                                              |
|-----------------------------|--------------------------------------|--------------------------|--------------|--------------|----------------------------------------------------------------------------------------------------------------------|
| 2019-10-29 06:52:45.000 UTC | 0406f0c1-47a8-4f71-8a94-18267b84042a | cloudtrail.amazonaws.com | LookupEvents | AccessDenied | User: arn:aws:iam::account:user/username is not authorized to perform: cloudtrail:LookupEvents with an explicit deny in an identity-based policy |
| 2019-10-29 06:41:48.000 UTC | 14e5e77c-f682-45e1-8c88-12d15af293dd | cloudtrail.amazonaws.com | LookupEvents | AccessDenied | User: arn:aws:iam::account:user/username is not authorized to perform: cloudtrail:LookupEvents because no identity-based policy allows the cloudtrail:LookupEvents action |

참고: CloudTrail 이벤트 출력은 결과를 전달하는 데 최대 15분이 걸릴 수 있습니다.

5.    선택적으로 예시 쿼리에서 다음 줄을 제거하여 모든 사용자의 오류를 가져옵니다.

AND userIdentity.arn = 'your-arn'

6.    선택적으로 예시 쿼리에서 다음 줄을 제거하여 선택한 기간의 모든 오류를 가져옵니다.

AND (lower(errorCode) LIKE '%accessdenied%' OR lower(errorCode) LIKE '%unauthorized%')

AWS CLI를 사용하여 IAM 권한 API 호출 실패 문제 해결

참고: 이 AWS CLI 스크립트를 사용하려면 jq 명령줄 JSON 프로세서가 필요합니다. 자습서 및 다운로드 지침은 JSON 출력 형식을 참조하십시오. yum 패키지를 사용하는 배포의 경우 다음 명령을 실행하십시오.

$ sudo yum install jq

1.    다음 AWS CLI 명령을 실행합니다.

참고: your-arn을 해당 리소스의 IAM ARN으로 바꾸십시오.

( echo "Time,Identity ARN,Event ID,Service,Action,Error,Message";
  aws cloudtrail lookup-events --start-time "2019-10-29T06:40:00Z" --end-time "2019-10-29T06:55:00Z" --query "Events[*].CloudTrailEvent" --output text \
    | jq -r ". | select(.userIdentity.arn == \"your-arn\" and .eventType == \"AwsApiCall\" and .errorCode != null
    and (.errorCode | ascii_downcase | (contains(\"accessdenied\") or contains(\"unauthorized\"))))
    | [.eventTime, .userIdentity.arn, .eventID, .eventSource, .eventName, .errorCode, .errorMessage] | @csv"
) | column -t -s'",'

참고: CloudTrail에 대한 조회 요청 속도는 계정당, 리전당 초당 요청 2회로 제한됩니다. 이 제한을 초과하면 스로틀링 오류가 발생합니다.

2.    이 예시 테이블 출력에는 지정된 기간의 ID ARN에 대한 권한 오류가 나열되어 있습니다.

참고: 지난 90일 동안 리전에서 발생한 이벤트를 조회할 수 있습니다.

Time                  Event ID                              Service                   Action        Error         Message
2019-10-29T06:52:45Z  0406f0c1-47a8-4f71-8a94-18267b84042a  cloudtrail.amazonaws.com  LookupEvents  AccessDenied  User: arn:aws:iam::account:user/username is not authorized to perform: cloudtrail:LookupEvents with an explicit deny in an identity-based policy
2019-10-29T06:41:48Z  14e5e77c-f682-45e1-8c88-12d15af293dd  cloudtrail.amazonaws.com  LookupEvents  AccessDenied  User: arn:aws:iam::account:user/username is not authorized to perform: cloudtrail:LookupEvents because no identity-based policy allows the cloudtrail:LookupEvents action

3.    (선택 사항) 다음 줄을 제거하여 모든 사용자의 오류를 가져옵니다.

.userIdentity.arn == \"your-arn\" and

4.    (선택 사항) 다음 줄을 제거하여 선택한 기간의 모든 오류를 가져옵니다.

and (.errorCode | ascii_downcase | (contains(\"accessdenied\") or contains(\"unauthorized\")))

승인되지 않음 오류 문제 해결

Athena와 이전 AWS CLI 예시 출력은 CloudTrail LookupEvents API 호출과 관련이 있습니다.

Deny 문이 포함되어 있기 때문에 액세스를 거부하는 IAM 정책은 명시적 거부 및 암시적 거부에 대한 오류 메시지에 특정 문구를 포함합니다. IAM 명시적 거부 오류에는 "with an explicit deny in a <type> policy"라는 문구가 포함됩니다. IAM 암시적 거부 오류에는 "because no <type> policy allows the <action> action"이라는 문구가 포함됩니다.

명시적 거부가 있는 CloudTrail:LookupEvents 출력은 관련 IAM 정책이 올바르지 않음을 나타냅니다.

명시적 거부는 이러한 정책 유형 중 하나에서 발생할 수 있습니다. 예를 들어 ID 기반 정책, 리소스 기반 정책, 권한 경계, 조직 SCP, 세션 정책이 있습니다. 명시적 거부 문은 항상 허용 문보다 우선합니다. 명시적 거부는 IAM 사용자 ID 기반 정책에 있습니다.

허용하는 ID 기반 정책이 없기 때문에 cloudtrail:LookupEvents 출력은 ID 기반 정책이 이 API 작업을 허용하지 않아 암시적 거부가 발생한다는 것을 나타냅니다. ID 기반 정책에는 cloudtrail:LookupEvents API 작업에 대한 명시적인 허용 문이 없습니다.

액세스를 설정하기 위해 AWS에서 평가하는 정책 유형은 다음과 같습니다.

IAM 정책의 평가 및 관리 방법에 대한 자세한 내용은 정책 평가 로직IAM 정책 관리를 참조하십시오.

관련 정보

IAM의 정책 및 권한

IAM 정책 문제 해결