Appearance
AWS IAM — Theory (Bản gốc slide / Original slide)
1. IAM là gì (What is IAM)
- IAM = Identity and Access Management — dịch vụ Global (không thuộc region nào cả)
- Root account được tạo mặc định khi mở tài khoản AWS — không nên dùng hoặc chia sẻ
- IAM = Identity and Access Management — a Global service (not tied to any single region)
- Root account is created by default when you open an AWS account — shouldn't be used or shared
2. Users & Groups
- User: người dùng trong tổ chức, có thể được nhóm lại
- Group: chỉ chứa User, không chứa Group khác (không nest được)
- User không bắt buộc phải thuộc Group nào, và có thể thuộc nhiều Group cùng lúc
- Users are people within your organization, and can be grouped
- Groups only contain Users, not other Groups (no nesting)
- Users don't have to belong to a group, and a user can belong to multiple groups at once
3. Permissions (Policies)
- User hoặc Group được gán các tài liệu JSON gọi là Policy
- Policy định nghĩa quyền hạn (permissions) của user
- Nguyên tắc least privilege: không cấp nhiều quyền hơn mức user thực sự cần
- Users or Groups can be assigned JSON documents called Policies
- These policies define the permissions of the user
- Apply the least privilege principle: don't give more permissions than a user needs
json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "ec2:Describe*",
"Resource": "*"
},
{
"Effect": "Allow",
"Action": "elasticloadbalancing:Describe*",
"Resource": "*"
},
{
"Effect": "Allow",
"Action": ["cloudwatch:ListMetrics", "cloudwatch:GetMetricStatistics", "cloudwatch:Describe*"],
"Resource": "*"
}
]
}4. Policy Inheritance
- Một user có thể nhận quyền từ nhiều nguồn cùng lúc: policy gắn trực tiếp (inline), và policy của (các) group mà user thuộc về
- Quyền cuối cùng của user = tổng hợp (union) tất cả các policy đó
- A user can receive permissions from multiple sources at once: a policy attached directly (inline), plus the policy(ies) of any group(s) the user belongs to
- The user's effective permissions are the union of all of these
5. Cấu trúc Policy (IAM Policies Structure)
Một Policy gồm:
- Version: phiên bản ngôn ngữ policy — luôn dùng
"2012-10-17" - Id: định danh cho policy (tùy chọn)
- Statement: một hoặc nhiều statement (bắt buộc)
Mỗi Statement gồm:
- Sid: định danh cho statement (tùy chọn)
- Effect:
AllowhoặcDeny - Principal: tài khoản/user/role mà policy này áp dụng cho
- Action: danh sách action được cho phép/từ chối
- Resource: danh sách resource mà action áp dụng lên
- Condition: điều kiện để statement có hiệu lực (tùy chọn)
A Policy consists of:
- Version: policy language version — always include
"2012-10-17" - Id: an identifier for the policy (optional)
- Statement: one or more individual statements (required)
Each Statement consists of:
- Sid: an identifier for the statement (optional)
- Effect: whether the statement allows or denies access (
Allow,Deny) - Principal: the account/user/role this policy applies to
- Action: the list of actions this policy allows or denies
- Resource: the list of resources the actions apply to
- Condition: conditions for when this statement is in effect (optional)
6. Password Policy
Có thể cấu hình:
- Độ dài tối thiểu của password
- Yêu cầu loại ký tự cụ thể: chữ hoa, chữ thường, số, ký tự đặc biệt (non-alphanumeric)
- Cho phép mọi IAM user tự đổi password của mình
- Yêu cầu đổi password sau một khoảng thời gian (password expiration)
- Ngăn việc dùng lại password cũ (prevent password re-use)
You can configure:
- A minimum password length
- Required character types: uppercase letters, lowercase letters, numbers, non-alphanumeric characters
- Allow all IAM users to change their own passwords
- Require users to change their password after some time (password expiration)
- Prevent password re-use
7. Multi-Factor Authentication (MFA)
- User có quyền truy cập account và có thể thay đổi cấu hình hoặc xóa resource → cần bảo vệ cả Root account lẫn IAM user
- MFA = mật khẩu bạn biết + thiết bị bảo mật bạn sở hữu
- Lợi ích chính: nếu password bị lộ/hack, account vẫn không bị chiếm được vì thiếu yếu tố thứ hai
- Users have access to your account and can possibly change configurations or delete resources — you want to protect both Root accounts and IAM users
- MFA = a password you know + a security device you own
- Main benefit: if a password is stolen or hacked, the account is not compromised, since the second factor is still missing
8. Các loại thiết bị MFA trên AWS (MFA Device Options)
- Virtual MFA device: Google Authenticator, Authy (chỉ chạy trên điện thoại) — hỗ trợ nhiều token trên cùng một thiết bị
- Universal 2nd Factor (U2F) Security Key: ví dụ YubiKey (bên thứ 3) — một khóa bảo mật vật lý dùng chung cho nhiều root/IAM user
- Hardware Key Fob MFA Device: cung cấp bởi Gemalto (bên thứ 3)
- Hardware Key Fob cho AWS GovCloud (US): cung cấp bởi SurePassID (bên thứ 3)
- Virtual MFA device: Google Authenticator, Authy (phone only) — supports multiple tokens on a single device
- Universal 2nd Factor (U2F) Security Key: e.g. YubiKey by Yubico (3rd party) — a single physical key supports multiple root and IAM users
- Hardware Key Fob MFA Device: provided by Gemalto (3rd party)
- Hardware Key Fob for AWS GovCloud (US): provided by SurePassID (3rd party)
9. Cách người dùng truy cập AWS (How Can Users Access AWS)
Có 3 cách:
- AWS Management Console: bảo vệ bằng password + MFA
- AWS Command Line Interface (CLI): bảo vệ bằng Access Keys
- AWS Software Developer Kit (SDK) — dùng cho code: bảo vệ bằng Access Keys
Về Access Keys:
- Được tạo qua AWS Console
- User tự quản lý access key của chính mình
- Access Key là bí mật, giống như password — không chia sẻ
- Access Key ID ~ giống username
- Secret Access Key ~ giống password
Three options:
- AWS Management Console: protected by password + MFA
- AWS Command Line Interface (CLI): protected by Access Keys
- AWS Software Developer Kit (SDK) — for code: protected by Access Keys
About Access Keys:
- Generated through the AWS Console
- Users manage their own access keys
- Access Keys are secret, just like a password — don't share them
- Access Key ID ≈ username
- Secret Access Key ≈ password
10. AWS CLI là gì (What's the AWS CLI)
- Công cụ cho phép tương tác với AWS service bằng lệnh ngay trên command-line shell
- Truy cập trực tiếp vào public API của các AWS service
- Có thể viết script để quản lý resource
- Mã nguồn mở: https://github.com/aws/aws-cli
- Là một lựa chọn thay thế cho AWS Management Console
- A tool that enables you to interact with AWS services using commands in your command-line shell
- Direct access to the public APIs of AWS services
- You can develop scripts to manage your resources
- It's open-source: https://github.com/aws/aws-cli
- An alternative to using the AWS Management Console
11. AWS SDK là gì (What's the AWS SDK)
- AWS Software Development Kit (SDK): tập hợp API/thư viện theo từng ngôn ngữ lập trình
- Cho phép truy cập và quản lý AWS service bằng code, nhúng ngay trong ứng dụng
- Hỗ trợ:
- SDK cho ngôn ngữ: JavaScript, Python, PHP, .NET, Ruby, Java, Go, Node.js, C++
- Mobile SDK: Android, iOS...
- IoT Device SDK: Embedded C, Arduino...
- Ví dụ: AWS CLI thực chất được xây dựng trên nền AWS SDK cho Python
- AWS Software Development Kit (SDK): language-specific APIs (a set of libraries)
- Enables you to access and manage AWS services programmatically, embedded within your application
- Supports:
- SDKs: JavaScript, Python, PHP, .NET, Ruby, Java, Go, Node.js, C++
- Mobile SDKs: Android, iOS...
- IoT Device SDKs: Embedded C, Arduino...
- Example: the AWS CLI is actually built on top of the AWS SDK for Python
12. IAM Roles cho Services (IAM Roles for Services)
- Một số AWS service cần thực hiện hành động thay mặt bạn (on your behalf)
- Để làm việc đó, ta gán quyền cho AWS service thông qua IAM Role
- Các role phổ biến: EC2 Instance Role, Lambda Function Role, Role cho CloudFormation
- Some AWS services need to perform actions on your behalf
- To do so, we assign permissions to AWS services with IAM Roles
- Common roles: EC2 Instance Roles, Lambda Function Roles, Roles for CloudFormation
13. IAM Security Tools
- IAM Credentials Report (mức account): báo cáo liệt kê toàn bộ user trong account và trạng thái các loại credentials của họ
- IAM Access Advisor (mức user): hiển thị các quyền (service permissions) đã cấp cho một user, và lần cuối các service đó được truy cập — dùng thông tin này để tinh chỉnh lại policy
- IAM Credentials Report (account-level): a report that lists all your account's users and the status of their various credentials
- IAM Access Advisor (user-level): shows the service permissions granted to a user and when those services were last accessed — use this information to revise your policies
14. IAM Guidelines & Best Practices
- Không dùng root account, trừ lúc setup tài khoản AWS
- Nguyên tắc: một người dùng vật lý = một AWS user
- Gán user vào group, và gán quyền cho group (thay vì từng user)
- Thiết lập password policy đủ mạnh
- Dùng và bắt buộc sử dụng MFA
- Tạo và dùng Role để cấp quyền cho AWS service
- Dùng Access Keys cho truy cập theo hướng lập trình (CLI/SDK)
- Kiểm tra (audit) quyền hạn trong account bằng IAM Credentials Report & IAM Access Advisor
- Không bao giờ chia sẻ IAM user & Access Keys
- Don't use the root account except for AWS account setup
- One physical user = one AWS user
- Assign users to groups, and assign permissions to groups (not individual users)
- Create a strong password policy
- Use and enforce the use of Multi-Factor Authentication (MFA)
- Create and use Roles for giving permissions to AWS services
- Use Access Keys for programmatic access (CLI / SDK)
- Audit permissions of your account using IAM Credentials Report & IAM Access Advisor
- Never share IAM users & Access Keys
Tổng kết chương IAM (IAM Section Summary)
- Users: ánh xạ tới một người dùng vật lý, có password để vào Console
- Groups: chỉ chứa Users
- Policies: tài liệu JSON mô tả quyền hạn cho user hoặc group
- Roles: dùng cho EC2 instance hoặc AWS service
- Security: MFA + Password Policy
- AWS CLI: quản lý AWS service bằng command-line
- AWS SDK: quản lý AWS service bằng ngôn ngữ lập trình
- Access Keys: dùng để truy cập AWS qua CLI hoặc SDK
- Audit: IAM Credential Reports & IAM Access Advisor
- Users: mapped to a physical user, has a password for AWS Console
- Groups: contains users only
- Policies: JSON document that outlines permissions for users or groups
- Roles: for EC2 instances or AWS services
- Security: MFA + Password Policy
- AWS CLI: manage your AWS services using the command-line
- AWS SDK: manage your AWS services using a programming language
- Access Keys: access AWS using the CLI or SDK
- Audit: IAM Credential Reports & IAM Access Advisor