Skip to content

dockerfile: check PSW variables for secrets - #7286

Merged
tonistiigi merged 3 commits into
moby:masterfrom
hezhizhen:codex/dockerfile-check-psw
Oct 21, 2026
Merged

tonistiigi merged 3 commits into
moby:masterfrom
hezhizhen:codex/dockerfile-check-psw

Conversation

@hezhizhen

Copy link
Copy Markdown
Contributor

Recognize psw as a sensitive name token so Jenkins-style _PSW variables trigger SecretsUsedInArgOrEnv for both ARG and ENV.

Fixes #6064.

The regression covers case-insensitive matching, token boundaries, and allowlisted names. It fails without the change and passes with it. Related frontend package tests and golangci-lint v2.14.0 pass.

Docker-based validation could not run because the Docker daemon is unavailable.

AI disclosure: OpenAI Codex prepared the code change, regression test, and PR description.

"password",
"pword",
"passwd",
"psw",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this only be detected with a _ prefix? So that something like DIPSWITCH doesn't get flagged?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing regex already requires _ or a string boundary on both sides of the token ((?:_|^) and (?:_|$)), so DIPSWITCH does not match. I verified this for both ARG and ENV.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added DIPSWITCH cases for both ARG and ENV in 35ed6ea. The regression test passes, confirming neither triggers a warning.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! Thx; missed that it already has the underscore handling 🙈👍

Signed-off-by: Zhizhen He <hezhizhen.yi@gmail.com>
Signed-off-by: Zhizhen He <hezhizhen.yi@gmail.com>
@hezhizhen
hezhizhen force-pushed the codex/dockerfile-check-psw branch from 35ed6ea to 04c80e3 Compare October 16, 2026 14:41
"github.com/stretchr/testify/require"
)

func TestSecretsUsedInArgOrEnvPSW(t *testing.T) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already testSecretsUsedInArgOrEnv test for this.

Signed-off-by: Zhizhen He <hezhizhen.yi@gmail.com>
@tonistiigi
tonistiigi merged commit ce2b38c into moby:master Oct 21, 2026
212 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dockerfile should check for ARGs or ENVs that ends with _PSW

3 participants