|
| 1 | +# Making an access key limited to specific calls on specific buckets |
| 2 | + |
| 3 | +Normally the Tigris Dashboard allows you to do everything you need to make |
| 4 | +access keys have the minimum scope possible. However sometimes you need more. |
| 5 | +Tigris allows you [to attach IAM policies](/docs/concepts/authnz/#iam-policies) |
| 6 | +to access keys. This blueprint will show you how to make up complicated policies |
| 7 | +for your buckets, such as this: |
| 8 | + |
| 9 | +- Read, List, and Write files to bucket `generated-images` |
| 10 | +- Read and List files in bucket `model-storage` |
| 11 | + |
| 12 | +Create a new access key in the [Tigris Dashboard](https://console.tigris.dev). |
| 13 | +Don't assign any permissions to it. Copy the access key ID and secret access |
| 14 | +keys into either your notes or a password manager, you will not be able to see |
| 15 | +them again. |
| 16 | + |
| 17 | +Copy this to `policy.json`: |
| 18 | + |
| 19 | +```json |
| 20 | +{ |
| 21 | + "Version": "2012-10-17", |
| 22 | + "Statement": [ |
| 23 | + { |
| 24 | + "Sid": "ListObjectsInBucket", |
| 25 | + "Effect": "Allow", |
| 26 | + "Action": ["s3:ListBucket"], |
| 27 | + "Resource": ["arn:aws:s3:::model-storage", "arn:aws:s3:::public-images"] |
| 28 | + }, |
| 29 | + { |
| 30 | + "Sid": "AllowFetchingObjects", |
| 31 | + "Effect": "Allow", |
| 32 | + "Action": "s3:GetObject", |
| 33 | + "Resource": [ |
| 34 | + "arn:aws:s3:::model-storage/*", |
| 35 | + "arn:aws:s3:::model-storage", |
| 36 | + "arn:aws:s3:::public-images/*", |
| 37 | + "arn:aws:s3:::public-images" |
| 38 | + ] |
| 39 | + }, |
| 40 | + { |
| 41 | + "Sid": "AllowPuttingImagesIntoPublicBucket", |
| 42 | + "Effect": "Allow", |
| 43 | + "Action": "s3:PutObject*", |
| 44 | + "Resource": ["arn:aws:s3:::public-images/*"] |
| 45 | + } |
| 46 | + ] |
| 47 | +} |
| 48 | +``` |
| 49 | + |
| 50 | +Open `policy.json` in your text editor and change the names of the buckets if |
| 51 | +you need to. |
| 52 | + |
| 53 | +Then export this variable to make IAM changes in Tigris: |
| 54 | + |
| 55 | +```text |
| 56 | +AWS_ENDPOINT_URL_IAM=https://fly.iam.storage.tigris.dev |
| 57 | +``` |
| 58 | + |
| 59 | +Create an IAM policy based on the document you edited: |
| 60 | + |
| 61 | +```text |
| 62 | +aws iam create-policy --policy-name sdxl-runner --policy-document file://./policy.json |
| 63 | +``` |
| 64 | + |
| 65 | +Copy down the ARN in the output, it should look something like this: |
| 66 | + |
| 67 | +```text |
| 68 | +arn:aws:iam::flyio_hunter2hunter2hunter2:policy/sdxl-runner |
| 69 | +``` |
| 70 | + |
| 71 | +Attach it to the token you just created: |
| 72 | + |
| 73 | +```text |
| 74 | +aws iam attach-user-policy \ |
| 75 | + --policy-arn arn:aws:iam::flyio_hunter2hunter2:policy/sdxl-runner \ |
| 76 | + --user-name tid_some_access_key_id |
| 77 | +``` |
0 commit comments