Skip to content

Commit 5c27f42

Browse files
committed
Optionally log API calls made by dom0
Developers normally edit the code to log the calls or use a management domain such as a GUIVM to see logged calls. Add a command-line option and environment variable to enable logging dom0 calls also. Fixes: QubesOS/qubes-issues#10689
1 parent f9225c1 commit 5c27f42

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

qubes/api/__init__.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,14 +322,17 @@ class QubesDaemonProtocol(asyncio.Protocol):
322322
buffer_size = 65536
323323
header = struct.Struct("Bx")
324324

325-
def __init__(self, handler, *args, app, debug=False, **kwargs):
325+
def __init__(
326+
self, handler, *args, app, debug=False, log_dom0_call=False, **kwargs
327+
):
326328
super().__init__(*args, **kwargs)
327329
self.handler = handler
328330
self.app = app
329331
self.untrusted_buffer = io.BytesIO()
330332
self.len_untrusted_buffer = 0
331333
self.transport = None
332334
self.debug = debug
335+
self.log_dom0_call = log_dom0_call
333336
self.event_sent = False
334337
self.mgmt = None
335338

@@ -388,6 +391,18 @@ def eof_received(self):
388391
return True
389392

390393
async def respond(self, src, meth, dest, arg, *, untrusted_payload):
394+
if self.log_dom0_call:
395+
call_fmt = (
396+
"received call %r+%r (%r → %r) with payload of %d bytes"
397+
)
398+
self.app.log.debug(
399+
call_fmt,
400+
meth,
401+
arg,
402+
src,
403+
dest,
404+
len(untrusted_payload),
405+
)
391406
exc_fmt = (
392407
"failed call %r+%r (%r → %r) with payload of %d bytes due to %r"
393408
)

qubes/tools/qubesd.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ def sighandler(loop, signame, servers, app):
3838
help="Enable verbose error logging (all exceptions with full "
3939
"tracebacks) and also send tracebacks to Admin API clients",
4040
)
41+
parser.add_argument(
42+
"--log-dom0-call",
43+
action="store_true",
44+
default=False,
45+
help="Enable logging API calls made by dom0",
46+
)
4147

4248

4349
def main(args=None):
@@ -64,6 +70,8 @@ def main(args=None):
6470
qubes.api.misc.QubesMiscAPI,
6571
app=args.app,
6672
debug=args.debug,
73+
log_dom0_call=args.log_dom0_call
74+
or os.environ.get("QUBES_LOG_DOM0_CALL"),
6775
)
6876
)
6977

0 commit comments

Comments
 (0)