Skip to content

Allow credentials in backup repository mount options for cifs mount - #14009

Open
abh1sar wants to merge 1 commit into
apache:4.22from
shapeblue:nas-cifs-mount
Open

Allow credentials in backup repository mount options for cifs mount#14009
abh1sar wants to merge 1 commit into
apache:4.22from
shapeblue:nas-cifs-mount

Conversation

@abh1sar

@abh1sar abh1sar commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Description

The SafeCommandOptions whitelist added for command injection hardening in 56ad044 only accepts [A-Za-z0-9,._=:/+-] and whitespace.
Mount options are how credentials reach a CIFS backup repository, and any realistic value is rejected: an Active Directory username such as user@domain, or a password containing @ ! # % ^ ~. Adding or updating such a repository fails with "contains unsupported or unsafe characters".

The list is now parsed for what it is, a comma separated list of "key" or "key=value" entries, with the punctuation that appears in credentials allowed in values only. It is not a loosening across the board. Keys keep the old restrictive character set, and everything the shell treats specially or expands is still rejected in both: whitespace, quotes, $ ` ; | & < > ( ) { } [ ] \ and the glob characters * and ?. Whitespace was previously accepted and is not any more, since that is what would let a value turn into extra mount arguments.

nasbackup.sh interpolated the options into the mount command unquoted, so a value containing whitespace or a glob was split or expanded by the shell before mount saw it. The command is now built as an array and the options passed as a single quoted argument, so the option list cannot influence anything but the -o argument regardless of what validation allows through.

Not that this doesn't affect existing repositories, only the new ones.

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • Test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

How did you try to break this feature and the system with this change?

The SafeCommandOptions whitelist added for command injection hardening only
accepted [A-Za-z0-9,._=:/+-] and whitespace. Mount options are how credentials
reach a CIFS backup repository, and any realistic value is rejected: an Active
Directory username such as user@domain, or a password containing @ ! # % ^ ~.
Adding or updating such a repository fails with "contains unsupported or unsafe
characters".

The list is now parsed for what it is, a comma separated list of "key" or
"key=value" entries, with the punctuation that appears in credentials allowed
in values only. It is not a loosening across the board. Keys keep the old
restrictive character set, and everything the shell treats specially or expands
is still rejected in both: whitespace, quotes, $ ` ; | & < > ( ) { } [ ] \ and
the glob characters * and ?. Whitespace was previously accepted and is not any
more, since that is what would let a value turn into extra mount arguments.

nasbackup.sh interpolated the options into the mount command unquoted, so a
value containing whitespace or a glob was split or expanded by the shell before
mount saw it. The command is now built as an array and the options passed as a
single quoted argument, so the option list cannot influence anything but the -o
argument regardless of what validation allows through.
@abh1sar

abh1sar commented Aug 29, 2026

Copy link
Copy Markdown
Contributor Author

@blueorangutan package

@abh1sar
abh1sar requested review from shwstppr and weizhouapache and a lite review from Copilot August 29, 2026 16:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates CloudStack’s handling of backup repository mount options so CIFS credentials (and similar secrets like cephx keys) can be provided safely, without reintroducing command injection risk.

Changes:

  • Replaces the overly restrictive SafeCommandOptions validation with a mount-options–aware validator (SafeMountCommandOptions) that allows common credential punctuation in values while keeping option keys restrictive.
  • Updates KVM nasbackup.sh to construct the mount command as an argument array and pass -o options as a single quoted argument.
  • Extends ParamProcessWorkerTest coverage for accepted/rejected mount option patterns (credentials punctuation, base64-like values, and unsafe tokens).

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
api/src/main/java/org/apache/cloudstack/api/ApiArgValidator.java Introduces SafeMountCommandOptions with key/value-aware parsing and tighter validation rules.
api/src/main/java/org/apache/cloudstack/api/command/user/backup/repository/AddBackupRepositoryCmd.java Switches mountOptions validation to SafeMountCommandOptions.
api/src/main/java/org/apache/cloudstack/api/command/user/backup/repository/UpdateBackupRepositoryCmd.java Switches mountOptions validation to SafeMountCommandOptions.
server/src/main/java/com/cloud/api/dispatch/ParamProcessWorker.java Routes the new validator in parameter validation dispatch.
server/src/test/java/com/cloud/api/dispatch/ParamProcessWorkerTest.java Adds tests for credential-friendly mount options and rejection of unsafe patterns.
scripts/vm/hypervisor/kvm/nasbackup.sh Builds mount invocation via an array and passes options as a single argument to avoid shell splitting/expansion.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines 92 to 95
final String value = String.valueOf(param);
if (StringUtils.isBlank(value)) {
return;
}
Comment on lines +292 to +294
mount_args=(-t "${NAS_TYPE}" "${NAS_ADDRESS}" "${mount_point}")
[[ -n "${MOUNT_OPTS}" ]] && mount_args+=(-o "${MOUNT_OPTS}")
mount "${mount_args[@]}" 2>&1 | tee -a "$logFile"
@codecov

codecov Bot commented Aug 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 54.54545% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 17.79%. Comparing base (7ea1dca) to head (17b20fd).

Files with missing lines Patch % Lines
...ava/org/apache/cloudstack/api/ApiArgValidator.java 60.00% 3 Missing and 1 partial ⚠️
...ava/com/cloud/api/dispatch/ParamProcessWorker.java 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##               4.22   #14009   +/-   ##
=========================================
  Coverage     17.79%   17.79%           
- Complexity    15995    15997    +2     
=========================================
  Files          5928     5928           
  Lines        534306   534310    +4     
  Branches      65383    65384    +1     
=========================================
+ Hits          95069    95087   +18     
+ Misses       428467   428452   -15     
- Partials      10770    10771    +1     
Flag Coverage Δ
uitests 3.69% <ø> (ø)
unittests 18.88% <54.54%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants