feat(config): support env substitution#4007
Draft
AkashKumar7902 wants to merge 1 commit into
Draft
Conversation
AkashKumar7902
force-pushed
the
issue-2521-config-env
branch
from
April 25, 2026 20:22
955a800 to
60196fb
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds environment variable substitution for string values in zot configuration files (supporting $VAR and ${VAR}), extends the same substitution behavior to referenced secret/config files (OpenID/OAuth2 credentials, LDAP credentials, session keys), and documents the syntax with an accompanying test suite update.
Changes:
- Introduce a Viper/mapstructure decode hook that expands
$VAR/${VAR}in all string fields and fails config loading when referenced env vars are unset. - Apply the same substitution to referenced secret files by adding the hook during secret-file unmarshalling.
- Factor config-file reading (including extensionless-file probing) into a shared helper and document the new behavior in
examples/README.md.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/cli/server/root.go | Switches to shared config reader; applies env-substitution decode hook to main config and secret-file loading. |
| pkg/cli/server/root_test.go | Adds coverage for env substitution in main config + OpenID credentials file, and failure on missing env var. |
| pkg/cli/server/config_loader.go | Adds shared config-file reader and env expansion implementation used via decode hook. |
| examples/README.md | Documents env var substitution syntax and behavior. |
Comments suppressed due to low confidence (1)
pkg/cli/server/root.go:1258
- When env substitution fails, the decode hook returns an error that already wraps zerr.ErrBadConfig. Returning errors.Join(zerr.ErrBadConfig, err) here will duplicate the ErrBadConfig message (errors.Join concatenates messages), producing user-facing errors like "invalid server config\ninvalid server config: …".
if err := viperInstance.Unmarshal(v, metadataConfig(metaData), viper.DecodeHook(envSubstitutionDecodeHook())); err != nil {
logger.Error().Err(err).Str("path", path).Msg("failed to unmarshal secret file config")
return errors.Join(zerr.ErrBadConfig, err)
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #2521
Validation