cloud-setup-databases: shell-escape values passed to EncryptionCLI - #14229
Open
jdscreations wants to merge 1 commit into
Open
jdscreations wants to merge 1 commit into
jdscreations wants to merge 1 commit into
Conversation
processEncryptionStuff()'s encrypt() built the java EncryptionCLI command by hand-wrapping each dynamic value in literal double quotes, then handed the joined string to runCmd(), which runs it through `subprocess.Popen(..., shell=True)`. Double quotes do not stop the shell from expanding "$..." inside them, so a password like `pa$sword` is silently truncated to `pa` before it ever reaches EncryptionCLI, and the wrong value gets encrypted into db.properties. Use shlex.quote() instead of manual double-quote wrapping for the jar path, the value being encrypted, and the management server secret key. shlex.quote() produces shell-safe quoting for arbitrary values, including but not limited to '$'. Verified with a standalone reproduction that shells out the same way runCmd() does: with the old double-quote wrapping, a password of `pa$sword` arrives at the child process as `pa`; with shlex.quote(), it arrives intact as `pa$sword`. Fixes: apache#14186 Signed-off-by: SiddharthSanch <111047247+SiddharthSanch@users.noreply.github.com>
|
Congratulations on your first Pull Request and welcome to the Apache CloudStack community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/cloudstack/blob/main/CONTRIBUTING.md)
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
processEncryptionStuff()'sencrypt()builds thejava ... EncryptionCLIcommand by hand-wrapping each dynamic value (jar path, value to encrypt, management server secret key) in literal double quotes, then hands the space-joined string torunCmd(), which runs it viasubprocess.Popen(' '.join(cmds), shell=True, ...).Double quotes do not stop the shell from expanding
"$..."inside them. So a password containing$— e.g.pa$sword— is silently truncated topaby the shell before it ever reachesEncryptionCLI, and the wrong value gets encrypted intodb.properties. This matches the exact behavior reported in the issue (decrypting what was stored yieldspa, notpa$sword).Fix: use
shlex.quote()instead of the manual double-quote wrapping, for all three dynamic values passed into the command list.shlex.quote()produces shell-safe quoting for arbitrary values, including but not limited to$.I kept the change scoped to
encrypt()— the otherrunCmd()caller for passwords (mysqlCmds, ~line 160) already uses single quotes ('--password=\'%s\''), which correctly prevents shell expansion, so that path isn't affected by this bug and I left it untouched.Fixes: #14186
Types of changes
Feature/Enhancement Scale or Bug Severity
Bug Severity
How Has This Been Tested?
The full script is a
.intemplate requiring the CloudStack build (waf/Maven) to substitute@COMMONLIBDIR@/@PYTHONDIR@and produce a runnable executable, andEncryptionCLIitself lives incloudstack-utils.jar. Rather than standing up the full build, I isolated the actual bug — shell quoting throughrunCmd()'sshell=Truepattern — in a standalone reproduction that shells out exactly the same way, substituting a trivial stand-in for the Java program so the arguments it actually receives are directly observable:Also verified
python3 -m py_compile setup/bindir/cloud-setup-databases.inpasses (valid Python syntax) and confirmed the same bug is present on this branch (4.22) prior to the fix.How did you try to break this feature and the system with this change?
shlex.quote()is the standard-library-correct way to safely pass arbitrary strings through ashell=Trueinvocation — it handles$, single quotes, backticks, semicolons, and whitespace generically, not just the$case in the report. Checked the other threerunCmd()call sites in this file (mysql invocation,build-classpath,DatabaseConfig) to confirm none of them pass user-controlled dynamic values needing the same treatment, and none were touched by this change.