Publish curated Unraid-AppOps-Gateway source from a506550ef83ef2d81651e37c98a89f7ee330c730
This commit is contained in:
1 parent
2facb8de34
commit
767e66921e
68 files changed
+15924
-313
No files matched your search
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import copy
|
||||
import hashlib
|
||||
import importlib.util
|
||||
import json
|
||||
import os
|
||||
@@ -106,6 +107,91 @@ def test_fixed_hub_state_reader_is_bounded_and_rejects_symlink_or_missing_state(
|
||||
assert attacker_state.read_bytes() == b'{"status":"attacker"}'
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
os.name == "nt" or not hasattr(os, "geteuid") or os.geteuid() != 0,
|
||||
reason="Hub state reader verifies root-owned fixed storage",
|
||||
)
|
||||
@pytest.mark.parametrize("state_file_mode", [0o640, 0o644, 0o660, 0o664, 0o666])
|
||||
def test_fixed_hub_state_reader_rejects_other_file_modes(
|
||||
store, tmp_path, monkeypatch, state_file_mode
|
||||
):
|
||||
controller_root = tmp_path / "controller"
|
||||
state_root = controller_root / "state"
|
||||
state_root.mkdir(parents=True, mode=0o700)
|
||||
controller_root.chmod(0o700)
|
||||
state_file = state_root / store.HUB_STATE_FILENAME
|
||||
state_file.write_bytes(b'{"status":"success"}')
|
||||
state_file.chmod(state_file_mode)
|
||||
monkeypatch.setattr(store, "CONTROLLER_STATE_PARENT", controller_root)
|
||||
monkeypatch.setattr(store, "CONTROLLER_STATE_DIRECTORY", state_root)
|
||||
|
||||
with pytest.raises(store.ReleaseStoreError, match="unavailable or untrusted"):
|
||||
store.read_hub_state_bytes(missing_ok=False)
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
os.name == "nt" or not hasattr(os, "geteuid") or os.geteuid() != 0,
|
||||
reason="external backup owner checks require root-owned POSIX fixtures",
|
||||
)
|
||||
def test_descriptor_helpers_verify_an_exact_external_owner(store, tmp_path):
|
||||
expected_owner = (99, 100)
|
||||
backup_root = tmp_path / "backups"
|
||||
backup_root.mkdir(mode=0o700)
|
||||
backup_root.chmod(0o700)
|
||||
os.chown(backup_root, *expected_owner)
|
||||
root_fd = os.open(backup_root, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW)
|
||||
attempt_fd = None
|
||||
try:
|
||||
attempt_fd = store.open_child_directory(
|
||||
root_fd,
|
||||
"attempt",
|
||||
create=True,
|
||||
mode=0o700,
|
||||
expected_owner=expected_owner,
|
||||
)
|
||||
artifact_fd = os.open(
|
||||
"manifest.json",
|
||||
os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_NOFOLLOW,
|
||||
0o600,
|
||||
dir_fd=attempt_fd,
|
||||
)
|
||||
try:
|
||||
os.write(artifact_fd, b"private manifest")
|
||||
os.fchmod(artifact_fd, 0o600)
|
||||
os.fchown(artifact_fd, *expected_owner)
|
||||
finally:
|
||||
os.close(artifact_fd)
|
||||
|
||||
assert store.read_at(
|
||||
attempt_fd,
|
||||
"manifest.json",
|
||||
max_bytes=64,
|
||||
expected_mode=0o600,
|
||||
expected_owner=expected_owner,
|
||||
) == b"private manifest"
|
||||
digest, size = store.sha256_at(
|
||||
attempt_fd,
|
||||
"manifest.json",
|
||||
max_bytes=64,
|
||||
expected_mode=0o600,
|
||||
expected_owner=expected_owner,
|
||||
)
|
||||
assert digest == hashlib.sha256(b"private manifest").hexdigest()
|
||||
assert size == len(b"private manifest")
|
||||
with pytest.raises(store.ReleaseStoreError, match="metadata is unsafe"):
|
||||
store.read_at(
|
||||
attempt_fd,
|
||||
"manifest.json",
|
||||
max_bytes=64,
|
||||
expected_mode=0o600,
|
||||
expected_owner=(0, 0),
|
||||
)
|
||||
finally:
|
||||
if attempt_fd is not None:
|
||||
os.close(attempt_fd)
|
||||
os.close(root_fd)
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
os.name == "nt" or not hasattr(os, "geteuid") or os.geteuid() != 0,
|
||||
reason="Hub state reader verifies root-owned fixed storage",
|
||||
|
||||
Reference in new issue
Block a user