Microservice:
- API based
- Use vault to get token with admin DB privileges to:
- create new database
- create a new readonly role where new users can be created from
- create a new fullaccess role where new users can be created from
REVOKE ALL ON DATABASE template0 FROM PUBLIC; REVOKE ALL ON DATABASE template1 FROM PUBLIC; ... to be found what is the actual commands to be ran
vault mount postgresql -path postgres/admin
vault write postgresql/admin/config/connection connection_url="postgresql://root:[email protected]:5432/public"
vault write postgresql/{{db_name}}/config/lease lease=5m lease_max=5m
vault write postgresql/admin/roles/admin sql=" CREATE ROLE "{{name}}" WITH LOGIN PASSWORD '{{password}}' VALID UNTIL '{{expiration}}'; GRANT ALL PERMISSIONS TO "{{name}}";"
Maybe needs access to the static secret with the root password, so it can configure the Vault connection
- create the DB
- create a role with read access only to the {{db_name}}: {{db_name}}_users_readonly
- create a role with read/write access only to the {{db_name}}: {{db_name}}_users_fullaccess
vault mount postgresql -path postgres/{{db_name}}
vault write postgresql/{{db_name}}/config/connection connection_url="postgresql://root:[email protected]:5432/{{db_name}}"
vault write postgresql/{{db_name}}/config/lease lease=1h lease_max=24h
vault write postgresql/{{db_name}}/roles/readonly sql=" CREATE ROLE "{{name}}" WITH LOGIN PASSWORD '{{password}}' VALID UNTIL '{{expiration}}'; GRANT {{db_name}}_users TO {{name}}; GRANT SELECT ON ALL TABLES IN SCHEMA public TO "{{name}}";"
vault write postgresql/{{db_name}}/roles/admin sql="CREATE ROLE "{{name}}" WITH LOGIN PASSWORD '{{password}}' VALID UNTIL '{{expiration}}';GRANT SELECT ON ALL TABLES IN SCHEMA public TO "{{name}}";"