IAM & STS
Who is allowed to do what, and how do we prove they are that "who". Exam themes: policy shapes, roles vs resource-based policies, permission boundaries, and federating in external identities (SAML, OIDC, GitHub Actions).
Ai được làm gì, và làm sao chứng minh mình đúng là "ai" đó. Exam hay xoáy vào: các dạng policy, role vs resource-based policy, permission boundary, và kéo identity từ ngoài vào (SAML, OIDC, GitHub Actions).
Prefer roles whenƯu tiên role khi
- EC2 / Lambda / ECS need AWS creds — attach a role, no keys on diskEC2 / Lambda / ECS cần cred — gán role, không có key trên máy
- Cross-account access with clean audit trailCross-account có audit rõ ràng
- Human devs via SSO / SAML federationDev truy cập qua SSO / SAML federation
- CI/CD via OIDC (GitHub Actions, GitLab)CI/CD qua OIDC (GitHub Actions, GitLab)
- On-prem servers via IAM Roles Anywhere — X.509 cert → temp creds, no stored keysServer on-prem qua IAM Roles Anywhere — X.509 cert → cred tạm, không lưu key
Prefer resource-based whenƯu tiên resource-based khi
- External account should keep its identity (S3 bucket → other account)Account ngoài phải giữ danh tính (S3 bucket → account khác)
- Same-account service-to-service call, no persona swapCùng account, service gọi service, không đổi persona
- You want the policy to live with the resourceMuốn policy sống cùng resource
Acronyms — what the letters stand forViết tắt — chữ cái là của từ gì
| ShortViết tắt | Stands forLà của từ |
|---|---|
| IAM | Identity & Access Management |
| STS | Security Token Service |
| SCP | Service Control Policy — org cap on principals— trần org cho principal |
| RCP | Resource Control Policy — org cap on resources— trần org cho resource |
| OU | Organizational Unit — a group of accounts in Organizations— nhóm account trong Organizations |
| SLR | Service-Linked Role |
| ABAC | Attribute-Based Access Control — allow by tag match— cho phép theo khớp tag |
| OIDC | OpenID Connect |
| SAML | Security Assertion Markup Language |
| MFA | Multi-Factor Authentication |
| ARN | Amazon Resource Name |
| ACL | Access Control List — legacy, pre-IAM grant— cách cấp quyền cũ, có trước IAM |
The vocabulary — each term answers one questionTừ vựng — mỗi khái niệm trả lời một câu hỏi
When a word blurs, snap it back to the question it answers. That alone disambiguates most exam wording. Khi rối, kéo mỗi khái niệm về đúng câu hỏi nó trả lời. Chỉ vậy là gỡ được phần lớn câu chữ trong exam.
| TermKhái niệm | Answers the question…Trả lời câu hỏi… |
|---|---|
| User | Who is this human (or app)?Con người (hay app) này là ai? |
| Group | What do these users share? — a bag of users, not an identity you assume; no nesting.Nhóm user này share quyền gì? — cái túi gom user, không phải identity để assume; không lồng nhau. |
| Role | Who / what may borrow this identity?Ai / cái gì được mượn danh tính này? |
| Trust policyTrust policy | WHO may assume the role? — it is the role's resource-based policy.AI được assume role? — nó chính là resource-based policy của role. |
| Permission policyPermission policy | WHAT is allowed?Được làm GÌ? |
| Resource policyResource policy | This resource lets WHO in? — the only policy with a Principal.Resource này cho AI vào? — policy duy nhất có Principal. |
Policy shapesCác dạng policy
Managed vs inline decides lifecycle. Identity-based vs resource-based decides where the policy lives. Managed vs inline quyết vòng đời. Identity-based vs resource-based quyết policy sống ở đâu.
AdministratorAccess · PowerUserAccess
Action vs NotAction
Action = allow/deny exactly these APIs. NotAction = allow/deny everything except these. Handy but easy to misuse — combine with tight Resource scoping.
Action = allow/deny đúng những API liệt kê. NotAction = allow/deny tất cả trừ những cái liệt kê. Tiện nhưng dễ sai — kết hợp Resource siết chặt.
Every policy type in one tableGom hết loại policy vào một bảng
Nine shapes, but two questions split them all: does it grant, or only cap? and does it carry a Principal? Only three ever grant (identity-based, resource-based, and the legacy ACL); everything else can only cut.
Chín dạng, nhưng chỉ hai câu là chia hết: nó cấp quyền, hay chỉ đặt trần? và nó có Principal không? Chỉ ba dạng cấp quyền (identity-based, resource-based, và ACL kiểu cũ); còn lại chỉ biết cắt.
| PolicyPolicy | Attached toGắn vào đâu | Principal? |
Grants?Cấp quyền? | Its one jobLàm đúng một việc |
|---|---|---|---|---|
| Identity-basedIdentity-based | User, group, roleUser, group, role | NoKhông | YesCó | What may this identity do?Identity này được làm gì? |
| Resource-basedResource-based | S3, SQS, KMS key, Lambda… | YesCó | YesCó | Who may touch this resource?Ai được đụng vào resource này? |
| Trust policyTrust policy | IAM roleIAM role | YesCó | Yes — assume onlyCó — chỉ để assume | Who may assume this role?Ai được assume role này? |
| Permission boundaryPermission boundary | One user or roleMột user hoặc role | NoKhông | No — capsKhông — chỉ đặt trần | Ceiling on that one entityTrần quyền của riêng entity đó |
| Session policySession policy | An STS sessionMột STS session | NoKhông | No — capsKhông — chỉ đặt trần | Shrinks the temp sessionSiết nhỏ phiên tạm |
| SCP | Root / OU / accountRoot / OU / account | Usually notThường không | No — capsKhông — chỉ đặt trần | Ceiling on principals in the accountTrần cho principal trong account |
| RCP | Root / OU / accountRoot / OU / account | "*" |
No — capsKhông — chỉ đặt trần | Ceiling on resources in the accountTrần cho resource trong account |
| ACL | S3 bucket / object…S3 bucket / object… | Not IAM JSONKhông theo IAM JSON | Yes — legacyCó — kiểu cũ | Pre-IAM grant — turn it offCấp quyền thời tiền-IAM — nên tắt |
| VPC endpoint policyVPC endpoint policy | A VPC endpointMột VPC endpoint | YesCó | No — filtersKhông — chỉ lọc | What may pass through the endpointCái gì được đi qua endpoint |
IAM policy ∩ endpoint policy ∩ resource/bucket policy — use it to say "traffic through this endpoint may only reach these buckets".
ACL — cách cấp quyền S3 từ trước khi có IAM: không JSON, chỉ là một grantee kèm một quyền. Giờ AWS khuyên tắt hẳn — đặt Object Ownership = Bucket owner enforced để vô hiệu ACL, rồi quản access chỉ bằng bucket policy + IAM. VPC endpoint policy — một resource policy nằm ngay trên endpoint; nó lọc request nào được đi qua chứ không tự cấp quyền gì. Quyền thực = IAM policy ∩ endpoint policy ∩ resource/bucket policy — dùng để nói "traffic qua endpoint này chỉ được với tới mấy bucket kia".
Role vs resource-based — the persona swapRole vs resource-based — đổi persona
| Assume roleAssume role | Resource-basedResource-based | |
|---|---|---|
| Your original permissionsQuyền gốc | Given upMất | KeptGiữ |
| Where policy livesPolicy sống ở đâu | On the roleTrên role | On the resourceTrên resource |
| Good forTốt cho | Cross-account, workloads on AWSCross-account, workload trên AWS | Shared bucket, cross-account fanoutBucket share, fanout cross-account |
Same JSON dialect, one field apart. Identity-based says "what can I do" and never names a principal — the principal is whatever it's attached to. Resource-based says "who may come in", so it must spell out the Principal. That single field is why a resource policy can grant an external account access while keeping its own identity.
Cùng một kiểu JSON, chỉ lệch một field. Identity-based nói "tôi được làm gì" và không bao giờ ghi principal — principal ngầm là entity nó gắn vào. Resource-based nói "ai được vào", nên phải ghi rõ Principal. Chính field đó khiến resource policy cấp quyền cho account bên ngoài mà vẫn giữ nguyên danh tính gốc.
Role flavors — same mechanism, different jobCác "vị" của role — cùng cơ chế, khác việc
These names aren't different features — they're all "a role an AWS service assumes on your behalf". They differ by who the role is for and who controls it. Những cái tên này không phải feature khác nhau — đều là "một role mà AWS service assume thay bạn". Khác nhau ở role dành cho ai và ai kiểm soát.
| Who actually uses itAi thực sự dùng | Controlled byAi kiểm soát | |
|---|---|---|
| Execution roleExecution role | The service runtime — Lambda writing logs, ECS pulling the imagePhần runtime của service — Lambda ghi log, ECS kéo image về | YouBạn |
| Task roleTask role | Your app code in the container — calling DynamoDB, S3…Code app trong container — gọi DynamoDB, S3… | YouBạn |
| Instance roleInstance role | EC2 (via an instance profile wrapper) — the SDK on the boxEC2 (qua vỏ instance profile) — SDK chạy trên máy | YouBạn |
| Service roleService role | An AWS service acting for you — CodeBuild, CodePipeline, ConfigMột AWS service làm thay bạn — CodeBuild, CodePipeline, Config | YouBạn |
| Service-linked roleService-linked role | The service managing its own resources — ELB creating ENIs, Auto Scaling calling EC2Service tự quản resource của chính nó — ELB tạo ENI, Auto Scaling gọi EC2 | AWS — lockedAWS — khoá |
Principal: Service + sts:AssumeRole) and the permissions. So what makes something a "service role" isn't "a service assumes it" — it's that you author the policy. The service-linked role is the one exception: a service assumes it too, but AWS predefines and locks both trust and permissions (AWSServiceRoleFor…). Same mechanism, opposite owner.
Cùng một thứ, chỉ khác tên theo từng service: execution role (Lambda), task role (ECS), instance role (EC2). Cái nào bạn cũng tự viết trust policy (Principal: Service + sts:AssumeRole) lẫn permission. Nên cái khiến một role là "service role" không phải "service assume nó" — mà là bạn viết policy. Service-linked role là ngoại lệ duy nhất: cũng được service assume, nhưng AWS định nghĩa sẵn và khoá cả trust lẫn permission (AWSServiceRoleFor…). Cùng cơ chế, ngược chủ.
The tell: name starts with AWSServiceRoleFor… or sits under path /aws-service-role/ → it's service-linked, hands off. Otherwise it's an ordinary role you own. AWS ships SLRs so a service can't be crippled by a mis-scoped role you'd otherwise have to hand-build.
Dấu hiệu nhận: tên bắt đầu bằng AWSServiceRoleFor… hoặc nằm ở path /aws-service-role/ → là service-linked, đừng đụng vào. Còn lại là role thường của bạn. AWS đóng gói SLR để service không hỏng vì một role bạn tự set thiếu quyền.
Grants vs guardrails — the evaluation chainGrant vs guardrail — chuỗi đánh giá
Only two policy types grant permission. The rest are guardrails that can only cut. A request needs ≥1 grant Allow AND every guardrail to pass — any explicit Deny, anywhere, wins. Chỉ hai loại policy cấp quyền. Còn lại là guardrail chỉ biết cắt. Một request cần ≥1 grant Allow VÀ mọi guardrail đều lọt — bất kỳ explicit Deny ở đâu cũng thắng.
Every gate but one only answers "am I blocking this?". The single green gate — a grant — is the only place a permission is ever added. That's why the phrase "all must allow" holds: the request has to survive every guardrail and find at least one Allow.
Mọi cửa trừ một chỉ trả lời "tôi có chặn không?". Cửa xanh duy nhất — một grant — là chỗ duy nhất quyền được thêm. Vì thế câu "tất cả phải Allow" mới đúng: request phải sống sót qua mọi guardrail và tìm được ít nhất một Allow.
- Permission boundary caps one IAM user or role. Classic use: let a dev team create roles, but every role they make is stuck inside the boundary — they can't escalate to admin. Permission boundary giới hạn một IAM user hoặc role. Dùng kinh điển: cho dev team tạo role, nhưng mọi role họ tạo đều kẹt trong boundary — không thể escalate lên admin.
-
Session policy is passed at
AssumeRoletime by the broker (SSO / app). Session permissions = role policy ∩ session policy — it can only shrink, never exceed the role. Session policy được broker (SSO / app) truyền lúcAssumeRole. Quyền session = policy của role ∩ session policy — chỉ thu nhỏ, không bao giờ vượt role.
SCP & RCP — org-wide guardrailsSCP & RCP — trần cấp tổ chức
Only exist inside AWS Organizations. Attach at Root / OU / Account and they flow down. SCP (Service Control Policy) guards the caller side, RCP (Resource Control Policy) guards the resource side. Chỉ tồn tại trong AWS Organizations. Gắn ở Root / OU / Account rồi chảy xuống. SCP (Service Control Policy) canh phía gọi, RCP (Resource Control Policy) canh phía resource.
Attach a cap at Root, an OU, or a single account — it applies to everything beneath. A permission must be allowed by the cap at every level it passes through (an intersection down the tree). Both SCP and RCP attach exactly here; the difference is what they filter.
Gắn trần ở Root, một OU, hay một account — áp cho mọi thứ bên dưới. Một quyền phải được cho phép ở trần của mọi tầng nó đi qua (giao ∩ đi xuống). SCP và RCP gắn đúng chỗ này; khác nhau ở cái chúng lọc.
A request has two sides. SCP filters the principal's account; RCP filters the resource's account. RCP is the only one that bites when the caller sits outside your org. Một request có hai phía. SCP lọc account của principal; RCP lọc account của resource. RCP là cái duy nhất cắn khi caller nằm ngoài org của bạn.
SCP can only trap principals inside your org — an external caller sails past it. RCP sits on the resource side, so it holds the line against anyone, in or out of the org. That asymmetry is the whole reason RCP was added.
SCP chỉ trói được principal trong org — người ngoài đi thẳng qua. RCP nằm ở phía resource nên giữ được cửa với bất kỳ ai, trong hay ngoài org. Chính sự bất đối xứng đó là lý do RCP ra đời.
// SCP — trói principal của mình
{ "Effect": "Deny", "Action": "*", "Resource": "*",
"Condition": { "StringNotEquals": { "aws:RequestedRegion": "us-east-1" } } }
{ "Effect": "Deny", "Action": "cloudtrail:StopLogging", "Resource": "*" }
// RCP — canh resource, chặn cả người ngoài org
{ "Effect": "Deny", "Principal": "*", "Action": "s3:*", "Resource": "*",
"Condition": { "StringNotEquals": { "aws:PrincipalOrgID": "o-myorg" } } }
{ "Effect": "Deny", "Principal": "*", "Action": "s3:*", "Resource": "*",
"Condition": { "Bool": { "aws:SecureTransport": "false" } } }
-
Neither grants. An account whose identities have no policies does nothing, even under a wide-open
FullAWSAccessSCP. Cả hai không cấp quyền. Account mà identity không có policy thì chẳng làm được gì, dù SCP cóFullAWSAccessmở toang. - SCP skips the management account and service-linked roles — don't run sensitive workloads in the management account expecting SCP protection. SCP bỏ qua management account và service-linked role — đừng chạy workload nhạy cảm ở management account rồi tưởng SCP che.
- RCP currently covers S3, STS, SQS, KMS, Secrets Manager (expanding). Other services aren't guarded by RCP yet. RCP hiện phủ S3, STS, SQS, KMS, Secrets Manager (đang mở rộng). Service khác chưa được RCP canh.
STS — the important APIsSTS — các API quan trọng
Sort the five by which persona you get back. The AssumeRole* family gives you a role. The other two derive from the calling IAM user — no role at all.
Phân loại 5 cái theo bạn nhận persona nào. Họ AssumeRole* cho bạn một role. Hai cái còn lại lấy quyền từ chính IAM user gọi — không có role nào.
| APIAPI | Use it whenDùng khi | Persona you getPersona nhận về |
|---|---|---|
AssumeRole |
Assume a role, same- or cross-accountAssume một role, same- hay cross-account | The role's permissionsQuyền của role |
AssumeRoleWithSAML |
User logged in via a SAML IdP (ADFS, Okta)User login qua SAML IdP (ADFS, Okta) | The role's permissionsQuyền của role |
AssumeRoleWithWebIdentity |
User logged in via an OIDC IdP (Google, Facebook…). AWS recommends Cognito instead.User login qua OIDC IdP (Google, Facebook…). AWS khuyên dùng Cognito thay thế. | The role's permissionsQuyền của role |
GetSessionToken |
Need an MFA-backed session for an existing IAM user (or root)Cần session có MFA cho IAM user sẵn có (hoặc root) | The same IAM user + MFAVẫn chính IAM user đó + MFA |
GetFederationToken |
A broker app hands temp creds to users from a non-AWS store (AD / custom DB)App broker phát cred tạm cho user từ kho ngoài AWS (AD / DB tự viết) | A federated user — broker ∩ passed policyMột federated user — broker ∩ policy truyền vào |
Top lane = assume a role, swap persona. Bottom two = no role: GetSessionToken is just you with MFA; GetFederationToken mints a synthetic identity through a broker. That single split answers most STS exam wording.
Làn trên = assume role, đổi persona. Hai làn dưới = không role: GetSessionToken chỉ là chính bạn + MFA; GetFederationToken tạo danh tính ảo qua broker. Chỉ cái phân đôi đó là trả lời được phần lớn câu STS trong exam.
GetSessionToken = MFA gatecổng MFA
Policies require aws:MultiFactorAuthPresent = true; the user calls GetSessionToken with their MFA code, and the returned session carries the MFA proof so the gated actions now work. Same permissions as the user — it adds MFA, not access.
Policy đòi aws:MultiFactorAuthPresent = true; user gọi GetSessionToken kèm mã MFA, session trả về mang dấu MFA nên các action bị khoá mới chạy được. Quyền y hệt user — nó thêm MFA, không thêm quyền.
GetFederationToken in one scenario: 5,000 staff already live in corporate AD — you don't want an IAM user each. A broker app authenticates them and vends scoped temp creds.
GetFederationToken qua một tình huống: 5.000 nhân viên đã có sẵn trong AD công ty — bạn không muốn tạo IAM user cho từng người. Một app broker xác thực họ rồi phát cred tạm đã siết nhỏ.
No IAM user per employee — identities stay in AD, AWS only ever sees a short-lived federated-user/bob. The one long-term key sits in the broker; everything downstream holds only temp creds. And CloudTrail still attributes actions to bob.
Không cần IAM user cho từng nhân viên — danh tính vẫn ở AD, AWS chỉ thấy federated-user/bob tạm thời. Long-term key duy nhất nằm ở broker; mọi thứ phía sau chỉ cầm cred tạm. Và CloudTrail vẫn quy đúng hành động về bob.
GetFederationToken is the legacy custom-broker pattern (no IdP, no role). Today prefer IAM Identity Center or SAML/OIDC + AssumeRole for staff, and Cognito for app/mobile users.
GetFederationToken là pattern broker tự viết kiểu cũ (không IdP, không role). Nay nên dùng IAM Identity Center hoặc SAML/OIDC + AssumeRole cho nhân viên, và Cognito cho user app/mobile.
STS & session tagsSTS & session tag
Session tags travel with the assumed session. Use them for ABAC: allow only if aws:PrincipalTag/team matches the resource tag.
Session tag đi cùng session. Dùng cho ABAC: chỉ Allow khi aws:PrincipalTag/team khớp resource tag.
aws:PrincipalTag/*, aws:RequestTag/*, aws:ResourceTag/*, aws:SourceIp, aws:MultiFactorAuthPresent.
aws:PrincipalTag/*, aws:RequestTag/*, aws:ResourceTag/*, aws:SourceIp, aws:MultiFactorAuthPresent.
-
Passing session tags needs
sts:TagSessionallowed in the role's trust policy — forget it andAssumeRolewithTagsfails with AccessDenied. Truyền session tag cầnsts:TagSessionđược Allow trong trust policy của role — quên làAssumeRolekèmTagsbáo AccessDenied. - External ID stops the confused deputy when a third party assumes your role — full section below. External ID chặn confused deputy khi bên thứ ba assume role của bạn — section riêng ở dưới.
Confused deputy & External IDConfused deputy & External ID
A trusted middle-man (the deputy) has real permission to assume your role. An attacker who shares that deputy tricks it into using that permission against your account. The ExternalId is a per-customer tag that binds each assume to "which customer am I acting for".
Một bên trung gian được tin (deputy) có quyền thật để assume role của bạn. Kẻ tấn công dùng chung deputy đó lừa nó xài quyền ấy lên chính account bạn. ExternalId là nhãn theo từng customer, buộc mỗi lần assume với "tôi đang làm thay customer nào".
Role A. Example Corp = the third-party SaaS you hired (the deputy), trusted to assume Role A. Attacker = another customer of Example Corp.
Bạn = customer, sở hữu Role A. Example Corp = SaaS bên thứ ba bạn thuê (deputy), được tin để assume Role A. Attacker = một customer khác của Example Corp.
The deputy isn't hacked — it has genuine, legitimate permission. The attacker simply feeds it your role ARN, and AWS's trust check ("is Example Corp allowed?") can't see on whose behalf the deputy is acting. That blind spot is the whole vulnerability.
Deputy không hề bị hack — nó có quyền thật, hợp lệ. Attacker chỉ đưa cho nó ARN role của bạn, và bước kiểm tra trust của AWS ("Example Corp có được phép không?") không thấy được deputy đang làm thay ai. Đúng cái điểm mù đó là toàn bộ lỗ hổng.
Fix: Example Corp assigns each customer a unique ExternalId; you add it as a condition on the trust policy. Now the deputy must say which customer it's acting for — and it can't be forced to send someone else's ID.
Cách chặn: Example Corp cấp cho mỗi customer một ExternalId riêng; bạn thêm nó làm condition trong trust policy. Giờ deputy phải khai đang làm thay customer nào — và không thể bị ép gửi ID của người khác.
Example Corp thinks the attacker's request is Customer B, so it sends B's ID (67890) — not A's. Role A demands 12345, they mismatch, denied. The attacker never gets to choose which ID the deputy sends; that's what actually protects you.
Example Corp tưởng request của attacker là của Customer B, nên nó gửi ID của B (67890) — không phải của A. Role A đòi 12345, lệch nhau, bị chặn. Attacker không bao giờ chọn được deputy gửi ID nào; chính điều đó mới bảo vệ bạn.
// Trust policy của Role A — thêm condition ExternalId
{
"Effect": "Allow",
"Principal": { "AWS": "<Example Corp's AWS account>" },
"Action": "sts:AssumeRole",
"Condition": {
"StringEquals": { "sts:ExternalId": "12345" }
}
}
- The third party generates the ID, unique per customer — they're the ones who know "12345 = Customer A". You just drop it into the trust policy condition. Bên thứ ba tạo ID, riêng cho từng customer — họ mới là bên chắc chắn "12345 = Customer A". Bạn chỉ việc bỏ nó vào condition của trust policy.
-
The ID rides inside the
AssumeRolerequest as a condition — checked during the assume, not after. It's not part of any access key or credential. ID đi trong chính requestAssumeRoledưới dạng condition — kiểm ngay lúc assume, không phải sau. Nó không nằm trong access key hay credential nào. - Exam reflex: "grant a third-party / vendor account access to your account" → cross-account role + External ID. Never share access keys. Phản xạ exam: "cấp cho account bên thứ ba / vendor quyền vào account bạn" → cross-account role + External ID. Không bao giờ share access key.
GitHub Actions ↔ AWS via OIDCGitHub Actions ↔ AWS qua OIDC
No long-lived access keys. GitHub becomes an OIDC identity provider; the role's trust condition pins which repo & branch may assume it. Không dùng access key vĩnh viễn. GitHub thành OIDC identity provider; trust condition của role ghim repo & branch nào được phép assume.
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::<ACCOUNT>: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"
}
}
}]
}
sub conditionThiếu condition sub
Without a sub filter any GitHub repo in the world could assume the role. This is the top OIDC mistake.
Không có filter sub, bất kỳ repo GitHub nào cũng assume được role. Đây là sai lầm OIDC số 1.
Service roles & iam:PassRoleService role & iam:PassRole
A service role is a role whose trusted principal is an AWS service, so the service can act on your behalf. The interesting part isn't the role — it's that handing a role to a service is itself a privileged action, gated by iam:PassRole.
Một service role là role có trusted principal là một service AWS, để service hành động thay bạn. Phần đáng chú ý không phải bản thân role — mà là việc trao một role cho service cũng là một hành động đặc quyền, canh bởi iam:PassRole.
Two layers of permission, deliberately disjoint: the human may only drive the service, and the service alone may build. That's how "engineers must provision only via CloudFormation" is actually enforced.
Hai tầng quyền, cố ý không giao nhau: con người chỉ được điều khiển service, và chỉ service mới được dựng. Đó là cách "kỹ sư chỉ được provisioning qua CloudFormation" thật sự được ép.
// trust policy của service role — ai được assume nó
{ "Effect": "Allow",
"Principal": { "Service": "cloudformation.amazonaws.com" },
"Action": "sts:AssumeRole" }
// quyền engineer cần để "đưa" role đó cho CloudFormation
{ "Effect": "Allow",
"Action": "iam:PassRole",
"Resource": "arn:aws:iam::123456789012:role/CloudFormationApprovedRole",
"Condition": { "StringEquals": { "iam:PassedToService": "cloudformation.amazonaws.com" } } }
iam:PassRoledoes not let the engineer assume the role. It only lets them say "service, use this role". Scope it to specific role ARNs — a wildcardPassRoleis a privilege-escalation hole.iam:PassRolekhông cho engineer assume role đó. Nó chỉ cho phép nói "service ơi, dùng role này". Giới hạn theo ARN cụ thể —PassRolevới wildcard là một lỗ leo thang đặc quyền.- A service role is an IAM role, never an IAM user. It has no access keys; the service gets short-lived STS credentials. If your Terraform or CI still uses an IAM user with long-lived keys, the modern shape is OIDC →
AssumeRoleWithWebIdentity→ deployment role.Service role là một IAM role, không bao giờ là IAM user. Nó không có access key; service nhận credential STS ngắn hạn. Nếu Terraform hay CI của bạn vẫn dùng IAM user với key dài hạn, hình dạng hiện đại là OIDC →AssumeRoleWithWebIdentity→ deployment role. - The same permission policy can be reused across several roles that differ only in trust — one trusting CloudFormation, one trusting the GitHub OIDC provider, one trusting CodeBuild.Cùng một permission policy dùng lại được cho nhiều role chỉ khác nhau ở phần trust — một cái trust CloudFormation, một cái trust GitHub OIDC provider, một cái trust CodeBuild.
- Lambda invoking
ecs:RunTaskneedsiam:PassRolefor both the task role and the task execution role — a very common missing permission.Lambda gọiecs:RunTaskcầniam:PassRolecho cả task role lẫn task execution role — một quyền rất hay bị thiếu.
IAM Access Analyzer
It reads your resource-based policies and answers one question: can anything outside my zone of trust reach this? It reasons about the policies mathematically — it is not looking at logs, so a finding means "this access is possible", not "this happened". Nó đọc resource-based policy của bạn và trả lời đúng một câu: có thứ gì ngoài zone of trust với tới được cái này không? Nó suy luận toán học trên policy — nó không nhìn log, nên một finding nghĩa là "truy cập này có thể xảy ra", không phải "đã xảy ra".
- Don't confuse it with the network analyzers. IAM Access Analyzer = permissions. VPC Network Access Analyzer = "is there any network path from the internet to this?" VPC Reachability Analyzer = "can this specific source reach that specific destination, and where does it stop?"Đừng nhầm với các analyzer về mạng. IAM Access Analyzer = quyền. VPC Network Access Analyzer = "có đường mạng nào từ internet tới cái này không?" VPC Reachability Analyzer = "nguồn cụ thể này có với tới đích cụ thể kia không, và tắc ở đâu?"
- "Access Analyzer for S3" in the S3 console is the same engine viewed through an S3 lens. It is a security tool — it says nothing about storage cost or access frequency, so it's a distractor in any storage-class question."Access Analyzer for S3" trong console S3 là cùng một bộ máy nhìn qua lăng kính S3. Nó là công cụ bảo mật — không nói gì về chi phí lưu trữ hay tần suất truy cập, nên là bẫy trong mọi câu hỏi về storage class.
- Run it from a delegated administrator account so findings from every member account land in one place.Chạy nó từ account delegated administrator để finding của mọi member account đổ về một chỗ.