feat: include authenticated user identity in HTTP access log#9991
feat: include authenticated user identity in HTTP access log#9991ardentperf wants to merge 1 commit into
Conversation
Set an X-Remote-User response header containing the authenticated
username on every request. This allows the access log to be configured
to include user identity via standard log format directives
(%({x-remote-user}o)s in gunicorn, %{X-Remote-User}o in Apache) without
requiring any changes to pgAdmin's session or auth behaviour.
Signed-off-by: Jeremy Schneider <schneider@ardentperf.com>
WalkthroughThe PR coordinates Flask and Gunicorn to expose authenticated user identity in HTTP access logs. The Flask ChangesUser Identity in HTTP Access Logs
🎯 1 (Trivial) | ⏱️ ~5 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
pkg/docker/gunicorn_config.py (2)
8-11: Consider privacy implications of logging user identities.The
access_log_formatnow includes authenticated usernames in HTTP access logs, which is the intended behavior per the PR objectives. However, deployments should be aware that:
- Usernames (e.g., email addresses like
admin@pgadmin.org) constitute personally identifiable information (PII)- Access logs may be subject to data retention policies under GDPR, CCPA, or other privacy regulations
- Log aggregation systems, backup procedures, and access controls should account for PII in logs
Consider documenting this change in deployment/administration guides so that operators can implement appropriate log handling policies for their regulatory environment.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pkg/docker/gunicorn_config.py` around lines 8 - 11, The access_log_format in pkg/docker/gunicorn_config.py now injects authenticated usernames via the X-Remote-User header (access_log_format), which exposes PII; update documentation and make the behavior configurable: add guidance in deployment/administration docs describing the PII risk, retention/aggregation/backup/access-control recommendations, and instructions to disable or anonymize usernames (e.g., provide a deploy-time option or env var to remove %({x-remote-user}o)s from access_log_format or enable masking) so operators can comply with GDPR/CCPA and other policies.
8-11: ⚡ Quick winConfirm Gunicorn access-log header lookup is case-insensitive (lowercase config is correct).
Gunicorn recommends using lowercase identifiers in
access_log_format, and internally normalizes header lookups for%({header-name}o)s(response headers). So%({x-remote-user}o)swill correctly pick upX-Remote-Usereven though the actual header is capitalized.
- Operational: logging the authenticated username can be sensitive (PII/auditing concerns); ensure retention/access controls align with your compliance requirements.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pkg/docker/gunicorn_config.py` around lines 8 - 11, The access_log_format line currently uses the lowercase header token %({x-remote-user}o)s; confirm that this is correct and leave it lowercase (Gunicorn normalizes header lookups so %({x-remote-user}o)s will match X-Remote-User), and add a short inline comment or README note next to access_log_format to document that header lookup is case-insensitive and that logging usernames may contain PII so retention/access controls must be applied; reference the access_log_format setting and the %({x-remote-user}o)s token when making these clarifications.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@pkg/docker/gunicorn_config.py`:
- Around line 8-11: The access_log_format in pkg/docker/gunicorn_config.py now
injects authenticated usernames via the X-Remote-User header
(access_log_format), which exposes PII; update documentation and make the
behavior configurable: add guidance in deployment/administration docs describing
the PII risk, retention/aggregation/backup/access-control recommendations, and
instructions to disable or anonymize usernames (e.g., provide a deploy-time
option or env var to remove %({x-remote-user}o)s from access_log_format or
enable masking) so operators can comply with GDPR/CCPA and other policies.
- Around line 8-11: The access_log_format line currently uses the lowercase
header token %({x-remote-user}o)s; confirm that this is correct and leave it
lowercase (Gunicorn normalizes header lookups so %({x-remote-user}o)s will match
X-Remote-User), and add a short inline comment or README note next to
access_log_format to document that header lookup is case-insensitive and that
logging usernames may contain PII so retention/access controls must be applied;
reference the access_log_format setting and the %({x-remote-user}o)s token when
making these clarifications.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: fddec9fa-afa7-41a9-b850-a7da26aafb89
📒 Files selected for processing (2)
pkg/docker/gunicorn_config.pyweb/pgadmin/__init__.py
Set an X-Remote-User response header containing the authenticated username on every request. This allows the access log to be configured to include user identity via standard log format directives (%({x-remote-user}o)s in gunicorn, %{X-Remote-User}o in Apache) without requiring any changes to pgAdmin's session or auth behaviour.
Closes #9990
Default gunicorn access log format is at https://gunicorn.org/reference/settings/?h=access_log#access_log_format and https://github.com/benoitc/gunicorn/blob/9bc5891b4b06f25a8ce0e707053dcb2fb9bf638c/gunicorn/config.py#L1413 ; I confirmed that all other fields are default; this PR only changes the user name field.
Performed an end-to-end test on kubernetes with KIND
With this PR:
Master Branch:
Summary by CodeRabbit