AWS - Federation Abuse

HackTricks 지원하기

SAML

SAML에 대한 정보는 다음을 확인하세요:

SAML을 통한 Identity Federation을 구성하려면 이름과 모든 SAML 구성을 포함하는 메타데이터 XML(엔드포인트, 공개 키가 있는 인증서)를 제공하면 됩니다.

OIDC - Github Actions 남용

Identity 공급자로 github action을 추가하려면:

  1. _Provider type_으로 OpenID Connect를 선택합니다.

  2. _Provider URL_에 https://token.actions.githubusercontent.com을 입력합니다.

  3. _Get thumbprint_를 클릭하여 공급자의 썸프린트를 가져옵니다.

  4. _Audience_에 sts.amazonaws.com을 입력합니다.

  5. github action이 필요로 하는 권한 및 공급자를 신뢰하는 신뢰 정책이 있는 새 역할을 만듭니다.

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Federated": "arn:aws:iam::0123456789:oidc-provider/token.actions.githubusercontent.com" }, "Action": "sts:AssumeRoleWithWebIdentity", "Condition": { "StringEquals": { "token.actions.githubusercontent.com:sub": [ "repo:ORG_OR_USER_NAME/REPOSITORY:pull_request", "repo:ORG_OR_USER_NAME/REPOSITORY:ref:refs/heads/main" ], "token.actions.githubusercontent.com:aud": "sts.amazonaws.com" } } } ] }

6. 이전 정책에서 어떻게 **조직**의 **저장소**에서 **특정 트리거**로 **특정 브랜치**만이 허가되었는지 확인하세요.
7. github action이 **가장할 수 있는 역할**의 **ARN**은 github action이 알아야 하는 "비밀"이므로 이를 **환경**의 **비밀** 내에 **저장**하세요.
8. 마지막으로 github action을 사용하여 워크플로에서 사용할 AWS 자격 증명을 구성하세요.
```yaml
name: 'test AWS Access'

# The workflow should only trigger on pull requests to the main branch
on:
pull_request:
branches:
- main

# Required to get the ID Token that will be used for OIDC
permissions:
id-token: write
contents: read # needed for private repos to checkout

jobs:
aws:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-region: eu-west-1
role-to-assume: ${{ secrets.READ_ROLE }}
role-session-name: OIDCSession

- run: aws sts get-caller-identity
shell: bash

OIDC - EKS 남용

# Crate an EKS cluster (~10min)
eksctl create cluster --name demo --fargate
# Create an Identity Provider for an EKS cluster
eksctl utils associate-iam-oidc-provider --cluster Testing --approve

OIDC 공급자를 생성하는 것은 간단하며, EKS 클러스터의 OIDC URL새로운 Open ID Identity 공급자로 설정함으로써 가능합니다. 이것은 일반적인 기본 정책입니다:

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::123456789098:oidc-provider/oidc.eks.us-east-1.amazonaws.com/id/20C159CDF6F2349B68846BEC03BE031B"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"oidc.eks.us-east-1.amazonaws.com/id/20C159CDF6F2349B68846BEC03BE031B:aud": "sts.amazonaws.com"
}
}
}
]
}

이 정책은 id20C159CDF6F2349B68846BEC03BE031BEKS 클러스터만 역할을 가정할 수 있다고 올바르게 나타내고 있습니다. 그러나 어떤 서비스 계정이 그 역할을 가정할 수 있는지 명시하지 않았기 때문에 웹 신원 토큰을 가진 ANY 서비스 계정이 그 역할을 가정할 수 있게 됩니다.

어떤 서비스 계정이 그 역할을 가정할 수 있는지 지정하려면, 서비스 계정 이름이 지정된 조건을 지정해야 합니다. 다음과 같이:

"oidc.eks.region-code.amazonaws.com/id/20C159CDF6F2349B68846BEC03BE031B:sub": "system:serviceaccount:default:my-service-account",

참고 자료

HackTricks 지원하기

Last updated