Un proxy che richiede autenticazione impedisce accessi non autorizzati e abilita accounting, policy per utente/gruppo, audit. Ecco i metodi standard, come funzionano "sotto il cofano" e come configurarli.
Classificazione metodi
| Metodo | Standard | Sicurezza | Casi d'uso | Supporto client |
|---|---|---|---|---|
| Nessuna (Transparent/Open) | - | Nessuna | Captive portal, filtro obbligatorio ISP/azienda, caching trasparente | Tutti (intercettazione L3/L4) |
| IP Allowlist (Transparent auth) | - | Bassa (IP spoofable) | Server, device IoT, subnet note | Nessuna config client |
| Basic Auth (RFC 7617) | HTTP 407 Proxy-Authenticate: Basic | Media (credenziali in Base64 = chiaro se no TLS) | Semplice, compatibilità universale, script, tool CLI | Tutti browser, curl, wget, librerie HTTP |
| Digest Auth (RFC 7616) | HTTP 407 Proxy-Authenticate: Digest | Media-Alta (challenge-response, no password in chiaro, ma replay possible se no nonce timeout) | Legacy, evita Basic su HTTP | Browser, curl, wget, alcune librerie |
| NTLM (NT LAN Manager) | Microsoft proprietario (MS-NLMP) | Alta (challenge-response, hash NTLMv2, session key) | Ambienti Active Directory, Windows Integrated Auth | IE, Edge, Chrome, Firefox (con config), app Windows (WinHTTP, WinINet) |
| Kerberos (SPNEGO/GSS-API) | RFC 4178, RFC 4559 (SPNEGO) | Molto Alta (ticket, mutual auth, delegation, no password hash in rete) | Enterprise AD, Single Sign-On, delegation, high security | Browser (SPNEGO), curl (--negotiate), librerie GSS-API, Java, .NET |
| OAuth 2.0 / OIDC / Bearer Token | RFC 6750, RFC 7662 | Alta (token short-lived, scope, revocabile) | Proxy moderni, API Gateway, Zero Trust, cloud (AWS, Azure, GCP) | App custom, browser (redirect), CLI (device flow) |
| Client Certificate (mTLS) | TLS 1.2/1.3 | Molto Alta (PKI, non ripudiabilità, mutual auth) | High security, device auth, Zero Trust, API | Browser (import cert), curl (--cert), librerie TLS |
Flusso HTTP Proxy Authentication (RFC 7235)
CLIENT → PROXY: GET https://example.com/ HTTP/1.1
Host: example.com
PROXY → CLIENT: HTTP/1.1 407 Proxy Authentication Required
Proxy-Authenticate: Basic realm="Corporate Proxy"
Proxy-Authenticate: NTLM
Proxy-Authenticate: Negotiate
CLIENT → PROXY: GET https://example.com/ HTTP/1.1
Host: example.com
Proxy-Authorization: Basic dXNlcjpwYXNz (Base64 user:pass)
# OPPURE
Proxy-Authorization: NTLM TlRMTVNTUAABAAA...
# OPPURE (Kerberos SPNEGO)
Proxy-Authorization: Negotiate YIIGawYGKwYBBQUCoIIGXzCCBlug...
PROXY → CLIENT: HTTP/1.1 200 OK (se auth ok) + Connessione al target
Basic Authentication: semplice ma insicuro su HTTP
- Credenziali:
Base64(username:password)→ Facilmente decodificabile - OBBLIGATORIO HTTPS end-to-end (Client ↔ Proxy) per non esporre credenziali
- Proxy deve validare contro: File htpasswd, LDAP, AD, RADIUS, Database, PAM
- Config Squid:
auth_param basic program /usr/lib/squid/basic_ldap_auth -b "ou=users,dc=corp" -f "sAMAccountName=%s" -h ldap.corp - Nessun mutual auth, nessun replay protection, nessun delegation.
NTLM: Challenge-Response Microsoft
- Client → Proxy:
Proxy-Authorization: NTLM(flags, workstation, domain) - Proxy → Client:
Proxy-Authenticate: NTLM(8-byte server challenge, target info, flags) - Client → Proxy:
Proxy-Authorization: NTLM(NTLMv2 response: HMAC-MD5(user domain password, challenge + client challenge + timestamp + target info), session key derivata) - Proxy valida: Contatta Domain Controller (Netlogon Secure Channel) OPPURE ha hash NTLM locale (se proxy joined domain)
Vantaggi: Password mai in rete, mutual auth (opzionale), session key per signing/sealing.
Limiti: Solo Windows/AD, NTLMv1 rotto (disabilitare), no delegation, vulnerabile a relay attacks (NTLM Relay) se no signing/EPA.
Kerberos (SPNEGO/GSS-API): Lo standard enterprise
Prerequisiti: Client e Proxy in stesso dominio/forest AD (o trust), SPN registrato (HTTP/proxy.corp), Keytab su proxy, sincronizzazione oraria (NTP <5 min), DNS funzionante (SRV _kerberos).
Flusso SPNEGO (Negotiate)
- Client → Proxy:
Proxy-Authorization: Negotiate - Proxy decifra Ticket con sua long-term key (da keytab) → Ottiene session key
- Proxy decifra Authenticator con session key → Verifica timestamp (replay protection), client principal
- Mutual Auth: Proxy → Client:
Proxy-Authenticate: Negotiate - Client verifica server authenticator → Entrambi autenticati
- Session key stabilita → Usata per wrapping traffico (se proxy supporta) o solo auth
Delegazione (Kerberos Constrained Delegation - KCD)
Proxy (service A) ottiene ticket per conto utente verso Backend (service B):
- Utente autentica su Proxy (AP-REQ con flag "forwardable")
- Proxy usa TGT utente (forwarded) → Richiede a KDC service ticket per "HTTP/backend.corp" (S4U2Proxy)
- KDC verifica: Proxy ha permesso "Trusted for delegation to HTTP/backend.corp" (msDS-AllowedToDelegateTo)
- KDC emette service ticket per backend → Proxy lo usa per accedere a backend come l'utente originale
Potente per: SSO end-to-end, audit trail identità reale fino al backend, policy per utente su backend.
Configurazione pratica: Squid + Kerberos (AD)
# 1. Keytab su proxy ktpass -princ HTTP/proxy.corp@CORP.LOCAL -mapuser proxy_svc -pass * -crypto AES256-SHA1 -ptype KRB5_NT_PRINCIPAL -out proxy.keytab # Copia proxy.keytab → /etc/squid/proxy.keytab (chown squid:squid, chmod 600) # 2. squid.conf auth_param negotiate program /usr/lib/squid/negotiate_kerberos_auth -d -s HTTP/proxy.corp@CORP.LOCAL -k /etc/squid/proxy.keytab auth_param negotiate children 20 startup=5 idle=10 auth_param negotiate keep_alive on auth_param negotiate realm Corporate Proxy (Kerberos) acl authenticated proxy_auth REQUIRED http_access allow authenticated http_access deny all # 3. DNS: A record proxy.corp → IP proxy. SPN: setspn -A HTTP/proxy.corp CORP\proxy_svc # 4. Client browser: Già usa credenziali Windows (Integrated Auth) se proxy in zona "Intranet" / "Trusted Sites"
Configurazione client: Browser e CLI
| Client | Basic | NTLM | Kerberos (SPNEGO) |
|---|---|---|---|
| Chrome/Edge | Auto (prompt) | Auto se zona Intranet/Trusted | Auto se zona Intranet/Trusted + SPN corretto |
| Firefox | Auto (prompt) | about:config → network.automatic-ntlm-auth.trusted-uris = "proxy.corp" | about:config → network.negotiate-auth.trusted-uris = "proxy.corp" + network.negotiate-auth.delegation-uris = "proxy.corp" |
| curl | curl -U user:pass -x proxy:3128 url | curl --proxy-ntlm -U : -x proxy:3128 url (usa credenziali Windows se SSPI) | curl --negotiate -U : -x proxy:3128 url (richiede GSS-API, kinit prima) |
| wget | wget --proxy-user=user --proxy-password=pass -e use_proxy=yes url | Non supportato nativamente | Non supportato nativamente |
| Python requests | requests.get(url, proxies=..., auth=HTTPProxyAuth(user,pass)) | requests-ntlm lib | requests-kerberos / requests-gssapi lib |
Sicurezza: Hardening proxy auth
- Disabilita Basic su HTTP: Solo su HTTPS (TLS 1.2+). Forza redirect HTTP→HTTPS per auth.
- Disabilita NTLMv1: Registry
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\LMCompatibilityLevel = 5(Solo NTLMv2 + Session Security) - EPA (Extended Protection for Authentication): Channel Binding (TLS) per NTLM/Kerberos → Previene relay attacks.
- Account lockout: Dopo N tentativi falliti (proxy + AD)
- Log auth: Successi + Fallimenti (IP, user, timestamp, metodo) → SIEM
- Password policy: Complessità, rotazione, no riutilizzo, MFA per account admin proxy
- Segmentazione: Proxy auth su VLAN management, non esposto Internet
- Certificati proxy: TLS valido (pubblico o PKI interna), HSTS, OCSP Stapling
Troubleshooting comune
| Sintomo | Causa probabile | Verifica / Fix |
|---|---|---|
| 407 loop (prompt infinite) | Credenziali errate, realm mismatch, client non invia auth | Log proxy (auth debug), curl -v per test manuale |
| Kerberos: "KRB5KDC_ERR_S_PRINCIPAL_UNKNOWN" | SPN non registrato / keytab mismatch / realm case-sensitive | setspn -L proxy_svc, klist -k /etc/squid/proxy.keytab, realm MAIUSCOLO |
| Kerberos: "Clock skew too great" | Orario proxy/client/DC >5 min diff | NTP sync su tutti (chrony, w32time) |
| NTLM: "Access denied" ma password giusta | NTLMv1 disabilitato lato DC, proxy usa v1 / Relay attack bloccato / Signing richiesto | LMCompatibilityLevel=5, EPA, signing richiesto |
| Firefox: "The proxy requires authentication" loop | Trusted URIs non configurati per NTLM/Negotiate | about:config → network.negotiate-auth.trusted-uris, network.automatic-ntlm-auth.trusted-uris |
| Transparent proxy: auth non funziona | Client non sa che proxy c'è → Non invia Proxy-Authorization | Transparent proxy NON supporta auth standard. Usa WPAD/PAC o config esplicita. |
- Telecamere di sorveglianza: aspetti legali, privacy, responsabilità e best practice (Italia)
- I server proxy bloccano il codice malevolo? Ruolo, limiti e architettura sicurezza
- --热点software