[英]AWS IAM Roles and policies in simple English?
我一直在使用 AWS PHP SDK,我似乎獲得了除 IAM 角色和權限之外的所有內容。
有人可以用最簡單的術語向我解釋 IAM 角色的工作原理,並用簡單的英語解釋以下術語: StatementId
、 Action
、 ARN
以及最重要的Principal
嗎?
為了讓您了解我困惑的根源,這是我最近遇到的一個問題。 我正在嘗試創建一個 API 網關,其中資源的方法觸發 Lambda 函數。 直到我復制粘貼了這一點,它才起作用:
$lambdaClient->addPermission([
'FunctionName' => 'fn name',
'StatementId' => 'ManagerInvokeAccess',
'Action' => 'lambda:InvokeFunction',
'Principal' => 'apigateway.amazonaws.com',
]);
但是在其他一些線程中,有人建議使用以下內容:
const permissions = {
FunctionName: target,
StatementId: 'api-gateway-execute',
Action: 'lambda:InvokeFunction',
Principal: 'apigateway.amazonaws.com',
SourceArn: 'arn:aws:execute-api:' + nconf.get('awsRegion') + ':' + nconf.get('awsAccountId') + ':' + nconf.get('apiGatewayId') + '/*'};
為什么第一個不包含任何帳戶信息而第二個包含任何帳戶信息? 然后還有另一個人粘貼了完全不同的東西來為他做同樣的工作。 最后一個例子中有太多的鍵(比如“Fn::Join”),我什至不知道從哪里開始,它做了什么。
如何找出在哪里可以找到這些政策? 我們是否只是從某個地方復制粘貼它們是否有辦法確定它們。 如果是這樣,必須始終指定哪些鍵。
任何幫助將不勝感激,因為我現在完全困惑。
首先,歡迎來到 AWS 的世界!!! :-D
讓我試着用一個類比來解釋你對如何理解 IAM(一般)的疑慮。
認為有一個組織叫做 ORG1。
Deparments of ORG1:
的部門Deparments of ORG1:
HR-dept、Test-dept、DEV-dept
Employees of ORG1:
EMP1, EMP2, EMP3 ... EMP10
Members of HR dept:
HR1、HR2、HR3
現在我想為 HR 部門創建一個角色,以授予他們雇用/暫停員工的權限。 該政策將如下所示:
{
"Version": "2012-10-17", // This is version of the template. Don't change this. This is NOT a date field for your use.
"Statement": [
{
"Sid": "SOME-RANDOM-ID-WITH-NUMBER-1P1PP43EZUVRM", // This is used as ID in some cases to identify different statments
"Principal": HR-dept, // the dept who is allowed to assume this role or the one who is allowed to invoke this role
"Effect": "Allow", // has only 2 values: ALLOW/DENY. Either You want to provided the below privileges or you want to striped off these privileges.
"Action": [
"hire",
"suspend",
], // these are privileges which are granted
"Resource": "EMP1", // the entity on whom do you want to apply those actions on. In this case employee EMP1.
"Condition": {
"ArnLike": {
"AWS:SourceArn": "HR*" // You want anyone from HR-dept whose id starts with HR to be able to execute the action.ie HR1,HR2 or HR3 .
}
}
}
]
}
現在嘗試從相同的角度理解下面的代碼(這段代碼在內部創建了一個類似於上面的模板):
const permissions = {
FunctionName: target,
StatementId: 'api-gateway-execute', // This is just an ID. Dont sweat about it.
Principal: 'apigateway.amazonaws.com', //which entity group the invoker belongs to
Action: 'lambda:InvokeFunction', // The privilege you are giving to API gateway api's
SourceArn: 'arn:aws:execute-api:.. blah blah blah' // ie. the exact Id of api-gateway which all has rights to invoke lambda function
};
在 AWS ARN
中,是資源的唯一ID
。 有點像公司中的EmployeeId
。這是全球唯一的。
相信我,乍一看,您在 AWS 中嘗試做的事情似乎很難理解,但在某個時候,您會開始感到舒適,因為您會繼續跨越所面臨的每個障礙。 然后您會欣賞 AWS 的可定制功能。
How does one figure out where to find these policies?
您需要參考特定服務的 AWS 文檔以了解它們支持哪些委托人、操作和語句。 例如,如果您需要找出 DynamoDB 的策略,請檢查DynamoDB API Permissions 。 一開始可能會令人困惑,因為 AWS 需要滿足使用 IAM 來授權其所有服務的需求,但隨着時間的推移,它變得簡單明了。
讓我解釋一下政策的每個部分
StatementId(Sid) - 它只是可選的語句標識符(例如 1、2、abcd 等),對於某些服務(例如 SQS、SNS),它需要唯一性。
操作 - 您的策略允許在 AWS 服務上執行的操作。 例如,對於 DynamoDB,您可以允許創建表、放置新項目等。對於 EC2 實例,它可以允許啟動和停止。
ARN(Amazon 資源名稱) - 這是一個唯一的名稱,用於唯一標識 AWS 資源,例如 EC2 服務器、S3 存儲桶、DynamoDB 表甚至 IAM 策略、角色等。
Principal - Principal 是限制誰可以使用這個策略。 它可以是用戶(IAM 用戶、聯合用戶或代入角色用戶)、AWS 賬戶、AWS 服務或其他被允許或拒絕訪問資源的委托人實體。
此外,您需要包含Resource參數,您可以在其中使用通配符“*”或其中包含賬戶 ID 的 ARN。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.