Skip to content

Commit 1e49515

Browse files
committed
Elevate eoapi db user permissions and rely on pgstac for db migrations.
1 parent 327b911 commit 1e49515

File tree

3 files changed

+13
-38
lines changed

3 files changed

+13
-38
lines changed

helm-chart/eoapi/templates/pgstacbootstrap/configmap.yaml

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -44,29 +44,3 @@ data:
4444
{{- end }}
4545
{{- end }}
4646
{{- end }}
47-
---
48-
{{- if .Values.postgrescluster.enabled }}
49-
apiVersion: v1
50-
kind: ConfigMap
51-
metadata:
52-
name: initdb
53-
data:
54-
initdb.sql: |
55-
\c {{ .Values.pgstacBootstrap.settings.database }}
56-
CREATE EXTENSION IF NOT EXISTS postgis;
57-
CREATE EXTENSION IF NOT EXISTS btree_gist;
58-
CREATE EXTENSION IF NOT EXISTS unaccent;
59-
CREATE ROLE pgstac_admin;
60-
CREATE ROLE pgstac_read;
61-
CREATE ROLE pgstac_ingest;
62-
ALTER DATABASE {{ .Values.pgstacBootstrap.settings.database }} OWNER TO {{ .Values.pgstacBootstrap.settings.user }};
63-
ALTER USER {{ .Values.pgstacBootstrap.settings.user }} SET search_path TO pgstac, public;
64-
ALTER ROLE {{ .Values.pgstacBootstrap.settings.user }} WITH CREATEROLE;
65-
ALTER DATABASE {{ .Values.pgstacBootstrap.settings.database }} set search_path to pgstac, public;
66-
GRANT CONNECT ON DATABASE {{ .Values.pgstacBootstrap.settings.database }} TO {{ .Values.pgstacBootstrap.settings.user }};
67-
GRANT ALL PRIVILEGES ON TABLES TO {{ .Values.pgstacBootstrap.settings.user }};
68-
GRANT ALL PRIVILEGES ON SEQUENCES TO {{ .Values.pgstacBootstrap.settings.user }};
69-
GRANT pgstac_read TO {{ .Values.pgstacBootstrap.settings.user }} WITH ADMIN OPTION;
70-
GRANT pgstac_ingest TO {{ .Values.pgstacBootstrap.settings.user }} WITH ADMIN OPTION;
71-
GRANT pgstac_admin TO {{ .Values.pgstacBootstrap.settings.user }} WITH ADMIN OPTION;
72-
{{- end }}

helm-chart/eoapi/templates/pgstacbootstrap/eoapiuser-permissions-upgrade.yaml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
{{- if and .Values.postgrescluster.enabled .Values.pgstacBootstrap.enabled }}
22
---
3-
# This job is part of the upgrade process from pre-0.7.0 versions.
4-
# Prior to 0.7.0, database schema updates were run with superuser privileges.
5-
# This job ensures proper permissions are granted to the eoapi user during upgrade.
6-
# TODO: Remove with the next mayor verson and add to documentation that one needs to
7-
# through 0.7.x when upgrading.
3+
# The eoapi database user runs pgstac migrate and needs some elevated permissions
4+
# without being a superuser.
85
apiVersion: batch/v1
96
kind: Job
107
metadata:
118
name: pgstac-eoapiuser-permissions-upgrade
129
labels:
1310
app: pgstac-eoapiuser-permissions-upgrade
1411
annotations:
15-
helm.sh/hook: "post-upgrade"
12+
helm.sh/hook: "post-install,post-upgrade"
1613
helm.sh/hook-weight: "-7"
1714
helm.sh/hook-delete-policy: "before-hook-creation"
1815
spec:
@@ -34,9 +31,8 @@ spec:
3431
set -e
3532
3633
# Run permission setup with superuser
37-
echo "Applying superuser permissions for upgrade from version {{ .Values.previousVersion }}..."
38-
PGUSER=postgres psql -f /opt/sql/initdb.sql
39-
34+
echo "Applying elevated permissions"
35+
PGUSER=postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE \"$PGDATABASE\" TO \"$EOAPI_USER\";"
4036
echo "Permissions upgrade complete"
4137
resources:
4238
{{- toYaml .Values.pgstacBootstrap.settings.resources | nindent 12 }}
@@ -49,6 +45,11 @@ spec:
4945
secretKeyRef:
5046
name: {{ $.Values.postgrescluster.name | default $.Release.Name }}-pguser-postgres
5147
key: user
48+
- name: EOAPI_USER
49+
valueFrom:
50+
secretKeyRef:
51+
name: {{ $.Values.postgrescluster.name | default $.Release.Name }}-pguser-eoapi
52+
key: user
5253
- name: PGPORT
5354
valueFrom:
5455
secretKeyRef:

helm-chart/eoapi/values.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,19 @@ comment_db: >
6969
postgresql:
7070
# Management type: "postgrescluster" (default), "external-plaintext", or "external-secret"
7171
type: "postgrescluster"
72-
72+
7373
# Configuration for external PostgreSQL (used when type is "external-plaintext" or "external-secret")
7474
external:
7575
# Connection information
7676
host: ""
7777
port: "5432"
7878
database: "eoapi"
79-
79+
8080
# Credentials configuration (used when type is "external-plaintext")
8181
credentials:
8282
username: ""
8383
password: ""
84-
84+
8585
# Secret reference (used when type is "external-secret")
8686
existingSecret:
8787
name: ""

0 commit comments

Comments
 (0)