Skip to content

Commit e317b31

Browse files
authored
Add proxy authentication with username:password format (#4)
* Add golang.org/x/net dependency for proxy support * Add proxy configuration support for upstream routing - Support HTTP, HTTPS, and SOCKS5 proxy protocols - Add proxy authentication with username:password format - Implement proxy-aware dialers for both HTTP and socket connections - Add fallback to direct connection when proxy fails - Include proxy configuration in startup logging - Support proxy URL and auth via CLI flags and environment variables * Add proxy configuration examples to deployment files * Update documentation for proxy configuration feature * resolve comment * resolve comment * resolve comment * resolve comment * resolve comment * resolve comment * resolve comment * resolve comment * resolve comment * resolve comment * resolve comment
1 parent 4004604 commit e317b31

13 files changed

Lines changed: 231 additions & 11 deletions

.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@ PROXY_METRICS_PORT=9090
1515
PROXY_HEALTH_PORT=8081
1616
PROXY_SHARED_HEALTH_PORT=true
1717
PROXY_SHARED_METRICS_PORT=true
18+
19+
# Proxy Configuration (optional)
20+
# PROXY_URL=http://proxy.example.com:8080
21+
# PROXY_URL=socks5://proxy.example.com:1080
22+
# PROXY_AUTH=username:password

.github/workflows/docker-build-push.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ jobs:
3838
uses: docker/build-push-action@v5
3939
with:
4040
context: .
41-
platforms: linux/amd64,linux/arm64
41+
platforms: linux/amd64,linux/arm64,linux/arm64/v8,linux/386,linux/s390x,linux/riscv64,linux/ppc64le,linux/arm/v7
4242
push: true
4343
tags: ${{ steps.meta.outputs.tags }}
4444
labels: ${{ steps.meta.outputs.labels }}
4545
cache-from: type=gha
46-
cache-to: type=gha,mode=max
46+
cache-to: type=gha,mode=max

README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ variables take precedence when both are provided.
135135
| `PROXY_HEADER_QUEUES` | `-header-queues` | X-Amz-Security-Token | Comma-separated headers for dedicated queues |
136136
| `PROXY_PERSISTENT_HEADERS` | `-persistent-headers` | (empty) | Persistent headers that cannot be overwritten 🔒 |
137137
| `PROXY_TIMEOUT` | `-timeout` | 0 | Request timeout in seconds (0 = infinite ⏳) |
138+
| `PROXY_URL` | `-proxy-url` | (empty) | Proxy URL for TARGET_HOST connections 🌐 |
139+
| `PROXY_AUTH` | `-proxy-auth` | (empty) | Proxy authentication (username:password) 🔐 |
138140

139141
### Persistent Headers 🔒
140142

@@ -183,6 +185,64 @@ export PROXY_PERSISTENT_HEADERS="User-Agent:mobile,X-Custom:always-present"
183185
./proxy-queue -target-host=api.example.com
184186
```
185187

188+
### Proxy Configuration 🌐
189+
190+
The proxy-queue can route all TARGET_HOST connections through an upstream proxy server. This is useful when your network requires proxy access to reach external services, or when you need to add an additional layer of routing.
191+
192+
#### Supported Proxy Types
193+
194+
| Proxy Type | URL Format | Features |
195+
|---------------|------------------------------------|----------------------------------------------------|
196+
| **HTTP** | `http://proxy.example.com:8080` | ✅ HTTP requests<br>❌ Socket connections |
197+
| **HTTPS** | `https://proxy.example.com:8080` | ✅ HTTP requests<br>❌ Socket connections |
198+
| **SOCKS5** | `socks5://proxy.example.com:1080` | ✅ HTTP requests<br>✅ Socket connections |
199+
200+
#### Configuration Methods
201+
202+
```bash
203+
# Command line flags
204+
./proxy-queue \
205+
-target-host=api.example.com \
206+
-proxy-url=socks5://proxy.company.com:1080 \
207+
-proxy-auth=username:password
208+
209+
# Environment variables
210+
export PROXY_URL=http://corporate-proxy:8080
211+
export PROXY_AUTH=myuser:mypass
212+
./proxy-queue -target-host=api.example.com
213+
214+
# Docker environment
215+
docker run -e PROXY_URL=socks5://proxy:1080 -e PROXY_AUTH=user:pass proxy-queue
216+
```
217+
218+
#### Authentication Support
219+
220+
The proxy supports username/password authentication for all proxy types:
221+
222+
```bash
223+
# Include auth in URL (HTTP/HTTPS only)
224+
export PROXY_URL=http://username:password@proxy.example.com:8080
225+
226+
# Separate auth parameter (recommended for security)
227+
export PROXY_URL=socks5://proxy.example.com:1080
228+
export PROXY_AUTH=username:password
229+
```
230+
231+
#### Security Features
232+
233+
- **No credential logging**: Proxy authentication is never logged in plaintext
234+
- **Fallback behavior**: If proxy connection fails, falls back to direct connection
235+
- **Connection validation**: Invalid proxy URLs are detected and logged
236+
- **Debug visibility**: Proxy usage is logged at debug level for troubleshooting
237+
238+
#### Proxy vs Direct Connection
239+
240+
| Connection Type | Proxy Required | Fallback Behavior |
241+
|-----------------|----------------|--------------------------------------|
242+
| **HTTP/HTTPS** | Optional | Falls back to direct connection |
243+
| **Socket** | Optional | Falls back to direct connection |
244+
| **Both** | Optional | Each connection type handles its own |
245+
186246
### Header-Based Queue Routing 📤
187247

188248
The proxy supports routing requests to dedicated queues based on specific HTTP headers. This is particularly

build/proxy-queue-darwin-amd64

69.1 KB
Binary file not shown.

build/proxy-queue-darwin-arm64

69 KB
Binary file not shown.

build/proxy-queue-linux-amd64

77.6 KB
Binary file not shown.

build/proxy-queue-linux-arm64

20.4 KB
Binary file not shown.
65.5 KB
Binary file not shown.
69.5 KB
Binary file not shown.

docker-compose.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: '3.8'
22

33
services:
44
proxy-queue:
5-
image: thanhlvcom/proxy-queue:latest
5+
image: thanhlvcom/proxy-queue:v1.2.0
66
ports:
77
- "6789:6789" # HTTP/HTTPS proxy
88
- "6799:6799" # Socket proxy
@@ -23,9 +23,13 @@ services:
2323
- PROXY_HEADER_QUEUES=X-Amz-Security-Token,Authorization
2424
- PROXY_PERSISTENT_HEADERS=x-token-test:token-1234
2525
- PROXY_LOG_LEVEL=info
26+
# Optional proxy configuration (uncomment and configure as needed)
27+
# - PROXY_URL=http://corporate-proxy:8080
28+
# - PROXY_URL=socks5://proxy.company.com:1080
29+
# - PROXY_AUTH=username:password
2630
restart: always
2731
healthcheck:
28-
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:6789/health"]
32+
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8081/health"]
2933
interval: 30s
3034
timeout: 10s
3135
retries: 3

0 commit comments

Comments
 (0)