apps(farrisilk): lab replica stack (Odoo 18 + plain Postgres + Metabase) on :8086/:8087
Odoo 18 (dated tag 18.0-20261112) on a plain postgres:16 container, not CNPG: the client runs bare Postgres on a Proxmox VM and this namespace mirrors that shape. Odoo's initContainer installs base,web once, applies the read-only BI grants/revokes and sets the admin login from a Secret. Metabase gets its own state in the same Postgres (db metabase) with a 1Gi heap and MB_ENCRYPTION_SECRET_KEY. Two bare-IP Gateways (8086 odoo, 8087 metabase) in ns internal, each with its own RouteConfiguration. Host firewall (nft on siriussec, ufw on rpi) carries 8086/8087 and was installed before the Gateways were pushed.
This commit is contained in:
parent
930752152e
commit
7f7f806616
14 changed files with 874 additions and 6 deletions
67
apps/base/farrisilk/postgres-init.yaml
Normal file
67
apps/base/farrisilk/postgres-init.yaml
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
# First-run provisioning for the lab Postgres: two databases (odoo, metabase)
|
||||
# and three roles. Runs once, from postgres:16's /docker-entrypoint-initdb.d,
|
||||
# only while PGDATA is empty.
|
||||
#
|
||||
# Why an init script instead of POSTGRES_DB/POSTGRES_USER: the stock image only
|
||||
# knows one database and one role, and this namespace needs
|
||||
# - `odoo` : owner of db `odoo`, CREATEDB (Odoo creates its own database
|
||||
# on first `-i base` and needs the privilege to do it)
|
||||
# - `metabase` : owner of db `metabase` (Metabase's own application DB)
|
||||
# - `metabase_ro` : the read-only BI identity used in §4 of the card, with
|
||||
# default_transaction_read_only + a statement timeout. Its
|
||||
# SELECT grants over Odoo's tables are applied AFTER Odoo has
|
||||
# installed them (the odoo Deployment's initContainer), because
|
||||
# at this point the `odoo` database has no tables at all.
|
||||
#
|
||||
# Passwords arrive as env vars from Secret `farrisilk/pg-users` (out of band);
|
||||
# nothing here is a credential literal.
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: pg-init
|
||||
namespace: farrisilk
|
||||
data:
|
||||
01-init-dbs.sh: |
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
: "${ODOO_DB_PASSWORD:?}"
|
||||
: "${METABASE_DB_PASSWORD:?}"
|
||||
: "${METABASE_RO_PASSWORD:?}"
|
||||
|
||||
# Roles + databases. psql autocommits each statement, which CREATE DATABASE
|
||||
# requires (it cannot run inside a transaction block).
|
||||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname postgres \
|
||||
-v odoo_pw="$ODOO_DB_PASSWORD" \
|
||||
-v metabase_pw="$METABASE_DB_PASSWORD" \
|
||||
-v ro_pw="$METABASE_RO_PASSWORD" <<'EOSQL'
|
||||
CREATE ROLE odoo LOGIN CREATEDB PASSWORD :'odoo_pw';
|
||||
CREATE ROLE metabase LOGIN PASSWORD :'metabase_pw';
|
||||
CREATE ROLE metabase_ro LOGIN PASSWORD :'ro_pw' CONNECTION LIMIT 10;
|
||||
|
||||
-- Read-only BI identity: these are role-level defaults, so they hold for
|
||||
-- every session Metabase opens, including ones it recycles.
|
||||
ALTER ROLE metabase_ro SET default_transaction_read_only = on;
|
||||
ALTER ROLE metabase_ro SET statement_timeout = '60s';
|
||||
ALTER ROLE metabase_ro SET idle_in_transaction_session_timeout = '60s';
|
||||
|
||||
CREATE DATABASE odoo OWNER odoo;
|
||||
CREATE DATABASE metabase OWNER metabase;
|
||||
|
||||
-- No cross-tenant CONNECT: the BI role reaches `odoo` only, the Metabase
|
||||
-- application role never reaches `odoo`. (PUBLIC carries CONNECT on every
|
||||
-- new database, which is the usual way a "read-only" role ends up able to
|
||||
-- reach databases it was never granted.)
|
||||
REVOKE CONNECT ON DATABASE odoo FROM PUBLIC;
|
||||
GRANT CONNECT ON DATABASE odoo TO odoo, metabase_ro;
|
||||
REVOKE CONNECT ON DATABASE metabase FROM PUBLIC;
|
||||
GRANT CONNECT ON DATABASE metabase TO metabase;
|
||||
EOSQL
|
||||
|
||||
# Schema-level setup in the (still empty) odoo database. Table grants and
|
||||
# the credential-table revokes are (re)applied by the odoo initContainer.
|
||||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname odoo <<'EOSQL'
|
||||
GRANT USAGE ON SCHEMA public TO metabase_ro;
|
||||
ALTER DEFAULT PRIVILEGES FOR ROLE odoo IN SCHEMA public
|
||||
GRANT SELECT ON TABLES TO metabase_ro;
|
||||
EOSQL
|
||||
Loading…
Reference in a new issue