Manage PostgreSQL users and roles for microservice platform
Contents
Microservice architecture states for one service has one database. However, the database administrator would like to have one credential to access multiple databases. Let’s take a look at how we can solve this with PostgreSQL roles.
Configuring database user for service
Each service can have credentials to access the database.
E.g. service account
can use user account_service
with password '<SECRET_PASSOWRD>'
has access to the account_service_db
database.
Create a new user for account service:
|
|
Grant access to the database tables and sequences:
|
|
Configuring role to access multiple databases services
An administrator can have credentials to access multiple databases.
E.g. user jhon_the_admin
with password '<ADMIN_SECRET_PASSOWRD>'
has access to the account_service
, aaa_service_db
and yyy_service
.
Create the admin group:
|
|
Link service roles to the admin_group:
|
|
Create the admin user:
|
|
Link the admin_group role to the admin user:
|
|