Add 'admin' option to create role
This commit is contained in:
parent
ff5c63ddf1
commit
83ef5ff5b6
|
|
@ -365,6 +365,9 @@ key.
|
||||||
role name to grant to team members created from the Teams API. The default is
|
role name to grant to team members created from the Teams API. The default is
|
||||||
`admin`, that role is created by Spilo as a `NOLOGIN` role.
|
`admin`, that role is created by Spilo as a `NOLOGIN` role.
|
||||||
|
|
||||||
|
* **add_admin_flag_to_robot_roles**
|
||||||
|
if `true`, the `team_admin_role` will have the rights to grant roles coming from PG manifests. Such roles will be created as in "CREATE ROLE 'role_from_manifest' ... ADMIN 'team_admin_role'". The default is `true`.
|
||||||
|
|
||||||
* **pam_role_name**
|
* **pam_role_name**
|
||||||
when set, the operator will add all team member roles to this group and add a
|
when set, the operator will add all team member roles to this group and add a
|
||||||
`pg_hba` line to authenticate members of that role via `pam`. The default is
|
`pg_hba` line to authenticate members of that role via `pam`. The default is
|
||||||
|
|
|
||||||
|
|
@ -709,11 +709,16 @@ func (c *Cluster) initRobotUsers() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("invalid flags for user %q: %v", username, err)
|
return fmt.Errorf("invalid flags for user %q: %v", username, err)
|
||||||
}
|
}
|
||||||
|
adminRole := ""
|
||||||
|
if c.OpConfig.AddAdminFlagToRobotRoles {
|
||||||
|
adminRole = c.OpConfig.TeamAdminRole
|
||||||
|
}
|
||||||
newRole := spec.PgUser{
|
newRole := spec.PgUser{
|
||||||
Origin: spec.RoleOriginManifest,
|
Origin: spec.RoleOriginManifest,
|
||||||
Name: username,
|
Name: username,
|
||||||
Password: util.RandomPassword(constants.PasswordLength),
|
Password: util.RandomPassword(constants.PasswordLength),
|
||||||
Flags: flags,
|
Flags: flags,
|
||||||
|
AdminRole: adminRole,
|
||||||
}
|
}
|
||||||
if currentRole, present := c.pgUsers[username]; present {
|
if currentRole, present := c.pgUsers[username]; present {
|
||||||
c.pgUsers[username] = c.resolveNameConflict(¤tRole, &newRole)
|
c.pgUsers[username] = c.resolveNameConflict(¤tRole, &newRole)
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ type PgUser struct {
|
||||||
Flags []string `yaml:"user_flags"`
|
Flags []string `yaml:"user_flags"`
|
||||||
MemberOf []string `yaml:"inrole"`
|
MemberOf []string `yaml:"inrole"`
|
||||||
Parameters map[string]string `yaml:"db_parameters"`
|
Parameters map[string]string `yaml:"db_parameters"`
|
||||||
|
AdminRole string `yaml:"admin_role"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// PgUserMap maps user names to the definitions.
|
// PgUserMap maps user names to the definitions.
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,7 @@ type Config struct {
|
||||||
EnableTeamsAPI bool `name:"enable_teams_api" default:"true"`
|
EnableTeamsAPI bool `name:"enable_teams_api" default:"true"`
|
||||||
EnableTeamSuperuser bool `name:"enable_team_superuser" default:"false"`
|
EnableTeamSuperuser bool `name:"enable_team_superuser" default:"false"`
|
||||||
TeamAdminRole string `name:"team_admin_role" default:"admin"`
|
TeamAdminRole string `name:"team_admin_role" default:"admin"`
|
||||||
|
AddAdminFlagToRobotRoles bool `name:"add_admin_flag_to_robot_roles" default:"true"`
|
||||||
EnableMasterLoadBalancer bool `name:"enable_master_load_balancer" default:"true"`
|
EnableMasterLoadBalancer bool `name:"enable_master_load_balancer" default:"true"`
|
||||||
EnableReplicaLoadBalancer bool `name:"enable_replica_load_balancer" default:"false"`
|
EnableReplicaLoadBalancer bool `name:"enable_replica_load_balancer" default:"false"`
|
||||||
// deprecated and kept for backward compatibility
|
// deprecated and kept for backward compatibility
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,10 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"reflect"
|
||||||
|
|
||||||
"github.com/zalando-incubator/postgres-operator/pkg/spec"
|
"github.com/zalando-incubator/postgres-operator/pkg/spec"
|
||||||
"github.com/zalando-incubator/postgres-operator/pkg/util"
|
"github.com/zalando-incubator/postgres-operator/pkg/util"
|
||||||
"reflect"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -19,6 +20,7 @@ const (
|
||||||
doBlockStmt = `SET LOCAL synchronous_commit = 'local'; DO $$ BEGIN %s; END;$$;`
|
doBlockStmt = `SET LOCAL synchronous_commit = 'local'; DO $$ BEGIN %s; END;$$;`
|
||||||
passwordTemplate = "ENCRYPTED PASSWORD '%s'"
|
passwordTemplate = "ENCRYPTED PASSWORD '%s'"
|
||||||
inRoleTemplate = `IN ROLE %s`
|
inRoleTemplate = `IN ROLE %s`
|
||||||
|
adminTemplate = `ADMIN %s`
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultUserSyncStrategy implements a user sync strategy that merges already existing database users
|
// DefaultUserSyncStrategy implements a user sync strategy that merges already existing database users
|
||||||
|
|
@ -113,6 +115,9 @@ func (strategy DefaultUserSyncStrategy) createPgUser(user spec.PgUser, db *sql.D
|
||||||
if len(user.MemberOf) > 0 {
|
if len(user.MemberOf) > 0 {
|
||||||
userFlags = append(userFlags, fmt.Sprintf(inRoleTemplate, quoteMemberList(user)))
|
userFlags = append(userFlags, fmt.Sprintf(inRoleTemplate, quoteMemberList(user)))
|
||||||
}
|
}
|
||||||
|
if user.AdminRole != "" {
|
||||||
|
userFlags = append(userFlags, fmt.Sprintf(adminTemplate, user))
|
||||||
|
}
|
||||||
|
|
||||||
if user.Password == "" {
|
if user.Password == "" {
|
||||||
userPassword = "PASSWORD NULL"
|
userPassword = "PASSWORD NULL"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue