Skip to content
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

db_encryption_key is not yaml escaped #216

Open
sethboyles opened this issue Jan 7, 2022 · 0 comments
Open

db_encryption_key is not yaml escaped #216

sethboyles opened this issue Jan 7, 2022 · 0 comments

Comments

@sethboyles
Copy link
Member

sethboyles commented Jan 7, 2022

Issue

db_encryption_key is incorrectly parsed if it has a leading #. This is because hashes are interpreted as comments if not escaped/quoted

We need to yaml_escape it (and potentially review other password/key fields) before rendering it to cloud_controller.yml

Context

with the following password:

egrep db_encryption_key /var/vcap/jobs/cloud_controller_ng/config/cloud_controller_ng.yml
db_encryption_key: #mypassword

bosh deployment prestart fails on cloud_controller_ng job with prestart logs reporting the following

Running migrations
[2022-01-06 14:29:08+0000] Running migration try number 1 of 3
[2022-01-06 14:31:43+0000] VCAP::CloudController::ValidateDatabaseKeys::DatabaseEncryptionKeyMissingError
[2022-01-06 14:31:43+0000] No database encryption keys are specified
[2022-01-06 15:16:55+0000] Waiting for bosh_dns

Steps to Reproduce

  1. Set cc.db_encryption_key to something like #mypassword in the bosh manifest
  2. Deploy

Expected result

The key is set correctly and the deploy succeeds

Current result

prestart fails with DatabaseEncryptionKeyMissingError

Possible Fix

Use

def yaml_escape(input_string)
chars_to_escape = /[:\\"\x00-\x1f\x7f]/
chars_needing_quotes = /[ !#'&%*,:>@\[\]\\`{|}]/
delimiter = (chars_needing_quotes.match(input_string) ||
chars_to_escape.match(input_string)) ? '"' : ''
fixed_string = input_string.gsub(/(#{chars_to_escape})/) { |m| "\\x#{'%x' % m.ord}" }
"#{delimiter}#{fixed_string}#{delimiter}"
end

We should probably also do a review and see if there are other fields that should be escaped

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

2 participants