Skip to content

Commit c534a00

Browse files
a2a-php - change: updated documentation
1 parent e2a812d commit c534a00

File tree

7 files changed

+601
-2286
lines changed

7 files changed

+601
-2286
lines changed

A2A_HTTPS_IMPLEMENTATION.md

Lines changed: 63 additions & 279 deletions
Original file line numberDiff line numberDiff line change
@@ -1,336 +1,120 @@
1-
# A2A Protocol HTTPS/TLS Security Implementation
1+
# A2A Protocol HTTPS/TLS Implementation
22

3-
## 🔐 Overview
3+
## Overview
44

5-
This implementation adds comprehensive HTTPS/TLS support to the A2A Protocol server while maintaining full backward compatibility with existing HTTP functionality. The server now provides production-grade security features without breaking any existing functionality.
5+
The reference server includes optional HTTPS-aware behaviour that lets operators terminate TLS in front of the PHP process while preserving full backward compatibility with the existing HTTP flow. The implementation introduces security headers, environment-based mode detection, and documentation for deploying behind nginx or Apache.
66

7-
## **VERIFIED: ALL TESTS PASSING**
7+
## Test status
88

9-
The HTTPS-enabled server has been thoroughly tested and **maintains 100% compatibility**:
9+
| Suite | Result (HTTPS mode) |
10+
| ----------- | ------------------- |
11+
| Mandatory | 25 / 25 passing |
12+
| Capability | 14 / 14 passing |
13+
| Quality | 12 / 12 passing |
14+
| Features | 15 / 15 passing |
1015

11-
-**Mandatory Tests: 25/25 PASSED** (A2A Protocol compliance)
12-
-**Capability Tests: 19/19 PASSED** (All declared features work)
13-
-**Quality Tests: 12/12 PASSED** (Production readiness)
14-
-**Feature Tests: 15/15 PASSED** (Optional features complete)
16+
HTTPS orchestration reuses the same protocol handlers as the HTTP server, so compliance remains unchanged.
1517

16-
## 🚀 Key Features
18+
## Key additions
1719

18-
### Security Enhancements
19-
- **HTTPS/TLS Support**: Encrypted communication for production environments
20-
- **Automatic Certificate Management**: Self-signed certificates for development
21-
- **Security Headers**: HSTS, CORS, and other security headers
22-
- **Production Mode Detection**: Automatic HTTPS mode switching
23-
- **Protocol Detection**: Smart HTTP/HTTPS detection and logging
20+
- HTTPS-aware server entry point (`https_a2a_server.php`) that detects production mode and applies security headers.
21+
- Self-signed certificate helper invoked by `start_https_server.sh` for local testing.
22+
- Support for the `A2A_MODE=production` environment variable to toggle strict security behaviour.
23+
- Logging extensions that capture whether a request arrived via HTTP or HTTPS (based on proxy headers).
24+
- Documentation covering nginx and Apache reverse-proxy setups.
2425

25-
### Backward Compatibility
26-
- **Zero Breaking Changes**: All existing functionality preserved
27-
- **Dual Mode Operation**: HTTP for development, HTTPS for production
28-
- **Seamless Switching**: Environment variable controls mode
29-
- **Existing API Intact**: All current endpoints and responses unchanged
26+
## Running the server
3027

31-
### Production Features
32-
- **Certificate Auto-Generation**: Self-signed certs for development
33-
- **Security Logging**: Enhanced logging with security context
34-
- **HTTPS Redirect Support**: Optional HTTP to HTTPS redirection
35-
- **Production Headers**: Security headers in production mode
28+
### Development (HTTP)
3629

37-
## 📁 Files Added
38-
39-
1. **`https_a2a_server.php`** - Main HTTPS-enabled server implementation
40-
2. **`start_https_server.sh`** - Interactive script for server management
41-
3. **Documentation** - This comprehensive guide
42-
43-
## 🔧 Usage
44-
45-
### Development Mode (HTTP)
4630
```bash
47-
# Standard HTTP mode - no changes needed
4831
php -S localhost:8081 https_a2a_server.php
49-
50-
# Agent Card: http://localhost:8081/.well-known/agent-card.json
51-
# Server Info: http://localhost:8081/server-info
5232
```
5333

54-
### Production Mode (HTTPS-aware)
55-
```bash
56-
# Enable production mode
57-
A2A_MODE=production php -S localhost:8443 https_a2a_server.php
34+
### Production-style execution
5835

59-
# Note: PHP built-in server doesn't support HTTPS directly
60-
# For real HTTPS, deploy behind nginx/Apache with SSL termination
36+
```bash
37+
A2A_MODE=production php -S localhost:8081 https_a2a_server.php
6138
```
6239

63-
### Interactive Management
40+
> The PHP built-in server does not provide native TLS. For encrypted traffic, place nginx or Apache in front and forward requests to the PHP process.
41+
42+
### Interactive helper
43+
6444
```bash
65-
# Use the interactive setup script
6645
./start_https_server.sh
6746
```
6847

69-
## 🏗️ Production Deployment
48+
The script guides users through generating self-signed certificates, configuring environment variables, and starting the server.
49+
50+
## Reverse-proxy configuration
51+
52+
### nginx example
7053

71-
### Option 1: Nginx SSL Termination (Recommended)
7254
```nginx
7355
server {
7456
listen 443 ssl http2;
75-
server_name your-domain.com;
76-
77-
ssl_certificate /path/to/your/certificate.crt;
78-
ssl_certificate_key /path/to/your/private.key;
79-
80-
# Security headers
57+
server_name a2a.example.com;
58+
59+
ssl_certificate /etc/letsencrypt/live/a2a.example.com/fullchain.pem;
60+
ssl_certificate_key /etc/letsencrypt/live/a2a.example.com/privkey.pem;
61+
8162
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
8263
add_header X-Content-Type-Options nosniff;
8364
add_header X-Frame-Options DENY;
84-
65+
8566
location / {
86-
proxy_pass http://localhost:8081;
67+
proxy_pass http://127.0.0.1:8081;
8768
proxy_set_header Host $host;
8869
proxy_set_header X-Real-IP $remote_addr;
8970
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
90-
proxy_set_header X-Forwarded-Proto $scheme;
71+
proxy_set_header X-Forwarded-Proto https;
9172
}
9273
}
9374
94-
# HTTP to HTTPS redirect
9575
server {
9676
listen 80;
97-
server_name your-domain.com;
98-
return 301 https://$server_name$request_uri;
77+
server_name a2a.example.com;
78+
return 301 https://$host$request_uri;
9979
}
10080
```
10181

102-
### Option 2: Apache SSL Termination
82+
### Apache example
83+
10384
```apache
10485
<VirtualHost *:443>
105-
ServerName your-domain.com
106-
86+
ServerName a2a.example.com
87+
10788
SSLEngine on
108-
SSLCertificateFile /path/to/your/certificate.crt
109-
SSLCertificateKeyFile /path/to/your/private.key
110-
111-
# Security headers
89+
SSLCertificateFile /etc/letsencrypt/live/a2a.example.com/fullchain.pem
90+
SSLCertificateKeyFile /etc/letsencrypt/live/a2a.example.com/privkey.pem
91+
11292
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
11393
Header always set X-Content-Type-Options nosniff
11494
Header always set X-Frame-Options DENY
115-
95+
11696
ProxyPreserveHost On
117-
ProxyPass / http://localhost:8081/
118-
ProxyPassReverse / http://localhost:8081/
97+
ProxyPass / http://127.0.0.1:8081/
98+
ProxyPassReverse / http://127.0.0.1:8081/
11999
</VirtualHost>
120100
121101
<VirtualHost *:80>
122-
ServerName your-domain.com
123-
Redirect permanent / https://your-domain.com/
102+
ServerName a2a.example.com
103+
Redirect permanent / https://a2a.example.com/
124104
</VirtualHost>
125105
```
126106

127-
### Option 3: Let's Encrypt (Free SSL)
128-
```bash
129-
# Install certbot
130-
sudo apt install certbot python3-certbot-nginx
131-
132-
# Get SSL certificate
133-
sudo certbot --nginx -d your-domain.com
134-
135-
# Auto-renewal
136-
sudo certbot renew --dry-run
137-
```
138-
139-
## 🔍 Security Features
140-
141-
### Environment Detection
142-
The server automatically detects production mode via:
143-
- `A2A_MODE=production` environment variable
144-
- HTTPS headers from proxy
145-
- Port-based detection (8443 = HTTPS mode)
146-
147-
### Certificate Management
148-
```php
149-
// Automatic self-signed certificate generation for development
150-
class HttpsConfigManager {
151-
// - 2048-bit RSA keys
152-
// - SHA-256 signing
153-
// - 1-year validity
154-
// - Proper file permissions
155-
}
156-
```
157-
158-
### Security Headers
159-
In production mode, the server adds:
160-
- `Strict-Transport-Security` (HSTS)
161-
- `X-Content-Type-Options: nosniff`
162-
- `X-Frame-Options: DENY`
163-
- CORS headers for API access
164-
165-
### Enhanced Logging
166-
All security events are logged with context:
167-
```
168-
[2025-07-18 18:09:07] INFO: Request received {
169-
"method": "POST",
170-
"uri": "/",
171-
"https": true,
172-
"user_agent": "curl/8.5.0",
173-
"remote_addr": "127.0.0.1"
174-
} (Protocol: HTTPS)
175-
```
176-
177-
## 🧪 Testing
178-
179-
### Test HTTP Mode
180-
```bash
181-
curl -X POST -H "Content-Type: application/json" \
182-
-d '{"jsonrpc": "2.0", "method": "ping", "params": {}, "id": "test"}' \
183-
http://localhost:8081
184-
```
185-
186-
### Test HTTPS Mode (behind proxy)
187-
```bash
188-
curl -X POST -H "Content-Type: application/json" \
189-
-d '{"jsonrpc": "2.0", "method": "ping", "params": {}, "id": "test"}' \
190-
https://your-domain.com
191-
```
192-
193-
### Run Full Test Suite
194-
```bash
195-
# Test HTTP mode
196-
cd a2a-tck
197-
python3 run_tck.py --sut-url http://localhost:8081 --category all
198-
199-
# Test HTTPS mode (with proper SSL setup)
200-
python3 run_tck.py --sut-url https://your-domain.com --category all
201-
```
202-
203-
## 📊 Performance Impact
204-
205-
### Minimal Overhead
206-
- **HTTP Mode**: Zero performance impact (identical to original)
207-
- **HTTPS Mode**: Only logging enhancements added
208-
- **Memory Usage**: < 1MB additional for SSL context
209-
- **CPU Impact**: Negligible (SSL handled by proxy)
210-
211-
### Benchmarks
212-
```bash
213-
# Original server performance maintained
214-
ab -n 1000 -c 10 http://localhost:8081/.well-known/agent-card.json
215-
216-
# HTTPS performance (behind nginx)
217-
ab -n 1000 -c 10 https://your-domain.com/.well-known/agent-card.json
218-
```
219-
220-
## 🔧 Configuration Options
221-
222-
### Environment Variables
223-
- `A2A_MODE=production` - Enable production/HTTPS mode
224-
- `A2A_FORCE_HTTPS=true` - Force HTTPS redirects
225-
- `A2A_CERT_DIR=/path/to/certs` - Custom certificate directory
226-
227-
### Runtime Detection
228-
```php
229-
// The server automatically detects:
230-
// 1. Environment variables
231-
// 2. Server headers (X-Forwarded-Proto)
232-
// 3. Port numbers (8443 = HTTPS)
233-
// 4. SSL context availability
234-
```
235-
236-
## 🚧 Migration Guide
237-
238-
### From HTTP to HTTPS
239-
240-
1. **Development Environment**
241-
```bash
242-
# No changes needed - both modes supported
243-
php -S localhost:8081 https_a2a_server.php # HTTP mode
244-
A2A_MODE=production php -S localhost:8081 https_a2a_server.php # HTTPS-aware mode
245-
```
246-
247-
2. **Production Environment**
248-
```bash
249-
# 1. Set up SSL proxy (nginx/Apache)
250-
# 2. Update environment variables
251-
# 3. Test with TCK suite
252-
# 4. Monitor logs for security events
253-
```
254-
255-
3. **Zero Downtime Migration**
256-
- Deploy HTTPS server alongside existing HTTP server
257-
- Test thoroughly with TCK suite
258-
- Switch traffic gradually via load balancer
259-
- Monitor for any issues
260-
261-
## 🔐 Security Best Practices
262-
263-
### Development
264-
- Use HTTP mode for local development
265-
- Self-signed certificates are auto-generated
266-
- Security headers still applied
267-
268-
### Staging
269-
- Use proper SSL certificates
270-
- Test with production-like setup
271-
- Validate security headers
272-
273-
### Production
274-
- Use certificates from trusted CA
275-
- Enable HSTS with long max-age
276-
- Monitor SSL certificate expiration
277-
- Regular security audits
278-
279-
## 📈 Monitoring
280-
281-
### Security Events
282-
Monitor these log patterns:
283-
```bash
284-
# HTTPS mode activation
285-
grep "Protocol: HTTPS" a2a_server.log
286-
287-
# Security header application
288-
grep "Strict-Transport-Security" access.log
289-
290-
# Certificate generation events
291-
grep "SSL certificate generated" a2a_server.log
292-
```
293-
294-
### Health Checks
295-
```bash
296-
# HTTP health check
297-
curl -f http://localhost:8081/.well-known/agent-card.json
298-
299-
# HTTPS health check
300-
curl -f https://your-domain.com/.well-known/agent-card.json
301-
302-
# SSL certificate validation
303-
openssl s_client -connect your-domain.com:443 -servername your-domain.com
304-
```
305-
306-
## 🎯 Benefits Achieved
307-
308-
### **Security Enhanced**
309-
- End-to-end encryption for production
310-
- Industry-standard TLS implementation
311-
- Comprehensive security headers
312-
- Certificate management automation
313-
314-
### **Zero Breaking Changes**
315-
- All existing functionality preserved
316-
- Same API endpoints and responses
317-
- Backward compatibility guaranteed
318-
- Seamless mode switching
319-
320-
### **Production Ready**
321-
- Proper SSL termination support
322-
- Security logging and monitoring
323-
- Performance optimization
324-
- Best practices implementation
107+
## Security features
325108

326-
### **Developer Friendly**
327-
- Interactive setup scripts
328-
- Comprehensive documentation
329-
- Easy local development
330-
- Clear migration path
109+
- HSTS (`Strict-Transport-Security`) enabled in production mode.
110+
- `X-Content-Type-Options: nosniff` and `X-Frame-Options: DENY` headers for clickjacking and MIME hardening.
111+
- Proxy detection through `X-Forwarded-Proto` to mark requests as HTTPS in logs.
112+
- Ability to force HTTPS redirects with `A2A_FORCE_HTTPS=true` when using the helper script.
331113

332-
## 🎉 **MISSION ACCOMPLISHED**
114+
## Monitoring
333115

334-
The A2A Protocol server now provides **production-grade HTTPS/TLS security** while maintaining **100% compatibility** with existing functionality. All tests continue to pass, and the implementation follows security best practices for modern web applications.
116+
- Application logs note whether HTTPS was detected: `"https": true` entries confirm TLS termination upstream.
117+
- Use `curl -v https://a2a.example.com/.well-known/agent-card.json` to verify certificate chains and headers.
118+
- Rotate and renew certificates with your preferred tooling (for example, `certbot` for Let's Encrypt).
335119

336-
**🔐 Your A2A server is now enterprise-ready with full HTTPS/TLS support!**
120+
These adjustments provide a clear path to deploying the A2A PHP server in secure environments without altering protocol behaviour.

0 commit comments

Comments
 (0)