Skip to content
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

Add header-based authentication support #5271

Open
wants to merge 2 commits into
base: 1.0-develop
Choose a base branch
from

Conversation

banddude
Copy link

@banddude banddude commented Jan 6, 2025

This PR adds support for header-based authentication, allowing users to authenticate via HTTP headers. This is particularly useful for proxy authentication via SSO providers like Authelia or Authentik.

Features:

  • New HeaderAuthentication middleware
  • Configurable header names for username and email
  • Optional automatic user creation
  • Comprehensive test suite
  • SQLite and MySQL compatibility

The feature can be enabled via environment variables:

AUTH_HEADER_ENABLED=true
AUTH_HEADER_AUTO_CREATE=true
AUTH_HEADER_USERNAME=X-Auth-Username
AUTH_HEADER_EMAIL=X-Auth-Email

Reverse Proxy Configuration

When using this feature with a reverse proxy, it is important to exclude the /api route from header authentication to prevent issues with API requests. Here is an example Nginx configuration:

location /api {
    proxy_pass http://panel:80;
    # Do not add auth headers for API routes
}

location / {
    proxy_pass http://panel:80;
    # Add auth headers here
    proxy_set_header X-Auth-Username $user;
    proxy_set_header X-Auth-Email $email;
}

This implementation provides a simple way to integrate with existing SSO solutions without requiring complex LDAP, SAML, or OIDC implementations. The proxy handles the authentication, and the panel trusts the headers it receives.

All tests are passing, and the implementation is compatible with both MySQL and SQLite databases.

Fixes #4026

MIKE and others added 2 commits January 5, 2025 23:35
This commit adds support for header-based authentication, allowing users to authenticate via HTTP headers. This is particularly useful for proxy authentication via SSO providers like Authelia or Authentik.

Features:\n- New HeaderAuthentication middleware\n- Configurable header names for username and email\n- Optional automatic user creation\n- Comprehensive test suite\n- SQLite and MySQL compatibility

The feature can be enabled via environment variables:\nAUTH_HEADER_ENABLED=true\nAUTH_HEADER_AUTO_CREATE=true\nAUTH_HEADER_USERNAME=X-Auth-Username\nAUTH_HEADER_EMAIL=X-Auth-Email
@Zaryu
Copy link

Zaryu commented Jan 6, 2025

You have to exclude the api route from pterodactyl on your reverse proxy, to bypass the api route, otherwise youll get an error with: "Request header to big"

@banddude
Copy link
Author

banddude commented Jan 7, 2025

Thanks for the feedback! You are right - I have updated the PR description to include recommended reverse proxy configuration. Users should exclude the /api route from header authentication to prevent issues with API requests.

For example, with Nginx:

location /api {
    proxy_pass http://panel:80;
    # Do not add auth headers for API routes
}

location / {
    proxy_pass http://panel:80;
    # Add auth headers here
    proxy_set_header X-Auth-Username $user;
    proxy_set_header X-Auth-Email $email;
}

This ensures API functionality remains unaffected while still allowing header authentication for the web interface.

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.

Authentication using http header
2 participants