Skip to content

feat: add Docker secrets support for sensitive env vars#276

Open
rafaelfariasbsb wants to merge 1 commit intoglpi-project:mainfrom
rafaelfariasbsb:feat/docker-secrets-support
Open

feat: add Docker secrets support for sensitive env vars#276
rafaelfariasbsb wants to merge 1 commit intoglpi-project:mainfrom
rafaelfariasbsb:feat/docker-secrets-support

Conversation

@rafaelfariasbsb
Copy link

Summary

  • Add _FILE suffix convention for sensitive environment variables (GLPI_DB_PASSWORD_FILE, GLPI_DB_USER_FILE, etc.)
  • Auto-detect secrets from /run/secrets/ (Docker Swarm, Kubernetes, Podman)
  • Fallback to standard environment variables for backward compatibility
  • Error handling for conflicts (both VAR and VAR_FILE set) and missing files

Follows the standard pattern used by official Docker images (MySQL, MariaDB, PostgreSQL), as discussed in #194.

Changes

File Description
glpi/files/opt/glpi/entrypoint/load-secrets.sh New script with file_env() function for secret resolution
glpi/files/opt/glpi/entrypoint.sh Source load-secrets.sh before other entrypoint scripts
README.md Documentation with examples for Docker Compose and Docker Swarm

Resolution order

  1. VAR_FILE — reads content from the file path specified
  2. /run/secrets/VAR — auto-detection of Docker Swarm / Kubernetes / Podman secrets
  3. VAR — standard environment variable (existing behavior, no breaking change)

Test plan

  • Env var fallback works (existing behavior preserved)
  • _FILE variable reads content from file and unsets _FILE var
  • Conflict detection: error when both VAR and VAR_FILE are set
  • Missing file detection: error with clear message when file doesn't exist
  • Docker image builds successfully

Closes #194

🤖 Generated with Claude Code

Comment on lines +133 to +171
```yaml
services:
glpi:
image: "glpi/glpi:latest"
environment:
GLPI_DB_HOST: db
GLPI_DB_PORT: 3306
GLPI_DB_NAME: glpi
GLPI_DB_USER: glpi
GLPI_DB_PASSWORD_FILE: /run/secrets/db_password
volumes:
- glpi_data:/var/glpi
- ./db_password.txt:/run/secrets/db_password:ro
depends_on:
- db
ports:
- "80:80"
```

#### Example with Docker Swarm

```yaml
services:
glpi:
image: "glpi/glpi:latest"
secrets:
- db_password
environment:
GLPI_DB_HOST: db
GLPI_DB_PORT: 3306
GLPI_DB_NAME: glpi
GLPI_DB_USER: glpi
# No need to set GLPI_DB_PASSWORD or GLPI_DB_PASSWORD_FILE.
# The secret is automatically detected at /run/secrets/GLPI_DB_PASSWORD.

secrets:
db_password:
file: ./db_password.txt
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think docker-compose could also have secrets.
So the section Example with Docker Swarm is a bit misleading,
We could propose both, and I'd say even more the swarm one should be the first proposed as it's cleaner.

In the example we could also explain various secrets possible settings like :

...
secrets:
  # Various secret source is possible
  db_password: 
    file: ./db_password.txt # From a file
    # environment: DB_PWD # From an env var
    # external: true # External secret

Add _FILE suffix convention and /run/secrets/ auto-detection for database
credentials, following the standard pattern used by official Docker images
(MySQL, MariaDB, PostgreSQL). This avoids exposing sensitive values in
environment variables, docker inspect, and process listings.

Closes glpi-project#194
@rafaelfariasbsb rafaelfariasbsb force-pushed the feat/docker-secrets-support branch from 9cb3d4d to 3aec3ea Compare February 26, 2026 10:41
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.

Add Variable GLPI_DB_PASSWORD_FILE like docker secret as do it MariaDB image

3 participants