Skip to content

Commit 856cee1

Browse files
Fix possible log cred leak (#442)
* Fix possible log cred leak [#184798214] * Fix possible log leak of CF password On 2023-03-27 we discovered that new stemcells were using OS audit tools to log every command run on a VM. This was causing CF authentication commands of the form `cf auth --client-credentials USERNAME PASSWORD` to be logged in plaintext to syslog. Internal shell commands like setting variables are not logged by OS audit tools, so this commit changes our auth from passing a password as an argument to passing a password as an environment variable when a binary is executed on linux the audit system will log the execution into syslog. This log includes the arguments provided to the binary call. In this script these arguments contain the admin creds for the created service broker. To avoid this, switch to use echo (a bash builtin) and <() process substition which in turn provides file descriptors. This can then be used with cf curl via the -d param which accepts a path via @ annotation. The cf cli currently doesn't support sourcing values from the environment or config files for this call. Even once it supports it, we cannot be totally sure that our release is running with the required cf cli version available. We assume that the cf cli is present on the VM that this errand is executed on, but we do not provide it via our release. This implementation uses cf curl instead. This way the data can be provided through means that will not log cleartext credentials into syslog. Co-authored-by: Gareth Smith <sgareth@vmware.com> * remove var export some work for avoiding this cred leak has already been done in 013342d --------- Co-authored-by: Gareth Smith <sgareth@vmware.com>
1 parent dbf0d2f commit 856cee1

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

jobs/nfsbrokerpush/templates/deploy.sh.erb

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,23 @@ function push_app() {
125125
fi
126126
popd > /dev/null
127127
}
128-
129128
function register_service() {
130-
cf create-service-broker $SERVICE_BROKER_NAME $USERNAME $PASSWORD $APP_URL || cf update-service-broker $SERVICE_BROKER_NAME $USERNAME $PASSWORD $APP_URL
129+
# We want to avoid providing creds as commandline params to binaries to avoid leaking creds via autitd logs. The below `cf curl` replaces the (create|update)-service-broker commands.
130+
# cf create-service-broker $SERVICE_BROKER_NAME $USERNAME $PASSWORD $APP_URL || cf update-service-broker $SERVICE_BROKER_NAME $USERNAME $PASSWORD $APP_URL
131+
if ! cf curl "/v2/service_brokers?q=name:$SERVICE_BROKER_NAME" | grep $SERVICE_BROKER_NAME; then
132+
echo "Creating service broker - name:${SERVICE_BROKER_NAME} host:${APP_URL}"
133+
echo "{\"auth_username\":\"${USERNAME}\",\"auth_password\":\"${PASSWORD}\",\"broker_url\":\"${APP_URL}\", \"name\": \"${SERVICE_BROKER_NAME}\"}" > ./data
134+
cf curl --fail \
135+
-X POST "/v2/service_brokers" \
136+
-d @./data
137+
rm data
138+
else
139+
echo "Updating service broker - name:${SERVICE_BROKER_NAME} host:${APP_URL}"
140+
broker_guid="$(cf curl /v2/service_brokers?q=name:$SERVICE_BROKER_NAME | grep \"guid\" | cut -f4 -d\")"
141+
cf curl --fail \
142+
-X PUT "/v2/service_brokers/${broker_guid}" \
143+
-d @<(echo "{\"auth_username\":\"${USERNAME}\",\"auth_password\":\"${PASSWORD}\",\"broker_url\":\"${APP_URL}\"}") > /dev/null
144+
fi
131145
}
132146

133147
function clean_up() {

jobs/nfsbrokerpush/templates/start.sh.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
raise 'missing credhub URL'
2525
end
2626
%>
27+
2728
bin/nfsbroker --listenAddr="0.0.0.0:$PORT" \
2829
--servicesConfig="./services.json" \
2930
--credhubURL="<%= credhub_url %>" \

spec/jobs/nfsbrokerpush/start_sh_spec.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141

4242
expect(tpl_output).to include("bin/nfsbroker --listenAddr=\"0.0.0.0:$PORT\"")
4343
expect(tpl_output).to include("--credhubURL=\"https://some-credhub-url:4321\"")
44+
expect(tpl_output).not_to include("--uaaClientID=\"client-id\"")
45+
expect(tpl_output).not_to include("--uaaClientSecret=\"client-secret\"")
4446
expect(tpl_output).to include("--servicesConfig=\"./services.json\"")
4547
expect(tpl_output).to include("--logLevel=\"some-log-level\"")
4648
expect(tpl_output).to include("--timeFormat=\"some-log-time-format\"")
@@ -60,10 +62,12 @@
6062
}
6163
end
6264

63-
it 'includes the credhub flags in the script' do
65+
it 'includes the unsensitive credhub flags in the script' do
6466
tpl_output = template.render(manifest_properties, consumes: credhub_link)
6567

6668
expect(tpl_output).to include("--credhubURL=\"https://some-credhub-url:4321\"")
69+
expect(tpl_output).not_to include("--uaaClientID=\"some-uaa-client-id\"")
70+
expect(tpl_output).not_to include("--uaaClientSecret=\"some-uaa-client-secret\"")
6771
expect(tpl_output).to include("--storeID=\"nfsbroker\"")
6872
end
6973

0 commit comments

Comments
 (0)