ΠΡΠ΅Π΄ΡΡΠ°Π²ΠΈΡΠ΅Π»Ρ Π½Π°ΡΠ΅Π³ΠΎ ΠΊΠ»ΠΈΠ΅Π½ΡΠ°, ΡΡΠ΅ΠΊ ΠΏΡΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΉ ΠΊΠΎΡΠΎΡΠΎΠ³ΠΎ ΠΎΠ±ΠΈΡΠ°Π΅Ρ Π² ΠΎΠ±Π»Π°ΠΊΠ΅ ΠΎΡ Microsoft (Azure), ΠΎΠ±ΡΠ°ΡΠΈΠ»ΡΡ Ρ ΠΏΡΠΎΠ±Π»Π΅ΠΌΠΎΠΉ: Ρ Π½Π΅Π΄Π°Π²Π½Π΅Π³ΠΎ Π²ΡΠ΅ΠΌΠ΅Π½ΠΈ ΡΠ°ΡΡΡ Π·Π°ΠΏΡΠΎΡΠΎΠ² Π½Π΅ΠΊΠΎΡΠΎΡΡΡ
ΠΊΠ»ΠΈΠ΅Π½ΡΠΎΠ² ΠΈΠ· ΠΠ²ΡΠΎΠΏΡ ΡΡΠ°Π»Π° Π·Π°Π²Π΅ΡΡΠ°ΡΡΡΡ ΠΎΡΠΈΠ±ΠΊΠΎΠΉ 400 (
ΠΠ΄Π½ΠΎ ΠΈΠ· ΠΏΡΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΉ β API, ΡΠ΅ΡΠ΅Π· ΠΊΠΎΡΠΎΡΡΠΉ Π² ΠΊΠΎΠ½Π΅ΡΠ½ΠΎΠΌ ΡΡΡΡΠ΅ ΠΏΡΠΈΡ
ΠΎΠ΄ΠΈΡ Π²Π΅ΡΡ ΡΡΠ°ΡΠΈΠΊ. ΠΡΠΎΡ ΡΡΠ°ΡΠΈΠΊ ΡΠ»ΡΡΠ°Π΅Ρ HTTP-ΡΠ΅ΡΠ²Π΅Ρ
ΠΡΠΈΠ±ΠΊΠ° Π² Ingress Π²ΡΠ³Π»ΡΠ΄Π΅Π»Π° ΡΠ»Π΅Π΄ΡΡΡΠΈΠΌ ΠΎΠ±ΡΠ°Π·ΠΎΠΌ:
{
"number_fields":{
"status":400,
"request_time":0.001,
"bytes_sent":465,
"upstream_response_time":0,
"upstream_retries":0,
"bytes_received":2328
},
"stream":"stdout",
"string_fields":{
"ingress":"app",
"protocol":"HTTP/1.1",
"request_id":"f9ab8540407208a119463975afda90bc",
"path":"/api/sign-in",
"nginx_upstream_status":"400",
"service":"app",
"namespace":"production",
"location":"/front",
"scheme":"https",
"method":"POST",
"nginx_upstream_response_time":"0.000",
"nginx_upstream_bytes_received":"120",
"vhost":"api.app.example.com",
"host":"api.app.example.com",
"user":"",
"address":"83.41.81.250",
"nginx_upstream_addr":"10.240.0.110:80",
"referrer":"https://api.app.example.com/auth/login?long_encrypted_header",
"service_port":"http",
"user_agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36",
"time":"2019-03-06T18:29:16+00:00",
"content_kind":"cache-headers-not-present",
"request_query":""
},
"timestamp":"2019-03-06 18:29:16",
"labels":{
"app":"nginx",
"pod-template-generation":"6",
"controller-revision-hash":"1682636041"
},
"namespace":"kube-nginx-ingress",
"nsec":6726612,
"source":"kubernetes",
"host":"k8s-node-55555-0",
"pod_name":"nginx-v2hcb",
"container_name":"nginx",
"boolean_fields":{}
}
ΠΡΠΈ ΡΡΠΎΠΌ Kestrel ΠΎΡΠ΄Π°Π²Π°Π»:
HTTP/1.1 400 Bad Request
Connection: close
Date: Wed, 06 Mar 2019 12:34:20 GMT
Server: Kestrel
Content-Length: 0
ΠΠ°ΠΆΠ΅ ΠΏΡΠΈ ΠΌΠ°ΠΊΡΠΈΠΌΠ°Π»ΡΠ½ΠΎΠΌ verbosity ΠΎΡΠΈΠ±ΠΊΠ° Kestrel ΡΠΎΠ΄Π΅ΡΠΆΠ°Π»Π° ΠΊΡΠ°ΠΉΠ½Π΅ ΠΌΠ°Π»ΠΎ ΠΏΠΎΠ»Π΅Π·Π½ΠΎΠΉ ΠΈΠ½ΡΠΎΡΠΌΠ°ΡΠΈΠΈ:
{
"number_fields":{"ThreadId":76},
"stream":"stdout",
"string_fields":{
"EventId":"{"Id"=>17, "Name"=>"ConnectionBadRequest"}",
"SourceContext":"Microsoft.AspNetCore.Server.Kestrel",
"ConnectionId":"0HLL2VJSST5KV",
"@mt":"Connection id "{ConnectionId}" bad request data: "{message}"",
"@t":"2019-03-07T13:06:48.1449083Z",
"@x":"Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException: Malformed request: invalid headers.n at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1Connection.TryParseRequest(ReadResult result, Boolean& endConnection)n at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.<ProcessRequestsAsync>d__185`1.MoveNext()",
"message":"Malformed request: invalid headers."
},
"timestamp":"2019-03-07 13:06:48",
"labels":{
"pod-template-hash":"2368795483",
"service":"app"
},
"namespace":"production",
"nsec":145341848,
"source":"kubernetes",
"host":"k8s-node-55555-1",
"pod_name":"app-67bdcf98d7-mhktx",
"container_name":"app",
"boolean_fields":{}
}
ΠΠ°Π·Π°Π»ΠΎΡΡ Π±Ρ, ΡΠΎΠ»ΡΠΊΠΎ tcpdump ΠΏΠΎΠΌΠΎΠΆΠ΅Ρ Π² ΡΠ΅ΡΠ΅Π½ΠΈΠΈ ΡΡΠΎΠΉ ΠΏΡΠΎΠ±Π»Π΅ΠΌΡβ¦ Π½ΠΎ ΠΏΠΎΠ²ΡΠΎΡΡ ΠΏΡΠΎ ΡΠ΅ΠΏΠΎΡΠΊΡ ΡΡΠ°ΡΠΈΠΊΠ°:
Π Π°ΡΡΠ»Π΅Π΄ΠΎΠ²Π°Π½ΠΈΠ΅
ΠΡΠ΅Π²ΠΈΠ΄Π½ΠΎ, ΡΡΠΎ ΠΏΠΎΡΠ»ΡΡΠ°ΡΡ ΡΡΠ°ΡΠΈΠΊ Π»ΡΡΡΠ΅ Π½Π° ΡΠΎΠΌ ΠΊΠΎΠ½ΠΊΡΠ΅ΡΠ½ΠΎΠΌ ΡΠ·Π»Π΅, Π³Π΄Π΅ Kubernetes ΡΠ°Π·Π²Π΅ΡΠ½ΡΠ» pod: ΠΎΠ±ΡΡΠΌ Π΄Π°ΠΌΠΏΠ° Π±ΡΠ΄Π΅Ρ ΡΠ°ΠΊΠΎΠΉ, ΡΡΠΎ ΠΏΠΎΠ»ΡΡΠΈΡΡΡ Π΄ΠΎΠ²ΠΎΠ»ΡΠ½ΠΎ Π±ΡΡΡΡΠΎ Π½Π°ΠΉΡΠΈ Ρ ΠΎΡΡ ΡΡΠΎ-ΡΠΎ. Π Π΄Π΅ΠΉΡΡΠ²ΠΈΡΠ΅Π»ΡΠ½ΠΎ, ΠΏΡΠΈ Π΅Π³ΠΎ ΡΠ°ΡΡΠΌΠΎΡΡΠ΅Π½ΠΈΠΈ Π±ΡΠ» Π·Π°ΠΌΠ΅ΡΠ΅Π½ ΡΠ°ΠΊΠΎΠΉ ΡΡΠ΅ΠΉΠΌ:
GET /back/user HTTP/1.1
Host: api.app.example.com
X-Request-ID: 27ceb14972da8c21a8f92904b3eff1e5
X-Real-IP: 83.41.81.250
X-Forwarded-For: 83.41.81.250
X-Forwarded-Host: api.app.example.com
X-Forwarded-Port: 443
X-Forwarded-Proto: https
X-Original-URI: /front/back/user
X-Scheme: https
X-Original-Forwarded-For: 83.41.81.250
X-Nginx-Geo-Client-Country: Spain
X-Nginx-Geo-Client-City: M.laga
Accept-Encoding: gzip
CF-IPCountry: ES
CF-RAY: 4b345cfd1c4ac691-MAD
CF-Visitor: {"scheme":"https"}
pragma: no-cache
cache-control: no-cache
accept: application/json, text/plain, */*
origin: https://app.example.com
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36
referer: https://app.example.com/auth/login
accept-language: en-US,en;q=0.9,en-GB;q=0.8,pl;q=0.7
cookie: many_encrypted_cookies; .AspNetCore.Identity.Application=something_encrypted;
CF-Connecting-IP: 83.41.81.250
True-Client-IP: 83.41.81.250
CDN-Loop: cloudflare
HTTP/1.1 400 Bad Request
Connection: close
Date: Wed, 06 Mar 2019 12:34:20 GMT
Server: Kestrel
Content-Length: 0
ΠΡΠΈ Π²Π½ΠΈΠΌΠ°ΡΠ΅Π»ΡΠ½ΠΎΠΌ ΡΠ°ΡΡΠΌΠΎΡΡΠ΅Π½ΠΈΠΈ Π΄Π°ΠΌΠΏΠ° Π±ΡΠ»ΠΎ Π·Π°ΠΌΠ΅ΡΠ΅Π½ΠΎ ΡΠ»ΠΎΠ²ΠΎ M.laga
. ΠΠ΅Π³ΠΊΠΎ Π΄ΠΎΠ³Π°Π΄Π°ΡΡΡΡ, ΡΡΠΎ Π² ΠΡΠΏΠ°Π½ΠΈΠΈ Π½Π΅Ρ Π³ΠΎΡΠΎΠ΄Π° M.laga (Π·Π°ΡΠΎ Π΅ΡΡΡ
ingress.kubernetes.io/configuration-snippet: |
proxy_set_header X-Nginx-Geo-Client-Country $geoip_country_name;
proxy_set_header X-Nginx-Geo-Client-City $geoip_city;
ΠΡΠΈ ΠΎΡΠΊΠ»ΡΡΠ΅Π½ΠΈΠΈ ΠΏΡΠΎΠ±ΡΠΎΡΠ° ΡΡΠΈΡ Π·Π°Π³ΠΎΠ»ΠΎΠ²ΠΊΠΎΠ² Π²ΡΡ ΡΡΠ°Π»ΠΎ Ρ ΠΎΡΠΎΡΠΎ! (ΠΡΠΊΠΎΡΠ΅ ΠΈ Π²ΠΎΠ²ΡΠ΅ Π²ΡΡΡΠ½ΠΈΠ»ΠΎΡΡ, ΡΡΠΎ ΡΡΠΈ Π·Π°Π³ΠΎΠ»ΠΎΠ²ΠΊΠΈ ΡΠ°ΠΌΠΎΠΌΡ ΠΏΡΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΡ Π±ΠΎΠ»ΡΡΠ΅ Π½Π΅ ΡΡΠ΅Π±ΠΎΠ²Π°Π»ΠΈΡΡ.)
Π’Π΅ΠΏΠ΅ΡΡ ΠΏΠΎΡΠΌΠΎΡΡΠΈΠΌ Π½Π° ΠΏΡΠΎΠ±Π»Π΅ΠΌΡ Π² Π±ΠΎΠ»Π΅Π΅ ΠΎΠ±ΡΠ΅ΠΌ Π²ΠΈΠ΄Π΅. ΠΡ Π»Π΅Π³ΠΊΠΎ Π²ΠΎΡΠΏΡΠΎΠΈΠ·Π²Π΅ΡΡΠΈ Π²Π½ΡΡΡΠΈ ΠΏΡΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΡ, Π΅ΡΠ»ΠΈ ΡΠ΄Π΅Π»Π°ΡΡ telnet-Π·Π°ΠΏΡΠΎΡ Π½Π° localhost:80
:
GET /back/user HTTP/1.1
Host: api.app.example.com
cache-control: no-cache
accept: application/json, text/plain, */*
origin: https://app.example.com
Cookie: test=Desiree
β¦ Π²ΠΎΠ·Π²ΡΠ°ΡΠ°Π΅ΡΡΡ 401 Unauthorized
, ΠΊΠ°ΠΊ ΠΈ ΠΎΠΆΠΈΠ΄Π°Π΅ΡΡΡ. Π ΡΡΠΎ ΡΠ»ΡΡΠΈΡΡΡ, Π΅ΡΠ»ΠΈ ΠΌΡ ΡΠ΄Π΅Π»Π°Π΅ΠΌ:
GET /back/user HTTP/1.1
Host: api.app.example.com
cache-control: no-cache
accept: application/json, text/plain, */*
origin: https://app.example.com
Cookie: test=DΓ©sirΓ©e
?
ΠΠ΅ΡΠ½ΡΡΡΡ 400 Bad request
β Π² Π»ΠΎΠ³Π΅ ΠΏΡΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΡ ΠΏΠΎΠ»ΡΡΠΈΠΌ ΡΠΆΠ΅ Π·Π½Π°ΠΊΠΎΠΌΡΡ Π½Π°ΠΌ ΠΎΡΠΈΠ±ΠΊΡ:
{
"@t":"2019-03-31T12:59:54.3746446Z",
"@mt":"Connection id "{ConnectionId}" bad request data: "{message}"",
"@x":"Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException: Malformed request: invalid headers.n at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1Connection.TryParseRequest(ReadResult result, Boolean& endConnection)n at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.<ProcessRequestsAsync>d__185`1.MoveNext()",
"ConnectionId":"0HLLLR1J974L9",
"message":"Malformed request: invalid headers.",
"EventId":{
"Id":17,
"Name":"ConnectionBadRequest"
},
"SourceContext":"Microsoft.AspNetCore.Server.Kestrel",
"ThreadId":71
}
ΠΡΠΎΠ³ΠΈ
ΠΠΎΠ½ΠΊΡΠ΅ΡΠ½ΠΎ Kestrel
ΠΠΎΠΏΠΎΠ»Π½ΠΈΡΠ΅Π»ΡΠ½ΡΠΉ ΡΠ°ΠΊΡΠΎΡ Π² Π½Π°ΡΠ΅ΠΌ ΡΠ»ΡΡΠ°Π΅ β ΠΌΠ΅Π½ΡΡΡ ΡΠ΅Π°Π»ΠΈΠ·Π°ΡΠΈΡ Kestrel Π² ΠΏΡΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ ΠΊΠ»ΠΈΠ΅Π½Ρ Π² Π΄Π°Π½Π½ΡΠΉ ΠΌΠΎΠΌΠ΅Π½Ρ Π½Π΅ ΠΏΠ»Π°Π½ΠΈΡΡΠ΅Ρ. ΠΠΏΡΠΎΡΠ΅ΠΌ, issues Π² ΡΠ°ΠΌΠΎΠΌ AspNetCore (
ΠΠΎΠ΄ΡΡΠΎΠΆΠΈΠ²Π°Ρ: Π·Π°ΠΌΠ΅ΡΠΊΠ° Π±ΠΎΠ»ΡΡΠ΅ Π½Π΅ ΠΎ ΡΠΏΠ΅ΡΠΈΡΠΈΡΠ΅ΡΠΊΠΈΡ ΠΏΡΠΎΠ±Π»Π΅ΠΌΠ°Ρ Kestrel ΠΈΠ»ΠΈ UTF-8 (Π² 2019-ΡΠΎ Π³ΠΎΠ΄Ρ?!), Π° ΠΎ ΡΠΎΠΌ, ΡΡΠΎ Π²Π½ΠΈΠΌΠ°ΡΠ΅Π»ΡΠ½ΠΎΡΡΡ ΠΈ ΠΏΠΎΡΠ»Π΅Π΄ΠΎΠ²Π°ΡΠ΅Π»ΡΠ½ΠΎΠ΅ ΠΈΠ·ΡΡΠ΅Π½ΠΈΠ΅ ΠΊΠ°ΠΆΠ΄ΠΎΠ³ΠΎ ΡΠ°Π³Π° Π²ΠΎ Π²ΡΠ΅ΠΌΡ ΠΏΠΎΠΈΡΠΊΠ° ΠΏΡΠΎΠ±Π»Π΅ΠΌΡ ΡΠ°Π½ΠΎ ΠΈΠ»ΠΈ ΠΏΠΎΠ·Π΄Π½ΠΎ ΠΏΡΠΈΠ½Π΅ΡΡΡ ΡΠ²ΠΎΠΈ ΠΏΠ»ΠΎΠ΄Ρ. Π£ΡΠΏΠ΅Ρ ΠΎΠ²!
P.S.
Π§ΠΈΡΠ°ΠΉΡΠ΅ ΡΠ°ΠΊΠΆΠ΅ Π² Π½Π°ΡΠ΅ΠΌ Π±Π»ΠΎΠ³Π΅:
- Β«
6 Π·Π°Π½ΠΈΠΌΠ°ΡΠ΅Π»ΡΠ½ΡΡ ΡΠΈΡΡΠ΅ΠΌΠ½ΡΡ Π±Π°Π³ΠΎΠ² ΠΏΡΠΈ ΡΠΊΡΠΏΠ»ΡΠ°ΡΠ°ΡΠΈΠΈ Kubernetes [ΠΈ ΠΈΡ ΡΠ΅ΡΠ΅Π½ΠΈΠ΅] Β»; - Β«
Kubernetes tips & tricks: ΠΏΠ΅ΡΡΠΎΠ½Π°Π»ΠΈΠ·ΠΈΡΠΎΠ²Π°Π½Π½ΡΠ΅ ΡΡΡΠ°Π½ΠΈΡΡ ΠΎΡΠΈΠ±ΠΎΠΊ Π² NGINX Ingress Β»; - Β«
ΠΠ±Π·ΠΎΡ ΠΈ ΡΡΠ°Π²Π½Π΅Π½ΠΈΠ΅ ΠΊΠΎΠ½ΡΡΠΎΠ»Π»Π΅ΡΠΎΠ² Ingress Π΄Π»Ρ Kubernetes Β»; - Β«
ΠΠΎΠ½ΠΈΡΠΎΡΠΈΠ½Π³ ping’ΠΎΠ² ΠΌΠ΅ΠΆΠ΄Ρ ΡΠ·Π»Π°ΠΌΠΈ Kubernetes β Π½Π°Ρ ΡΠ΅ΡΠ΅ΠΏΡ Β»; - Β«
3 Π½Π΅ΠΎΠ±ΡΡΠ½ΡΡ ΠΊΠ΅ΠΉΡΠ° ΠΎ ΡΠ΅ΡΠ΅Π²ΠΎΠΉ ΠΏΠΎΠ΄ΡΠΈΡΡΠ΅ΠΌΠ΅ Linux Β».
ΠΡΡΠΎΡΠ½ΠΈΠΊ: habr.com