Skip to content

Commit 252bd07

Browse files
authored
WPB-11617: Setup a scoped user for cargohold (#814)
* feat: add cargohold IAM setup * feat: add changelog entry for cargohold IAM setup * update the comments * remove the flag from zauth cmd * remove the delete object permission from th policy
1 parent 3b71450 commit 252bd07

File tree

4 files changed

+82
-5
lines changed

4 files changed

+82
-5
lines changed

ansible/minio.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
# The second minio instance on this server.
2525
server2:
2626
server_addr: ":9092"
27+
# Cargohold IAM setup
28+
cargohold_policy_name: "cargohold-assets-policy"
29+
cargohold_user_name: "cargohold-user"
2730
roles:
2831
- role: ansible-minio
2932
minio_layout: server1
@@ -60,12 +63,79 @@
6063
run_once: true
6164
tags: mc-config
6265

66+
# Cargohold IAM Setup
67+
- name: "Create cargohold policy file"
68+
copy:
69+
content: |
70+
{
71+
"Version": "2012-10-17",
72+
"Statement": [
73+
{
74+
"Effect": "Allow",
75+
"Action": [
76+
"s3:GetObject",
77+
"s3:PutObject",
78+
"s3:ListBucket"
79+
],
80+
"Resource": [
81+
"arn:aws:s3:::assets",
82+
"arn:aws:s3:::assets/*"
83+
]
84+
}
85+
]
86+
}
87+
dest: "/tmp/{{ cargohold_policy_name }}.json"
88+
run_once: true
89+
tags: cargohold-iam
90+
91+
- name: "Add cargohold policy to MinIO"
92+
shell: "mc admin policy create local {{ cargohold_policy_name }} /tmp/{{ cargohold_policy_name }}.json"
93+
run_once: true
94+
ignore_errors: yes # Policy might already be attached, which is fine
95+
tags: cargohold-iam
96+
97+
- name: "Generate random password for cargohold user"
98+
set_fact:
99+
cargohold_temp_password: "{{ 999999999999999999999 | random | to_uuid }}"
100+
run_once: true
101+
tags: cargohold-iam
102+
103+
- name: "Create cargohold IAM user"
104+
shell: "mc admin user add local {{ cargohold_user_name }} {{ cargohold_temp_password }}"
105+
run_once: true
106+
ignore_errors: yes # Will fail if user already exists, which is fine
107+
tags: cargohold-iam
108+
109+
- name: "Attach policy to cargohold user"
110+
shell: "mc admin policy attach local {{ cargohold_policy_name }} --user {{ cargohold_user_name }}"
111+
run_once: true
112+
ignore_errors: yes # Policy might already be attached
113+
tags: cargohold-iam
114+
115+
- name: "Create service account for cargohold with specific access key"
116+
shell: "mc admin user svcacct add --access-key {{ minio_cargohold_access_key }} --secret-key {{ minio_cargohold_secret_key }} local {{ cargohold_user_name }}"
117+
run_once: true
118+
register: cargohold_svcacct_result
119+
ignore_errors: yes # Will fail if key already exists, which is fine
120+
tags: cargohold-iam
121+
122+
- name: "Verify cargohold service account"
123+
shell: "mc admin user svcacct ls local {{ cargohold_user_name }}"
124+
run_once: true
125+
register: cargohold_svcacct_list
126+
tags: cargohold-iam
127+
128+
- name: "List cargohold service accounts"
129+
debug:
130+
var: cargohold_svcacct_list.stdout
131+
tags: cargohold-iam
63132
- name: "remove unneeded config aliases added by default"
64133
shell: "mc config host rm {{ item }}"
65134
with_items:
66135
- gcs
67136
- s3
68137
- play
138+
ignore_errors: yes
69139
tags: mc-config
70140

71141
# This play has to run after minio is installed and buckets are configured

bin/offline-secrets.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ zrest="$(tr -dc A-Za-z0-9 </dev/urandom | head -c 64)"
1212
minio_access_key="$(tr -dc A-Za-z0-9 </dev/urandom | head -c 20)"
1313
minio_secret_key="$(tr -dc A-Za-z0-9 </dev/urandom | head -c 42)"
1414

15+
minio_cargohold_access_key="$(tr -dc A-Za-z0-9 </dev/urandom | head -c 20)"
16+
minio_cargohold_secret_key="$(tr -dc A-Za-z0-9 </dev/urandom | head -c 30)"
17+
1518
zauth="$(sudo docker run $ZAUTH_CONTAINER -m gen-keypair)"
1619

1720
zauth_public=$(echo "$zauth" | awk 'NR==1{ print $2}')
@@ -46,8 +49,8 @@ brig:
4649
secret: "dummy"
4750
cargohold:
4851
secrets:
49-
awsKeyId: "$minio_access_key"
50-
awsSecretKey: "$minio_secret_key"
52+
awsKeyId: "$minio_cargohold_access_key"
53+
awsSecretKey: "$minio_cargohold_secret_key"
5154
rabbitmq:
5255
username: wire-server
5356
password: verysecurepassword
@@ -94,6 +97,8 @@ if [[ ! -f $ANSIBLE_DIR/inventory/offline/group_vars/all/secrets.yaml ]]; then
9497
cat << EOT > $ANSIBLE_DIR/inventory/offline/group_vars/all/secrets.yaml
9598
minio_access_key: "$minio_access_key"
9699
minio_secret_key: "$minio_secret_key"
100+
minio_cargohold_access_key: "$minio_cargohold_access_key"
101+
minio_cargohold_secret_key: "$minio_cargohold_secret_key"
97102
EOT
98103
fi
99104

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Changed: cargohold service will use the scoped `cargohold user` with least privilege, so that it has the necessary access to its bucket `assets` only

values/wire-server/prod-secrets.example.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ cannon:
3535

3636
cargohold:
3737
secrets:
38-
# these only need to be changed if using real AWS services
39-
awsKeyId: dummykey
40-
awsSecretKey: dummysecret
38+
# Change the awsKeyId and awsSecretKey with the IAM user credentials for cargohold
39+
# Get the secrets and key from the ansible/inventory/offline/group_vars/all/secrets.yml
40+
awsKeyId: dummykey # replace with minio_cargohold_access_key
41+
awsSecretKey: dummysecret # replace with minio_cargohold_secret_key
4142
rabbitmq:
4243
username: wire-server
4344
password: verysecurepassword

0 commit comments

Comments
 (0)