Skip to content

Conversation

@alok87
Copy link

@alok87 alok87 commented Oct 28, 2025

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):

  1. User authenticates with OAuth provider (Google, GitHub, Okta, etc.)
  2. Reverse proxy validates the OAuth token and adds user's email to X-Forwarded-User header
  3. Auth proxy middleware intercepts the request and:
    • Validates the request comes from a whitelisted proxy IP (security check)
    • Extracts user email from the X-Forwarded-User header
    • Looks up the user in MongoDB by email
    • If user doesn't exist and auto-signup is enabled:
      • Creates a shared team called "Auth Proxy Team" (if it doesn't exist)
      • Creates the user and assigns them to this team
      • Sets up default connections and sources
    • Attaches the user to the request object
    • Establishes a Passport.js session
  4. User is logged in - no password needed!

The 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

AUTH_PROXY_ENABLED=true                    # Enable auth proxy
AUTH_PROXY_HEADER_NAME=X-Forwarded-User    # Header with user email
AUTH_PROXY_AUTO_SIGN_UP=true               # Auto-create users
AUTH_PROXY_WHITELIST=172.17.0.1,10.0.0.1   # Trusted proxy IPs

New Files

  • packages/api/src/middleware/authProxy.ts - Auth proxy middleware with IP whitelisting, user auto-provisioning, and session management

Modified Files

  • packages/api/src/middleware/auth.ts - Enhanced isUserAuthenticated() to check auth proxy first when enabled
  • packages/api/src/config.ts - Added 4 new environment variables for auth proxy configuration
  • packages/api/src/utils/logger.ts - Fixed default log level bug (??||)

How It Works

User → OAuth Provider → OAuth2 Proxy (adds header) → HyperDX → Logged in!

Testing

Test with header

$ curl -H "X-Forwarded-User: user@example.com" http://localhost:8000/me
{"accessKey":"2X","createdAt":"2025-10-28T12:13:56.866Z","email":"user@example.com","id":"6900b38438e3ac5d85d7d85c","name":"user@example.com","team":{"_id":"690091e6052a7002886b430d","name":"testuser@example.com's Team","allowedAuthMethods":[],"collectorAuthenticationEnforced":true,"hookId":"410ad587-3373-41c8-b685-693f7728b47e","apiKey":"219bf044-0dba-4d04-8698-ba545c65d18d","createdAt":"2025-10-28T09:50:30.101Z","updatedAt":"2025-10-28T09:50:30.101Z","__v":0,"id":"690091e6052a7002886b430d"},"usageStatsEnabled":false,"aiAssistantEnabled":true}

Verify in MongoDB

docker exec mongosh hyperdx --eval "db.users.find({email: 'user@example.com'})"


## Security Notes

⚠️ **MUST** set `AUTH_PROXY_WHITELIST` in production to prevent header spoofing  

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
@changeset-bot
Copy link

changeset-bot bot commented Oct 28, 2025

⚠️ No Changeset found

Latest commit: 7e01212

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Oct 28, 2025

@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();
Copy link
Member

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({

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed, plz check

Comment on lines 83 to 87
// 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 });
Copy link
Member

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

Copy link
Author

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)
Copy link
Member

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?

Copy link
Author

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 =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: can use splitAndTrimCSV (

export function splitAndTrimCSV(input: string): string[] {
return input
.split(',')
.map(column => column.trim())
.filter(column => column.length > 0);
}
)

Copy link
Author

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 || '';
Copy link
Member

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, good idea, used.

@alok87 alok87 force-pushed the feat-auth-proxy-1144 branch from 5ae01a2 to 7e01212 Compare October 29, 2025 07:06
@MikeShi42
Copy link
Contributor

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.

@MikeShi42 MikeShi42 closed this Oct 30, 2025
@alok87
Copy link
Author

alok87 commented Oct 30, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request - support auth proxy authentication

3 participants