-
Notifications
You must be signed in to change notification settings - Fork 25
feat: add Docker secrets support for sensitive env vars #276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rafaelfariasbsb
wants to merge
1
commit into
glpi-project:main
Choose a base branch
from
rafaelfariasbsb:feat/docker-secrets-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| #!/bin/bash | ||
| set -e -u -o pipefail | ||
|
|
||
| # Docker secrets support for GLPI | ||
| # Resolves sensitive environment variables from files (Docker secrets, Kubernetes secrets, or _FILE suffix). | ||
| # | ||
| # Priority order: | ||
| # 1. VAR_FILE environment variable (points to a file containing the value) | ||
| # 2. /run/secrets/VAR file (Docker Swarm / Kubernetes / Podman) | ||
| # 3. Existing environment variable value (default behavior) | ||
|
|
||
| # file_env - Read an environment variable from a file, following the Docker _FILE convention. | ||
| # Usage: file_env VAR [DEFAULT] | ||
| # | ||
| # Based on the pattern used by official Docker images (mysql, mariadb, postgres). | ||
| file_env() { | ||
| local var="$1" | ||
| local default="${2:-}" | ||
|
|
||
| local file_var="${var}_FILE" | ||
| local val="$default" | ||
|
|
||
| # Get current values | ||
| local current_val="${!var:-}" | ||
| local file_val="${!file_var:-}" | ||
|
|
||
| if [ -n "$current_val" ] && [ -n "$file_val" ]; then | ||
| echo "ERROR: Both $var and $file_var are set. These are mutually exclusive." | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [ -n "$file_val" ]; then | ||
| # _FILE variable is set, read from the specified file | ||
| if [ ! -f "$file_val" ]; then | ||
| echo "ERROR: Secret file '$file_val' specified in $file_var does not exist." | ||
| exit 1 | ||
| fi | ||
| if [ ! -r "$file_val" ]; then | ||
| echo "ERROR: Secret file '$file_val' specified in $file_var is not readable." | ||
| exit 1 | ||
| fi | ||
| val="$(< "$file_val")" | ||
| unset "$file_var" | ||
| elif [ -f "/run/secrets/$var" ]; then | ||
| # Docker Swarm / Kubernetes / Podman secret | ||
| val="$(< "/run/secrets/$var")" | ||
| elif [ -n "$current_val" ]; then | ||
| # Use existing environment variable | ||
| val="$current_val" | ||
| fi | ||
|
|
||
| export "$var"="$val" | ||
| } | ||
|
|
||
| # List of environment variables that support secret file resolution | ||
| secret_vars=( | ||
| GLPI_DB_HOST | ||
| GLPI_DB_PORT | ||
| GLPI_DB_NAME | ||
| GLPI_DB_USER | ||
| GLPI_DB_PASSWORD | ||
| ) | ||
|
|
||
| for var in "${secret_vars[@]}"; do | ||
| file_env "$var" | ||
| done |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
swarmone should be the first proposed as it's cleaner.In the example we could also explain various secrets possible settings like :