From 86f6497a647c9217f278019084dfb2c003f1fe2c Mon Sep 17 00:00:00 2001 From: brice Date: Thu, 5 Nov 2026 21:52:26 +0000 Subject: [PATCH] Split secrets out of .env into .env.secrets Same split as flyfun-weather and flyfun-apps: plain configuration stays in .env, secrets (DATABASE_URL, JWT_SECRET, GOOGLE_CLIENT_SECRET, APPLE_PRIVATE_KEY) move to .env.secrets, which the owner's config repo keeps sops-encrypted and syncfiles decrypts on the host (mode 600). - docker-compose: .env.secrets as an optional second env_file (only HOST_DATA_DIR is interpolated, so nothing is blanked by the split). - .gitignore / .dockerignore: .env.* ignored, samples re-included. The old `.env` entries did not match .env.secrets (public repo; image context). - scripts/asc.py, scripts/play.py: load .env.secrets after .env. - .env.sample split, new .env.secrets.sample. No code path changes: the app reads os.environ (compose in prod; the dev server sets ENVIRONMENT=development and loads no .env). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01W8cMQN8Qa8jZk17v72poeo --- .dockerignore | 1 + .env.sample | 13 +++++++++---- .env.secrets.sample | 14 ++++++++++++++ .gitignore | 4 ++++ docker-compose.yml | 6 +++++- scripts/asc.py | 1 + scripts/play.py | 1 + 7 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 .env.secrets.sample diff --git a/.dockerignore b/.dockerignore index 307dea7..a92f928 100644 --- a/.dockerignore +++ b/.dockerignore @@ -29,3 +29,4 @@ __pycache__/ .DS_Store **/.DS_Store .env +.env.* diff --git a/.env.sample b/.env.sample index d609f93..9f856ae 100644 --- a/.env.sample +++ b/.env.sample @@ -1,11 +1,16 @@ +# Plain configuration. Secrets (DB URL with its password, JWT secret, OAuth client +# secrets, private keys) go in .env.secrets next to it: see .env.secrets.sample. +# docker compose passes both files to the container; scripts/asc.py and play.py load +# .env then .env.secrets. Each key belongs in exactly one of the two. + # Required in production ENVIRONMENT=production -DATABASE_URL=mysql+pymysql://user:pass@shared-mysql:3306/flyfun -JWT_SECRET=change-me-in-production +# DATABASE_URL: in .env.secrets +# JWT_SECRET: in .env.secrets # OAuth (shared with flyfun-weather — same credentials) GOOGLE_CLIENT_ID= -GOOGLE_CLIENT_SECRET= +# GOOGLE_CLIENT_SECRET: in .env.secrets # Apple Sign In – native iOS token validation APPLE_APP_IDS=net.ro-z.flyfun-forms @@ -14,7 +19,7 @@ APPLE_APP_IDS=net.ro-z.flyfun-forms # APPLE_CLIENT_ID= # APPLE_TEAM_ID= # APPLE_KEY_ID= -# APPLE_PRIVATE_KEY= +# APPLE_PRIVATE_KEY: in .env.secrets # Optional: airports.db for name resolution # AIRPORTS_DB=/app/data/airports.db diff --git a/.env.secrets.sample b/.env.secrets.sample new file mode 100644 index 0000000..e5b4289 --- /dev/null +++ b/.env.secrets.sample @@ -0,0 +1,14 @@ +# FlyFun Forms secrets: copy to .env.secrets (gitignored, keep it mode 600) and fill in. +# Plain configuration is in .env (see .env.sample). docker compose passes both files to +# the container. In the owner's setup this file is sops-encrypted in the config repo and +# decrypted by syncfiles on the host that uses it: don't hand-edit it there. + +# Required in production +DATABASE_URL=mysql+pymysql://user:pass@shared-mysql:3306/flyfun +JWT_SECRET=change-me-in-production + +# OAuth (shared with flyfun-weather: same credentials; GOOGLE_CLIENT_ID is in .env) +GOOGLE_CLIENT_SECRET= + +# Optional: Apple web OAuth private key (only if using the browser-based flow) +# APPLE_PRIVATE_KEY= diff --git a/.gitignore b/.gitignore index 2b4873f..45cce7e 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,10 @@ __pycache__/ *.pyc *.egg-info/ .env +# .env.secrets (sops-managed secrets) and any other .env.* file; the samples stay tracked +.env.* +!.env.sample +!.env.secrets.sample # App Store Connect keys live in ~/.appstoreconnect/private_keys/; this guards # against an accidental `git add` of a downloaded AuthKey_*.p8. *.p8 diff --git a/docker-compose.yml b/docker-compose.yml index 37d37ef..2b1a73c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,7 +8,11 @@ services: # published ports bypass the host firewall, so "8030:8030" would expose # plain HTTP (no TLS, no Caddy limits) on the public interface. - "127.0.0.1:8030:8030" - env_file: .env + env_file: + - .env + # secrets split out of .env (sops-managed on the host); optional until prod has it + - path: .env.secrets + required: false environment: - ENVIRONMENT=production volumes: diff --git a/scripts/asc.py b/scripts/asc.py index 248551e..cd7598e 100644 --- a/scripts/asc.py +++ b/scripts/asc.py @@ -815,6 +815,7 @@ def main() -> None: if load_dotenv is not None: load_dotenv(Path(__file__).resolve().parent.parent / ".env") + load_dotenv(Path(__file__).resolve().parent.parent / ".env.secrets") # sops-managed secrets, if present config = AscConfig.from_env() asc = Asc( diff --git a/scripts/play.py b/scripts/play.py index bcb61e3..56a1b00 100644 --- a/scripts/play.py +++ b/scripts/play.py @@ -505,6 +505,7 @@ def main() -> None: args = build_parser().parse_args() if load_dotenv is not None: load_dotenv(REPO / ".env") + load_dotenv(REPO / ".env.secrets") # sops-managed secrets, if present key = Path(os.environ.get("PLAY_SERVICE_ACCOUNT_JSON") or DEFAULT_KEY).expanduser() play = Play(os.environ.get("PLAY_PACKAGE_NAME") or DEFAULT_PACKAGE, key, getattr(args, "dry_run", False)) COMMANDS[args.command](play, args)