You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by "jdscreations (via GitHub)" <gi...@apache.org> on 2026/09/23 09:35:15 UTC
[PR] cloud-setup-databases: shell-escape values passed to EncryptionCLI [cloudstack]
jdscreations opened a new pull request, #14229:
URL: https://github.com/apache/cloudstack/pull/14229
### Description
`processEncryptionStuff()`'s `encrypt()` builds the `java ... EncryptionCLI` command 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 to `runCmd()`, which runs it via `subprocess.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 to `pa` by the shell before it ever reaches `EncryptionCLI`, and the *wrong* value gets encrypted into `db.properties`. This matches the exact behavior reported in the issue (decrypting what was stored yields `pa`, not `pa$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 other `runCmd()` 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
- [x] Bug fix (non-breaking change which fixes an issue)
### Feature/Enhancement Scale or Bug Severity
#### Bug Severity
- [x] Major
### How Has This Been Tested?
The full script is a `.in` template requiring the CloudStack build (waf/Maven) to substitute `@COMMONLIBDIR@`/`@PYTHONDIR@` and produce a runnable executable, and `EncryptionCLI` itself lives in `cloudstack-utils.jar`. Rather than standing up the full build, I isolated the actual bug — shell quoting through `runCmd()`'s `shell=True` pattern — 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:
```
=== OLD (double-quote wrapping) ===
'pa\npa\n' # password 'pa$sword' arrives truncated to 'pa'
=== NEW (shlex.quote) ===
'pa$sword\npa$sword\n' # password arrives intact
```
Also verified `python3 -m py_compile setup/bindir/cloud-setup-databases.in` passes (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 a `shell=True` invocation — it handles `$`, single quotes, backticks, semicolons, and whitespace generically, not just the `$` case in the report. Checked the other three `runCmd()` 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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] cloud-setup-databases: shell-escape values passed to EncryptionCLI [cloudstack]
Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #14229:
URL: https://github.com/apache/cloudstack/pull/14229#issuecomment-5933426766
## [Codecov](https://app.codecov.io/gh/apache/cloudstack/pull/14229?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 4.02%. Comparing base ([`ac8d69c`](https://app.codecov.io/gh/apache/cloudstack/commit/ac8d69c5c1d7d2a30b9e49e8f484a365123557d9?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`3181ad7`](https://app.codecov.io/gh/apache/cloudstack/commit/3181ad7b369b01ce08d3a06a6de53703f6f4be07?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
:warning: Report is 7 commits behind head on 4.22.
> :exclamation: There is a different number of reports uploaded between BASE (ac8d69c) and HEAD (3181ad7). Click for more details.
>
> <details><summary>HEAD has 1 upload less than BASE</summary>
>
>| Flag | BASE (ac8d69c) | HEAD (3181ad7) |
>|------|------|------|
>|unittests|1|0|
></details>
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## 4.22 #14229 +/- ##
=============================================
- Coverage 17.98% 4.02% -13.97%
=============================================
Files 5930 449 -5481
Lines 535649 38239 -497410
Branches 65590 7082 -58508
=============================================
- Hits 96343 1538 -94805
+ Misses 428330 36489 -391841
+ Partials 10976 212 -10764
```
| [Flag](https://app.codecov.io/gh/apache/cloudstack/pull/14229/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [uitests](https://app.codecov.io/gh/apache/cloudstack/pull/14229/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `4.02% <ø> (ø)` | |
| [unittests](https://app.codecov.io/gh/apache/cloudstack/pull/14229/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
</details>
[:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/cloudstack/pull/14229?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] cloud-setup-databases: shell-escape values passed to EncryptionCLI [cloudstack]
Posted by "dajiaohuang (via GitHub)" <gi...@apache.org>.
dajiaohuang commented on PR #14229:
URL: https://github.com/apache/cloudstack/pull/14229#issuecomment-6392693765
Confirmed on the 4.22 branch: `cloud-setup-encryption.in::processEncryptionStuff()` constructs the same `EncryptionCLI` invocation with double-quoted interpolated classpath, input and key values, then passes the joined argument list through `runCmd()`. That means shell expansion can affect those values there too (not only in `cloud-setup-databases.in`). Please consider applying the same safe quoting approach to this companion script and covering the dynamic arguments with synthetic inputs, or clarify why its invocation is outside this fix. I did not use real credentials or execute either setup script.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] cloud-setup-databases: shell-escape values passed to EncryptionCLI [cloudstack]
Posted by "Damans227 (via GitHub)" <gi...@apache.org>.
Damans227 commented on code in PR #14229:
URL: https://github.com/apache/cloudstack/pull/14229#discussion_r4274006008
##########
setup/bindir/cloud-setup-databases.in:
##########
@@ -418,8 +419,13 @@ for example:
def processEncryptionStuff(self):
def encrypt(value):
- cmd = ['java','-classpath','"' + self.encryptionJarPath + '"','com.cloud.utils.crypt.EncryptionCLI','-i','"' + value + '"', '-p', '"' +
- self.mgmtsecretkey + '"', self.encryptorVersion]
+ # runCmd() joins this list with spaces and runs it through a shell, so each
+ # dynamic value must be shell-escaped with shlex.quote() rather than hand-wrapped
+ # in double quotes: double quotes still let the shell expand "$..." in the value
+ # (e.g. a password of pa$sword is truncated to pa), silently corrupting it.
+ cmd = ['java', '-classpath', shlex.quote(self.encryptionJarPath),
+ 'com.cloud.utils.crypt.EncryptionCLI', '-i', shlex.quote(value),
Review Comment:
can we do the same in cloud-setup-encryption? it builds this command with double quotes too, so a $ in the password still gets cut off there
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] cloud-setup-databases: shell-escape values passed to EncryptionCLI [cloudstack]
Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on PR #14229:
URL: https://github.com/apache/cloudstack/pull/14229#issuecomment-5792460024
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)
Here are some useful points:
- In case of a new feature add useful documentation (raise doc PR at https://github.com/apache/cloudstack-documentation)
- Be patient and persistent. It might take some time to get a review or get the final approval from the committers.
- Pay attention to the quality of your code, ensure tests are passing and your PR doesn't have conflicts.
- Please follow [ASF Code of Conduct](https://github.com/apache/.github/blob/main/.github/CODE_OF_CONDUCT.md) for all communication including (but not limited to) comments on Pull Requests, Issues, Mailing list and Slack.
- Be sure to read the [CloudStack Coding Conventions](https://cwiki.apache.org/confluence/display/CLOUDSTACK/Coding+conventions).
Apache CloudStack is a community-driven project and together we are making it better 🚀.
In case of doubts contact the developers at:
Mailing List: dev@cloudstack.apache.org (https://cloudstack.apache.org/mailing-lists.html)
Slack: https://apachecloudstack.slack.com/
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org