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
์ต๋ํ ์์ธํ ์ค๋ช ํ๋๋ผ๋ 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๊ฐ ํฌ๋๋ฅผ ๋ฐฐํฌํ ๊ฒฝ์ฐ: ๋คํ์ ์์ ์ต์ํ ๋ฌด์ธ๊ฐ๋ฅผ ๋งค์ฐ ๋น ๋ฅด๊ฒ ์ฐพ์ ์ ์์ ์ ๋์ ๋๋ค. ๊ทธ๋ฆฌ๊ณ ์ค์ ๋ก ๊ทธ๊ฒ์ ์กฐ์ฌํ์ ๋ ๋ค์๊ณผ ๊ฐ์ ํ๋ ์์ด ๋ฐ๊ฒฌ๋์์ต๋๋ค.
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;
์ด ํค๋ ์ ๋ฌ์ ๋นํ์ฑํํ ํ ๋ชจ๋ ๊ฒ์ด ๊ด์ฐฎ์์ก์ต๋๋ค! (์ ํ๋ฆฌ์ผ์ด์ ์์ฒด์๋ ๋ ์ด์ ์ด๋ฌํ ํค๋๊ฐ ํ์ํ์ง ์๋ค๋ ๊ฒ์ด ๊ณง ๋ถ๋ช ํด์ก์ต๋๋ค.)
์ด์ ๋ฌธ์ ๋ฅผ ์ดํด๋ณด์ ๋ ์ผ๋ฐ์ ์ผ๋ก. ํ
๋ท ์์ฒญ์ ํตํด ์ ํ๋ฆฌ์ผ์ด์
๋ด์์ ์ฝ๊ฒ ์ฌํํ ์ ์์ต๋๋ค. 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 ๊ตฌํ์ ๋ณ๊ฒฝํ ๊ณํ์ด ์๋ค๋ ๊ฒ์
๋๋ค. ๊ทธ๋ฌ๋ AspNetCore ์์ฒด์ ๋ฌธ์ (
์์ฝํ์๋ฉด, ์ด ๋ ธํธ๋ ๋ ์ด์ Kestrel ๋๋ UTF-8(2019๋ ?!)์ ํน์ ๋ฌธ์ ์ ๊ดํ ๊ฒ์ด ์๋๋ผ ๋ค์๊ณผ ๊ฐ์ ์ฌ์ค์ ๊ดํ ๊ฒ์ ๋๋ค. ๋ง์์ฑ๊น๊ณผ ๊พธ์คํ ๊ณต๋ถ ๋ฌธ์ ๋ฅผ ์ฐพ๋ ๋์ ์ทจํ๋ ๋ชจ๋ ๋จ๊ณ๋ ์กฐ๋ง๊ฐ ๊ฒฐ์ค์ ๋งบ์ ๊ฒ์ ๋๋ค. ํ์ด์ ๋น์ด์!
PS
๋ธ๋ก๊ทธ์์๋ ์ฝ์ด๋ณด์ธ์.
- ยซ
์ฟ ๋ฒ๋คํฐ์ค ์ด์์ ์ฌ๋ฏธ์๋ ์์คํ ๋ฒ๊ทธ 6๊ฐ์ง [๋ฐ ํด๋น ์๋ฃจ์ ] "; - ยซ
Kubernetes ํ ๋ฐ ์๋ น: NGINX Ingress์ ์ฌ์ฉ์ ์ง์ ์ค๋ฅ ํ์ด์ง "; - ยซ
Kubernetes์ฉ Ingress ์ปจํธ๋กค๋ฌ ๊ฐ์ ๋ฐ ๋น๊ต "; - ยซ
Kubernetes ๋ ธ๋ ๊ฐ ํ ๋ชจ๋ํฐ๋ง - ๋ ์ํผ "; - ยซ
Linux ๋คํธ์ํฌ ํ์ ์์คํ ์ ๊ดํ 3๊ฐ์ง ํน์ดํ ์ฌ๋ก ".
์ถ์ฒ : habr.com