cloud-init eats final EOL of sshd_config
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
cloud-init |
Fix Released
|
Medium
|
Scott Moser | ||
cloud-init (Ubuntu) |
Fix Released
|
Medium
|
Chad Smith | ||
Bug Description
cloud-init reads in sshd_config, and then writes it out again, but eats the final newline.
It also changes the file mode to 644, which I don't like since the original was 600, but I haven't yet found a decent way to change that.
While I'm at it, spellcheck in comment.
HAND
diff --git a/cloudinit/
index eb0bdab0..ed30a9d9 100755
--- a/cloudinit/
+++ b/cloudinit/
@@ -215,7 +215,7 @@ def handle(_name, cfg, cloud, log, args):
lines = [str(l) for l in new_lines]
- util.write_
+ util.write_
try:
cmd = cloud.distro.
diff --git a/cloudinit/util.py b/cloudinit/util.py
index 33019579..a8e84da8 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -1691,7 +1691,7 @@ def chmod(path, mode):
def write_file(
"""
Writes a file with the given content and sets the file mode as specified.
- Resotres the SELinux context if possible.
+ Restores the SELinux context if possible.
@param filename: The full path of the file to write.
@param content: The content to write to the file.
Related branches
- Douglas Jordan: Pending requested
- Chad Smith: Pending requested
-
Diff: 170 lines (+86/-8)2 files modifiedcloudinit/sources/DataSourceAzure.py (+14/-6)
tests/unittests/test_datasource/test_azure.py (+72/-2)
- Server Team CI bot: Approve (continuous-integration)
- Ryan Harper: Approve
-
Diff: 440 lines (+273/-70)4 files modifiedcloudinit/config/cc_set_passwords.py (+45/-60)
cloudinit/config/tests/test_set_passwords.py (+71/-0)
cloudinit/ssh_util.py (+63/-7)
tests/unittests/test_sshutil.py (+94/-3)
Changed in cloud-init: | |
status: | New → Confirmed |
importance: | Undecided → Medium |
I think the change for the permissions would best happen in write_file.
We'd like to say: use existing mode if the file exists, otherwise use X.
maybe an argument: use_existing_ mode=True
that would use the existing mode if the file exixsted, otherwise would use 'mode'.
adn default that to False (for backwards compat).
A simpler change for *just this* looks like: config/ cc_set_ passwords. py config/ cc_set_ passwords. py
pw_ auth))
--- a/cloudinit/
+++ b/cloudinit/
@@ -215,7 +215,13 @@ def handle(_name, cfg, cloud, log, args):
lines = [str(l) for l in new_lines] file(ssh_ util.DEF_ SSHD_CFG, "\n".join(lines)) exists( ssh_util. DEF_SSHD_ CFG): IMODE(os. lstat(ssh_ util.DEF_ SSHD_CFG) .st_mode) file(ssh_ util.DEF_ SSHD_CFG, "\n".join(lines) + "\n",
- util.write_
+ import os, stat
+ mode = 0o600
+ if os.path.
+ mode = stat.S_
+
+ util.write_
+ mode=mode)
try: init_cmd # Default service
cmd = cloud.distro.