Repository navigation
docker::registry: accept Sensitive password - #1066
Conversation
|
CI spec tests are failing because of I've created #1068 to cover the change for the puppetlabs/reboot max version boundary. |
|
@Scholdan : Looks like CI spec tests are running again! Green on basic spec tests, going to run the acceptance testing next. |
|
Running CI tests for this PR here: #1071 |
|
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. |
c5f944b to
84b5815
Compare
|
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. |
|
Running CI tests for this PR here: #1078 |
|
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.
84b5815 to
378f2f2
Compare
|
Running CI tests for this PR in #1082 |
|
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
left a comment
There was a problem hiding this comment.
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 standalonereceipt => truespec (in the commit above) passes on this PR's code, so that path is fine, just untested. It asserts Sensitive file content, an emptyenvironmentand a Sensitivecommand. - The
receipt => truebranch ofspec/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 fromregistry.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.
| $docker_command = $docker::params::docker_command | ||
|
|
||
| $_password = if $password =~ Sensitive { $password.unwrap } else { $password } | ||
| $_sensitive = ($password =~ Sensitive) and ($facts['os']['family'] != 'windows') |
There was a problem hiding this comment.
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:
| $_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)') | |
| } | |
| } |
There was a problem hiding this comment.
Thanks, good catch. Cherry-picked your commit as 85ea052: a Sensitive password now fails on Windows instead of leaking into the exec environment.
| $docker_auth = "${title}${auth_environment}${auth_cmd}${local_user}" | ||
|
|
||
| if $auth_environment != '' { | ||
| if $_sensitive { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| Enum[present,absent] $ensure = 'present', | ||
| Optional[String] $username = undef, | ||
| Optional[String] $password = undef, | ||
| Optional[Variant[String, Sensitive[String]]] $password = undef, |
There was a problem hiding this comment.
#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.
| } 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}" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Documented in the @param password docs and the README in 2474d69.
| 'pass_hash' => 'test1234', | ||
| 'receipt' => false | ||
| }, | ||
| 'with username => user1, and password => Sensitive(secret)' => { |
There was a problem hiding this comment.
Test gaps: this Sensitive case runs with receipt => false and also runs on Windows.
- L71 uses
'receipt' => false, so the Sensitive filecontent(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 thetests.eachloop 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.
There was a problem hiding this comment.
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.
| version: '<docker_version>' | ||
| ``` | ||
|
|
||
| To keep the password out of the catalog stored in PuppetDB and out of reports, pass it as `Sensitive` |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Done in 2474d69: Linux-only, no email on Docker <= 1.10, no Deferred, and the brief ps exposure.
…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.
|
Thanks @Scholdan, the fixes look good. I verified the new head
Note that no acceptance test exercises From the testing side this is good to go. I'm closing #1085. |
Summary
docker::registryonly acceptsOptional[String] $password, and the password reaches the catalog in three places: the defined-type parameter, the auth exec'senvironment(password=...anddocker_auth=..., serialized in clear asDeferred('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
passwordbeSensitive[String]. When it is (Linux):docker login -u <user> --password-stdin <server>viaprintf '%s' '<pw>' |inside the execcommand, which is wrapped inSensitive(redacted in catalog, logs and reports); nothing password-related is put in the execenvironmentany more ($docker_authwas only needed at runtime on Windows);contentisSensitive.Plain
Stringpasswords 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 withemailon 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
environmentis a parameter, so it cannot be marked Sensitive without a per-run agent warning; moving the secret into the Sensitive-awarecommand(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 storesDocker::Registrywithoutpasswordand the exec withoutcommand.'->'\''), covered by the new spec case.Related Issues (if any)
Partially addresses #789: supports
Sensitiveliteral/Hiera values only.Deferred(andSensitive(Deferred(...))) can't work in this design becausepw_hashand the login command are built at compile time.Checklist
spec/defines/registry_spec.rb: new case withSensitive("se'cret"); shared example extended;spec/defines/registry_sensitive_spec.rbcovers the Windows/email guards andreceipt => true)docker::registrycredentials)puppet agent -ton Ubuntu hosts against a private registry; login succeeds, catalog in PuppetDB has no password)