-
Notifications
You must be signed in to change notification settings - Fork 322
feat: support auth proxy / reverse proxy authentication #1306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
hyperdx folks want to run behind their own reverse proxies which owns auth, hyperdx should natively support headers to allow such logins Fixes hyperdxio#1144
|
|
@alok87 is attempting to deploy a commit to the HyperDX Team on Vercel. A member of the Team first needs to authorize it. |
| name: AUTH_PROXY_TEAM_NAME, | ||
| collectorAuthenticationEnforced: true, | ||
| }); | ||
| await team.save(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: use createTeam
| export async function createTeam({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed, plz check
| // Use a constant team name for all auth proxy users | ||
| const AUTH_PROXY_TEAM_NAME = 'Auth Proxy Team'; | ||
|
|
||
| // Find or create the shared team | ||
| let team = await Team.findOne({ name: AUTH_PROXY_TEAM_NAME }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use getTeam here because the app only supports a single team
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed, plz check
| */ | ||
| function isAllowedProxyIP(req: Request): boolean { | ||
| if (!config.AUTH_PROXY_WHITELIST) { | ||
| return true; // No whitelist = allow all (not recommended for production) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't we set this to false by default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed, plz check
| return true; // No whitelist = allow all (not recommended for production) | ||
| } | ||
|
|
||
| const allowedIPs = config.AUTH_PROXY_WHITELIST.split(',').map(ip => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: can use splitAndTrimCSV (
hyperdx/packages/common-utils/src/utils.ts
Lines 29 to 34 in 2d06172
| export function splitAndTrimCSV(input: string): string[] { | |
| return input | |
| .split(',') | |
| .map(column => column.trim()) | |
| .filter(column => column.length > 0); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
used
| const allowedIPs = config.AUTH_PROXY_WHITELIST.split(',').map(ip => | ||
| ip.trim(), | ||
| ); | ||
| const clientIP = req.ip || req.socket.remoteAddress || ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we want to extract IP from headers like x-forwarded-for
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, good idea, used.
5ae01a2 to
7e01212
Compare
|
Hi @alok87 just to mirror what I've shared over Slack: We really appreciate you raising contributions to the project. Unfortunately we won’t be able to accept the contribution upstream since it overlaps with functionality we reserve for our commercial enterprise offering. While we aim to keep as much as possible open source, certain features that largely are relevant to enterprises (like SSO/SAML, RBAC, etc.) are kept separate to help ensure the long-term sustainability of the project. Please don’t hesitate to reach out for future contributions if you’d like clarification on our development roadmap or the types of contributions we can accept. |
|
I get the SSO business model, but there's a key distinction: my PR doesn't implement SSO/SAML at all. It just reads an X-Forwarded-User header from external auth systems like OAuth2 Proxy or Authelia (all open source). The actual SSO happens outside HyperDX. This was basic reverse proxy compatibility which any open source expects - Grafana, Kibana, and most self-hostable apps support this out of the box. Rejecting this is like calling "read an IP from X-Forwarded-For" an enterprise feature. It just makes the OSS version incompatible with standard infrastructure. |
Proxy Support for auth
Implements authentication proxy support to enable password-less login via reverse proxy headers (OAuth2 Proxy, Authelia, etc.). Fixes #1144
✅ Security: IP whitelist validation prevents header spoofing
✅ Auto-provisioning: Creates users and shared team on first login
✅ Backward compatible: Existing auth methods unchanged
✅ Production ready: Works with OAuth2 Proxy, Authelia, Nginx, Traefik
When a user accesses HyperDX through a reverse proxy (like OAuth2 Proxy):
X-Forwarded-UserheaderX-Forwarded-UserheaderThe middleware runs before the existing authentication check, so if auth proxy is enabled, it takes priority. If disabled or the header is missing, it falls back to normal password authentication.
Code and Config Changes
Configuration added
New Files
packages/api/src/middleware/authProxy.ts- Auth proxy middleware with IP whitelisting, user auto-provisioning, and session managementModified Files
packages/api/src/middleware/auth.ts- EnhancedisUserAuthenticated()to check auth proxy first when enabledpackages/api/src/config.ts- Added 4 new environment variables for auth proxy configurationpackages/api/src/utils/logger.ts- Fixed default log level bug (??→||)How It Works
Testing
Test with header
Verify in MongoDB
docker exec mongosh hyperdx --eval "db.users.find({email: 'user@example.com'})"