Skip to content

Commit c8436f9

Browse files
committed
read password from env var
1 parent fb5d594 commit c8436f9

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

manifests/registry.pp

+13-5
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,14 @@
5353
$exec_path = ['c:/Windows/Temp/', 'C:/Program Files/Docker/']
5454
$exec_provider = 'powershell'
5555
$password_env = '$env:password'
56+
$exec_user = undef
5657
} else {
5758
$exec_environment = ['HOME=/root']
5859
$exec_path = ['/bin', '/usr/bin']
5960
$exec_timeout = 0
6061
$exec_provider = undef
6162
$password_env = "\${password}"
63+
$exec_user = $local_user
6264
}
6365

6466
if $ensure == 'present' {
@@ -67,7 +69,7 @@
6769
$auth_environment = "password=${password}"
6870
}
6971
elsif $username != undef and $password != undef {
70-
$auth_cmd = "${docker_command} login -u '${username}' -p ${password_env} ${server}"
72+
$auth_cmd = "${docker_command} login -u '${username}' -p '${password_env}' ${server}"
7173
$auth_environment = "password=${password}"
7274
}
7375
else {
@@ -80,6 +82,7 @@
8082
$auth_environment = ''
8183
}
8284

85+
$docker_auth = "${title}${auth_environment}${auth_cmd}${local_user}"
8386
if $receipt {
8487

8588
# server may be an URI, which can contain /
@@ -90,7 +93,7 @@
9093
$local_user_strip = regsubst($local_user, '-', '', 'G')
9194

9295
$_pass_hash = $pass_hash ? {
93-
Undef => pw_hash("${title}${auth_environment}${auth_cmd}${local_user}", 'SHA-512', $local_user_strip),
96+
Undef => pw_hash($docker_auth, 'SHA-512', $local_user_strip),
9497
default => $pass_hash
9598
}
9699
$_auth_command = "${auth_cmd} || rm -f \"/root/registry-auth-puppet_receipt_${server_strip}_${local_user}\""
@@ -101,7 +104,6 @@
101104
notify => Exec["${title} auth"],
102105
}
103106
} else {
104-
$pass = "${title}${auth_environment}${auth_cmd}${local_user}"
105107
$_auth_command = $auth_cmd
106108
$pw_hash_path = 'C:/Windows/Temp/compute_hash.ps1'
107109
$passfile = "C:/Windows/Temp/registry-auth-puppet_receipt_${server_strip}_${local_user}"
@@ -124,10 +126,16 @@
124126
$_auth_command = $auth_cmd
125127
}
126128

129+
if $auth_environment != '' {
130+
$exec_env = concat($exec_environment, $auth_environment, "docker_auth=${docker_auth}")
131+
} else {
132+
$exec_env = concat($exec_environment, "docker_auth=${docker_auth}")
133+
}
134+
127135
exec { "${title} auth":
128-
environment => concat($exec_environment, $auth_environment),
136+
environment => $exec_env,
129137
command => $_auth_command,
130-
#user => $local_user,
138+
user => $exec_user,
131139
path => $exec_path,
132140
timeout => $exec_timeout,
133141
provider => $exec_provider,

spec/defines/registry_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,22 @@
4040

4141
context 'with ensure => present and username => user1, and password => secret and email => [email protected]' do
4242
let(:params) { { 'ensure' => 'present', 'username' => 'user1', 'password' => 'secret', 'email' => '[email protected]', 'version' => '17.06', 'pass_hash' => 'test1234', 'receipt' => false } }
43-
it { should contain_exec('localhost:5000 auth').with_command("docker login -u 'user1' -p \"${password}\" localhost:5000").with_environment('password=secret') }
43+
it { should contain_exec('localhost:5000 auth').with_command("docker login -u 'user1' -p '${password}' localhost:5000").with_environment(/password=secret/) }
4444
end
4545

4646
context 'with ensure => present and username => user1, and password => secret and email => [email protected] and version < 1.11.0' do
4747
let(:params) { { 'ensure' => 'present', 'username' => 'user1', 'password' => 'secret', 'email' => '[email protected]', 'version' => '1.9.0', 'pass_hash' => 'test1234', 'receipt' => false } }
48-
it { should contain_exec('localhost:5000 auth').with_command("docker login -u 'user1' -p \"${password}\" -e '[email protected]' localhost:5000").with_environment('password=secret') }
48+
it { should contain_exec('localhost:5000 auth').with_command("docker login -u 'user1' -p '${password}' -e '[email protected]' localhost:5000").with_environment(/password=secret/) }
4949
end
5050

5151
context 'with username => user1, and password => secret' do
5252
let(:params) { { 'username' => 'user1', 'password' => 'secret', 'version' => '17.06', 'pass_hash' => 'test1234', 'receipt' => false } }
53-
it { should contain_exec('localhost:5000 auth').with_command("docker login -u 'user1' -p \"${password}\" localhost:5000").with_environment('password=secret') }
53+
it { should contain_exec('localhost:5000 auth').with_command("docker login -u 'user1' -p '${password}' localhost:5000").with_environment(/password=secret/) }
5454
end
5555

5656
context 'with username => user1, and password => secret and local_user => testuser' do
5757
let(:params) { { 'username' => 'user1', 'password' => 'secret', 'local_user' => 'testuser', 'version' => '17.06', 'pass_hash' => 'test1234', 'receipt' => false } }
58-
it { should contain_exec('localhost:5000 auth').with_command("docker login -u 'user1' -p \"${password}\" localhost:5000").with_user('testuser').with_environment('password=secret') }
58+
it { should contain_exec('localhost:5000 auth').with_command("docker login -u 'user1' -p '${password}' localhost:5000").with_user('testuser').with_environment(/password=secret/) }
5959
end
6060

6161
context 'with an invalid ensure value' do

templates/windows/compute_hash.ps1.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#file computes the 512SHA for a given string and writes it to a file
22

3-
$String = "<%= @pass %>"
3+
$String = $env:docker_auth
44
$HashName = "SHA512"
55
$StringBuilder = New-Object System.Text.StringBuilder
66
[System.Security.Cryptography.HashAlgorithm]::Create($HashName).ComputeHash([System.Text.Encoding]::UTF8.GetBytes($String))|%{

0 commit comments

Comments
 (0)