-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix(mounts): escape special characters in fstab mount paths #6911
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
ekalinin
wants to merge
1
commit into
canonical:main
Choose a base branch
from
ekalinin:fix/mounts-escape-fstab-paths
base: main
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.
+169
−6
Open
Changes from all commits
Commits
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| #cloud-config | ||
| mounts: | ||
| - [ /dev/sr0, "/mnt/Cdrom Drive", auto, "uid=1000,gid=1000", "0", "0" ] |
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 |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| """Integration test for gh-6911. | ||
|
|
||
| cc_mounts historically wrote /etc/fstab entries without escaping, so a | ||
| space in the device (fs_spec) or mount point (fs_file) produced an | ||
| unparseable line and broke ``mount -a``. Verify that a mount point | ||
| containing a space is octal-escaped in /etc/fstab, that cloud-init logs | ||
| stay clean, and that the real (unescaped) directory is created. | ||
|
|
||
| A network fs_spec (contains ``:``) with ``noauto`` keeps the entry in | ||
| fstab without cloud-init attempting the actual mount, so the test does | ||
| not depend on any real device or NFS server. | ||
|
|
||
| https://github.com/canonical/cloud-init/issues/3603 | ||
| """ | ||
|
|
||
| import pytest | ||
|
|
||
| from tests.integration_tests.instances import IntegrationInstance | ||
| from tests.integration_tests.util import verify_clean_log | ||
|
|
||
| USER_DATA = """\ | ||
| #cloud-config | ||
| mounts: | ||
| - - server.example:/export | ||
| - /mnt/Cdrom Drive | ||
| - nfs | ||
| - defaults,noauto | ||
| - "0" | ||
| - "0" | ||
| """ | ||
|
|
||
|
|
||
| @pytest.mark.user_data(USER_DATA) | ||
| def test_mount_point_with_space_is_escaped(client: IntegrationInstance): | ||
| # cloud-init should have configured mounts without any errors. | ||
| log = client.read_from_file("/var/log/cloud-init.log") | ||
| verify_clean_log(log) | ||
| assert "SUCCESS: config-mounts ran successfully" in log | ||
|
|
||
| # The space must be octal-escaped (\040) in the /etc/fstab entry. | ||
| fstab = client.read_from_file("/etc/fstab") | ||
| assert "/mnt/Cdrom\\040Drive" in fstab | ||
|
|
||
| # The real directory (with a literal space) must have been created. | ||
| assert client.execute("test -d '/mnt/Cdrom Drive'").ok |
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
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.
Uh oh!
There was an error while loading. Please reload this page.