Expected Behavior
MINIO_CONFIG_ENV_FILE should accept the same narrow assignment forms that its existing parser already advertises, while treating insignificant whitespace around the first = as formatting:
MINIO_ROOT_USER = minio
export MINIO_ROOT_PASSWORD = "minio secret"
Whitespace outside the assignment should be discarded. Whitespace enclosed by a matching pair of single or double quotes must remain part of the parsed value.
Malformed assignments must stop startup with a diagnostic that identifies the file and line without logging the value.
Current Behavior
parsEnvEntry trims the complete line, splits once on =, and stores both tokens without trimming them individually. KEY = VALUE therefore becomes the environment entry "KEY "=" VALUE".
On Unix, the trailing space does not make os.Setenv fail. The new entry is installed under the wrong name and every exact lookup of KEY misses it. loadEnvVarsFromFiles also discards the os.Setenv result, so there is no error or warning.
This is especially deceptive with a systemd deployment:
- A cold start may work because systemd parses
EnvironmentFile= itself and installs KEY correctly.
mc admin service restart executes the server again with the current process environment rather than asking systemd to reread the file.
- A changed line such as
KEY = new installs KEY while the inherited KEY=old remains active.
- The restart succeeds but continues using the stale value.
Upstream report: minio#21682.
Impact
This is a configuration-integrity and fail-safe defect, not a direct privilege-escalation primitive: modifying the environment file already requires operator-level access. Its consequences can nevertheless be security-relevant because credential, KMS, identity-provider, audit-target, and trusted-proxy changes can remain stale or fall back to a default with no diagnostic.
The Helm chart also exposes this parser through extraSecret and /tmp/silo-config-env/config.env, so the affected path is part of SILO's supported deployment surface.
Root Cause
parsEnvEntry trims only the complete line, not the key/value tokens.
- Environment-variable names are not syntax-validated.
minioEnvironFromFile returns parse errors without a file line number.
- The malformed-entry error includes the complete input line and can disclose a password or token.
loadEnvVarsFromFiles ignores os.Setenv errors.
- The
export prefix is removed with strings.TrimPrefix, even when it is not a standalone token.
Proposed Resolution
Parsing contract
- Continue to ignore blank lines and lines whose first non-whitespace character is
#.
- Recognize
export only when followed by assignment-separating whitespace; a valid bare name such as exportFOO must not be rewritten to FOO.
- Split on the first
= only, so values may contain additional = characters.
- Apply
strings.TrimSpace to the key and value tokens.
- Strip one matching pair of outer single or double quotes after token trimming. This preserves whitespace inside the quotes.
- Keep empty values valid.
Validation and diagnostics
- Accept portable shell/systemd-style environment names only:
[A-Za-z_][A-Za-z0-9_]*.
- Do not restrict names to
MINIO_; syntactically valid variables used by embedded components or dependencies remain supported.
- Reject NUL in a value before applying any entry.
- Wrap parser failures as
<path>:<1-based-line>: <reason>.
- Report the invalid key where useful, but never include the assignment value in an error.
- Check every
os.Setenv result and fail startup if applying a validated entry still fails.
- Preserve the existing all-or-nothing parse behavior: no entries are applied until the complete file has parsed successfully.
Regression coverage
Add table-driven tests for:
- spaces and tabs on either side of
=;
- bare and standalone
export assignments;
exportFOO remaining a bare variable name;
- single- and double-quoted values with leading, trailing, and interior spaces;
- unquoted outer whitespace trimming;
- empty values and values containing additional
= characters;
- valid underscore/digit placement;
- empty, digit-leading, hyphenated, and whitespace-containing names;
- NUL in a name or value;
- missing
=;
- exact file/line diagnostics and proof that a secret value is not present in the error.
Verification gate:
go test ./cmd -run 'Test_(parsEnvEntry|minioEnvironFromFile)' -count=1
go test ./cmd -count=1
go vet ./cmd
gofmt -l cmd/common-main.go cmd/common-main_test.go
git diff --check
Compatibility and Non-goals
The intended behavior change is narrow: assignments that previously created unusable whitespace-bearing keys become effective, while malformed names fail loudly instead of being silently ignored. A value that intentionally needs leading or trailing whitespace must quote it.
This issue does not claim full systemd EnvironmentFile= compatibility. Backslash continuations, multiline quoted values, escape processing, semicolon comments, and inline comments remain out of scope and should be handled separately.
Variable removal across mc admin service restart is also a separate inherited-environment problem; this parser fix corrects assignments that are present in the file.
Prior Art
Expected Behavior
MINIO_CONFIG_ENV_FILEshould accept the same narrow assignment forms that its existing parser already advertises, while treating insignificant whitespace around the first=as formatting:Whitespace outside the assignment should be discarded. Whitespace enclosed by a matching pair of single or double quotes must remain part of the parsed value.
Malformed assignments must stop startup with a diagnostic that identifies the file and line without logging the value.
Current Behavior
parsEnvEntrytrims the complete line, splits once on=, and stores both tokens without trimming them individually.KEY = VALUEtherefore becomes the environment entry"KEY "=" VALUE".On Unix, the trailing space does not make
os.Setenvfail. The new entry is installed under the wrong name and every exact lookup ofKEYmisses it.loadEnvVarsFromFilesalso discards theos.Setenvresult, so there is no error or warning.This is especially deceptive with a systemd deployment:
EnvironmentFile=itself and installsKEYcorrectly.mc admin service restartexecutes the server again with the current process environment rather than asking systemd to reread the file.KEY = newinstallsKEYwhile the inheritedKEY=oldremains active.Upstream report: minio#21682.
Impact
This is a configuration-integrity and fail-safe defect, not a direct privilege-escalation primitive: modifying the environment file already requires operator-level access. Its consequences can nevertheless be security-relevant because credential, KMS, identity-provider, audit-target, and trusted-proxy changes can remain stale or fall back to a default with no diagnostic.
The Helm chart also exposes this parser through
extraSecretand/tmp/silo-config-env/config.env, so the affected path is part of SILO's supported deployment surface.Root Cause
parsEnvEntrytrims only the complete line, not the key/value tokens.minioEnvironFromFilereturns parse errors without a file line number.loadEnvVarsFromFilesignoresos.Setenverrors.exportprefix is removed withstrings.TrimPrefix, even when it is not a standalone token.Proposed Resolution
Parsing contract
#.exportonly when followed by assignment-separating whitespace; a valid bare name such asexportFOOmust not be rewritten toFOO.=only, so values may contain additional=characters.strings.TrimSpaceto the key and value tokens.Validation and diagnostics
[A-Za-z_][A-Za-z0-9_]*.MINIO_; syntactically valid variables used by embedded components or dependencies remain supported.<path>:<1-based-line>: <reason>.os.Setenvresult and fail startup if applying a validated entry still fails.Regression coverage
Add table-driven tests for:
=;exportassignments;exportFOOremaining a bare variable name;=characters;=;Verification gate:
Compatibility and Non-goals
The intended behavior change is narrow: assignments that previously created unusable whitespace-bearing keys become effective, while malformed names fail loudly instead of being silently ignored. A value that intentionally needs leading or trailing whitespace must quote it.
This issue does not claim full systemd
EnvironmentFile=compatibility. Backslash continuations, multiline quoted values, escape processing, semicolon comments, and inline comments remain out of scope and should be handled separately.Variable removal across
mc admin service restartis also a separate inherited-environment problem; this parser fix corrects assignments that are present in the file.Prior Art