How does the role assignment work in Postgres Operator?

5/17/2020

I am using https://postgres-operator.readthedocs.io/en/latest/ and have deployed:

kind: "postgresql"
apiVersion: "acid.zalan.do/v1"

metadata:
  name: "acid-databaker-db"
  namespace: "dev"
  labels:
    team: acid

spec:
  teamId: "acid"
  postgresql:
    version: "12"
  numberOfInstances: 2
  volume:
    size: "2Gi"
  users:
    admin:
      - superuser
      - createdb
    kcadmin: [] 
  databases:
    keycloak: kcadmin
  allowedSourceRanges:
    # IP ranges to access your cluster go here

  resources:
    requests:
      cpu: 100m
      memory: 100Mi
    limits:
      cpu: 500m
      memory: 500Mi

everything is up and running and I can connect to database, but I do not understand this part:

  users:
    admin:
      - superuser
      - createdb
    kcadmin: [] 
  databases:
    keycloak: kcadmin

According to the doc, admin is a role - right? What about kcadmin? Is it an user or role? If it is an user, what kind of role does the kcadmin has?

-- zero_coding
kubernetes
postgresql

1 Answer

5/19/2020

This is a community wiki answer based on the correct info from the comments and with more explanation and details.

In your use case:

  users:
    admin:
      - superuser
      - createdb
    kcadmin: [] 
  databases:
    keycloak: kcadmin

we see two users: admin and kcadmin.

User admin has two manifest roles: superuser and createdb.

User kcadmin has no manifest roles.

Manifest roles are defined as a dictionary, with a role name as a key and a list of role options as a value. For a role without any options it is best to supply the empty list [], like with your kcadmin user.

The following roles can be used: superuser, inherit, login, nologin, createrole, createdb, replication and bypassrls.

I hope it helps.

-- OhHiMark
Source: StackOverflow