-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
gh-145417: Do not preserve SELinux context when copying venv scripts #145454
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
Changes from 5 commits
de24338
ec2958b
1428e75
8778209
52ee5ef
eec4e46
c4d32d5
88fae45
7dc69f0
878d3b8
75bd937
a76da3e
89c0c92
431c4ac
9bcf6db
ead93d7
97652be
4e127d8
0e506f1
ace163b
d15ad82
7abaefc
2c23790
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -373,6 +373,47 @@ def create_contents(self, paths, filename): | |
| with open(fn, 'wb') as f: | ||
| f.write(b'Still here?') | ||
|
|
||
| def test_install_scripts_mtime(self): | ||
| """ | ||
| Test that install_scripts does not preserve mtime when copying scripts. | ||
| Using mtime serves as a proxy to verify that shutil.copy2 (and thus | ||
| SELinux bin_t contexts) is not being used during script installation. | ||
Shrey-N marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| See gh-145417. | ||
| """ | ||
| import time | ||
|
||
|
|
||
| venv_dir = os.path.dirname(venv.__file__) | ||
| src_path = os.path.join(venv_dir, 'scripts', 'common', 'Activate.ps1') | ||
| src_mtime = os.path.getmtime(src_path) | ||
| if abs(time.time() - src_mtime) < 1.0: | ||
| time.sleep(1.1) | ||
|
||
|
|
||
| rmtree(self.env_dir) | ||
| venv.create(self.env_dir) | ||
|
|
||
| dst_path = os.path.join(self.env_dir, self.bindir, 'Activate.ps1') | ||
| self.assertTrue(os.path.exists(dst_path), "Activate.ps1 not found in venv") | ||
| dst_mtime = os.path.getmtime(dst_path) | ||
|
|
||
| # shutil.copy should update mtime, whereas shutil.copy2 would preserve it | ||
| self.assertNotEqual(src_mtime, dst_mtime, | ||
| "mtime was preserved, meaning shutil.copy2 was used") | ||
|
|
||
| # Permissions and content should still match | ||
| src_stat = os.stat(src_path) | ||
| dst_stat = os.stat(dst_path) | ||
| self.assertEqual(src_stat.st_mode, dst_stat.st_mode, "File modes do not match") | ||
|
|
||
| with open(src_path, 'rb') as f: | ||
| src_data = f.read() | ||
| with open(dst_path, 'rb') as f: | ||
| dst_data = f.read() | ||
| self.assertEqual(src_data, dst_data, "File contents do not match") | ||
|
|
||
| self.assertNotIn(b'__VENV_PYTHON__', src_data, | ||
| "Test assumes Activate.ps1 is a static file, not a template") | ||
|
||
|
|
||
|
|
||
| def test_overwrite_existing(self): | ||
| """ | ||
| Test creating environment in an existing directory. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| gh-145417: Fixed venv to prevent incorrect preservation of SELinux contexts when copying scripts by using shutil.copy instead of shutil.copy2. |
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.
It's useful to link the issue here so people reading this know why it matters.