Skip to content

Commit 1c66ddc

Browse files
authored
Merge pull request #9285 from shirady/iam-user-policy-docs
IAM | Doc | User Inline Policy Documentation
2 parents 45fe1e7 + 7a6e62e commit 1c66ddc

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

docs/design/IamUserInlinePolicy.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# IAM User Policy
2+
In a containerized deployment, we added the IAM user policy.
3+
When used, it adds a layer of permission to the users under the account.
4+
We decided that IAM user inline policies are checked for authorization only in S3 operations (`src/endpoint/s3/s3_rest.js`).
5+
6+
## User Without IAM User Policy
7+
We decided that when a user is created under the account (and has access keys), it can operate all S3 operations (unless there is a bucket policy which do not authorize it).
8+
9+
## User With IAM User Policy
10+
The user’s inline policy is embedded in the user.
11+
If a user has a user policy, the ability to perform an S3 operation is based on his user inline policy.
12+
13+
### Supported IAM User Inline Policies Operations
14+
- IAM PutUserPolicy: UserName, PolicyDocument, PolicyName
15+
- IAM DeleteUserPolicy: UserName, PolicyName
16+
- IAM GetUserPolicy: UserName, PolicyName
17+
- IAM ListUserPolicies: UserName
18+
19+
#### Put User Policy Notes
20+
- Like AWS, we do not validate the policy JSON, which means that a user can have invalid user policies.
21+
- The policy JSON structure is the same as the bucket policy except for 2 differences:
22+
(1) There is no field of `Principal` in the JSON, as the policy is embedded in a user.
23+
(2) We do not support the `Condition` field (as we decided at this point).
24+
(for additional information, see the schema `iam_user_policy_document` in `common_api`).
25+
- The limitation for the IAM policies is the total size of all the policies on a user.
26+
- If a user had a policy and the account root user put a different user policy document with the same name, then the policy will be replaced.
27+
28+
#### Under The Hood
29+
For every S3 request, authorization (`authorize_request` in `src/endpoint/s3/s3_rest.js`) is performed.
30+
The authorization now will have:
31+
1. Authorization handle for signed request and anonymous requests.
32+
2. Authorization handle according to bucket policy.
33+
3. Authorization handle according to the user IAM policy (the new added layer - only for IAM users).
34+
35+
If one of the layers does not permit it would result in `AccessDenied` error.
36+
37+
Since the structure of the policy document of bucket policy and IAM user policy is similar (but not identical), the decision of whether the request is authorized to perform the S3 operation by using the same functions as bucket policy (except for the difference that was mentioned before - we do not check `Condition` and `Principal` fields).
38+
39+
We check if the IAM policy has explicit `DENY`, otherwise, we look for explicit `ALLOW`.
40+
If we have an IAM policy and we didn’t have both, then it is an `IMPLICIT_DENY` and it would result in an `AccessDenied` error.
41+
42+
## Demo
43+
Use an account (either it’s the admin account or a newly created one from the CLI).
44+
In S3: the account creates a bucket.
45+
In IAM: the account creates a user, an access key, and puts a user inline policy.
46+
Check the ability of the user to perform S3 operations according to the IAM policy.
47+
48+
1. Create the alias for the account:
49+
- `alias account-s3=’AWS_ACCESS_KEY=<access-key> AWS_SECRET_ACCESS_KEY=<secret-key> aws --no-verify-ssl --endpoint-url <endpoint-url-s3>`
50+
- `alias account-iam=‘AWS_ACCESS_KEY=<access-key> AWS_SECRET_ACCESS_KEY=<secret-key> aws --no-verify-ssl --endpoint-url <endpoint-url-iam>’`
51+
2. Check the connection to the endpoint:
52+
- Try to list the users (should be an empty list if any user was not created): `account-iam iam list-users; echo $?`
53+
- Try to list the buckets: `account-iam s3 ls; echo $?`
54+
3. Create a bucket: `account-s3 is3 mb s3://bucket-account`
55+
4. Create a user: `account-iam iam create-user --user-name Robert`
56+
5. Create access keys to the user: `account-iam iam create-access-keys --user-name Robert`
57+
6. Create the alias for the user: `alias user-robert-s3=’AWS_ACCESS_KEY=<access-key> AWS_SECRET_ACCESS_KEY=<secret-key> aws --no-verify-ssl --endpoint-url <endpoint-url-s3>`
58+
59+
### No IAM User policy
60+
7. User can create a bucket under the account: `user-robert-s3 s3 mb s3://bucket-robert`
61+
8. User can put object in the bucket that the account root user created: `echo ‘test_data’ | user-robert-s3 cp - s3://bucket-account/test_object.txt`
62+
63+
### With IAM User Policy
64+
9. Add user inline policy - so the IAM user cannot create a bucket, but can put an object.
65+
`admin-iam iam put-user-policy --user-name Robert --policy-name policy_deny_create_bucket_allow_put_object --policy-document file://policy_deny_create_bucket_allow_put_object.json`
66+
67+
`policy_deny_create_bucket_allow_put_object.json`
68+
69+
```json
70+
{
71+
“Version”: “2012-10-17",
72+
“Statement”: [
73+
{
74+
“Effect”: “Deny”,
75+
“Action”: [
76+
“s3:CreateBucket”
77+
],
78+
“Resource”: “*”
79+
},
80+
{
81+
“Effect”: “Allow”,
82+
“Action”: [
83+
“s3:PutObject”
84+
],
85+
“Resource”: “*”
86+
}
87+
]
88+
}
89+
```
90+
91+
10. User can put object in the account bucket: `echo ‘test_data’ | user-robert-s3 cp - s3://bucket-account/test_object2.txt` (should work)
92+
11. User cannot create a bucket under the account: u`ser-robert-s3 s3 mb s3://bucket-robert-2` (should throw `AccessDenied` error)
93+
94+
### Notes:
95+
The IAM policy (like bucket policy) is read from the account info, which is saved in the endpoint cache. Currently, the cache does not invalidate those changes immediately. For local testing, you may temporarily reduce the cache expiry in `src/sdk/object_sdk.js` by setting `expiry_ms: 1`, but this should never be committed to the repository.

0 commit comments

Comments
 (0)