Skip to content

Commit 598d1c4

Browse files
committed
Remove admin user from pgadmin secret. Generate a random password for setup user on startup. Adjust tests accordingly.
1 parent 000db83 commit 598d1c4

File tree

8 files changed

+5
-134
lines changed

8 files changed

+5
-134
lines changed

internal/controller/standalone_pgadmin/controller.go

-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,6 @@ func (r *PGAdminReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
125125
_ *corev1.Service
126126
)
127127

128-
_, err = r.reconcilePGAdminSecret(ctx, pgAdmin)
129-
130128
if err == nil {
131129
clusters, err = r.getClustersForPGAdmin(ctx, pgAdmin)
132130
}

internal/controller/standalone_pgadmin/pod.go

+1-9
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,6 @@ func pod(
124124
Name: "PGADMIN_SETUP_EMAIL",
125125
Value: fmt.Sprintf("admin@%s.%s.svc", inPGAdmin.Name, inPGAdmin.Namespace),
126126
},
127-
{
128-
Name: "PGADMIN_SETUP_PASSWORD",
129-
ValueFrom: &corev1.EnvVarSource{SecretKeyRef: &corev1.SecretKeySelector{
130-
LocalObjectReference: corev1.LocalObjectReference{
131-
Name: naming.StandalonePGAdmin(inPGAdmin).Name,
132-
},
133-
Key: "password",
134-
}},
135-
},
136127
{
137128
Name: "PGADMIN_LISTEN_PORT",
138129
Value: fmt.Sprintf("%d", pgAdminPort),
@@ -292,6 +283,7 @@ func startupScript(pgadmin *v1beta1.PGAdmin) []string {
292283
// - https://www.pgadmin.org/docs/pgadmin4/development/server_deployment.html#standalone-gunicorn-configuration
293284
// - https://docs.gunicorn.org/en/latest/configure.html
294285
var startScript = fmt.Sprintf(`
286+
export PGADMIN_SETUP_PASSWORD="$(date +%%s | sha256sum | base64 | head -c 32)"
295287
PGADMIN_DIR=%s
296288
APP_RELEASE=$(cd $PGADMIN_DIR && python3 -c "import config; print(config.APP_RELEASE)")
297289

internal/controller/standalone_pgadmin/pod_test.go

+2-10
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ containers:
5151
- --
5252
- |-
5353
monitor() {
54+
export PGADMIN_SETUP_PASSWORD="$(date +%s | sha256sum | base64 | head -c 32)"
5455
PGADMIN_DIR=/usr/local/lib/python3.11/site-packages/pgadmin4
5556
APP_RELEASE=$(cd $PGADMIN_DIR && python3 -c "import config; print(config.APP_RELEASE)")
5657
@@ -103,11 +104,6 @@ containers:
103104
env:
104105
- name: PGADMIN_SETUP_EMAIL
105106
106-
- name: PGADMIN_SETUP_PASSWORD
107-
valueFrom:
108-
secretKeyRef:
109-
key: password
110-
name: pgadmin-
111107
- name: PGADMIN_LISTEN_PORT
112108
value: "5050"
113109
name: pgadmin
@@ -229,6 +225,7 @@ containers:
229225
- --
230226
- |-
231227
monitor() {
228+
export PGADMIN_SETUP_PASSWORD="$(date +%s | sha256sum | base64 | head -c 32)"
232229
PGADMIN_DIR=/usr/local/lib/python3.11/site-packages/pgadmin4
233230
APP_RELEASE=$(cd $PGADMIN_DIR && python3 -c "import config; print(config.APP_RELEASE)")
234231
@@ -281,11 +278,6 @@ containers:
281278
env:
282279
- name: PGADMIN_SETUP_EMAIL
283280
284-
- name: PGADMIN_SETUP_PASSWORD
285-
valueFrom:
286-
secretKeyRef:
287-
key: password
288-
name: pgadmin-
289281
- name: PGADMIN_LISTEN_PORT
290282
value: "5050"
291283
image: new-image

internal/controller/standalone_pgadmin/secret.go

-98
This file was deleted.

internal/controller/standalone_pgadmin/users.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ type pgAdminUserForJson struct {
5252
Username string `json:"username"`
5353
}
5454

55-
// reconcilePGAdminUsers reconciles the default admin user and the users listed in the pgAdmin spec,
56-
// adding them to the pgAdmin secret, and creating/updating them in pgAdmin when appropriate.
55+
// reconcilePGAdminUsers reconciles the users listed in the pgAdmin spec, adding them
56+
// to the pgAdmin secret, and creating/updating them in pgAdmin when appropriate.
5757
func (r *PGAdminReconciler) reconcilePGAdminUsers(ctx context.Context, pgadmin *v1beta1.PGAdmin) error {
5858
const container = naming.ContainerPGAdmin
5959
var podExecutor Executor
@@ -163,9 +163,6 @@ func (r *PGAdminReconciler) writePGAdminUsers(ctx context.Context, pgadmin *v1be
163163

164164
// Initialize secret data map, or copy existing data if not nil
165165
intentUserSecret.Data = make(map[string][]byte)
166-
if existingUserSecret.Data != nil {
167-
intentUserSecret.Data = existingUserSecret.Data
168-
}
169166

170167
setupScript := fmt.Sprintf(`
171168
PGADMIN_DIR=%s

testing/kuttl/e2e-other/standalone-pgadmin-v8/files/02-pgadmin.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ kind: PGAdmin
33
metadata:
44
name: pgadmin
55
spec:
6-
adminUsername: [email protected]
76
dataVolumeClaimSpec:
87
accessModes:
98
- "ReadWriteOnce"

testing/kuttl/e2e/standalone-pgadmin/files/00-pgadmin-check.yaml

-8
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,3 @@ status:
3232
ready: true
3333
started: true
3434
phase: Running
35-
---
36-
apiVersion: v1
37-
kind: Secret
38-
metadata:
39-
labels:
40-
postgres-operator.crunchydata.com/role: pgadmin
41-
postgres-operator.crunchydata.com/pgadmin: pgadmin
42-
type: Opaque

testing/kuttl/e2e/standalone-pgadmin/files/02-pgadmin.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ kind: PGAdmin
33
metadata:
44
name: pgadmin
55
spec:
6-
adminUsername: [email protected]
76
dataVolumeClaimSpec:
87
accessModes:
98
- "ReadWriteOnce"

0 commit comments

Comments
 (0)