Skip to content

Commit 0be3701

Browse files
committed
E2E Test for GSSAPI Authentication With PG
Adds an end-to-end test to verify the ability to properly configure PostgreSQL for GSSAPI authentication. This is specifically done using Kerberos, i.e. a ticket issued by a Kerberos KDC server is utilized to log into PostgreSQL when running the test. Please note that this specific test has been added to a "e2e-other" directory, since additional configuration and infrastructure (e.g. a a running Kerberos Key Distribution Center) must be in place in order to successfully run the test. [sc-13319]
1 parent 55315cc commit 0be3701

File tree

7 files changed

+135
-0
lines changed

7 files changed

+135
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: krb5
5+
---
6+
apiVersion: v1
7+
kind: Secret
8+
metadata:
9+
name: krb5-keytab
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestStep
3+
commands:
4+
- command: kubectl exec -n krb5 -it krb5-kdc-0 -- /krb5-scripts/krb5.sh "${NAMESPACE}"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: postgres-operator.crunchydata.com/v1beta1
2+
kind: PostgresCluster
3+
metadata:
4+
name: gssapi
5+
status:
6+
instances:
7+
- name: instance1
8+
readyReplicas: 1
9+
replicas: 1
10+
updatedReplicas: 1
11+
---
12+
apiVersion: v1
13+
kind: Service
14+
metadata:
15+
name: gssapi-primary
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
apiVersion: postgres-operator.crunchydata.com/v1beta1
2+
kind: PostgresCluster
3+
metadata:
4+
name: gssapi
5+
spec:
6+
config:
7+
files:
8+
- secret:
9+
name: krb5-keytab
10+
- configMap:
11+
name: krb5
12+
patroni:
13+
dynamicConfiguration:
14+
postgresql:
15+
pg_hba:
16+
- host postgres postgres 0.0.0.0/0 scram-sha-256
17+
- host all [email protected] 0.0.0.0/0 gss
18+
parameters:
19+
krb_server_keyfile: /etc/postgres/krb5.keytab
20+
users:
21+
- name: postgres
22+
postgresVersion: 14
23+
instances:
24+
- name: instance1
25+
dataVolumeClaimSpec:
26+
accessModes:
27+
- "ReadWriteOnce"
28+
resources:
29+
requests:
30+
storage: 1Gi
31+
backups:
32+
pgbackrest:
33+
repos:
34+
- name: repo1
35+
volume:
36+
volumeClaimSpec:
37+
accessModes:
38+
- "ReadWriteOnce"
39+
resources:
40+
requests:
41+
storage: 1Gi
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: batch/v1
2+
kind: Job
3+
metadata:
4+
name: psql-connect-gssapi
5+
status:
6+
succeeded: 1
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
apiVersion: batch/v1
2+
kind: Job
3+
metadata:
4+
name: psql-connect-gssapi
5+
spec:
6+
template:
7+
spec:
8+
restartPolicy: Never
9+
containers:
10+
- name: psql
11+
image: us.gcr.io/container-suite/crunchy-postgres:centos8-14.1-5.1.0-rc.1-0
12+
command:
13+
- bash
14+
- -c
15+
- --
16+
- |-
17+
psql -c 'create user "[email protected]";'
18+
kinit -k -t /krb5-conf/krb5.keytab [email protected]
19+
psql -U [email protected] -h gssapi-primary.$(NAMESPACE).svc.cluster.local -d postgres \
20+
-c 'select version();'
21+
env:
22+
- name: NAMESPACE
23+
valueFrom: { fieldRef: { fieldPath: metadata.namespace } }
24+
- name: PGHOST
25+
valueFrom: { secretKeyRef: { name: gssapi-pguser-postgres, key: host } }
26+
- name: PGPORT
27+
valueFrom: { secretKeyRef: { name: gssapi-pguser-postgres, key: port } }
28+
- name: PGUSER
29+
valueFrom: { secretKeyRef: { name: gssapi-pguser-postgres, key: user } }
30+
- name: PGPASSWORD
31+
valueFrom: { secretKeyRef: { name: gssapi-pguser-postgres, key: password } }
32+
- name: PGDATABASE
33+
value: postgres
34+
- name: KRB5_CONFIG
35+
value: /krb5-conf/krb5.conf
36+
volumeMounts:
37+
- name: krb5-conf
38+
mountPath: /krb5-conf
39+
volumes:
40+
- name: krb5-conf
41+
projected:
42+
sources:
43+
- configMap:
44+
name: krb5
45+
- secret:
46+
name: krb5-keytab
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# GSSAPI Authentication
2+
3+
This test verifies that it is possible to properly configure PostgreSQL for GSSAPI
4+
authentication. This is done by configuring a PostgresCluster for GSSAPI authentication,
5+
and then utilizing a Kerberos ticket that has been issued by a Kerberos KDC server to log into
6+
PostgreSQL.
7+
8+
## Assumptions
9+
10+
- A Kerberos Key Distribution Center (KDC) Pod named `krb5-kdc-0` is deployed inside of a `krb5`
11+
namespace within the Kubernetes cluster
12+
- The KDC server (`krb5-kdc-0`) contains a `/krb5-conf/krb5.sh` script that can be run as part
13+
of the test to create the Kerberos principals, keytab secret and client configuration needed to
14+
successfully run the test

0 commit comments

Comments
 (0)