According to security best practices, how should an Amazon EC2 instance be given access to an Amazon S3 bucket?
A. Hard code an IAM user’s secret key and access key directly in the application, and upload the file.
B. Store the IAM user’s secret key and access key in a text file on the EC2 instance, read the keys, then upload the file.
C. Have the EC2 instance assume a role to obtain the privileges to upload the file.
D. Modify the S3 bucket policy so that any service can upload to it at any time.
C
技巧:排除明顯錯誤選項,在沒有明顯錯誤的選項中選擇最合理的選項。
題目的要求是,根據安全最佳實踐,Amazon EC2 實例應如何獲得對 Amazon S3 存儲桶的訪問權限。
A. 不正確。直接在應用程序中硬編碼 IAM 用戶的密鑰和訪問密鑰是非常不安全的,因為一旦代碼泄露或被攻擊,密鑰就可能被濫用。
B. 不正確。將密鑰存儲在 EC2 實例上的文本文件中同樣不安全。這種存儲方式容易被惡意用戶或軟件訪問,導致密鑰泄露。
C. 正確。讓 EC2 實例承擔一個角色(即使用 IAM 角色)是最佳實踐。用戶可以為 EC2 實例配置一個 IAM 角色,該角色具有對 S3 存儲桶的訪問權限。這樣,EC2 實例無需存儲或管理密鑰,而是使用 AWS 提供的安全機制來獲得所需的權限。
D. 不正確。修改 S3 存儲桶策略以允許任何服務隨時上傳文件是極其不安全的,因為這會使存儲桶暴露給潛在的惡意用戶。