Skip to content

docker::registry: accept Sensitive password - #1066

Merged
SugatD merged 3 commits into
puppetlabs:mainfrom
Scholdan:sensitive-registry-password
Oct 27, 2026
Merged

SugatD merged 3 commits into
puppetlabs:mainfrom
Scholdan:sensitive-registry-password

Conversation

@Scholdan

@Scholdan Scholdan commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

docker::registry only accepts Optional[String] $password, and the password reaches the catalog in three places: the defined-type parameter, the auth exec's environment (password=... and docker_auth=..., serialized in clear as Deferred('docker::env', ...) arguments), and the receipt file whose content is a crypt hash of a string embedding the password. All of it is stored by PuppetDB and visible in reports.

This PR lets password be Sensitive[String]. When it is (Linux):

  • the password is fed to docker login -u <user> --password-stdin <server> via printf '%s' '<pw>' | inside the exec command, which is wrapped in Sensitive (redacted in catalog, logs and reports); nothing password-related is put in the exec environment any more ($docker_auth was only needed at runtime on Windows);
  • the receipt file's content is Sensitive.

Plain String passwords behave exactly as before, so this is opt-in with no behaviour change for existing users. A Sensitive password fails compilation on Windows and together with email on Docker <= 1.10 (both would need the password in the exec environment). During login the password is briefly visible in the process list (ps); this is documented.

Additional Context

  • Root cause: exec environment is a parameter, so it cannot be marked Sensitive without a per-run agent warning; moving the secret into the Sensitive-aware command (using --password-stdin, the documented way to avoid -p) is the only sink that redacts cleanly. Tested on Puppet 8.4 agents: Exec[... auth] refreshes and logs in successfully, PuppetDB stores Docker::Registry without password and the exec without command.
  • Shell-quoting of the password is handled (' -> '\''), covered by the new spec case.

Related Issues (if any)

Partially addresses #789: supports Sensitive literal/Hiera values only. Deferred (and Sensitive(Deferred(...))) can't work in this design because pw_hash and the login command are built at compile time.

Checklist

  • 🟢 Spec tests. (spec/defines/registry_spec.rb: new case with Sensitive("se'cret"); shared example extended; spec/defines/registry_sensitive_spec.rb covers the Windows/email guards and receipt => true)
  • 🟢 Acceptance tests. (not run; no acceptance coverage exists for docker::registry credentials)
  • Manually verified. (puppet agent -t on Ubuntu hosts against a private registry; login succeeds, catalog in PuppetDB has no password)

@Scholdan
Scholdan requested a review from a team as a code owner August 25, 2026 08:21
@CLAassistant

CLAassistant commented Aug 25, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@jst-cyr

jst-cyr commented Aug 28, 2026

Copy link
Copy Markdown
Member

CI spec tests are failing because of puppetlabs-reboot having an invalid range to accept the latest release (6.0.0). It looks like this is going to be blocked until we resolve the range for reboot.

I've created #1068 to cover the change for the puppetlabs/reboot max version boundary.

@Scholdan

Copy link
Copy Markdown
Contributor Author

@jst-cyr #1068 got merged :)

@jst-cyr

jst-cyr commented Sep 10, 2026

Copy link
Copy Markdown
Member

@Scholdan : Looks like CI spec tests are running again! Green on basic spec tests, going to run the acceptance testing next.

@jst-cyr

jst-cyr commented Sep 10, 2026

Copy link
Copy Markdown
Member

Running CI tests for this PR here: #1071

@jst-cyr

jst-cyr commented Sep 11, 2026

Copy link
Copy Markdown
Member

Acceptance Test Results: https://github.com/puppetlabs/puppetlabs-docker/actions/runs/34531698608?pr=1071

Mostly green, with failures on CentOS 7, CentOS 8, Debian 10, Debian 11, and Ubuntu 20.04. These failures match exactly to the failures we are seeing with the nightly on main, so are not introduced by the changes in this PR.

From a testing perspective, looking good. Still needs engineering review when the team has time.

@jst-cyr
jst-cyr force-pushed the sensitive-registry-password branch from c5f944b to 84b5815 Compare September 23, 2026 15:00
@jst-cyr

jst-cyr commented Sep 23, 2026

Copy link
Copy Markdown
Member

There have been some updates in the main branch so I have rebased this PR and will rerun the tests to ensure we are still in the same state as before.

@jst-cyr

jst-cyr commented Sep 23, 2026

Copy link
Copy Markdown
Member

Running CI tests for this PR here: #1078

@jst-cyr

jst-cyr commented Sep 23, 2026

Copy link
Copy Markdown
Member

Acceptance Test Results: https://github.com/puppetlabs/puppetlabs-docker/actions/runs/35879454851?pr=1078

Mostly green, but failing on CentOS 8, Debian 10, and Debian 11. All of these failures match exactly to the failures currently seen in nightly tests against main (primarily infrastructure/provisioning issues, not functionality issues).

Still good after rebase, but still needs engineering review.

A Sensitive password is kept out of the catalog (and therefore PuppetDB
and reports): on Linux it is fed to 'docker login --password-stdin' from
a Sensitive exec command instead of the exec environment, $docker_auth is
no longer exported into the environment, and the receipt hash file content
is Sensitive. Plain String passwords, Windows, and the Docker <= 1.10
'-e email' path behave exactly as before.
@jst-cyr

jst-cyr commented Oct 16, 2026

Copy link
Copy Markdown
Member

Running CI tests for this PR in #1082

@jst-cyr

jst-cyr commented Oct 16, 2026

Copy link
Copy Markdown
Member

Acceptance Test Results: https://github.com/puppetlabs/puppetlabs-docker/actions/runs/38840580401/job/116997738583?pr=1082

Mostly green, failures against CentOS 8 and Debian 11, both provisioning issues that are also seen in nightly's against main. No new failures introduced by this PR. We are still good for engineering review here with latest changes pulled down and rebased.

@SugatD SugatD left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for this, @Scholdan. Keeping the password out of PuppetDB is worthwhile, and --password-stdin inside a Sensitive command is a sound approach. Plain-String users are unaffected, because every changed branch is gated on $_sensitive.

I ran this locally (Puppet 8.10, Ruby 3.2). The existing 80 specs pass, but I found two bugs where a Sensitive password is combined with other options, plus a few coverage and docs gaps. Details are inline (Windows: registry.pp:59; email + Docker <= 1.10: registry.pp:109; #789 scope: registry.pp:46).

Proposed fixes: commit 3eabfe4 adds the two guards (+9 lines in registry.pp) and specs for them, on top of this PR's commit. It is running in the draft PR #1085. With it applied, the registry specs show 82 examples / 0 failures, the full spec suite 3045 / 0, and rubocop and puppet-lint are clean. Without the registry.pp change, the two new guard specs fail. Acceptance on #1085 is green for Ubuntu 20.04/22.04, CentOS 7/9, Debian 10 and Windows 2016/2019/2022; CentOS 8 and Debian 11 fail the same way as nightly main (provisioning / docker-ce install).

Two test notes that don't fit an inline comment:

  • The new spec only covers receipt => false. A standalone receipt => true spec (in the commit above) passes on this PR's code, so that path is fine, just untested. It asserts Sensitive file content, an empty environment and a Sensitive command.
  • The receipt => true branch of spec/shared_examples/registry.rb (about L98-110) looks stale: it expects a literal /${local_user_home}/... path and a command without the ( ...; exit 1;) wrapper from registry.pp:131. No current case reaches it. Optional follow-up.

Also, no Litmus acceptance test exercises docker::registry credentials, so I haven't verified a live docker login.

Comment thread manifests/registry.pp
$docker_command = $docker::params::docker_command

$_password = if $password =~ Sensitive { $password.unwrap } else { $password }
$_sensitive = ($password =~ Sensitive) and ($facts['os']['family'] != 'windows')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: Sensitive on Windows exposes the password.

$_sensitive is only "Sensitive and not Windows". On Windows $_password is unwrapped (L58) and goes into $exec_env (L112-113), so it lands in the catalog in clear text. Reproduced locally: environment => [..., "password=TOPSECRET", "docker_auth=...password=TOPSECRET..."]. The docs say Windows is handled like a plain String, but a user who passes Sensitive(...) will expect it to stay out of the catalog.

The same variable also causes the email + Docker <= 1.10 problem (see my comment on L109). Suggest failing loudly rather than silently leaking or dropping the password:

Suggested change
$_sensitive = ($password =~ Sensitive) and ($facts['os']['family'] != 'windows')
$_sensitive = ($password =~ Sensitive) and ($facts['os']['family'] != 'windows')
if $password =~ Sensitive {
if $facts['os']['family'] == 'windows' {
fail('docker::registry: a Sensitive password is not supported on Windows (it would be exposed in the exec environment)')
}
if $email != undef and $version != undef and $version =~ /1[.][1-9]0?/ {
fail('docker::registry: a Sensitive password cannot be combined with `email` on Docker <= 1.10 (it needs the password in the environment)')
}
}

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.

Thanks, good catch. Cherry-picked your commit as 85ea052: a Sensitive password now fails on Windows instead of leaking into the exec environment.

Comment thread manifests/registry.pp
$docker_auth = "${title}${auth_environment}${auth_cmd}${local_user}"

if $auth_environment != '' {
if $_sensitive {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: the password is dropped from the environment on the legacy email path.

With a Sensitive password, email and Docker <= 1.10, the first branch (L87-89) still builds -p "${password_env}" and sets auth_environment, but if $_sensitive { $exec_env = $exec_environment } here drops password=.... Reproduced on Ubuntu: environment => [] with command docker login -u 'u' -p "${password}" -e 'a@b.c' example.com. ${password} expands to an empty string, so the login fails or runs with an empty password.

The PR description says this path behaves exactly as before, which isn't true for a Sensitive password. The guard suggested on L59 covers it; the alternative is to keep Sensitive off this branch and unwrap like before.

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.

Fixed by the same guard in 85ea052: Sensitive + email on Docker <= 1.10 now fails instead of running with an empty password. I've also corrected the PR description.

Comment thread manifests/registry.pp
Enum[present,absent] $ensure = 'present',
Optional[String] $username = undef,
Optional[String] $password = undef,
Optional[Variant[String, Sensitive[String]]] $password = undef,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

#789 is only partly addressed.

Variant[String, Sensitive[String]] still rejects Sensitive[Deferred], and $username (L44) is unchanged. #789 is about Deferred(...) and Sensitive(Deferred(...)). pw_hash and the interpolation in this define run at compile time, so Deferred can't work in this design. Please reword "Addresses #789" in the description to say this covers Sensitive literal and Hiera values only, and mention the Deferred limitation in the param docs.

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.

Agreed. Reworded the description to "Partially addresses #789" (Sensitive literal/Hiera values only) and documented in the @param password docs and README that Deferred isn't supported (2474d69).

Comment thread manifests/registry.pp
} elsif $username != undef and $_password != undef and $_sensitive {
# Password only in the (Sensitive) command, never in the environment.
$_password_quoted = regsubst($_password, "'", "'\\\\''", 'G')
$auth_cmd = "printf '%s' '${_password_quoted}' | ${docker_command} login -u '${username}' --password-stdin ${server}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Docs: the password is visible in ps for the duration of the login.

With printf '%s' '...' | docker login, the password is in the sh -c argv, so other local users can see it in ps. The old env var was only readable by the owner. This is still much better than PuppetDB and reports, but worth one sentence in the @param password docs (L15-21) and the README.

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.

Documented in the @param password docs and the README in 2474d69.

'pass_hash' => 'test1234',
'receipt' => false
},
'with username => user1, and password => Sensitive(secret)' => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Test gaps: this Sensitive case runs with receipt => false and also runs on Windows.

  • L71 uses 'receipt' => false, so the Sensitive file content (registry.pp:135) is never exercised.
  • This case also runs on every Windows platform, so it will start failing once the Windows guard (comment on registry.pp:59) is added. Skipping Sensitive cases on Windows inside the tests.each loop fixes that:
      tests.each do |title, local_params|
        # Sensitive passwords are rejected on Windows (see registry_sensitive_spec.rb)
        next if os.include?('windows') && local_params['password'].respond_to?(:unwrap)

The new spec/defines/registry_sensitive_spec.rb in the linked commit covers the two guards and receipt => true.

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.

Covered by your commit (85ea052): Windows is skipped for Sensitive cases and registry_sensitive_spec.rb adds the guard and receipt => true specs. I've left the stale shared-example branch for a follow-up, as you suggested.

Comment thread README.md
version: '<docker_version>'
```

To keep the password out of the catalog stored in PuppetDB and out of reports, pass it as `Sensitive`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please note here that Sensitive is Linux-only (and not usable with email on Docker <= 1.10), that Deferred values aren't supported, and that the password is briefly visible in the process list during login (see my comment on registry.pp:93).

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.

Done in 2474d69: Linux-only, no email on Docker <= 1.10, no Deferred, and the brief ps exposure.

SugatD and others added 2 commits October 27, 2026 10:29
…rd combinations

Fail on Windows and on Docker <= 1.10 with email, where a Sensitive
password would be exposed in or dropped from the exec environment.
Add specs for these guards and for Sensitive with receipt => true, and
make the shared example's file content assertion Sensitive-aware.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sensitive is Linux only, not combinable with email on Docker <= 1.10,
does not support Deferred, and the password is briefly visible in ps.
@Scholdan

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review, @SugatD! I cherry-picked your fix commit (85ea052, authorship kept) and added the doc updates in 2474d69. The description is updated too. #1085 can be closed now.

@SugatD

SugatD commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Thanks @Scholdan, the fixes look good. I verified the new head 2474d69 against the test branch from #1085:

Note that no acceptance test exercises docker::registry credentials, so a live docker login with a Sensitive password isn't covered by CI. The stale receipt => true branch in spec/shared_examples/registry.rb can be a follow-up.

From the testing side this is good to go. I'm closing #1085.

@SugatD
SugatD merged commit f63f8c7 into puppetlabs:main Oct 27, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[3.9.1] Deferred/Sensitive not woking for docker::registry

5 participants