Skip to content

Commit

Permalink
Set 722 file permissions on UDS socket
Browse files Browse the repository at this point in the history
The permissions of the socket created by aiohttp aren't as permissive as
the ones set by the real agent. (see
aio-libs/aiohttp#4155)

from @devinsba:

test agent:

```
cnb@my-app:/var/run/datadog$ ls -la
total 4
drwxr-xr-x 2 root root   60 Aug  1 21:24 .
drwxr-xr-x 1 root root 4096 Aug  1 21:24 ..
srwxr-xr-x 1 root root    0 Aug  1 21:24 apm.socket
```

real agent:

```
cnb@my-app:/var/run/datadog$ ls -la
total 4
drwxr-xr-x 2 root root   80 Aug  1 21:30 .
drwxr-xr-x 1 root root 4096 Aug  1 21:31 ..
srwx-w--w- 1 root root    0 Aug  1 21:30 apm.socket
```

aiohttp doesn't seem to have a configurable way
to set these permissions but it does let us create and
manage a socket ourselves, so let's try that.
  • Loading branch information
Kyle-Verhoog committed Aug 2, 2022
1 parent 9c2acf3 commit 42789e5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 10 additions & 1 deletion ddapm_test_agent/agent.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import argparse
import atexit
import base64
from collections import OrderedDict
import json
import logging
import os
import pprint
import socket
import sys
from typing import Awaitable
from typing import Callable
Expand Down Expand Up @@ -722,6 +724,13 @@ def main(args: Optional[List[str]] = None) -> None:
print(_get_version())
sys.exit(0)

apm_sock: Optional[socket.socket] = None
if parsed_args.trace_uds_socket is not None:
apm_sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
apm_sock.bind(parsed_args.trace_uds_socket)
os.chmod(parsed_args.trace_uds_socket, 0o722)
atexit.register(lambda: os.unlink(parsed_args.trace_uds_socket))

if parsed_args.trace_request_delay is not None:
log.info(
"Trace request stall seconds setting set to %r.",
Expand All @@ -744,7 +753,7 @@ def main(args: Optional[List[str]] = None) -> None:
trace_request_delay=parsed_args.trace_request_delay,
)

web.run_app(app, path=parsed_args.trace_uds_socket, port=parsed_args.port)
web.run_app(app, sock=apm_sock, port=parsed_args.port)


if __name__ == "__main__":
Expand Down
4 changes: 4 additions & 0 deletions releasenotes/notes/uds-permissions-903266ac6445b873.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
fixes:
- |
Use 722 permissions for UDS socket to match the agent.

0 comments on commit 42789e5

Please sign in to comment.