Skip to content

Commit bd91bdb

Browse files
committed
wip
1 parent 035c13a commit bd91bdb

File tree

6 files changed

+22
-11
lines changed

6 files changed

+22
-11
lines changed

charts/ext-postgres-operator/crds/db.movetokube.com_postgresusers_crd.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ spec:
4141
type: string
4242
role:
4343
type: string
44+
iamAuthentication:
45+
type: boolean
46+
default: false
4447
secretName:
4548
type: string
4649
secretTemplate:

pkg/apis/db/v1alpha1/postgresuser_types.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,21 @@ type PostgresUserSpec struct {
1616
// +optional
1717
SecretTemplate map[string]string `json:"secretTemplate,omitempty"` // key-value, where key is secret field, value is go template
1818
// +optional
19-
Privileges string `json:"privileges"`
19+
Privileges string `json:"privileges"`
20+
IamAuthentication bool `json:"iamAuthentication"`
2021
// +optional
2122
Annotations map[string]string `json:"annotations,omitempty"`
2223
}
2324

2425
// PostgresUserStatus defines the observed state of PostgresUser
2526
// +k8s:openapi-gen=true
2627
type PostgresUserStatus struct {
27-
Succeeded bool `json:"succeeded"`
28-
PostgresRole string `json:"postgresRole"`
29-
PostgresLogin string `json:"postgresLogin"`
30-
PostgresGroup string `json:"postgresGroup"`
31-
DatabaseName string `json:"databaseName"`
28+
Succeeded bool `json:"succeeded"`
29+
PostgresRole string `json:"postgresRole"`
30+
PostgresLogin string `json:"postgresLogin"`
31+
PostgresGroup string `json:"postgresGroup"`
32+
DatabaseName string `json:"databaseName"`
33+
IamAuthentication bool `json:"iamAuthentication"`
3234
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
3335
// Important: Run "operator-sdk generate k8s" to regenerate code after modifying this file
3436
// Add custom validation using kubebuilder tags: https://book.kubebuilder.io/beyond_basics/generating_crd.html

pkg/controller/postgresuser/postgresuser_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func (r *ReconcilePostgresUser) Reconcile(request reconcile.Request) (reconcile.
177177
// Create user role
178178
suffix := utils.GetRandomString(6)
179179
role = fmt.Sprintf("%s-%s", instance.Spec.Role, suffix)
180-
login, err = r.pg.CreateUserRole(role, password)
180+
login, err = r.pg.CreateUserRole(role, password, instance.spec.IamAuthentication)
181181
if err != nil {
182182
return r.requeue(instance, errors.NewInternalError(err))
183183
}

pkg/postgres/aws.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,17 @@ func (c *awspg) CreateDB(dbname, role string) error {
3939
return c.pg.CreateDB(dbname, role)
4040
}
4141

42-
func (c *awspg) CreateUserRole(role, password string) (string, error) {
43-
returnedRole, err := c.pg.CreateUserRole(role, password)
42+
func (c *awspg) CreateUserRole(role, password string, iamAuthentication *bool) (string, error) {
43+
returnedRole, err := c.pg.CreateUserRole(role, password, iamAuthentication)
4444
if err != nil {
4545
return "", err
4646
}
47+
if iamAuthentication != nil && *iamAuthentication {
48+
err = c.GrantRole("rds_iam", role)
49+
if err != nil {
50+
return "", err
51+
}
52+
}
4753
// On AWS RDS the postgres user isn't really superuser so he doesn't have permissions
4854
// to ALTER DEFAULT PRIVILEGES FOR ROLE unless he belongs to the role
4955
err = c.GrantRole(role, c.user)

pkg/postgres/postgres.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type PG interface {
1313
CreateSchema(db, role, schema string, logger logr.Logger) error
1414
CreateExtension(db, extension string, logger logr.Logger) error
1515
CreateGroupRole(role string) error
16-
CreateUserRole(role, password string) (string, error)
16+
CreateUserRole(role, password string, iamAuthentication *bool) (string, error)
1717
UpdatePassword(role, password string) error
1818
GrantRole(role, grantee string) error
1919
SetSchemaPrivileges(schemaPrivileges PostgresSchemaPrivileges, logger logr.Logger) error

pkg/postgres/role.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (c *pg) CreateGroupRole(role string) error {
2828
return nil
2929
}
3030

31-
func (c *pg) CreateUserRole(role, password string) (string, error) {
31+
func (c *pg) CreateUserRole(role, password string, iamAuthentication *bool) (string, error) {
3232
_, err := c.db.Exec(fmt.Sprintf(CREATE_USER_ROLE, role, password))
3333
if err != nil {
3434
return "", err

0 commit comments

Comments
 (0)