Skip to content

MINIO_CONFIG_ENV_FILE silently ignores assignments with spaces around = #65

Description

@Vonng

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:

  1. A cold start may work because systemd parses EnvironmentFile= itself and installs KEY correctly.
  2. mc admin service restart executes the server again with the current process environment rather than asking systemd to reread the file.
  3. A changed line such as KEY = new installs KEY while the inherited KEY=old remains active.
  4. 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

  1. Continue to ignore blank lines and lines whose first non-whitespace character is #.
  2. Recognize export only when followed by assignment-separating whitespace; a valid bare name such as exportFOO must not be rewritten to FOO.
  3. Split on the first = only, so values may contain additional = characters.
  4. Apply strings.TrimSpace to the key and value tokens.
  5. Strip one matching pair of outer single or double quotes after token trimming. This preserves whitespace inside the quotes.
  6. Keep empty values valid.

Validation and diagnostics

  1. Accept portable shell/systemd-style environment names only: [A-Za-z_][A-Za-z0-9_]*.
  2. Do not restrict names to MINIO_; syntactically valid variables used by embedded components or dependencies remain supported.
  3. Reject NUL in a value before applying any entry.
  4. Wrap parser failures as <path>:<1-based-line>: <reason>.
  5. Report the invalid key where useful, but never include the assignment value in an error.
  6. Check every os.Setenv result and fail startup if applying a validated entry still fails.
  7. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions