-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrant-access.sh
executable file
·50 lines (39 loc) · 1.51 KB
/
grant-access.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env bash
# Grant AWS ReadOnly access to Byondlabs
set -e
AWS_USER=$(aws sts get-caller-identity --output text --query 'Arn' | tr -d '\r')
AWS_ACCOUNT=$(aws sts get-caller-identity --output text --query 'Account' | tr -d '\r')
echo "Running as AWS user: ${AWS_USER}"
echo "For AWS account: ${AWS_ACCOUNT}"
echo
echo "Press enter to continue..."
read -r
echo "Creating custom role \`ByondLabsRole\`: "
aws iam create-role \
--role-name ByondLabsRole \
--assume-role-policy-document file://assume-role-trust-policy.json
aws iam attach-role-policy \
--role-name ByondLabsRole \
--policy-arn arn:aws:iam::aws:policy/ReadOnlyAccess
aws iam attach-role-policy \
--role-name ByondLabsRole \
--policy-arn arn:aws:iam::aws:policy/job-function/Billing
aws iam attach-role-policy \
--role-name ByondLabsRole \
--policy-arn arn:aws:iam::aws:policy/AWSSavingsPlansReadOnlyAccess
echo "Creating byondlabs custom policies: "
aws iam create-policy \
--policy-name ByondLabsBillingPolicy \
--policy-document file://billing-policy.json
echo "Created \`ByondLabsBillingPolicy\` policy"
aws iam create-policy \
--policy-name ByondLabsReadOnlyPolicy \
--policy-document file://readonly-policy.json
echo "Attaching policies to the role"
aws iam attach-role-policy \
--role-name ByondLabsRole \
--policy-arn "arn:aws:iam::${AWS_ACCOUNT}:policy/ByondLabsBillingPolicy"
aws iam attach-role-policy \
--role-name ByondLabsRole \
--policy-arn "arn:aws:iam::${AWS_ACCOUNT}:policy/ByondLabsReadOnlyPolicy"
echo "Role created successfully!"