Il flusso di richiesta è il seguente;Vernice aggiungendo automaticamente il bilanciamento del carico IP all'intestazione X-Forwarded-For
HAProxy --> Varnish (4.0.1) --> Apache web backends
Quando una nuova richiesta arriva a HAProxy, viene aggiunto l'indirizzo IP del client al X-Forwarded-For
intestazione (che è buono!). Tuttavia, sembra che Varnish stia aggiungendo anche l'IP HAProxy
. Quando la richiesta arriva al mio vcl_recv
di routine, l'intestazione X-Forwarded-For
è:
X-Forwarded-For: end-user-ip, haproxy-ip
Si può vedere che nel varnishlog
uscita:
* <<Request>> 8
- Begin req 7 rxreq
- Timestamp Start: 1409262358.542659 0.000000 0.000000
- Timestamp Req: 1409262358.542659 0.000000 0.000000
- ReqStart 192.168.1.103 48193
- ReqMethod PURGE
- ReqURL /some/path
- ReqProtocol HTTP/1.1
- ReqHeader Authorization: Basic xxx
- ReqHeader User-Agent: curl/7.30.0
- ReqHeader Host: example.com
- ReqHeader Accept: */*
- ReqHeader X-Forwarded-For: 1.2.3.4
- ReqHeader Connection: close
- ReqUnset X-Forwarded-For: 1.2.3.4
- ReqHeader X-Forwarded-For: 1.2.3.4, 192.168.1.101
- VCL_call RECV
- ReqUnset X-Forwarded-For: 1.2.3.4, 192.168.1.101
- VCL_acl NO_MATCH purge_acl
- Debug "VCL_error(403, Not allowed.)"
- VCL_return synth
La ragione per cui ho bisogno l'indirizzo IP del client accurata è così posso controllarlo in base alle regole ACL per PURGE
/BAN
. Poiché l'ultimo IP nell'intestazione X-Forwarded-For
è quello di HAProxy, il controllo ACL non riesce per tutti gli IP. Ecco la relativa sezione del mio config:
acl purge_acl {
"1.2.3.4";
}
sub vcl_recv {
set req.backend_hint = load_balancer.backend();
if (req.method == "PURGE") {
if (!std.ip(req.http.X-forwarded-for, "0.0.0.0") ~ purge_acl) {
return(synth(403, "Not allowed."));
}
ban("obj.http.x-url ~ " + req.url);
return(synth(200, "Ban added"));
}
}
Tutte le idee come posso contare unicamente sulla X-Forwarded-For
colpo di testa da HAProxy, senza smalto manomissione con esso?
Una nota a margine, sembra che Varnish sta facendo esattamente questo (anche se questo non è in mv config VCL):
if (req.restarts == 0) {
if (req.http.X-Forwarded-For) {
set req.http.X-Forwarded-For = req.http.X-Forwarded-For + ", " + client.ip;
} else {
set req.http.X-Forwarded-For = client.ip;
}
}
Eccellente grazie per essere tornato in questo post –