Skip to content

Commit 558834e

Browse files
committed
Use separate credentials for controller and invoker.
1 parent 967f005 commit 558834e

File tree

10 files changed

+133
-8
lines changed

10 files changed

+133
-8
lines changed

ansible/group_vars/all

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,12 @@ db:
233233
admin:
234234
user: "{{ db_username | default(lookup('ini', 'db_username section=db_creds file={{ playbook_dir }}/db_local.ini')) }}"
235235
pass: "{{ db_password | default(lookup('ini', 'db_password section=db_creds file={{ playbook_dir }}/db_local.ini')) }}"
236+
controller:
237+
user: "{{ db_controller_user | default(lookup('ini', 'db_username section=controller file={{ playbook_dir }}/db_local.ini')) }}"
238+
pass: "{{ db_controller_pass | default(lookup('ini', 'db_password section=controller file={{ playbook_dir }}/db_local.ini')) }}"
239+
invoker:
240+
user: "{{ db_invoker_user | default(lookup('ini', 'db_username section=invoker file={{ playbook_dir }}/db_local.ini')) }}"
241+
pass: "{{ db_invoker_pass | default(lookup('ini', 'db_password section=invoker file={{ playbook_dir }}/db_local.ini')) }}"
236242

237243
apigateway:
238244
port:

ansible/roles/controller/tasks/deploy.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@
7878
include_tasks: "{{ openwhisk_home }}/ansible/tasks/db/checkDb.yml"
7979
vars:
8080
dbName: "{{ item }}"
81+
dbUser: "{{ db.credentials.controller.user }}"
82+
dbPass: "{{ db.credentials.controller.pass }}"
8183
with_items:
8284
- "{{ db.whisk.actions }}"
8385
- "{{ db.whisk.auth }}"
@@ -162,8 +164,8 @@
162164
"CONFIG_whisk_couchdb_protocol": "{{ db.protocol }}"
163165
"CONFIG_whisk_couchdb_host": "{{ db.host }}"
164166
"CONFIG_whisk_couchdb_port": "{{ db.port }}"
165-
"CONFIG_whisk_couchdb_username": "{{ db.credentials.admin.user }}"
166-
"CONFIG_whisk_couchdb_password": "{{ db.credentials.admin.pass }}"
167+
"CONFIG_whisk_couchdb_username": "{{ db.credentials.controller.user }}"
168+
"CONFIG_whisk_couchdb_password": "{{ db.credentials.controller.pass }}"
167169
"CONFIG_whisk_couchdb_provider": "{{ db.provider }}"
168170
"CONFIG_whisk_couchdb_databases_WhiskAuth": "{{ db.whisk.auth }}"
169171
"CONFIG_whisk_couchdb_databases_WhiskEntity": "{{ db.whisk.actions }}"

ansible/roles/invoker/tasks/deploy.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@
9090
include_tasks: "{{ openwhisk_home }}/ansible/tasks/db/checkDb.yml"
9191
vars:
9292
dbName: "{{ item }}"
93+
dbUser: "{{ db.credentials.invoker.user }}"
94+
dbPass: "{{ db.credentials.invoker.pass }}"
9395
with_items:
9496
- "{{ db.whisk.actions }}"
9597
- "{{ db.whisk.activations }}"
@@ -182,8 +184,8 @@
182184
"CONFIG_whisk_couchdb_protocol": "{{ db.protocol }}"
183185
"CONFIG_whisk_couchdb_host": "{{ db.host }}"
184186
"CONFIG_whisk_couchdb_port": "{{ db.port }}"
185-
"CONFIG_whisk_couchdb_username": "{{ db.credentials.admin.user }}"
186-
"CONFIG_whisk_couchdb_password": "{{ db.credentials.admin.pass }}"
187+
"CONFIG_whisk_couchdb_username": "{{ db.credentials.invoker.user }}"
188+
"CONFIG_whisk_couchdb_password": "{{ db.credentials.invoker.pass }}"
187189
"CONFIG_whisk_couchdb_provider": "{{ db.provider }}"
188190
"CONFIG_whisk_couchdb_databases_WhiskAuth": "{{ db.whisk.auth }}"
189191
"CONFIG_whisk_couchdb_databases_WhiskEntity": "{{ db.whisk.actions }}"

ansible/tasks/db/checkDb.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
---
44
# Checks, that the Database exists
55
# dbName - name of the database to check
6+
# dbUser - name of the user which should have access rights
7+
# dbPass - password of the user which should have access
68

79
- name: check if {{ dbName }} with {{ db.provider }} exists
810
uri:
911
url: "{{ db.protocol }}://{{ db.host }}:{{ db.port }}/{{ dbName }}"
1012
method: HEAD
1113
status_code: 200
12-
user: "{{ db.credentials.admin.user }}"
13-
password: "{{ db.credentials.admin.pass }}"
14+
user: "{{ dbUser }}"
15+
password: "{{ dbPass }}"
1416
force_basic_auth: yes

ansible/tasks/db/createUsers.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
2+
# license agreements; and to You under the Apache License, Version 2.0.
3+
---
4+
# Create all required users in _users-database
5+
# http://docs.couchdb.org/en/2.0.0/intro/security.html#users-documents
6+
7+
- name: create required users
8+
uri:
9+
url: "{{ db.protocol }}://{{ db.host }}:{{ db.port }}/_users/org.couchdb.user:{{ item.value.user }}"
10+
method: PUT
11+
status_code: 201,409
12+
body_format: json
13+
body: |
14+
{
15+
"name": "{{ item.value.user }}",
16+
"password": "{{ item.value.pass }}",
17+
"roles": [],
18+
"type": "user"
19+
}
20+
user: "{{ db.credentials.admin.user }}"
21+
password: "{{ db.credentials.admin.pass }}"
22+
force_basic_auth: yes
23+
with_dict: "{{ db.credentials }}"
24+
# Don't create the admin user again, if a component is using admin access.
25+
when: item.value.user != db.credentials.admin.user
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
2+
# license agreements; and to You under the Apache License, Version 2.0.
3+
---
4+
# Grant the specified users permissions to the specified database.
5+
# dbName - name of the database
6+
# admins - all users with admin access
7+
# readers - all users that have read access on the database
8+
# writers - all users that have write access on the database
9+
10+
# If a component uses admin credentials, the admin user will not be added to the list (as it already has all access rights).
11+
- set_fact:
12+
readerList: "{{ readers | default([]) | difference([db.credentials.admin.user]) }}"
13+
writerList: "{{ writers | default([]) | difference([db.credentials.admin.user]) }}"
14+
adminList: "{{ admins | default([]) | difference([db.credentials.admin.user]) }}"
15+
16+
# http://docs.couchdb.org/en/2.0.0/api/database/security.html
17+
- name: grant permissions for CouchDB
18+
uri:
19+
url: "{{ db.protocol }}://{{ db.host }}:{{ db.port }}/{{ dbName }}/_security"
20+
method: PUT
21+
status_code: 200
22+
body_format: json
23+
body: |
24+
{
25+
"admins": {
26+
"names": [ {{ adminList | join('", "') }} ],
27+
"roles": []
28+
},
29+
"members": {
30+
"names": [ "{{ readerList | union(writerList) | join('", "') }}" ],
31+
"roles": []
32+
}
33+
}
34+
user: "{{ db.credentials.admin.user }}"
35+
password: "{{ db.credentials.admin.pass }}"
36+
force_basic_auth: yes
37+
when: db.provider == 'CouchDB'
38+
39+
# https://console.bluemix.net/docs/services/Cloudant/api/authorization.html#authorization
40+
- name: grant permissions for Cloudant
41+
uri:
42+
url: "{{ db.protocol }}://{{ db.host }}:{{ db.port }}/{{ dbName }}/_security"
43+
method: PUT
44+
status_code: 200
45+
body_format: json
46+
body: |
47+
{
48+
"cloudant": {
49+
{% for item in readerList | union(writerList) | union(adminList) %}"{{ item }}": [ {% if item in readerList %}"_reader"{% if item in writerList %}, "_writer"{% if item in adminList %}, "_admin"{% endif %}{% endif %}{% endif %} ], {% endfor %}
50+
}
51+
}
52+
user: "{{ db.credentials.admin.user }}"
53+
password: "{{ db.credentials.admin.pass }}"
54+
force_basic_auth: yes
55+
when: db.provider == 'Cloudant'

ansible/tasks/initdb.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
dbName: "{{ db.whisk.auth }}"
1010
forceRecreation: False
1111

12+
- include_tasks: db/grantPermissions.yml
13+
vars:
14+
dbName: "{{ db.whisk.auth }}"
15+
readers:
16+
- "{{ db.credentials.controller.user }}"
17+
- "{{ db.credentials.invoker.user }}"
18+
1219
- include_tasks: db/recreateDoc.yml
1320
vars:
1421
dbName: "{{ db.whisk.auth }}"

ansible/tasks/recreateViews.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,3 @@
2121
- "{{ openwhisk_home }}/ansible/files/filter_design_document.json"
2222
- "{{ openwhisk_home }}/ansible/files/activations_design_document_for_activations_db.json"
2323
- "{{ openwhisk_home }}/ansible/files/logCleanup_design_document_for_activations_db.json"
24-
when: db.whisk.activations != db.whisk.actions

ansible/tasks/wipeDatabase.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,34 @@
44
# Wipe transient databases. You should know what you are doing here.
55
# withViews: True or False. Says, if the views have to be recreated.
66

7+
- include_tasks: db/createUsers.yml
8+
79
- include_tasks: db/recreateDb.yml
810
vars:
911
dbName: "{{ db.whisk.actions }}"
1012
forceRecreation: True
13+
- include_tasks: db/grantPermissions.yml
14+
vars:
15+
dbName: "{{ db.whisk.actions }}"
16+
readers:
17+
- "{{ db.credentials.controller.user }}"
18+
- "{{ db.credentials.invoker.user }}"
19+
writers:
20+
- "{{ db.credentials.controller.user }}"
21+
1122
- include_tasks: db/recreateDb.yml
1223
vars:
1324
dbName: "{{ db.whisk.activations }}"
1425
forceRecreation: True
15-
when: db.whisk.activations != db.whisk.actions
26+
- include_tasks: db/grantPermissions.yml
27+
vars:
28+
dbName: "{{ db.whisk.activations }}"
29+
readers:
30+
- "{{ db.credentials.controller.user }}"
31+
- "{{ db.credentials.invoker.user }}"
32+
writers:
33+
- "{{ db.credentials.controller.user }}"
34+
- "{{ db.credentials.invoker.user }}"
1635

1736
- include_tasks: recreateViews.yml
1837
when: withViews == True

ansible/templates/db_local.ini.j2

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,11 @@ db_password={{ lookup('env', 'OW_DB_PASSWORD')|default('some_passw0rd', true) }}
55
db_protocol={{ lookup('env', 'OW_DB_PROTOCOL')|default('http', true) }}
66
db_host={{ lookup('env', 'OW_DB_HOST')|default(groups['db']|first, true) }}
77
db_port={{ lookup('env', 'OW_DB_PORT')|default('5984', true) }}
8+
9+
[controller]
10+
db_username={{ lookup('env', 'OW_DB_CONTROLLER_USERNAME') | default(db_prefix + 'controller0', true) }}
11+
db_password={{ lookup('env', 'OW_DB_CONTROLLER_PASSWORD') | default('some_controller_passw0rd', true) }}
12+
13+
[invoker]
14+
db_username={{ lookup('env', 'OW_DB_INVOKER_USERNAME') | default(db_prefix + 'invoker0', true) }}
15+
db_password={{ lookup('env', 'OW_DB_INVOKER_PASSWORD') | default('some_invoker_passw0rd', true) }}

0 commit comments

Comments
 (0)