Skip to content

Commit 84dac3b

Browse files
committed
Fix escaping for LDAP creds in nfsv3driver job
- use single quotes to avoid bash interpretation of sequences like !$ - add quoting for apostrophe characters in strings - add unit tests Authored-by: Julian Hjortshoj <hjortshojj@vmware.com> [#174504248] Improper quoting of LDAP service account credentials in BOSH scripts
1 parent 75a91cf commit 84dac3b

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

jobs/nfsv3driver/templates/start.sh.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ chown -R vcap:vcap $RUN_DIR
1717
echo $$ > $PIDFILE
1818

1919
# ldap connection and credential info are passed via environment
20-
export LDAP_SVC_USER="<%= p("nfsv3driver.ldap_svc_user") %>"
21-
export LDAP_SVC_PASS="<%= p("nfsv3driver.ldap_svc_password") %>"
20+
export LDAP_SVC_USER='<%= p("nfsv3driver.ldap_svc_user").gsub("'", "'\"'\"'") %>'
21+
export LDAP_SVC_PASS='<%= p("nfsv3driver.ldap_svc_password").gsub("'", "'\"'\"'") %>'
2222
export LDAP_HOST="<%= p("nfsv3driver.ldap_host") %>"
2323
export LDAP_PORT="<%= p("nfsv3driver.ldap_port") %>"
2424
export LDAP_PROTO="<%= p("nfsv3driver.ldap_proto") %>"

spec/jobs/nfsv3driver/start_sh_spec.rb

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@
5252
it 'sets the allowedOptions flag correctly' do
5353
tpl_output = template.render(manifest_properties, consumes: mapfs_link)
5454

55-
expect(tpl_output).to include("export LDAP_SVC_USER=\"service-user\"")
56-
expect(tpl_output).to include("export LDAP_SVC_PASS=\"service-password\"")
55+
expect(tpl_output).to include("export LDAP_SVC_USER='service-user'")
56+
expect(tpl_output).to include("export LDAP_SVC_PASS='service-password'")
5757
expect(tpl_output).to include("export LDAP_HOST=\"some-host\"")
5858
expect(tpl_output).to include("export LDAP_PORT=\"1234\"")
5959
expect(tpl_output).to include("export LDAP_PROTO=\"udp\"")
@@ -62,6 +62,28 @@
6262
end
6363
end
6464

65+
context 'when ldap properties contain bash special characters' do
66+
let(:manifest_properties) do
67+
{
68+
"nfsv3driver" => {
69+
"ldap_svc_user" => "Patrick O'Malley",
70+
"ldap_svc_password" => "!que&pasa!${xxx}$?",
71+
"ldap_host" => "some-host",
72+
"ldap_port" => 1234,
73+
"ldap_proto" => "udp",
74+
"ldap_user_fqdn" => "cn=Users,dc=corp,dc=test,dc=com",
75+
"ldap_ca_cert" => "some-ca-cert",
76+
}
77+
}
78+
end
79+
80+
it 'escapes the properties correctly' do
81+
tpl_output = template.render(manifest_properties, consumes: mapfs_link)
82+
83+
expect(tpl_output).to include("export LDAP_SVC_USER='Patrick O'\"'\"'Malley'")
84+
expect(tpl_output).to include("export LDAP_SVC_PASS='!que&pasa!${xxx}$?'")
85+
end
86+
end
6587
context 'when configured with ldap with a null ca cert' do
6688
let(:manifest_properties) do
6789
{

0 commit comments

Comments
 (0)