You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tooling.apache.org by sb...@apache.org on 2026/09/11 16:36:23 UTC
(tooling-trusted-releases) branch main updated: Fix release announcement recipients and sandboxed rsync uploads (#1592)
This is an automated email from the ASF dual-hosted git repository.
sbp pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tooling-trusted-releases.git
The following commit(s) were added to refs/heads/main by this push:
new e0b97e70 Fix release announcement recipients and sandboxed rsync uploads (#1592)
e0b97e70 is described below
commit e0b97e70ffdcf9d4a5e93942135fc769399a12ae
Author: tison <wa...@gmail.com>
AuthorDate: Sat Sep 12 00:36:17 2026 +0800
Fix release announcement recipients and sandboxed rsync uploads (#1592)
* Allow release announcements to the foundation mailing list
* Run sandboxed rsync uploads from their destination directory
* Mock process-group signals in worker termination tests
---
atr/ssh.py | 14 +++++++----
atr/tasks/message.py | 4 +++-
tests/unit/test_manager_terminate.py | 6 +++++
tests/unit/test_message.py | 45 +++++++++++++++++++++++++++++++-----
tests/unit/test_ssh_rsync_write.py | 12 +++-------
5 files changed, 60 insertions(+), 21 deletions(-)
diff --git a/atr/ssh.py b/atr/ssh.py
index edd19ef5..ca658887 100644
--- a/atr/ssh.py
+++ b/atr/ssh.py
@@ -290,11 +290,12 @@ async def server_stop(server: asyncssh.SSHAcceptor) -> None:
log.info("SSH server stopped")
-def _build_rsync_write_argv(argv: list[str], path: safe.StatePath) -> list[str]:
+def _build_rsync_write_argv(argv: list[str]) -> list[str]:
"""Build the rsync command for a write, adding enforced server side limits."""
if len(argv) < 2 or argv[-2] != ".":
raise RuntimeError("Validated rsync write argv must end with '.' and the destination path")
- return [*argv[:-2], f"--max-size={_RSYNC_MAX_UPLOAD_SIZE}", "--info=skip2", ".", str(path)]
+ # Use exactly '.' so rsync does not reopen ancestors outside the Landlock sandbox
+ return [*argv[:-2], f"--max-size={_RSYNC_MAX_UPLOAD_SIZE}", "--info=skip2", ".", "."]
async def _drain_stderr(stream: asyncio.StreamReader) -> bytes:
@@ -677,13 +678,13 @@ async def _step_07b_process_validated_rsync_write(
nonlocal exit_status
if old_rev is not None:
log.info(f"Using old revision {old_rev.number} and interim path {path}")
- rsync_argv = _build_rsync_write_argv(argv, path)
+ rsync_argv = _build_rsync_write_argv(argv)
rsync_argv = sandbox.command(rsync_argv, rw_paths=[str(path)])
###################################################
### Calls _step_08_execute_rsync_upload_command ###
###################################################
- exit_status = await _step_08_execute_rsync(process, rsync_argv)
+ exit_status = await _step_08_execute_rsync(process, rsync_argv, cwd=path)
if exit_status != 0:
if old_rev is not None:
for_revision = f"successor of revision {old_rev.number}"
@@ -757,7 +758,9 @@ async def _step_07c_ensure_release_object_for_write(project_key: safe.ProjectKey
await data.commit()
-async def _step_08_execute_rsync(process: asyncssh.SSHServerProcess, argv: list[str]) -> int:
+async def _step_08_execute_rsync(
+ process: asyncssh.SSHServerProcess, argv: list[str], *, cwd: safe.StatePath | None = None
+) -> int:
"""Execute the modified rsync command."""
log.info(f"Executing modified rsync command: {' '.join(argv)}")
proc = await asyncio.create_subprocess_exec(
@@ -765,6 +768,7 @@ async def _step_08_execute_rsync(process: asyncssh.SSHServerProcess, argv: list[
stdin=asyncio.subprocess.PIPE,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
+ cwd=cwd,
)
stderr_stream = proc.stderr
drain = asyncio.create_task(_drain_stderr(stderr_stream)) if stderr_stream is not None else None
diff --git a/atr/tasks/message.py b/atr/tasks/message.py
index ae90f5d6..5ec2ac6a 100644
--- a/atr/tasks/message.py
+++ b/atr/tasks/message.py
@@ -96,7 +96,9 @@ def _verify_recipients(task_args: args.Send, sender_asf_uid: str) -> None:
sending_to_self = addr == f"{sender_asf_uid}@apache.org"
# audit_guidance we intentionally allow users to send messages to committees they are not a part of
sending_to_committee = recipient_domain.endswith(".apache.org")
- if not (sending_to_self or sending_to_committee):
+ # The foundation announcement list is on the root domain, unlike committee lists
+ sending_to_announce = addr == "announce@apache.org"
+ if not (sending_to_self or sending_to_committee or sending_to_announce):
raise SendError(f"You are not permitted to send emails to {addr}")
diff --git a/tests/unit/test_manager_terminate.py b/tests/unit/test_manager_terminate.py
index df5ce291..2aaca747 100644
--- a/tests/unit/test_manager_terminate.py
+++ b/tests/unit/test_manager_terminate.py
@@ -78,6 +78,8 @@ async def test_stop_worker_kills_the_group_when_a_child_survives(monkeypatch: py
async def test_stop_worker_reports_a_child_which_outlives_the_deadline(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(manager, "_live_process_group_members", lambda pgid: [123])
+ killpg = mock.Mock()
+ monkeypatch.setattr("os.killpg", killpg)
monkeypatch.setattr(manager, "_KILL_WAIT_SECONDS", 0.05)
monkeypatch.setattr(manager, "_KILL_POLL_SECONDS", 0.01)
errors = []
@@ -86,6 +88,7 @@ async def test_stop_worker_reports_a_child_which_outlives_the_deadline(monkeypat
await manager.WorkerManager().stop_worker(worker_process)
+ assert killpg.call_args_list == [mock.call(999, signal.SIGTERM), mock.call(999, signal.SIGKILL)]
assert len(errors) == 1
assert "live members after SIGKILL" in errors[0]
assert worker_process.stopping is False
@@ -105,6 +108,8 @@ async def test_stop_worker_waits_for_a_child_which_is_slow_to_die(monkeypatch: p
# The child is still listed for the first few looks after SIGKILL, as it is in reality
looks = [[123], [123], [123], []]
monkeypatch.setattr(manager, "_live_process_group_members", lambda pgid: looks.pop(0) if looks else [])
+ killpg = mock.Mock()
+ monkeypatch.setattr("os.killpg", killpg)
monkeypatch.setattr(manager, "_KILL_POLL_SECONDS", 0.01)
errors = []
monkeypatch.setattr(manager.log, "error", lambda message: errors.append(message))
@@ -112,6 +117,7 @@ async def test_stop_worker_waits_for_a_child_which_is_slow_to_die(monkeypatch: p
await manager.WorkerManager().stop_worker(worker_process)
+ assert killpg.call_args_list == [mock.call(999, signal.SIGTERM), mock.call(999, signal.SIGKILL)]
assert errors == []
assert worker_process.stopping is True
diff --git a/tests/unit/test_message.py b/tests/unit/test_message.py
index d283e3d6..bee2d709 100644
--- a/tests/unit/test_message.py
+++ b/tests/unit/test_message.py
@@ -15,7 +15,7 @@
# specific language governing permissions and limitations
# under the License.
-"""Tests for ASF ID validation in atr.tasks.message module."""
+"""Tests for sender and recipient validation in atr.tasks.message module."""
import contextlib
import unittest.mock as mock
@@ -143,6 +143,31 @@ async def test_send_rejects_invalid_asf_id(monkeypatch: "MonkeyPatch") -> None:
await message.send(_send_args(email_sender="nosuchuser@apache.org"))
+@pytest.mark.asyncio
+@pytest.mark.parametrize("recipient_field", ["email_to", "email_cc", "email_bcc"])
+@pytest.mark.parametrize("recipient", ["otheruser@apache.org", "announce@example.org", "announce@notapache.org"])
+async def test_send_rejects_unauthorized_recipients(
+ monkeypatch: "MonkeyPatch", recipient_field: str, recipient: str
+) -> None:
+ monkeypatch.setattr(
+ "atr.tasks.message.ldap.account_lookup",
+ mock.AsyncMock(
+ return_value=ldap.Result(
+ dn="uid=validuser,ou=people,dc=apache,dc=org", uid=["validuser"], cn=["Valid User"]
+ )
+ ),
+ )
+ mock_storage_write = mock.MagicMock()
+ monkeypatch.setattr("atr.tasks.message.storage.write", mock_storage_write)
+ task_args = _send_args()
+ task_args[recipient_field] = recipient if (recipient_field == "email_to") else [recipient]
+
+ with pytest.raises(message.SendError, match="You are not permitted to send emails"):
+ await message.send(task_args)
+
+ mock_storage_write.assert_not_called()
+
+
@pytest.mark.asyncio
async def test_send_returns_warnings_on_partial_failure(monkeypatch: "MonkeyPatch") -> None:
monkeypatch.setattr(
@@ -176,8 +201,12 @@ async def test_send_returns_warnings_on_partial_failure(monkeypatch: "MonkeyPatc
@pytest.mark.asyncio
-async def test_send_succeeds_with_valid_asf_id(monkeypatch: "MonkeyPatch") -> None:
- """Test that a valid ASF UID passes LDAP validation and sends the email."""
+@pytest.mark.parametrize("recipient_field", ["email_to", "email_cc", "email_bcc"])
+@pytest.mark.parametrize("recipient", ["dev@project.apache.org", "validuser@apache.org", "announce@apache.org"])
+async def test_send_succeeds_with_valid_asf_id(
+ monkeypatch: "MonkeyPatch", recipient_field: str, recipient: str
+) -> None:
+ """A valid ASF sender can deliver to each permitted recipient in any envelope field."""
# ldap.account_lookup returns a dict for a known UID
monkeypatch.setattr(
"atr.tasks.message.ldap.account_lookup",
@@ -197,12 +226,14 @@ async def test_send_succeeds_with_valid_asf_id(monkeypatch: "MonkeyPatch") -> No
mock_write.as_foundation_committer.return_value = mock_wafc
@contextlib.asynccontextmanager
- async def mock_storage_write(_asf_uid: str): # type: ignore[no-untyped-def]
+ async def mock_storage_write(_asf_uid: str) -> AsyncIterator[mock.MagicMock]:
yield mock_write
monkeypatch.setattr("atr.tasks.message.storage.write", mock_storage_write)
- result = await message.send(_send_args(email_sender="validuser@apache.org"))
+ task_args = _send_args(email_to="private@project.apache.org")
+ task_args[recipient_field] = recipient if (recipient_field == "email_to") else [recipient]
+ result = await message.send(task_args)
# Verify the result
assert result is not None
@@ -210,7 +241,9 @@ async def test_send_succeeds_with_valid_asf_id(monkeypatch: "MonkeyPatch") -> No
assert result.mail_send_warnings == []
# Verify mail.send was called exactly once
- mock_mail_send.assert_called_once()
+ mock_mail_send.assert_awaited_once()
+ sent_message = mock_mail_send.call_args.args[0]
+ assert getattr(sent_message, recipient_field) == task_args[recipient_field]
def test_send_task_args_omits_only_empty_message_id() -> None:
diff --git a/tests/unit/test_ssh_rsync_write.py b/tests/unit/test_ssh_rsync_write.py
index 4df8d03a..ccdee647 100644
--- a/tests/unit/test_ssh_rsync_write.py
+++ b/tests/unit/test_ssh_rsync_write.py
@@ -19,19 +19,13 @@
from __future__ import annotations
-from typing import TYPE_CHECKING
-
import atr.ssh as ssh
-if TYPE_CHECKING:
- import pathlib
-
-def test_build_rsync_write_argv_adds_server_side_limits(tmp_path: pathlib.Path) -> None:
+def test_build_rsync_write_argv_adds_server_side_limits() -> None:
argv = ["rsync", "--server", "-vlogDtpre.iLsfxCIvu", "--delete", ".", "/proj/v1/"]
- path = tmp_path / "atr-write" / "revision"
- result = ssh._build_rsync_write_argv(argv, path)
+ result = ssh._build_rsync_write_argv(argv)
assert result == [
"rsync",
@@ -41,6 +35,6 @@ def test_build_rsync_write_argv_adds_server_side_limits(tmp_path: pathlib.Path)
f"--max-size={ssh._RSYNC_MAX_UPLOAD_SIZE}",
"--info=skip2",
".",
- str(path),
+ ".",
]
assert argv == ["rsync", "--server", "-vlogDtpre.iLsfxCIvu", "--delete", ".", "/proj/v1/"]
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tooling.apache.org
For additional commands, e-mail: commits-help@tooling.apache.org