Vá EC2 instance bằng Patch Manager và Maintenance Windows
Với hàng trăm EC2 instance, việc vá và chạy lệnh thủ công trên từng instance không còn khả thi; cần thực hiện đồng loạt trên các managed node, theo lịch và có kiểm soát.
MFTECH có hơn 200 EC2 instance; mỗi tháng đều có bản vá bảo mật cho hệ điều hành. Systems Manager thực hiện việc này thông qua SSM Agent chạy trên instance: Patch Manager vá theo lịch, Run Command thực thi lệnh trên cả nhóm instance, Automation thực thi runbook nhiều bước. Bước đầu tiên là cấp quyền để agent giao tiếp với Systems Manager. Các instance đã có IAM role riêng để truy cập RDS và Secrets Manager:
Cách cấp quyền theo từng instance vẫn được hỗ trợ: gắn managed policy AmazonSSMManagedInstanceCore vào role mà instance profile đang dùng (có thể thêm vào role hiện có, không cần thay role). Systems Manager khuyến nghị cấp quyền ở cấp account bằng Default Host Management Configuration khi điều kiện cho phép, vì không phải sửa từng role. Sau khi bật, instance có thể mất tới 30 phút để dùng thông tin xác thực của role mặc định, và cấu hình phải được bật riêng ở từng Region.
Trong đợt vá trước, mọi bản vá đều báo thành công nhưng người dùng vẫn gặp lỗi và timeout, do instance reboot trong khi ALB vẫn tiếp tục định tuyến request tới. So sánh hai phương án vá trong cùng một Maintenance Window:
Chọn phương án vá, sau đó chọn Mở Maintenance Window. Người dùng vẫn mua hàng lúc 2h sáng.
- Quản lý mọi EC2 instance bằng Systems Manager mà không cần tạo instance profile: Default Host Management Configuration (yêu cầu IMDSv2, SSM Agent 3.2.582.0 trở lên).
- Cấp quyền theo từng instance: thêm AmazonSSMManagedInstanceCore vào role hiện có (mỗi instance profile chỉ chứa một role).
- Hybrid activation chỉ dành cho máy không phải EC2.
- Vá instance phía sau load balancer: Automation runbook AWSEC2-PatchLoadBalancerInstance (gỡ khỏi load balancer hoặc target group, chờ connection draining, chạy AWS-RunPatchBaseline, gắn lại), thực thi trong Maintenance Window.
Patching EC2 instances with Patch Manager and Maintenance Windows
With hundreds of EC2 instances, patching and running commands by hand on each instance is no longer feasible; the work must run in bulk across managed nodes, on a schedule and under control.
MFTECH has more than 200 EC2 instances; every month brings security patches for the operating system. Systems Manager does this through the SSM Agent running on the instances: Patch Manager patches on a schedule, Run Command runs commands on a whole group of instances, Automation runs multi-step runbooks. The first step is to grant the agent permission to communicate with Systems Manager. The instances already have their own IAM role to access RDS and Secrets Manager:
Granting permissions per instance is still supported: attach the AmazonSSMManagedInstanceCore managed policy to the role that the instance profile uses (it can be added to the existing role; the role does not need to be replaced). Systems Manager recommends granting access at the account level with Default Host Management Configuration when the use case allows, because no role has to be edited. After it is turned on, instances can take up to 30 minutes to use the credentials of the default role, and the setting must be turned on in each Region.
In the previous patch cycle, every patch reported success but users still saw errors and timeouts, because instances rebooted while the ALB kept routing requests to them. Compare two patching approaches in the same Maintenance Window:
Chọn phương án vá, sau đó chọn Mở Maintenance Window. Người dùng vẫn mua hàng lúc 2h sáng.
- Manage every EC2 instance with Systems Manager without creating instance profiles: Default Host Management Configuration (requires IMDSv2, SSM Agent 3.2.582.0 or later).
- Per-instance permissions: add AmazonSSMManagedInstanceCore to the existing role (an instance profile contains only one role).
- Hybrid activations are only for non-EC2 machines.
- Patch instances behind a load balancer: the Automation runbook AWSEC2-PatchLoadBalancerInstance (removes the instance from the load balancer or target group, waits for connection draining, runs AWS-RunPatchBaseline, reattaches it), run in a Maintenance Window.