Skip to content

Commit 5b53748

Browse files
committed
properly escape quotes in passwords by calling to_ruby
database passwords can contain special characters, especially " and ' so we can't just print the value of the field enclosed by double quotes as that would break whenever the user uses a literal " in their password using to_ruby here and not to_yaml, as the former gives us correct escaping without the whole `---` and `\n` enclosing that to_yaml forces. using to_yaml would require to pass *the whole* config hash to it
1 parent b1a2286 commit 5b53748

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

spec/classes/foreman_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,17 @@
484484

485485
it { should contain_user('foreman').with('groups' => []) }
486486
end
487+
488+
describe 'with sensitive passwords' do
489+
let(:params) do
490+
super().merge(db_password: sensitive('secret'))
491+
end
492+
493+
it 'should configure the database' do
494+
should contain_file('/etc/foreman/database.yml')
495+
.with_content(/password: "secret"/)
496+
end
497+
end
487498
end
488499
end
489500
end

templates/database.yml.epp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@
3030
username: <%= $username %>
3131
<% } -%>
3232
<% if $password { -%>
33-
password: "<%= $password %>"
33+
password: <%= stdlib::to_ruby($password) %>
3434
<% } -%>
3535
pool: <%= $db_pool %>

0 commit comments

Comments
 (0)