Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OBS-1724 Add option to give select only access to DB #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ansible/inventories/pih_rimu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ all:
port: 3306
knagel:
ips:
- 10.160.28.102
- 72.93.97.81
mysql_user: knagel
read_only: true
port: 3306
openboxes:
ips:
Expand Down
24 changes: 23 additions & 1 deletion ansible/playbooks/users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
| list
| unique }}

- name: Enabling DB access for users listed in firewall config
- name: Enabling DB full access for users listed in firewall config
changed_when: true
when: inventory.get('firewall') and inventory.get('mysql', {}).get('enabled')
ansible.builtin.command:
Expand All @@ -107,6 +107,28 @@
loop: >-
{{ inventory.firewall.values()
| selectattr('mysql_user', 'defined')
| selectattr('read_only', 'undefined')
| subelements('ips') }}

- name: Enabling DB read only access for users listed in firewall config
changed_when: true
when: inventory.get('firewall') and inventory.get('mysql', {}).get('enabled')
ansible.builtin.command:
argv:
- mysql
- -u
- root
- -p{{ vault.db_users.root.password }}
- -e
- >-
DROP USER IF EXISTS '{{ item[0].mysql_user }}'@'{{ item[1] }}';
CREATE USER '{{ item[0].mysql_user }}'@'{{ item[1] }}' IDENTIFIED BY '{{ vault.db_users[item[0].mysql_user].password }}';
GRANT SELECT ON `{{ inventory.db_name }}`.* TO '{{ item[0].mysql_user }}'@'{{ item[1] }}';
FLUSH PRIVILEGES;
loop: >-
{{ inventory.firewall.values()
| selectattr('mysql_user', 'defined')
| selectattr('read_only', 'true')
| subelements('ips') }}

- name: Creating database user for New Relic
Expand Down