Skip to content

Add HTTP authentication support for connectors and listeners#405

Merged
bearice merged 1 commit intomasterfrom
feature/http-authentication
Aug 18, 2025
Merged

Add HTTP authentication support for connectors and listeners#405
bearice merged 1 commit intomasterfrom
feature/http-authentication

Conversation

@bearice
Copy link
Member

@bearice bearice commented Aug 16, 2025

Summary

This PR implements HTTP Basic Authentication support for both HTTP connectors (upstream proxy authentication) and HTTP listeners (client authentication), providing comprehensive authentication capabilities for the redproxy-rs proxy server.

Key Features

🔗 HTTP Connectors (Outbound Authentication)

  • New HttpAuthData struct with username and password fields
  • Updated HttpConnectorConfig to include optional auth field
  • Enhanced http_forward_proxy_connect() to add Proxy-Authorization: Basic <credentials> header
  • Full support for both CONNECT tunneling and HTTP forward proxy modes with authentication

🛡️ HTTP Listeners (Inbound Authentication)

  • Updated HttpListenerConfig to include AuthData field (following existing SOCKS pattern)
  • Enhanced http_forward_proxy_handshake() to parse and validate Proxy-Authorization/Authorization headers
  • Integration with existing AuthData validation system (supports both static users and command-based auth)
  • Proper error handling with 407 Proxy Authentication Required responses

⚡ QUIC Integration

  • Updated QUIC connectors to pass auth parameter (None for backward compatibility)
  • Updated QUIC listeners to support authentication using the same AuthData system

Technical Implementation

  • HTTP Basic Authentication: Standard Basic <base64(username:password)> encoding
  • Robust base64 handling: Proper encoding/decoding with validation and error handling
  • Backward compatibility: All auth fields are optional, no breaking changes to existing configs
  • Comprehensive testing: Added tests for authentication functionality and base64 operations

Configuration Examples

HTTP Connector with Authentication:

connectors:
  - name: upstream-proxy
    type: http
    server: proxy.example.com
    port: 8080
    auth:
      username: myuser
      password: mypass

HTTP Listener with Authentication:

listeners:
  - name: http-proxy
    type: http
    bind: 0.0.0.0:8080
    auth:
      required: true
      users:
        - username: client1
          password: secret123

Test Plan

  • All existing tests pass (71/71)
  • New authentication tests added and passing
  • Base64 encoding/decoding tests with edge cases
  • HTTP connector authentication integration test
  • Release build verification completed
  • Backward compatibility verified - existing configs work unchanged

Dependencies

  • Added base64 crate for proper credential encoding

🤖 Generated with Claude Code

This commit implements HTTP Basic Authentication for both HTTP connectors
(upstream proxy authentication) and HTTP listeners (client authentication).

## Features Added

### HTTP Connectors (Outbound Authentication)
- Add HttpAuthData struct with username/password fields
- Update HttpConnectorConfig to include optional auth field
- Modify http_forward_proxy_connect() to add Proxy-Authorization header
- Support authentication for both CONNECT tunneling and HTTP forward proxy modes

### HTTP Listeners (Inbound Authentication)
- Update HttpListenerConfig to include AuthData field
- Modify http_forward_proxy_handshake() to parse and validate auth headers
- Integration with existing AuthData validation system
- Return 407 Proxy Authentication Required for failed authentication

### QUIC Integration
- Update QUIC connectors to pass auth parameter (None for compatibility)
- Update QUIC listeners to support authentication using AuthData system

## Technical Implementation
- HTTP Basic Authentication with proper base64 encoding/decoding
- Support for both Proxy-Authorization and Authorization headers
- Backward compatible - all auth fields are optional
- Comprehensive test coverage including auth functionality
- All 71 existing tests continue to pass

## Dependencies
- Add base64 crate for proper credential encoding

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@bearice bearice merged commit e9935b9 into master Aug 18, 2025
3 of 4 checks passed
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.

1 participant