Skip to content
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

Restrict permissions for locking files #3254

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions luigi/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
# Create a pid file if it does not exist
try:
os.mkdir(pid_dir)
os.chmod(pid_dir, 0o777)
os.chmod(pid_dir, 0o775)

Check warning on line 103 in luigi/lock.py

View check run for this annotation

Codecov / codecov/patch

luigi/lock.py#L103

Added line #L103 was not covered by tests
except OSError as exc:
if exc.errno != errno.EEXIST:
raise
Expand Down Expand Up @@ -153,8 +153,8 @@
with open(pid_file, 'w') as f:
f.writelines('{}\n'.format(pid) for pid in pids_set)

# Make the .pid-file writable by all (when the os allows for it)
# Make the .pid-file writable by user or group (when the os allows for it)
if os.name != 'nt':
s = os.stat(pid_file)
if os.getuid() == s.st_uid:
os.chmod(pid_file, s.st_mode | 0o777)
os.chmod(pid_file, 0o664)

Check warning on line 160 in luigi/lock.py

View check run for this annotation

Codecov / codecov/patch

luigi/lock.py#L160

Added line #L160 was not covered by tests
4 changes: 2 additions & 2 deletions test/lock_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def test_acquiring_partially_taken_lock(self):
self.assertTrue(acquired)

s = os.stat(self.pid_file)
self.assertEqual(s.st_mode & 0o777, 0o777)
self.assertEqual(s.st_mode & 0o777, 0o664)

def test_acquiring_lock_from_missing_process(self):
fake_pid = 99999
Expand All @@ -111,7 +111,7 @@ def test_acquiring_lock_from_missing_process(self):
self.assertTrue(acquired)

s = os.stat(self.pid_file)
self.assertEqual(s.st_mode & 0o777, 0o777)
self.assertEqual(s.st_mode & 0o777, 0o664)

@mock.patch('os.kill')
def test_take_lock_with_kill(self, kill_fn):
Expand Down