Repository navigation
docker::registry: accept Sensitive password #1066
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -13,7 +13,12 @@ | |||||||||||||||||||||||
| # | ||||||||||||||||||||||||
| # @param password | ||||||||||||||||||||||||
| # Password for authentication to private Docker registry. Leave undef if | ||||||||||||||||||||||||
| # auth is not required. | ||||||||||||||||||||||||
| # auth is not required. May be given as Sensitive: on Linux the password is | ||||||||||||||||||||||||
| # then fed to `docker login --password-stdin` from a Sensitive exec command | ||||||||||||||||||||||||
| # instead of the exec environment, and the receipt hash is Sensitive too, so | ||||||||||||||||||||||||
| # it is neither stored in the catalog (PuppetDB) nor shown in reports. On | ||||||||||||||||||||||||
| # Windows (and for Docker <= 1.10 with `email`) the value is unwrapped and | ||||||||||||||||||||||||
| # handled like a plain String. | ||||||||||||||||||||||||
| # | ||||||||||||||||||||||||
| # @param pass_hash | ||||||||||||||||||||||||
| # The hash to be used for receipt. If left as undef, a hash will be generated | ||||||||||||||||||||||||
|
|
@@ -38,7 +43,7 @@ | |||||||||||||||||||||||
| Optional[String] $server = $title, | ||||||||||||||||||||||||
| Enum[present,absent] $ensure = 'present', | ||||||||||||||||||||||||
| Optional[String] $username = undef, | ||||||||||||||||||||||||
| Optional[String] $password = undef, | ||||||||||||||||||||||||
| Optional[Variant[String, Sensitive[String]]] $password = undef, | ||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #789 is only partly addressed.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||||||
| Optional[String] $pass_hash = undef, | ||||||||||||||||||||||||
| Optional[String] $email = undef, | ||||||||||||||||||||||||
| String $local_user = 'root', | ||||||||||||||||||||||||
|
|
@@ -50,6 +55,9 @@ | |||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| $docker_command = $docker::params::docker_command | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| $_password = if $password =~ Sensitive { $password.unwrap } else { $password } | ||||||||||||||||||||||||
| $_sensitive = ($password =~ Sensitive) and ($facts['os']['family'] != 'windows') | ||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Sensitive on Windows exposes the password.
The same variable also causes the
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if $facts['os']['family'] == 'windows' { | ||||||||||||||||||||||||
| $exec_environment = ["PATH=${facts['docker_program_files_path']}/Docker/",] | ||||||||||||||||||||||||
| $exec_timeout = 3000 | ||||||||||||||||||||||||
|
|
@@ -76,12 +84,17 @@ | |||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if $ensure == 'present' { | ||||||||||||||||||||||||
| if $username != undef and $password != undef and $email != undef and $version != undef and $version =~ /1[.][1-9]0?/ { | ||||||||||||||||||||||||
| if $username != undef and $_password != undef and $email != undef and $version != undef and $version =~ /1[.][1-9]0?/ { | ||||||||||||||||||||||||
| $auth_cmd = "${docker_command} login -u '${username}' -p \"${password_env}\" -e '${email}' ${server}" | ||||||||||||||||||||||||
| $auth_environment = "password=${password}" | ||||||||||||||||||||||||
| } elsif $username != undef and $password != undef { | ||||||||||||||||||||||||
| $auth_environment = "password=${_password}" | ||||||||||||||||||||||||
| } 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}" | ||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Docs: the password is visible in With
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Documented in the |
||||||||||||||||||||||||
| $auth_environment = '' | ||||||||||||||||||||||||
| } elsif $username != undef and $_password != undef { | ||||||||||||||||||||||||
| $auth_cmd = "${docker_command} login -u '${username}' -p \"${password_env}\" ${server}" | ||||||||||||||||||||||||
| $auth_environment = "password=${password}" | ||||||||||||||||||||||||
| $auth_environment = "password=${_password}" | ||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||
| $auth_cmd = "${docker_command} login ${server}" | ||||||||||||||||||||||||
| $auth_environment = '' | ||||||||||||||||||||||||
|
|
@@ -93,7 +106,10 @@ | |||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| $docker_auth = "${title}${auth_environment}${auth_cmd}${local_user}" | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if $auth_environment != '' { | ||||||||||||||||||||||||
| if $_sensitive { | ||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: the password is dropped from the environment on the legacy With a Sensitive 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed by the same guard in 85ea052: Sensitive + |
||||||||||||||||||||||||
| # $docker_auth embeds the password; only needed at runtime on Windows. | ||||||||||||||||||||||||
| $exec_env = $exec_environment | ||||||||||||||||||||||||
| } elsif $auth_environment != '' { | ||||||||||||||||||||||||
| $exec_env = concat($exec_environment, $auth_environment, "docker_auth=${docker_auth}") | ||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||
| $exec_env = concat($exec_environment, "docker_auth=${docker_auth}") | ||||||||||||||||||||||||
|
|
@@ -116,7 +132,7 @@ | |||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| file { "/${_local_user_home}/registry-auth-puppet_receipt_${server_strip}_${local_user}": | ||||||||||||||||||||||||
| ensure => $ensure, | ||||||||||||||||||||||||
| content => $_pass_hash, | ||||||||||||||||||||||||
| content => if $_sensitive { Sensitive($_pass_hash) } else { $_pass_hash }, | ||||||||||||||||||||||||
| owner => $local_user, | ||||||||||||||||||||||||
| group => $local_user, | ||||||||||||||||||||||||
| notify => Exec["${title} auth"], | ||||||||||||||||||||||||
|
|
@@ -149,7 +165,7 @@ | |||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| exec { "${title} auth": | ||||||||||||||||||||||||
| environment => Deferred('docker::env', [$exec_env]), | ||||||||||||||||||||||||
| command => Deferred('sprintf', [$_auth_command]), | ||||||||||||||||||||||||
| command => if $_sensitive { Sensitive($_auth_command) } else { Deferred('sprintf', [$_auth_command]) }, | ||||||||||||||||||||||||
| user => $exec_user, | ||||||||||||||||||||||||
| path => $exec_path, | ||||||||||||||||||||||||
| timeout => $exec_timeout, | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,6 +62,14 @@ | |
| 'pass_hash' => 'test1234', | ||
| 'receipt' => false | ||
| }, | ||
| 'with username => user1, and password => Sensitive(secret)' => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test gaps: this Sensitive case runs with
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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Covered by your commit (85ea052): Windows is skipped for Sensitive cases and |
||
| 'ensure' => 'present', | ||
| 'username' => 'user1', | ||
| 'password' => RSpec::Puppet::Sensitive.new("se'cret"), | ||
| 'version' => '17.06', | ||
| 'pass_hash' => 'test1234', | ||
| 'receipt' => false | ||
| }, | ||
| 'with username => user1, and password => secret and local_user => testuser' => { | ||
| 'username' => 'user1', | ||
| 'password' => 'secret', | ||
|
|
||
There was a problem hiding this comment.
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
emailon Docker <= 1.10), thatDeferredvalues aren't supported, and that the password is briefly visible in the process list during login (see my comment onregistry.pp:93).There was a problem hiding this comment.
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
emailon Docker <= 1.10, noDeferred, and the briefpsexposure.