Skip to content

fix: persist Docker environment variables into SSH login sessions - #127

Merged
avoidwork merged 3 commits into
mainfrom
feat/fix-ssh-env-var-forwarding
Jun 7, 2026
Merged

fix: persist Docker environment variables into SSH login sessions#127
avoidwork merged 3 commits into
mainfrom
feat/fix-ssh-env-var-forwarding

Conversation

@avoidwork

Copy link
Copy Markdown
Owner

What

Environment variables set by Docker (e.g. via docker-compose.yml environment: keys or --env) were not available in SSH login sessions, even though they worked fine inside the container for npm start.

Why

The previous entrypoint used eval to export env vars only within the entrypoint process context. When a user connected via SSH, sshd spawned a new login shell that sourced .profile, but the Docker-injected variables were not persisted anywhere accessible to that session.

How

Three changes:

  1. docker-entrypoint.sh — reads env vars from /proc/self/environ, filters internal vars, and writes them as export KEY=value statements to /etc/madz-env.sh. Creates a profile.d script so every login shell sources this file.

  2. Dockerfile.profile now sources /etc/profile.d/madz-env.sh before running npm start, ensuring env vars are available both in SSH sessions and when npm starts.

  3. sshd_config — replaced the hardcoded AcceptEnv OPENAI_API_KEY, AcceptEnv OPENROUTER_API_KEY, etc. list with AcceptEnv * for development simplicity.

Testing

  • All tests passing (1054/1054)
  • Lint and formatting passing
  • Coverage maintained

Checklist

  • All JSDoc annotations present on public APIs
  • Unit tests written and passing
  • oxlint and oxfmt pass
  • No hardcoded secrets or credentials introduced
  • 100% code coverage maintained

- Write container env vars to /etc/madz-env.sh at entrypoint startup
  so they are sourced into every SSH user session via profile.d
- Update .profile to source /etc/profile.d/madz-env.sh
- Replace hardcoded AcceptEnv list with AcceptEnv * for development
@avoidwork avoidwork self-assigned this Jun 7, 2026
@avoidwork
avoidwork enabled auto-merge (squash) June 7, 2026 14:57
@avoidwork
avoidwork disabled auto-merge June 7, 2026 14:58
avoidwork added 2 commits June 7, 2026 11:01
- Write container env vars to /etc/madz-env.sh at entrypoint startup
  so they are sourced into every SSH user session via profile.d
- Update .profile to source /etc/profile.d/madz-env.sh
- Add AcceptEnv * to sshd_config for development

Key fix: use 'tr /proc/self/environ' instead of command substitution
to avoid command-line argument length limits that silently truncated
the env dump.
@avoidwork
avoidwork force-pushed the feat/fix-ssh-env-var-forwarding branch from 58de7f5 to b46c9fc Compare June 7, 2026 15:43
@avoidwork
avoidwork enabled auto-merge (squash) June 7, 2026 15:43
@avoidwork
avoidwork merged commit f7a500f into main Jun 7, 2026
2 checks passed
@avoidwork
avoidwork deleted the feat/fix-ssh-env-var-forwarding branch June 7, 2026 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant