feat: use different creds for api and consumer with restrictive rights

This commit is contained in:
Alexis Fourmaux 2026-05-13 18:25:23 +02:00
parent 611600c2d8
commit 11b7c14dc7
7 changed files with 16 additions and 1 deletions

5
.gitignore vendored
View file

@ -218,3 +218,8 @@ __marimo__/
# Streamlit # Streamlit
.streamlit/secrets.toml .streamlit/secrets.toml
## Specific env files that may contain secrets
api.env
consumer.env

1
server/api.env.example Normal file
View file

@ -0,0 +1 @@
DATABASE_URI='postgresql://simugaz_api:changeme@db/simugaz'

View file

@ -15,7 +15,7 @@ log = logging.getLogger(__name__)
_MIN_CONN = 1 _MIN_CONN = 1
_MAX_CONN = 10 _MAX_CONN = 10
DB_URI = os.getenv("DATABASE_URI", "postgresql://simugaz:simugaz@db/simugaz") DB_URI = os.getenv("DATABASE_URI", "postgresql://user:password@db/simugaz")
@lru_cache(maxsize=1) @lru_cache(maxsize=1)

View file

@ -0,0 +1 @@
DATABASE_URI='postgresql://simugaz_consumer:changemetoo@db/simugaz'

View file

@ -7,6 +7,7 @@ services:
networks: networks:
- lora-gateway_mqtt - lora-gateway_mqtt
- database - database
env_file: consumer.env
api: api:
build: ./backend build: ./backend
@ -18,6 +19,7 @@ services:
networks: networks:
- public - public
- database - database
env_file: api.env
webui: webui:
build: ./frontend build: ./frontend

View file

@ -0,0 +1,6 @@
CREATE USER simugaz_api WITH PASSWORD 'changeme';
GRANT SELECT ON TABLE device, reading TO simugaz_api;
CREATE USER simugaz_consumer WITH PASSWORD 'changemetoo';
GRANT SELECT, INSERT ON TABLE device TO simugaz_consumer;
GRANT INSERT ON TABLE reading TO simugaz_consumer;