Skip to content

Commit 7d66382

Browse files
committed
Merge remote-tracking branch 'origin/pr/174'
* origin/pr/174: tests: fix POLICY_PROGRAM and update documentation
2 parents 98e0acd + 34211a2 commit 7d66382

File tree

2 files changed

+82
-14
lines changed

2 files changed

+82
-14
lines changed

doc/qrexec-policy-daemon.rst

+10-13
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,23 @@ Optional arguments:
2020
- assume_yes_for_ask=yes
2121
- just_evaluate=yes
2222

23+
End of request is always an empty line.
2324

2425
Response
2526
--------
2627

27-
`result=allow/deny`
28+
result=allow/deny
2829

30+
All responses that do not start with result=allow or result=deny are incorrect and will be rejected.
2931
Any possible extensions may be placed on next lines.
30-
All responses that do not start with `result=allow` or `result=deny` are
31-
incorrect and will be rejected.
32-
33-
End of request is always an empty line.
3432
Response is always terminated by EOF.
3533

34+
- result=allow requires autostart= and either target= or target_uuid= extensions.
35+
- result=deny forbids autostart=, target= and target_uuid= extensions.
36+
3637
Extensions include:
3738

38-
- `target=`: Name of the target, optionally preceded by `@dispvm:`
39-
`@dispvm:` prefix means that this is a disposable VM template and a new disposable VM will be created automatically.
40-
In allow responses, ignored if `target_uuid=` is present, required otherwise.
41-
Forbidden in deny responses.
42-
- `autostart=`: `True` to automatically start the VM, `False` to not start it.
43-
Anything else is invalid.
44-
Required in allow responses, forbidden in deny responses.
45-
- `requested_target=`: Normalized version of the target domain.
39+
- target=: The name of the target domain. If prefixed with @dispvm:, it indicates a disposable VM template, and a new disposable VM will be created automatically.
40+
- target_uuid=: The UUID of the target domain.
41+
- autostart=: True to automatically start the VM, False to not start it. Anything else is invalid.
42+
- requested_target=: Normalized version of the target domain.

qrexec/tests/socket/daemon.py

+72-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import socket
3131

3232
import psutil
33+
import pytest
3334

3435
from . import qrexec
3536
from . import util
@@ -49,9 +50,27 @@ class TestDaemon(unittest.TestCase):
4950
POLICY_PROGRAM = """\
5051
#!/bin/sh
5152
53+
# -- remote_domain_name target_name service_name
5254
echo "$@" > {tempdir}/qrexec-policy-params
55+
5356
sleep $(cat {tempdir}/qrexec-policy-sleep || echo 0)
54-
exit $(cat {tempdir}/qrexec-policy-exitcode || echo 1)
57+
exit_code=$(cat {tempdir}/qrexec-policy-exitcode || echo 1)
58+
59+
# Prepare the response based on the exit code
60+
if [ "$exit_code" -eq 0 ]; then
61+
# Allow response
62+
printf 'result=allow\n'
63+
printf 'autostart=True\n'
64+
printf 'user=toto\n'
65+
printf 'target=%s\n' "$3"
66+
printf 'requested_target=%s\n' "$3"
67+
else
68+
# Deny response
69+
echo "result=deny"
70+
fi
71+
# End of response
72+
73+
exit $exit_code
5574
"""
5675

5776
def setUp(self):
@@ -268,6 +287,58 @@ def recv_refused(agent):
268287
)
269288
recv_refused(agent)
270289

290+
def test_new_style_request(self):
291+
"""
292+
Test that qrexec-daemon accepts request.
293+
"""
294+
agent = self.start_daemon_with_agent()
295+
agent.handshake()
296+
297+
target_domain_name = "target_domain"
298+
ident = "ab"
299+
300+
# check policy program output
301+
policy_program_path = os.path.join(self.tempdir, "qrexec-policy-exec")
302+
303+
# set deny
304+
self.set_policy_params(1, 1)
305+
306+
result = subprocess.run(
307+
[policy_program_path, "--", "somedomain", "anotherdomain", "someservice"],
308+
capture_output=True,
309+
text=True
310+
)
311+
assert result.stdout == "result=deny\n"
312+
313+
# set allow
314+
self.set_policy_params(1, 0)
315+
316+
result = subprocess.run(
317+
[policy_program_path, "--", "somedomain", "anotherdomain", "someservice"],
318+
capture_output=True,
319+
text=True
320+
)
321+
assert result.stdout == """result=allow
322+
autostart=True
323+
user=toto
324+
target=anotherdomain
325+
requested_target=anotherdomain
326+
"""
327+
328+
# check allowed request
329+
agent.send_message(
330+
qrexec.MSG_TRIGGER_SERVICE3,
331+
struct.pack("<64s32s", self.domain_name.encode(), ident.encode())
332+
+ b"a\0",
333+
)
334+
message_type, data = agent.recv_message()
335+
self.assertEqual(message_type, qrexec.MSG_EXEC_CMDLINE)
336+
self.assertTrue(
337+
os.path.exists(
338+
os.path.join(self.tempdir, "qrexec-policy-params")
339+
)
340+
)
341+
271342
def test_qsb_089(self):
272343
"""
273344
Test that qrexec-daemon doesn't corrupt memory on empty request

0 commit comments

Comments
 (0)