2013-12-12 92 views
5

我知道您可以設置IAM策略來限制對服務的訪問。但是,是否可以制定允許訪問部分服務的策略?AWS IAM訪問管理

E.g.我是兩個EC2實例。我需要創建兩個用戶,以便他們可以訪問AWS控制檯,但每個用戶只能訪問一個EC2實例。

回答

5

是的,你可以用Resource-Level Permissions for EC2

做這個資源的結構陳述in the documentation如下:

arn:aws:[service]:[region]:[account]:resourceType/resourcePath 

這裏是你將如何組織的IAM政策爲每個用戶:

用戶1

{ 
    "Version": "2012-10-17", 
    "Statement": [{ 
     "Effect": "Allow", 
     "Action": "ec2:*", 
     "Resource": "arn:aws:ec2:us-east-1:123456789012:instance/InstanceIdOne" 
    } 
    ] 
} 

用戶2

{ 
    "Version": "2012-10-17", 
    "Statement": [{ 
     "Effect": "Allow", 
     "Action": "ec2:*", 
     "Resource": "arn:aws:ec2:us-east-1:123456789012:instance/InstanceIdTwo" 
    } 
    ] 
} 
1

政策沒有獲得EC2:DescribeInstance將無法正常工作。您需要允許DescribeInstances訪問所有資源,並根據需要管理其他訪問,如修改,刪除特定實例。

簡而言之,允許所有用戶執行諸如描述標籤,實例,NetworkACL,圖像等所有基本操作,並允許特定的破壞性操作(如修改和刪除)選擇用戶。

在這裏您參考 http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_Operations.html

EC2動作列表所以,你有2個選項 -

  1. 創建一個策略如下圖所示,並附上相同的策略,以兩個用戶

    { 
        "Version": "2012-10-17", 
        "Statement": [{ 
        "Effect": "Allow", 
        "Action": "ec2:*Describe*", 
        "Resource":"*", 
        }, 
        { 
        "Effect": "Allow", 
        "Action": [ 
         "ec2:*Modify*", 
         "ec2:*Delete*" 
        ], 
        "Principal": { "AWS": "arn:aws:iam::AWS-account-ID:user/**user-name-1**" }, 
        "Resource": "arn:aws:ec2:us-east-1:AWS-account-ID:instance/**InstanceIdOne**" 
    }, 
    { 
        "Effect": "Allow", 
        "Action": [ 
         "ec2:*Modify*", 
         "ec2:*Delete*" 
    ], 
        "Principal": { "AWS": "arn:aws:iam::AWS-account-ID:user/**user-name-2**" }, 
        "Resource": "arn:aws:ec2:us-east-1:AWS-account-ID:instance/**InstanceIdTwo**" 
    } 
    ]} 
    
  2. 創建2個不同的策略。以下爲一個例子

    { 
        "Version": "2012-10-17", 
        "Statement": [{ 
        "Effect": "Allow", 
        "Action": "ec2:*Describe*", 
        "Resource":"*", 
        }, 
        { 
        "Effect": "Allow", 
        "Action": [ 
         "ec2:*Modify*", 
         "ec2:*Delete*" 
        ], 
        "Principal": { "AWS": "arn:aws:iam::AWS-account-ID:user/**user-name-1**" }, 
        "Resource": "arn:aws:ec2:us-east-1:AWS-account-ID:instance/**InstanceIdOne**" 
    } 
    ]}