AWS Systems Manager (SSM)
SSM Agent, Session Manager, Run Command, Patch Manager chi tiết
AWS Systems Manager là bộ công cụ quản lý infrastructure, giúp quản lý EC2 instances, on-premises servers, và các AWS resources một cách tập trung.
Tổng Quan
Các Tính Năng Chính
| Feature | Mô tả | Use Case |
|---|---|---|
| Session Manager | SSH/RDP không cần mở port | Secure access to instances |
| Run Command | Chạy commands trên nhiều instances | Batch operations |
| Patch Manager | Quản lý OS patches | Security compliance |
| Parameter Store | Lưu trữ config/secrets | Configuration management |
| State Manager | Maintain desired state | Compliance |
| Automation | Automate runbooks | Operational tasks |
1️⃣ SSM Agent
Khái Niệm
SSM Agent là software chạy trên EC2/on-premises để giao tiếp với Systems Manager service.
Pre-installed AMIs
| AMI Type | SSM Agent |
|---|---|
| Amazon Linux 2/2023 | ✅ Pre-installed |
| Ubuntu 16.04+ | ✅ Pre-installed |
| Windows Server 2016+ | ✅ Pre-installed |
| Other AMIs | ❌ Cần install manually |
Requirements
2️⃣ Session Manager (Deep Dive)
[!IMPORTANT] Session Manager là cách được khuyến nghị để access EC2 instances - thay thế hoàn toàn SSH truyền thống.
Khái Niệm
Session Manager cho phép access EC2 instances mà không cần SSH, không cần bastion host, không cần mở port 22.
Kiến Trúc Chi Tiết
Lợi Ích So Với SSH
| Category | Traditional SSH | Session Manager |
|---|---|---|
| Inbound Ports | ❌ Mở port 22 | ✅ Không cần mở port |
| SSH Keys | ❌ Phải quản lý, rotate | ✅ Không cần SSH keys |
| Bastion Host | ❌ Cần maintain, cost | ✅ Không cần bastion |
| Authentication | SSH keys | ✅ IAM (MFA support) |
| Authorization | Server-level | ✅ IAM policies (granular) |
| Audit | ❌ Manual logging | ✅ CloudWatch/S3 auto-log |
| Session Recording | ❌ Không có | ✅ Full session recording |
| Network | Cần direct access | ✅ Qua HTTPS, works anywhere |
| Cross-platform | Khác nhau theo OS | ✅ Same cho Linux/Windows |
Requirements
VPC Endpoints cho Private Subnet
Cách Sử Dụng
1. Qua AWS Console
2. Qua AWS CLI
3. SSH Proxy qua Session Manager
Có thể dùng SSH commands thông qua Session Manager (để tương thích với tools cần SSH):
Advanced Features
1. Port Forwarding
2. Port Forwarding to Remote Host
3. Session Logging (Audit)
IAM Policy Examples
Basic Session Manager Access
Restrict Document Types
Session Manager vs SSH Comparison
Limitations
| Limitation | Workaround |
|---|---|
| No SCP/SFTP | Use S3 + aws s3 cp |
| Session timeout | Default 20 mins idle, configurable up to 60 mins |
| File transfer | Upload to S3, download with aws cli |
| No X11 forwarding | Not supported |
| Concurrent sessions | Default limit, can request increase |
Exam Tips
| Topic | Remember |
|---|---|
| No port 22 | Session Manager không cần mở inbound port |
| No bastion | Không cần bastion host |
| IAM auth | Sử dụng IAM để authenticate, không phải SSH keys |
| VPC Endpoints | Cần cho private subnet không có internet |
| Audit | CloudWatch Logs + S3 cho session logging |
| Port forwarding | Có thể tunnel ports (RDS, etc.) |
3️⃣ Run Command
Khái Niệm
Run Command cho phép chạy commands trên nhiều instances cùng lúc mà không cần SSH.
Common Documents
| Document | Mô tả |
|---|---|
| AWS-RunShellScript | Run shell commands (Linux) |
| AWS-RunPowerShellScript | Run PowerShell (Windows) |
| AWS-UpdateSSMAgent | Update SSM Agent |
| AWS-ConfigureAWSPackage | Install/uninstall packages |
Target Selection
4️⃣ Parameter Store
Khái Niệm
Parameter Store là secure, hierarchical storage cho configuration data và secrets.
Parameter Types
| Type | Mô tả | Encryption | Use Case |
|---|---|---|---|
| String | Plain text | Không | Config values |
| StringList | Comma-separated | Không | Lists |
| SecureString | Encrypted | KMS | Passwords, API keys |
Tiers
| Standard | Advanced | |
|---|---|---|
| Max size | 4 KB | 8 KB |
| Max params | 10,000 | 100,000 |
| Policies | Không | Có (expiration, notification) |
| Cost | Free | Charged |
Sử dụng
Integration với các Services
Parameter Store vs Secrets Manager
| Parameter Store | Secrets Manager | |
|---|---|---|
| Cost | Free (Standard tier) | $0.40/secret/month |
| Rotation | Không có built-in | Có automatic rotation |
| Cross-account | Không | Có |
| Max size | 8 KB | 64 KB |
| Use case | Config, simple secrets | Database credentials, API keys với rotation |
[!TIP] Dùng Parameter Store cho configs và secrets đơn giản. Dùng Secrets Manager khi cần automatic rotation (ví dụ: RDS passwords).
5️⃣ Patch Manager
Khái Niệm
Patch Manager tự động hóa việc patching OS và applications.
Patch Baseline
| Component | Mô tả |
|---|---|
| Operating System | Linux, Windows, macOS |
| Approval Rules | Auto-approve patches after X days |
| Approved Patches | Explicitly approved list |
| Rejected Patches | Explicitly rejected list |
6️⃣ Automation
Khái Niệm
Automation cho phép tạo runbooks để automate common maintenance tasks.
Common Use Cases
| Use Case | Document |
|---|---|
| Restart instance | AWS-RestartEC2Instance |
| Create AMI | AWS-CreateImage |
| Update CloudFormation | AWS-UpdateCloudFormationStack |
| Remediate | Custom remediation runbooks |
EventBridge Integration
📋 Exam Tips
| Topic | Remember |
|---|---|
| SSM Agent | Pre-installed on modern AMIs, cần IAM Role |
| Session Manager | No SSH, no port 22, uses IAM |
| Run Command | Execute commands on multiple instances |
| Parameter Store | Free tier, SecureString encrypted by KMS |
| Secrets Manager | Có rotation, cross-account, costs money |
| Patch Manager | Baselines, Patch Groups, Maintenance Windows |
Common Scenarios
🔗 Related Resources
- EC2 - Compute instances
- IAM - Identity and Access Management
- VPC - Networking
- CloudFormation - Infrastructure as Code