Skip to content

Reject unsupported *_FILE variables in Docker Compose support - #52120

Open
DDINGJOO wants to merge 1 commit into
spring-projects:mainfrom
DDINGJOO:docker-compose-reject-file-env
Open

DDINGJOO wants to merge 1 commit into
spring-projects:mainfrom
DDINGJOO:docker-compose-reject-file-env

Conversation

@DDINGJOO

@DDINGJOO DDINGJOO commented Oct 9, 2026

Copy link
Copy Markdown

The official PostgreSQL, MySQL, MariaDB, ClickHouse and Neo4j images accept credentials through *_FILE variables (Docker secrets). Docker Compose support doesn't read those files, which was decided in #37188. The MongoDB and Elasticsearch environments already reject them with a clear ... is not supported message, but the other environments silently ignore them:

Compose environment Before
POSTGRES_PASSWORD_FILE No PostgreSQL password found, which is misleading because a password was provided
POSTGRES_USER_FILE Silently falls back to the postgres user
NEO4J_AUTH_FILE Silently falls back to AuthTokens.none()
MYSQL_*_FILE, MARIADB_*_FILE, CLICKHOUSE_PASSWORD_FILE Misleading No ... password found / No ..._DATABASE defined, or a silent default user

In the silent cases the application starts and only fails later, when it connects.

This PR makes these environments fail fast with <NAME>_FILE is not supported, matching MongoDB and Elasticsearch. The check only applies when the plain variable that would have been used is absent. Setups that combine a *_FILE variable with a plain variable that Spring Boot actually uses keep working, for example MYSQL_ROOT_PASSWORD_FILE with MYSQL_USER and MYSQL_PASSWORD, or POSTGRES_PASSWORD_FILE with POSTGRES_HOST_AUTH_METHOD=trust. Tests cover both the rejected and the unchanged cases.

The JDBC and R2DBC copies of each environment class are updated identically.

I looked at the official images' entrypoints to confirm which *_FILE variables they support (file_env in docker-library postgres/mysql, _mariadb_file_env in mariadb-docker, CLICKHOUSE_PASSWORD_FILE in the ClickHouse entrypoint, and the generic NEO4J_*_FILE handling in the Neo4j entrypoint).

The official PostgreSQL, MySQL, MariaDB, ClickHouse and Neo4j images
allow credentials to be provided through *_FILE variables (Docker
secrets). Docker Compose support does not read these files, as decided
in spring-projectsgh-37188, and the MongoDB and Elasticsearch environments already
reject them with a clear "is not supported" message.

The other environments silently ignored them instead. Depending on the
variable, this either produced a misleading error ("No PostgreSQL
password found" when POSTGRES_PASSWORD_FILE is set) or connected with
a default value: POSTGRES_USER_FILE fell back to the "postgres" user
and NEO4J_AUTH_FILE fell back to no authentication, so the failure only
surfaced later at connection time.

Fail fast with a "<NAME>_FILE is not supported" message in these cases.
The check only applies when the plain variable that would have been
used is absent, so setups that combine a *_FILE variable with a plain
one that Spring Boot actually uses (for example MYSQL_ROOT_PASSWORD_FILE
with MYSQL_USER and MYSQL_PASSWORD) keep working.

Signed-off-by: DDINGJOO <173995233+DDINGJOO@users.noreply.github.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue that has not yet been triaged. Contributions will not be accepted. label Oct 9, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue that has not yet been triaged. Contributions will not be accepted.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants