Repository navigation
Nas backup: Allow credentials in backup repository mount options for cifs mount #14009
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
Open
abh1sar
wants to merge
3
commits into
apache:4.20
Choose a base branch
from
shapeblue:nas-cifs-mount
base: 4.20
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+149
−13
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -95,7 +95,7 @@ public static class TestCmd extends BaseCmd { | |
| @Parameter(name = "vmHostNameParam", type = CommandType.STRING, validations = {ApiArgValidator.RFCComplianceDomainName}) | ||
| String vmHostNameParam; | ||
|
|
||
| @Parameter(name = "mountOptions", type = CommandType.STRING, validations = {ApiArgValidator.SafeCommandOptions}) | ||
| @Parameter(name = "mountOptions", type = CommandType.STRING, validations = {ApiArgValidator.SafeMountCommandOptions}) | ||
| String mountOptions; | ||
|
|
||
| @Override | ||
|
|
@@ -151,6 +151,126 @@ public void processMountOptionsParameter_Valid() { | |
| Assert.assertEquals("vers=4.1,soft,timeo=600,retrans=2", cmd.mountOptions); | ||
| } | ||
|
|
||
| @Test | ||
| public void processMountOptionsParameter_AcceptsCifsCredentials() { | ||
| final HashMap<String, String> params = new HashMap<String, String>(); | ||
| // CIFS credentials routinely contain punctuation that is harmless in a mount option list. | ||
| final String options = "[email protected],password=P@ssw0rd!#%^~,vers=3.0"; | ||
| params.put("mountOptions", options); | ||
| final TestCmd cmd = new TestCmd(); | ||
| paramProcessWorkerSpy.processParameters(cmd, params); | ||
| Assert.assertEquals(options, cmd.mountOptions); | ||
| } | ||
|
|
||
| @Test | ||
| public void processMountOptionsParameter_AcceptsBase64LikePassword() { | ||
| final HashMap<String, String> params = new HashMap<String, String>(); | ||
| final String options = "username=backup,password=YWJjZGVmZ2g="; | ||
| params.put("mountOptions", options); | ||
| final TestCmd cmd = new TestCmd(); | ||
| paramProcessWorkerSpy.processParameters(cmd, params); | ||
| Assert.assertEquals(options, cmd.mountOptions); | ||
| } | ||
|
|
||
| @Test | ||
| public void processMountOptionsParameter_AcceptsCephFsOptions() { | ||
| final HashMap<String, String> params = new HashMap<String, String>(); | ||
| // A CephFS repository is mounted with the cephx user and a bare option such as defaults. | ||
| final String options = "name=user,secret=xyz,defaults"; | ||
| params.put("mountOptions", options); | ||
| final TestCmd cmd = new TestCmd(); | ||
| paramProcessWorkerSpy.processParameters(cmd, params); | ||
| Assert.assertEquals(options, cmd.mountOptions); | ||
| } | ||
|
|
||
| @Test | ||
| public void processMountOptionsParameter_AcceptsCephFsBase64Secret() { | ||
| final HashMap<String, String> params = new HashMap<String, String>(); | ||
| // A cephx key is base64, so it can contain + / and trailing =. | ||
| final String options = "name=cloudstack,secret=AQBvE2VmS0J8FxAA9F1c2Wq+8kZ3Xn5Yz7Lw==,defaults"; | ||
| params.put("mountOptions", options); | ||
| final TestCmd cmd = new TestCmd(); | ||
| paramProcessWorkerSpy.processParameters(cmd, params); | ||
| Assert.assertEquals(options, cmd.mountOptions); | ||
| } | ||
|
|
||
| @Test | ||
| public void processMountOptionsParameter_AcceptsCephFsSecretFile() { | ||
| final HashMap<String, String> params = new HashMap<String, String>(); | ||
| final String options = "name=user,secretfile=/etc/ceph/secret.key,_netdev"; | ||
| params.put("mountOptions", options); | ||
| final TestCmd cmd = new TestCmd(); | ||
| paramProcessWorkerSpy.processParameters(cmd, params); | ||
| Assert.assertEquals(options, cmd.mountOptions); | ||
| } | ||
|
|
||
| @Test(expected = ServerApiException.class) | ||
| public void processMountOptionsParameter_RejectCephFsSecretWithCommandSubstitution() { | ||
| final HashMap<String, String> params = new HashMap<String, String>(); | ||
| params.put("mountOptions", "name=user,secret=$(cat /etc/ceph/keyring)"); | ||
| final TestCmd cmd = new TestCmd(); | ||
| paramProcessWorkerSpy.processParameters(cmd, params); | ||
| } | ||
|
|
||
| @Test | ||
| public void processMountOptionsParameter_AcceptsEmptyValueToClearTheOptions() { | ||
| final HashMap<String, String> params = new HashMap<String, String>(); | ||
| params.put("mountOptions", ""); | ||
| final TestCmd cmd = new TestCmd(); | ||
| paramProcessWorkerSpy.processParameters(cmd, params); | ||
| Assert.assertEquals("", cmd.mountOptions); | ||
| } | ||
|
|
||
| @Test(expected = ServerApiException.class) | ||
| public void processMountOptionsParameter_RejectWhitespaceOnly() { | ||
| final HashMap<String, String> params = new HashMap<String, String>(); | ||
| // Only looks empty: the backup script would hand this to mount as an option. | ||
| params.put("mountOptions", " "); | ||
| final TestCmd cmd = new TestCmd(); | ||
| paramProcessWorkerSpy.processParameters(cmd, params); | ||
| } | ||
|
|
||
| @Test(expected = ServerApiException.class) | ||
| public void processMountOptionsParameter_RejectWhitespace() { | ||
| final HashMap<String, String> params = new HashMap<String, String>(); | ||
| // Whitespace would turn into additional arguments to mount. | ||
| params.put("mountOptions", "vers=4.1,soft -o remount,rw"); | ||
| final TestCmd cmd = new TestCmd(); | ||
| paramProcessWorkerSpy.processParameters(cmd, params); | ||
| } | ||
|
|
||
| @Test(expected = ServerApiException.class) | ||
| public void processMountOptionsParameter_RejectCommandSubstitution() { | ||
| final HashMap<String, String> params = new HashMap<String, String>(); | ||
| params.put("mountOptions", "vers=4.1,password=$(id)"); | ||
| final TestCmd cmd = new TestCmd(); | ||
| paramProcessWorkerSpy.processParameters(cmd, params); | ||
| } | ||
|
|
||
| @Test(expected = ServerApiException.class) | ||
| public void processMountOptionsParameter_RejectBackticks() { | ||
| final HashMap<String, String> params = new HashMap<String, String>(); | ||
| params.put("mountOptions", "vers=4.1,password=`id`"); | ||
| final TestCmd cmd = new TestCmd(); | ||
| paramProcessWorkerSpy.processParameters(cmd, params); | ||
| } | ||
|
|
||
| @Test(expected = ServerApiException.class) | ||
| public void processMountOptionsParameter_RejectGlob() { | ||
| final HashMap<String, String> params = new HashMap<String, String>(); | ||
| params.put("mountOptions", "vers=4.1,credentials=/etc/*"); | ||
| final TestCmd cmd = new TestCmd(); | ||
| paramProcessWorkerSpy.processParameters(cmd, params); | ||
| } | ||
|
|
||
| @Test(expected = ServerApiException.class) | ||
| public void processMountOptionsParameter_RejectOptionWithoutKey() { | ||
| final HashMap<String, String> params = new HashMap<String, String>(); | ||
| params.put("mountOptions", "vers=4.1,=value"); | ||
| final TestCmd cmd = new TestCmd(); | ||
| paramProcessWorkerSpy.processParameters(cmd, params); | ||
| } | ||
|
|
||
| @Test(expected = ServerApiException.class) | ||
| public void processMountOptionsParameter_RejectCodeLikeContent() { | ||
| final HashMap<String, String> params = new HashMap<String, String>(); | ||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@abh1sar should these
SafeMountCommandOptionsrefactors also be made in4.20branch?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, rebased to 4.20