ืžื”ื—ื™ื™ื ืขื Kubernetes: ืื™ืš ืฉืจืช ื”-HTTP ืœื ื”ืขื“ื™ืฃ ืืช ื”ืกืคืจื“ื™ื

ืžื”ื—ื™ื™ื ืขื Kubernetes: ืื™ืš ืฉืจืช ื”-HTTP ืœื ื”ืขื“ื™ืฃ ืืช ื”ืกืคืจื“ื™ื

ื ืฆื™ื’ ืฉืœ ื”ืœืงื•ื— ืฉืœื ื•, ืฉืžื—ืกื ื™ืช ื”ื™ื™ืฉื•ืžื™ื ืฉืœื• ื ืžืฆืืช ื‘ืขื ืŸ ืžื‘ื™ืช Microsoft (Azure), ื˜ื™ืคืœ ื‘ื‘ืขื™ื”: ืœืื—ืจื•ื ื”, ื›ืžื” ื‘ืงืฉื•ืช ืžื—ืœืง ืžื”ืœืงื•ื—ื•ืช ืžืื™ืจื•ืคื” ื”ื—ืœื• ืœื”ืกืชื™ื™ื ื‘ืฉื’ื™ืื” 400 (ื‘ืงืฉื” ื’ืจื•ืขื”). ื›ืœ ื”ื™ื™ืฉื•ืžื™ื ื›ืชื•ื‘ื™ื ื‘-.NET, ืคืจื•ืกื™ื ื‘-Kubernetes...

ืื—ืช ื”ืืคืœื™ืงืฆื™ื•ืช ื”ื™ื ื”-API, ืฉื“ืจื›ื• ืžื’ื™ืขื” ื‘ืกื•ืคื• ืฉืœ ื“ื‘ืจ ื›ืœ ื”ืชืขื‘ื•ืจื”. ืœืชืขื‘ื•ืจื” ื–ื• ืžืื–ื™ืŸ ืฉืจืช ื”-HTTP ืงืกื˜ืจืœ, ืžื•ื’ื“ืจ ืขืœ ื™ื“ื™ ืœืงื•ื— .NET ื•ืžืชืืจื— ื‘ืคื•ื“. ืขื ืื™ืชื•ืจ ื‘ืื’ื™ื, ื”ื™ื” ืœื ื• ืžื–ืœ ื‘ืžื•ื‘ืŸ ื–ื” ืฉื”ื™ื” ืžืฉืชืžืฉ ืกืคืฆื™ืคื™ ืฉืฉื—ื–ืจ ื‘ืขืงื‘ื™ื•ืช ืืช ื”ื‘ืขื™ื”. ืขื ื–ืืช, ื”ื›ืœ ื”ื™ื” ืžืกื•ื‘ืš ืขืœ ื™ื“ื™ ืฉืจืฉืจืช ื”ืชื ื•ืขื”:

ืžื”ื—ื™ื™ื ืขื Kubernetes: ืื™ืš ืฉืจืช ื”-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":{}
}

ื‘ืžืงื‘ื™ืœ, ืงืกื˜ืจืœ ื ืชืŸ:

HTTP/1.1 400 Bad Request
Connection: close
Date: Wed, 06 Mar 2019 12:34:20 GMT
Server: Kestrel
Content-Length: 0

ืืคื™ืœื• ืขื ืžื™ืœื•ืœื™ืช ืžืจื‘ื™ืช, ืฉื’ื™ืืช ื”ืงืกื˜ืจืœ ื”ื›ื™ืœื” ื‘ืฆื•ืจื” ืงื™ืฆื•ื ื™ืช ืžืขื˜ ืžื™ื“ืข ืฉื™ืžื•ืฉื™:

{
   "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: ืื™ืš ืฉืจืช ื”-HTTP ืœื ื”ืขื“ื™ืฃ ืืช ื”ืกืคืจื“ื™ื

ื—ืงื™ืจื”

ื‘ืจื•ืจ ืฉืขื“ื™ืฃ ืœื”ืงืฉื™ื‘ ืœืชื ื•ืขื” ืขืœ ื”ืฆื•ืžืช ื”ืกืคืฆื™ืคื™ ื”ื–ื”, ืฉื‘ื• Kubernetes ืคืจืกื” ืคื•ื“: ื ืคื— ื”-dump ื™ื”ื™ื” ื›ื–ื” ืฉื ื™ืชืŸ ื™ื”ื™ื” ืœืžืฆื•ื ืœืคื—ื•ืช ืžืฉื”ื• ื“ื™ ืžื”ืจ. ื•ืื›ืŸ, ื›ืฉื‘ื“ืงื ื• ืื•ืชื•, ื”ื‘ื—ื™ื ื• ื‘ืคืจื™ื™ื ื”ื‘ื:

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. ืงืœ ืœื ื—ืฉ ืฉืื™ืŸ ืขื™ืจ ืžืœื’ื” ื‘ืกืคืจื“ (ืื‘ืœ ื™ืฉ ืžืœืื’ื”). ื‘ื”ืชื‘ืกืก ืขืœ ื”ืจืขื™ื•ืŸ ื”ื–ื”, ื”ืกืชื›ืœื ื• ืขืœ ืชืฆื•ืจื•ืช Ingress, ืฉื ืจืื™ื ื• ืืช ื–ื• ืฉื”ื•ื›ื ืกื” ืœืคื ื™ ื—ื•ื“ืฉ (ืœืคื™ ื‘ืงืฉืช ื”ืœืงื•ื—) ืงื˜ืข "ืœื ืžื–ื™ืง".:

    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
}

ืชื•ืฆืื•ืช ืฉืœ

ื‘ืžื™ื•ื—ื“ ืงืกื˜ืจืœ ืœื ื™ื›ื•ืœ ืขื™ื‘ื•ื“ ื ื›ื•ืŸ ืฉืœ ื›ื•ืชืจื•ืช HTTP ืขื ื”ืชื•ื•ื™ื ื”ื ื›ื•ื ื™ื ื‘-UTF-8, ื”ื›ืœื•ืœื™ื ื‘ืฉืžื•ืช ืฉืœ ืžืกืคืจ ื’ื“ื•ืœ ืœืžื“ื™ ืฉืœ ืขืจื™ื.

ื’ื•ืจื ื ื•ืกืฃ ื‘ืขื ื™ื™ื ื ื• ื”ื•ื ืฉื”ืœืงื•ื— ืื™ื ื• ืžืชื›ื ืŸ ื›ื™ื•ื ืœืฉื ื•ืช ืืช ื™ื™ืฉื•ื ืงืกื˜ืจืœ ื‘ืืคืœื™ืงืฆื™ื”. ืขื ื–ืืช, ื‘ืขื™ื•ืช ื‘- AspNetCore ืขืฆืžื” (โ„– 4318, โ„– 7707) ืื•ืžืจื™ื ืฉื–ื” ืœื ื™ืขื–ื•ืจ...

ืœืกื™ื›ื•ื: ื”ื”ืขืจื” ื›ื‘ืจ ืœื ืขื•ืกืงืช ื‘ื‘ืขื™ื•ืช ื”ืกืคืฆื™ืคื™ื•ืช ืฉืœ ืงืกื˜ืจืœ ืื• UTF-8 (ื‘-2019?!), ืืœื ืขืœ ื”ืขื•ื‘ื“ื” ืฉ ืžื™ื™ื ื“ืคื•ืœื ืก ื•ืœื™ืžื•ื“ ืขืงื‘ื™ ื›ืœ ืฆืขื“ ืฉืชื ืงื•ื˜ ื‘ื–ืžืŸ ื—ื™ืคื•ืฉ ื‘ืขื™ื•ืช ื™ื‘ื™ื ื‘ืžื•ืงื“ื ืื• ื‘ืžืื•ื—ืจ ืคืจื™. ื‘ื”ืฆืœื—ื”!

ื .ื‘.

ืงืจื ื’ื ื‘ื‘ืœื•ื’ ืฉืœื ื•:

ืžืงื•ืจ: www.habr.com

ื”ื•ืกืคืช ืชื’ื•ื‘ื”