fix(scheduled-jobs): write a linked crontab through its link, with the target's mode
driver / standard (pull_request) Successful in 16s
driver / lint (pull_request) Successful in 20s
driver / types (pull_request) Successful in 1m11s
driver / test (3.12) (pull_request) Successful in 1m25s
driver / test (3.13) (pull_request) Successful in 1m18s
driver / lowest (pull_request) Successful in 40s
driver / build (pull_request) Successful in 36s
driver / security (pull_request) Successful in 1m8s
CI / driver (pull_request) Successful in 2m54s
driver / publish (pull_request) Skipped
driver / standard (pull_request) Successful in 16s
driver / lint (pull_request) Successful in 20s
driver / types (pull_request) Successful in 1m11s
driver / test (3.12) (pull_request) Successful in 1m25s
driver / test (3.13) (pull_request) Successful in 1m18s
driver / lowest (pull_request) Successful in 40s
driver / build (pull_request) Successful in 36s
driver / security (pull_request) Successful in 1m8s
CI / driver (pull_request) Successful in 2m54s
driver / publish (pull_request) Skipped
stat without -L gave the link's own mode, 777, and install replaced the link with a plain file of that mode: cron ignores a file anyone may write, so every job in it stopped (/etc/cron.d/vzdump on older PVE links to /etc/pve/vzdump.cron). The file the link names is written instead. Refs #86
This commit is contained in:
1 parent
df476a12f2
commit
edef6cf07c
2 files changed
+18
-2
No files matched your search
@@ -244,8 +244,11 @@ class PosixScheduledJobsMixin(ScheduledJobsMixin):
|
||||
if user is not None:
|
||||
self._sj_write_crontab(user, text)
|
||||
return
|
||||
mode, owner, group = self._sj_checked([*self.STAT_ARGV, path]).stdout.split()[:3]
|
||||
self._sj_install(text, path, mode, owner, group)
|
||||
# Through a symbolic link to the file it names, with that file's mode: the
|
||||
# link's own mode is 777, and cron ignores a file anyone may write.
|
||||
real = self._sj_checked(["readlink", "-f", "--", path]).stdout.strip() or path
|
||||
mode, owner, group = self._sj_checked([*self.STAT_ARGV, real]).stdout.split()[:3]
|
||||
self._sj_install(text, real, mode, owner, group)
|
||||
|
||||
def _sj_line(self, job: dict[str, object], text: str) -> CronLine:
|
||||
"""The job's line in *text* as it is now, read again for the write."""
|
||||
|
||||
@@ -335,6 +335,19 @@ class TestSwitching:
|
||||
assert f"install -D -m {mode & 0o777:o}" in host.log()
|
||||
assert os.stat(path).st_mode == mode
|
||||
|
||||
def test_a_linked_file_is_written_through_its_link(self, root: Path):
|
||||
real = root / "etc/vzdump.cron"
|
||||
real.write_text("0 1 * * * root vzdump --all\n")
|
||||
real.chmod(0o640)
|
||||
link = root / "etc/cron.d/vzdump"
|
||||
link.symlink_to(real)
|
||||
host = Host(root)
|
||||
job = self._cron(host, str(link))
|
||||
host.manage_scheduled_job(job["key"], "disable", digest=job["digest"])
|
||||
assert link.is_symlink()
|
||||
assert real.read_text() == "#napalm-disabled: 0 1 * * * root vzdump --all\n"
|
||||
assert real.stat().st_mode & 0o777 == 0o640
|
||||
|
||||
def test_a_users_line_goes_through_crontab(self, root: Path):
|
||||
host = Host(root)
|
||||
job = self._cron(host, str(root / "spool/www-data"))
|
||||
|
||||
Reference in new issue
Block a user