Identity Federation & Active Directory
Let identities that live outside AWS in — no IAM users. Exam themes: the four flavors (SAML, custom broker, web identity, Identity Center), what actually travels on the wire, and how Active Directory / ADFS / AWS Directory Services fit together.
Cho danh tính ngoài AWS vào — không tạo IAM user. Bài exam: bốn flavor (SAML, custom broker, web identity, Identity Center), thứ gì thật sự chạy trên dây, và AD / ADFS / AWS Directory Services ghép với nhau ra sao.
Reach for which flavorChọn flavor nào
- SAML 2.0 / ADFS — corporate has a SAML-compatible IdP, workforce needs Console/CLISAML 2.0 / ADFS — công ty có IdP hỗ trợ SAML, workforce cần Console/CLI
- Custom Identity Broker — IdP is not SAML 2.0 compatibleCustom Identity Broker — IdP không hỗ trợ SAML 2.0
- Web Identity + Cognito — web/mobile app, users log in with Google / Facebook / AppleWeb Identity + Cognito — app web/mobile, user login qua Google / Facebook / Apple
- IAM Identity Center — many accounts in an Organization, want one portal + permission setsIAM Identity Center — nhiều account trong Organization, muốn 1 portal + permission set
Not the right toolKhông phải chỗ dùng
- Web Identity Federation without Cognito — AWS says use Cognito insteadWeb Identity Federation không Cognito — AWS khuyên dùng Cognito
- Federating customers into IAM roles one-by-one — that's Cognito's jobFederate từng khách vào IAM role — đó là việc của Cognito
- Manual per-account SAML wiring for a big Organization — use Identity CenterWire SAML thủ công từng account cho Org lớn — dùng Identity Center
What federation isFederation là gì
User management stays outside AWS. AWS and the Identity Provider (IdP) hold a trust; the user logs into the IdP, gets a credential the IdP vouches for, and trades it for AWS access. Quản lý user nằm ngoài AWS. AWS và Identity Provider (IdP) giữ một trust; user login vào IdP, nhận credential do IdP bảo lãnh, rồi đổi lấy quyền vào AWS.
Three edges: user↔IdP (login), IdP↔AWS (the trust set up once), user→AWS (access). No IAM user is ever created — the trust is what makes AWS accept the IdP's word.
Ba cạnh: user↔IdP (login), IdP↔AWS (trust dựng một lần), user→AWS (truy cập). Không tạo IAM user nào — chính trust khiến AWS chịu tin lời IdP.
The four flavorsBốn flavor
AssumeRoleWithSAML. The "old way".IdP công ty (ADFS). AssumeRoleWithSAML. Kiểu "cũ".
AssumeRole / GetFederationToken.IdP không hỗ trợ SAML. AssumeRole / GetFederationToken.
AssumeRoleWithWebIdentity.App/mobile, Google/FB/Apple. AssumeRoleWithWebIdentity.
SAML 2.0 Federation — the flowSAML 2.0 Federation — luồng chạy
The IdP authenticates the user against its store, hands back a signed SAML assertion, and the user trades that to STS for temp creds. Trust is set up both ways between AWS IAM and the SAML IdP. IdP xác thực user với kho của nó, trả về SAML assertion có chữ ký, user đổi cái đó lấy cred tạm ở STS. Trust dựng cả hai chiều giữa AWS IAM và SAML IdP.
Left half happens in the corporate network (auth → assertion). Right half is pure STS: assertion in, temp creds out, then normal signed API calls. The user never holds a long-lived AWS key.
Nửa trái xảy ra trong mạng công ty (auth → assertion). Nửa phải thuần STS: đưa assertion vào, nhận cred tạm ra, rồi gọi API ký bình thường. User không bao giờ giữ AWS key vĩnh viễn.
What actually travels on the wire — the three artifacts: Thứ thật sự chạy trên dây — ba vật thể:
<!-- STEP 3: SAML assertion (signed XML), trimmed -->
<saml:Assertion>
<saml:Subject><saml:NameID>[email protected]</saml:NameID></saml:Subject>
<saml:Conditions>
<saml:Audience>urn:amazon:webservices</saml:Audience> <!-- dành cho AWS -->
</saml:Conditions>
<saml:AttributeStatement>
<saml:Attribute Name="https://aws.amazon.com/SAML/Attributes/Role">
arn:aws:iam::123456789012:role/CorpDev,arn:aws:iam::123456789012:saml-provider/CorpADFS
</saml:Attribute>
<saml:Attribute Name="…/RoleSessionName">[email protected]</saml:Attribute>
<saml:Attribute Name="…/SessionDuration">3600</saml:Attribute>
</saml:AttributeStatement>
<ds:Signature>… ký bằng X.509 cert của IdP …</ds:Signature> <!-- AWS tin chữ ký -->
</saml:Assertion>
# STEP 4: trade the assertion for creds (no AWS access key needed)
aws sts assume-role-with-saml \
--role-arn arn:aws:iam::123456789012:role/CorpDev \
--principal-arn arn:aws:iam::123456789012:saml-provider/CorpADFS \
--saml-assertion "PHNhbWw6QXNzZXJ0aW9u…(base64 của XML ở B3)…"
// STEP 5: STS returns 3-part temp creds
{ "Credentials": {
"AccessKeyId": "ASIAWXYZEXAMPLE123", // ASIA… = tạm (key thường = AKIA…)
"SecretAccessKey": "wJalrXUtnFEMI/K7MDENG/EXAMPLE",
"SessionToken": "FQoGZXIvYXdzEJ…//////////wEa…",// dấu hiệu cred tạm
"Expiration": "2026-08-13T09:15:00Z" },
"AssumedRoleUser": { "Arn": "arn:aws:sts::123456789012:assumed-role/CorpDev/[email protected]" } }
Role attribute is a pairRole attribute là một cặp
Its value is role-arn,saml-provider-arn (comma-separated). Those map straight onto the two AssumeRoleWithSAML params. Multiple Role values → the Console shows a role picker.
Giá trị là role-arn,saml-provider-arn (cách nhau dấu phẩy). Hai cái này map thẳng vào 2 tham số của AssumeRoleWithSAML. Nhiều giá trị Role → Console hiện màn hình chọn role.
POSTs the assertion to https://signin.aws.amazon.com/saml; AWS sign-in calls STS itself, builds a sign-in URL, and redirects the browser into the Console. The user never sees the creds.
Với Console, browser POST assertion tới https://signin.aws.amazon.com/saml; AWS sign-in tự gọi STS, dựng sign-in URL rồi redirect browser vào Console. User không thấy cred.
Custom Identity BrokerCustom Identity Broker
Use it only when the IdP is not SAML 2.0 compatible. Your broker app authenticates the user, picks the right IAM role, and calls STS itself. Chỉ dùng khi IdP không hỗ trợ SAML 2.0. App broker của bạn xác thực user, tự chọn IAM role phù hợp, rồi gọi STS.
The tell vs SAML: here the broker calls STS (step 3) and hands the user a token/URL (step 4) — the user never talks to STS directly. The broker owns both the authentication and the role-mapping.
Khác SAML ở chỗ: ở đây broker gọi STS (bước 3) rồi đưa user token/URL (bước 4) — user không hề nói chuyện trực tiếp với STS. Broker ôm cả phần xác thực lẫn map role.
- The broker must determine the appropriate IAM Role for each user — that logic lives in your code, not in AWS. Broker phải tự quyết IAM Role phù hợp cho từng user — logic đó nằm trong code của bạn, không phải AWS.
-
Uses the STS API
AssumeRoleorGetFederationTokento mint temp creds, then hands a token/URL back to the user. Dùng STSAssumeRolehoặcGetFederationTokentạo cred tạm, rồi trả token/URL cho user. - Same shape as SAML federation, but you build the authentication + role-mapping instead of relying on SAML. Cùng dạng với SAML federation, nhưng bạn tự làm phần xác thực + map role thay vì dựa vào SAML.
Web Identity Federation & CognitoWeb Identity Federation & Cognito
For web/mobile app users logging in with Google / Facebook / Apple / any OIDC IdP. Without Cognito → AssumeRoleWithWebIdentity directly (AWS says don't). With Cognito → the recommended path.
Cho user app web/mobile login qua Google / Facebook / Apple / bất kỳ OIDC IdP. Không Cognito → gọi thẳng AssumeRoleWithWebIdentity (AWS khuyên đừng). Có Cognito → đường khuyến nghị.
The blue hop (IdP → app) is the same ID token in both — a standard OIDC JWT; the IdP has no idea Cognito exists. Only the consumer differs: raw sends it straight to STS; Cognito takes it, re-issues its own token, and brokers the exchange.
Chặng xanh (IdP → app) là cùng một ID token ở cả hai — một OIDC JWT chuẩn; IdP không biết Cognito tồn tại. Chỉ khác ở bên tiêu thụ: raw đưa thẳng cho STS; Cognito nhận vào, tự phát token của nó, rồi làm trung gian đổi creds.
| Without CognitoKhông Cognito | With CognitoCó Cognito | |
|---|---|---|
| Who trades the tokenAi đổi token | Client → STS directlyClient → STS trực tiếp | Client → Cognito → STSClient → Cognito → STS |
| AWS stanceAWS khuyến nghị | Not recommendedKhông khuyên | PreferredƯu tiên |
| ExtrasThêm | —— | Anonymous users · MFA · data syncUser ẩn danh · MFA · đồng bộ dữ liệu |
AssumeRoleWithWebIdentity is a stateless swap: token in → creds out, nothing remembered. Cognito keeps a persistent identity ID (+ optionally a user directory), and that's what unlocks all three: anonymous users (issues creds for a guest role with no upstream token — raw can't, it requires a token) · MFA (Cognito actively runs the login, so it can challenge; raw only validates a token someone else made) · data sync (needs a durable identity to attach data to).
Raw AssumeRoleWithWebIdentity là swap không trạng thái: đưa token vào → nhả creds → quên sạch. Cognito giữ một identity ID bền vững (+ tùy chọn cả user directory), và đó là thứ mở khóa cả ba: user ẩn danh (cấp creds cho guest role mà không cần token upstream — raw không làm được vì bắt buộc có token) · MFA (Cognito chủ trì login nên có thể thách thức; raw chỉ verify token do bên khác phát) · data sync (cần danh tính bền để gắn dữ liệu).
After web-identity auth you can pin each user to their own data with an IAM policy variable — the IdP's user-id substituted into the resource ARN: Sau khi auth web-identity, có thể ghim mỗi user vào đúng data của họ bằng IAM policy variable — user-id của IdP được thế vào ARN resource:
{ "Effect": "Allow",
"Action": ["s3:GetObject", "s3:PutObject"],
"Resource": "arn:aws:s3:::myBucket/game/${www.amazon.com:user_id}/*" }
// các biến hay gặp:
// cognito-identity.amazonaws.com:sub graph.facebook.com:id
// www.amazon.com:user_id accounts.google.com:sub
Old way vs new way — SAML vs IAM Identity CenterOld way vs new way — SAML vs IAM Identity Center
| SAML 2.0 (old)SAML 2.0 (cũ) | IAM Identity Center (new)IAM Identity Center (mới) | |
|---|---|---|
| SetupSetup | Manual: SAML provider + roles per accountThủ công: SAML provider + role từng account | Managed: one identity source + permission setsManaged: một identity source + permission set |
| ScopePhạm vi | Per-account wiringWire từng account | Whole Organization at onceCả Organization một lần |
| Login portalCổng đăng nhập | You build it (IdP side)Bạn tự dựng (bên IdP) | Built-in AWS access portalAWS access portal có sẵn |
| Under the hoodUnder the hood | AssumeRoleWithSAMLAssumeRoleWithSAML |
Managed federation + STSFederation managed + STS |
What is Active Directory (AD)?Active Directory (AD) là gì?
Microsoft's identity database, on any Windows Server with AD Domain Services. Think "the company's registry office + gate guard": it knows every user/computer/printer and checks passwords. Cơ sở dữ liệu danh tính của Microsoft, trên Windows Server có AD Domain Services. Hình dung "phòng hộ tịch + bảo vệ cổng": biết mọi user/máy tính/máy in và kiểm password.
The Domain Controller is the server that runs AD and answers "is this password right?". Everything managed — users, computers, printers, file shares, security groups — is an object in its database.
Domain Controller là server chạy AD và trả lời "password này đúng không?". Mọi thứ được quản — user, máy tính, máy in, file share, security group — đều là object trong CSDL của nó.
corp.com); domains form a tree; a group of trees is a forest. AD is queried over the LDAP protocol.
Object = thứ được quản (user, PC…). Object nằm trong domain (một namespace như corp.com); các domain tạo thành tree; nhóm tree là forest. AD được truy vấn qua giao thức LDAP.
What is ADFS?ADFS là gì?
AD only works inside the corporate network. ADFS is the add-on that turns an AD login into a signed SAML token that external apps trust — giving Single Sign-On across AWS Console, Dropbox, Office365, etc. AD chỉ chạy trong mạng công ty. ADFS là phần gắn thêm, biến login AD thành SAML token có chữ ký mà app bên ngoài tin — cho Single Sign-On qua AWS Console, Dropbox, Office365, v.v.
AWS Directory ServicesAWS Directory Services
Three ways to have "AD" in AWS. Pick by: do you need a real Microsoft AD, do users stay on-prem, or just something cheap and AD-compatible. Ba cách để có "AD" trong AWS. Chọn theo: cần AD Microsoft thật, user ở on-prem, hay chỉ cần thứ rẻ và tương thích AD.
Managed AD = a real Microsoft AD you run in AWS, can two-way-trust on-prem. AD Connector = a thin proxy; auth is forwarded to on-prem, nothing stored. Simple AD = cheap Samba, none of the trust/MFA/SQL extras.
Managed AD = AD Microsoft thật chạy trong AWS, two-way trust được với on-prem. AD Connector = proxy mỏng; auth chuyển về on-prem, không lưu gì. Simple AD = Samba rẻ, không có trust/MFA/SQL.
| Managed Microsoft AD | AD Connector | Simple AD | |
|---|---|---|---|
| What it isLà gì | Real MS AD in your VPCAD Microsoft thật trong VPC | Gateway/proxy to on-prem ADGateway/proxy về on-prem AD | Samba, AD-compatibleSamba, tương thích AD |
| Users managedUser quản ở | In AWS (or joined to on-prem)Trong AWS (hoặc join on-prem) | Solely on-premisesChỉ ở on-premises | In AWSTrong AWS |
| Trust with on-premTrust với on-prem | Yes (forest trust)Có (forest trust) | No trust — it is on-premKhông — nó chính là on-prem | NoKhông |
| MFA · RDS SQL · SSO | YesCó | MFA yes; no SQL, no seamless joinMFA có; không SQL, không seamless join | No MFA, no SQL, no SSOKhông MFA, SQL, SSO |
Domain join — what it means to join ADDomain join — "gia nhập AD" nghĩa là gì
Domain join = make a machine (an EC2 instance) a member of the AD domain. After joining, the box has a computer account in AWS Managed AD, trusts the DC, and AD users log in with their AD credentials — no local accounts. AWS Managed AD is the DC; the EC2 is the member. Domain join = biến một máy (một EC2 instance) thành member của AD domain. Join xong, máy có computer account trong AWS Managed AD, tin DC, và user AD login được bằng credential AD — khỏi local account. AWS Managed AD là DC; EC2 là member.
Same box, two states. Before: an island with only a local Administrator. After the join it holds a computer account in the domain, so AD logins, Group Policy and Kerberos all flow through the DC. It's "enrol the machine into the company network".
Cùng một máy, hai trạng thái. Trước: một ốc đảo chỉ có local Administrator. Sau khi join, máy có computer account trong domain, nên login AD, Group Policy và Kerberos đều đi qua DC. Chính là "cho máy gia nhập mạng công ty".
AmazonSSMManagedInstanceCore, pick the directory at launch → SSM joins it for you, no manual command. Manual: Windows Add-Computer/sconfig, Linux realm join + sssd. Either way the instance must reach the directory's DNS (point instance DNS at the directory IPs) and the security group must allow AD ports (DNS 53, Kerberos 88, LDAP 389…).
Seamless join (cách AWS): gán cho EC2 một IAM role có AmazonSSMManagedInstanceCore, chọn directory lúc launch → SSM join giúp, không cần gõ tay. Thủ công: Windows Add-Computer/sconfig, Linux realm join + sssd. Cách nào thì instance cũng phải tới được DNS của directory (trỏ DNS instance về IP directory) và security group cho phép các port AD (DNS 53, Kerberos 88, LDAP 389…).
- WorkSpaces, RDS for SQL Server, FSx for Windows, SharePoint all domain-join the same way — they're AD members exactly like the EC2 above. WorkSpaces, RDS for SQL Server, FSx for Windows, SharePoint đều domain-join y hệt — chúng là member của AD đúng như con EC2 ở trên.
- This is why a Google / SAML identity can't reach a domain-joined resource: it authenticates via Kerberos/LDAP against the DC, not a SAML token. Domain-joined workloads need a real AD identity. Đây là lý do identity Google / SAML không "vào" được resource đã domain-join: nó xác thực bằng Kerberos/LDAP với DC, không phải SAML token. Workload domain-joined cần identity AD thật.
- Seamless join fails silently without the SSM agent + IAM role, or if the instance can't resolve the directory's DNS. First things to check when a join won't complete. Seamless join fail lặng lẽ nếu thiếu SSM agent + IAM role, hoặc instance không resolve được DNS của directory. Đó là chỗ kiểm đầu tiên khi join không xong.
Connect to on-prem AD — forest trust & replicationNối on-prem AD — forest trust & replication
To join AWS Managed AD with on-prem AD you need Direct Connect or VPN, then a forest trust. Trust ≠ sync: it lets one directory trust the other's logins, it doesn't copy accounts. Để nối AWS Managed AD với on-prem AD cần Direct Connect hoặc VPN, rồi một forest trust. Trust ≠ sync: nó cho directory này tin login của directory kia, không copy account.
Three flavors: one-way each direction, or two-way. "AWS ⇒ on-prem" means AWS-side resources trust on-prem identities. Separately, you can run a self-managed AD replica on EC2 so logins survive a DX/VPN outage.
Ba kiểu: một chiều mỗi hướng, hoặc hai chiều. "AWS ⇒ on-prem" nghĩa là resource phía AWS tin identity on-prem. Ngoài ra, có thể chạy AD replica tự quản trên EC2 để login vẫn sống khi DX/VPN sập.
Why the replica must be self-managed AD on EC2, not Managed AD: replication only happens inside the same domain/forest. Read the domain names — the EC2 replica shares the on-prem domain; Managed AD is always its own. Vì sao replica phải là AD tự quản trên EC2, không phải Managed AD: replication chỉ xảy ra trong cùng một domain/forest. Đọc domain name — EC2 replica dùng chung domain on-prem; Managed AD luôn là domain riêng.
Same domain (onpremAD…) → replication → a full local copy that survives a DX/VPN outage. Different domain (awsAD…) → only a trust, which never copies the directory.
Cùng domain (onpremAD…) → replication → bản sao local đầy đủ, sống khi DX/VPN sập. Khác domain (awsAD…) → chỉ có trust, không bao giờ copy directory.
- AD Connector needs on-prem reachability (VPN/DX) too, but sets up no trust — it just forwards LDAP auth to on-prem. AD Connector cũng cần với tới on-prem (VPN/DX), nhưng không dựng trust — chỉ forward LDAP auth về on-prem.
- Managed AD integrations: RDS for SQL Server, WorkSpaces, QuickSight, WorkDocs, Connect, and 3rd-party SaaS via SAML through AWS SSO. Managed AD tích hợp: RDS for SQL Server, WorkSpaces, QuickSight, WorkDocs, Connect, và SaaS bên thứ ba qua SAML nhờ AWS SSO.
Takeaway — the identity pieces at a glanceTakeaway — các mảnh identity nhìn một phát
| One-line roleVai trò một dòng | Calls STS?Gọi STS? | |
|---|---|---|
| AD | Identity database + authenticator (users, devices, passwords)Database identity + verify login (user, device, password) | NoKhông |
| ADFS | SAML IdP in front of AD → issues assertion so external apps accept the login (SSO)SAML IdP đứng trước AD → phát assertion để app ngoài chấp nhận login (SSO) | No — the user trades the assertion at STSKhông — user cầm assertion gọi STS |
| AD Connector | AWS proxy that forwards LDAP auth to on-prem AD — no SAML, nothing storedProxy AWS forward LDAP auth về on-prem AD — không SAML, không lưu gì | No — the app/sign-in page doesKhông — app/sign-in page gọi |
| Simple AD | Cheap standalone Samba directory — no trust, no MFA, no SQLDirectory Samba standalone rẻ — không trust, không MFA, không SQL | NoKhông |
| AWS Managed AD | A real Microsoft AD run by AWS in your VPC; can forest-trust on-prem. Federation to apps is via IAM Identity Center, not built in.AD Microsoft thật do AWS chạy trong VPC; forest-trust được on-prem. Federation ra app là nhờ IAM Identity Center, không tích hợp sẵn. | NoKhông |
| IAM Identity Center | The managed federation / SSO layer — the "new way" (org-wide portal + permission sets)Lớp federation / SSO managed — "new way" (portal org-wide + permission set) | It brokers the temp credsNó môi giới cấp creds tạm |
| STS | The exchange desk: token/assertion in → temp creds outQuầy đổi: token/assertion vào → creds tạm ra | — (it is STS)— (nó là STS) |