필자는 CICD공부 OIDC인증 방법에 알게되어 공부및 기록에 있어 정리하게되었다
AWS OIDC(OpenID Connect)는 AWS IAM과 외부 인증 제공자(GitHub, Google, Okta 등)를 연동하여 인증을 수행하는 방식
이를 통해 액세스 키 없이 AWS 리소스에 접근할 수 있으며, 보안성이 뛰어나다
구분 | 기존 IAM 방식 (Access Key) | OIDC 방식 (OpenID Connect) |
---|---|---|
인증 방식 | 액세스 키 (AWS_ACCESS_KEY, AWS_SECRET_ACCESS_KEY) 사용 | OIDC Provider를 통해 IAM Role Assume |
보안 위험 | 키 유출 시 계정 탈취 가능 | 액세스 키 없음 → 보안 강화 |
관리 부담 | 키 주기적 회전 필요 | 키 관리 불필요 |
CI/CD 적용 | GitHub Secrets에 키 저장 필요 | GitHub Actions에서 IAM Role Assume |
✅ OIDC 방식이 더 안전하고 관리 부담이 적음!
aws iam create-open-id-connect-provider \
--url https://token.actions.githubusercontent.com \
--client-id-list sts.amazonaws.com \
--thumbprint-list <THUMBPRINT>
✅ GitHub OIDC를 AWS IAM과 연결
aws iam create-role \
--role-name GitHubActionsRole \
--assume-role-policy-document file://trust-policy.json
📌 trust-policy.json (IAM Role 설정)
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::<AWS_ACCOUNT_ID>:oidc-provider/token.actions.githubusercontent.com"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"token.actions.githubusercontent.com:sub": "repo:my-org/my-repo:ref:refs/heads/main"
}
}
}
]
}
✅ GitHub Actions에서 AWS IAM Role Assume 가능
aws iam attach-role-policy \
--role-name GitHubActionsRole \
--policy-arn arn:aws:iam::aws:policy/AmazonEKSClusterPolicy
✅ IAM Role이 EKS 클러스터 배포 가능하도록 설정
- name: AWS OIDC 인증
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: arn:aws:iam::<AWS_ACCOUNT_ID>:role/GitHubActionsRole
role-session-name: GitHubActionsSession
aws-region: ap-northeast-2
✅ IAM 액세스 키 없이 GitHub Actions에서 AWS 인증 가능
name: Deploy to EKS
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: 코드 체크아웃
uses: actions/checkout@v3
- name: AWS OIDC 인증
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: arn:aws:iam::<AWS_ACCOUNT_ID>:role/GitHubActionsRole
role-session-name: GitHubActionsSession
aws-region: ap-northeast-2
- name: kubectl 설정
run: aws eks update-kubeconfig --name my-eks-cluster --region ap-northeast-2
- name: 애플리케이션 배포
run: kubectl apply -f k8s/deployment.yaml
✅ GitHub Actions가 OIDC를 통해 IAM Role을 Assume하여 EKS 배포 가능
✔️ OIDC를 사용하면 AWS 액세스 키 없이 보안성이 강화됨
✔️ GitHub Actions, Kubernetes(EKS)와 연동하여 CI/CD 자동화 가능
✔️ IAM Role을 통해 AWS 리소스에 안전하게 접근 가능