Merge pull request #963 from tdurieux/fix/vector-nginx-log-access

fix: let Vector read restricted Nginx access logs
This commit is contained in:
Thomas Durieux authored and GitHub committed 2026-11-15 00:17:45 +01:00
commit c08db8a775
3 files changed
+33 -2

No files matched your search

+11 -1
View File
@@ -41,7 +41,13 @@ on `fix/remaining-production-findings`; do not deploy it without that base.
can exceed 10 MiB between checks; this is not a hard file quota. Use a dedicated
filesystem quota if hard local containment is needed. Use rename/reopen, not
copytruncate. Vector excludes compressed history and reads new files from end.
6. Set `DOCKER_LOG_DIR` if Docker's data root differs from `/var/lib/docker/containers`,
6. Set `NGINX_LOG_GID` to the numeric group owning the access log
(`stat -c %g /var/log/nginx/anonymous.access.json`; normally the host `adm`
group). Vector receives this supplementary group while retaining no Linux
capabilities and read-only mounts. Keep logs `0640` and ensure logrotate
creates replacements with the same group, as in `nginx.logrotate`; do not
make access logs world-readable. Recreate Vector after changing this setting.
Set `DOCKER_LOG_DIR` if Docker's data root differs from `/var/lib/docker/containers`,
and `NGINX_LOG_DIR` if needed. The collector mounts these directories read-only;
it has no Docker socket, host PID namespace or ability to restart applications.
Start with `docker compose -f deploy/logging/compose.yml up -d`.
@@ -320,3 +326,7 @@ node-redis client against a disposable loopback-only Redis container. It checks
cold concurrent statistics, recent/grouped-history reads, overload rejection and
subsequent transaction integrity, unavailable fallback, and restart recovery.
The fixture uses only synthetic counters and removes its container on exit.
For the focused restricted-file/rotation regression, run
`LOGGING_ACCESS_ONLY=1 python3 scripts/test-logging.py`. This uses synthetic
`0640` logs in an isolated Docker project and preserves capability restrictions.
+2
View File
@@ -26,6 +26,8 @@ services:
command: [--config, /etc/vector/vector.yaml]
# File access only: no Docker API socket and no host PID namespace.
user: '0:0'
# Match the host logrotate group; keep cap_drop ALL and read-only mounts.
group_add: ['${NGINX_LOG_GID:?Set the numeric group owning Nginx access logs}']
volumes:
- ./vector.yaml:/etc/vector/vector.yaml:ro
- ./sanitize.vrl:/etc/vector/sanitize.vrl:ro
+20 -1
View File
@@ -45,12 +45,15 @@ with tempfile.TemporaryDirectory(prefix=PROJECT) as temp:
log = docker / 'fixture/fixture-json.log'
log.touch()
edge = nginx / 'anonymous.access.json'
reader_gid = os.getgid() if os.getgid() != 0 else 65534
edge.touch()
if os.getuid() == 0: os.chown(edge, 65534, reader_gid)
edge.chmod(0o640) # root without DAC capabilities needs the supplementary group
password = temp / 'password'
password.write_text(secrets.token_urlsafe(32))
password.chmod(0o644) # temp directory is 0700; Grafana uid must read the bind mount
env = {**os.environ, 'GRAFANA_ADMIN_USER': 'local-test', 'GRAFANA_PASSWORD_FILE': str(password),
'DOCKER_LOG_DIR': str(docker), 'NGINX_LOG_DIR': str(nginx), 'GRAFANA_PORT': '0'}
'NGINX_LOG_GID': str(reader_gid), 'DOCKER_LOG_DIR': str(docker), 'NGINX_LOG_DIR': str(nginx), 'GRAFANA_PORT': '0'}
override = temp / 'override.yml'
override.write_text(yaml.safe_dump({'services': {
'victorialogs': {'ports': ['127.0.0.1::9428']},
@@ -121,6 +124,22 @@ with tempfile.TemporaryDirectory(prefix=PROJECT) as temp:
assert len(query('event:job_failed')) == 1
assert all('requestId' not in r['_stream'] and 'instance' not in r['_stream'] for r in rows)
print('PASS ingestion, privacy allowlist, malformed input, API/streamer/job/edge correlation')
# Rename/create rotation must retain read access to both inodes.
edge.rename(nginx / 'anonymous.access.json.1')
edge.touch(); edge.chmod(0o640)
if os.getuid() == 0: os.chown(edge, 65534, reader_gid)
time.sleep(2) # discover the empty replacement before appending (read_from=end)
rotation_id = str(uuid.uuid4())
with edge.open('a') as out:
out.write(json.dumps({'status': 502, 'request_time': 0.1,
'app_request_id': rotation_id, 'route': '/api/repo/:id'}) + '\n')
wait_for(lambda: len(query('requestId:="' + rotation_id + '"')) == 1)
inspection = json.loads(run(['docker', 'inspect', compose('ps', '-q', 'vector')]))[0]
assert str(reader_gid) in inspection['HostConfig']['GroupAdd']
assert 'ALL' in inspection['HostConfig']['CapDrop']
print('PASS restricted 0640 Nginx access and rename/create rotation with no capabilities')
if os.environ.get('LOGGING_ACCESS_ONLY') == '1':
sys.exit(0)
# Query every shipped dashboard and alert expression against the real server.
dashboard = json.loads((CONFIG / 'grafana/dashboards/operations.json').read_text())
for panel in dashboard['panels']: