Bỏ qua tới nội dung
CloudDojo
Phần 3/6 · 5 phút

IAM role cho ứng dụng thay cho access key

0/12
Từ khóa của phần nàyChọn một từ để xem nghĩa trước khi đọc

Ứng dụng cần quyền để gọi dịch vụ AWS; thay vì lưu thông tin xác thực cố định (access key) trong mã nguồn, ứng dụng nên nhận quyền tạm thời thông qua một IAM role.

Ứng dụng của MFTECH chạy trên EC2 instance cần đọc dữ liệu từ một bảng DynamoDB. Phương án đơn giản nhưng rủi ro là lưu access key trong mã nguồn: khi mã nguồn bị lộ, access key cũng bị lộ. Phương án an toàn:

Bước 0/3
EC2 web-1DynamoDBbảng orders
EC2 instance web-1 cần đọc bảng orders trong DynamoDB. Thực hiện lần lượt từng bước để cấp quyền mà không lưu access key trên instance.

Nguyên tắc tương tự áp dụng cho các trường hợp khác:

Giải pháp đề xuấtTạo role tại production, developer assume role đó

Role tại account đích có trust policy tin cậy account dev. Developer sử dụng credentials tạm thời của role, không cần tạo user mới tại production.

Xem ứng dụng nhận thẻ tạm thời từ IAM role thay cho access key cất trong mã nguồn.
Ghi nhớ:
  • Ứng dụng trên AWS sử dụng IAM role, không sử dụng access key.
  • Truy cập cross-account: tạo role tại account đích và assume role đó.
Part 3/6 · 5 phút

IAM roles for applications instead of access keys

0/12
Từ khóa của phần nàyChọn một từ để xem nghĩa trước khi đọc

Applications need permissions to call AWS services; instead of storing fixed credentials (access keys) in the code, they should receive temporary permissions through an IAM role.

MFTECH’s application on an EC2 instance needs to read data from a DynamoDB table. The simple but risky option is to store an access key in the source code: when the source code leaks, the access key leaks too. The secure option:

Bước 0/3
EC2 web-1DynamoDBorders table
EC2 instance web-1 needs to read the orders table in DynamoDB. Perform each step in turn to grant access without storing an access key on the instance.

The same principle applies to other cases:

Giải pháp đề xuấtCreate a role in production, and the developer assumes it

The role in the target account has a trust policy that trusts the dev account. The developer uses the role's temporary credentials, without a new user in production.

Xem ứng dụng nhận thẻ tạm thời từ IAM role thay cho access key cất trong mã nguồn.
Ghi nhớ:
  • Applications on AWS use IAM roles, not access keys.
  • Cross-account access: create a role in the target account and assume it.

Kiểm tra nhanh

Trả lời để ghi nhận đã đọc phần này. Câu trả lời sai sẽ được nhắc ôn lại vào những ngày sau.

Ứng dụng trên EC2 của MFTECH cần đọc S3. Cách cấp quyền đúng?
Ứng dụng ở account A của MFTECH cần truy cập tài nguyên ở account B. Cách làm đúng?

Đã trả lời 0/2 câu