Upgrade to Pro — share decks privately, control downloads, hide ads and more …

AMEBA OWND DE HTTP/2

Take
August 29, 2016

AMEBA OWND DE HTTP/2

道玄坂BeerBash#1 LT夏祭 CA系メディアサービス編 発表資料
http://dogenzaka-beerbash.connpass.com/event/37072/

Take

August 29, 2016
Tweet

More Decks by Take

Other Decks in Technology

Transcript

  1. ࣗݾ঺հ ➤ 16 ৽ଔΤϯδχΞ ➤ 6݄͔Β Ameba Ownd ➤ αʔόαΠυΛ୲౰

    ➤ Go ݴޠͰ։ൃ ➤ Πϯϑϥ, ো֐ରԠ ➤ HN: τϚτ ➤ TDD: τϚτۦಈ։ൃ
  2. ࿩͢͜ͱ ➤ HTTP/2 ͷ؆୯ͳઆ໌ ➤ ELB ͱ Proxy Protocol ➤

    ALPN ରԠ (Chrome 51+) nginx 1.10.1 + openssl 1.0.2h
  3. HTTP/2 ➤ HTTP/1.1 ͸ςΩετ(ASCII)ϕʔεͷϓϩτίϧ ➤ ਓؒʹ͸༏͍͕͠ίϯϐϡʔλʹͱͬͯ͸൥ࡶ ➤ όΠφϦΛૹΔࡍ͸ Base64 encoding

    ౳ͰςΩετʹ͢Δ ➤ HTTP/2 ͸όΠφϦϓϩτίϧ ➤ ղੳ͠΍͘͢ίϯϐϡʔλʹ༏͍͠(ਓؒ͸ͭΒ͍) ➤ ϔομѹॖ͕ޮ͘ (HPACK)
  4. HTTP/2 ➤ HTTP/1.1 ·Ͱ͸ TCP ίωΫγϣϯΛ૿΍͢͜ͱͰฒྻʹ
 ϦΫΤετΛૹΓɺμ΢ϯϩʔυ͍ͯͨ͠ ➤ HTTP/2 ͔Β͸1ͭͷ

    TCP ίωΫγϣϯͰϦΫΤετଟॏԽ HTTP1.1 / TCP TCP HTTP/2 HTTP/2 HTTP/2 HTTP1.1 / TCP HTTP1.1 / TCP
  5. ͔ͭͯ ELB ͸ HTTP/2 ʹରԠ͍ͯ͠ͳ͔ͬͨ ➤ AWS ͷ Elastic Load

    Balancing ➤ (چདྷͷ) Classic Load Balancer ͸ HTTP/2 ඇରԠ ➤ Application Load Balancer ͸ HTTP/2 ରԠʂ
 →ࠓޙݕ౼͍ͨ͠
  6. CLASSIC LOAD BALANCER ➤ HTTP/2 ରԠ͢Δʹ͸ EC2 ্ͷ Web αʔόͰऴ୺ॲཧΛ͢

    Δඞཁ͕༗ΔͨΊɺ ELB Ͱ͸ TCP Ͱϩʔυόϥϯγϯά͢Δ ͔͠ํ๏͸ͳ͍ ➤ IP ΑΓ্ͷϨΠϠͷ TCP Ͱॲཧ͢ΔͨΊ઀ଓݩͷ IP ΞυϨ ε͕ ELB ͷ΋ͷʹॻ͖׵Θͬͯ͠·͏
  7. PROTOCOL STACK ➤ ELB Ͱ TCP ϩʔυόϥϯγ ϯά͢Δͱ TCP ҎԼͷ಺༰

    ͸όοΫΤϯυ΁ಧ͔ͳ͍ ➤ ઀ଓݩͷ IP ΞυϨε͸ IP ύέοτͷϔομʹॻ͔Ε ͍ͯΔͷͰࣦΘΕΔ Ethernet IP TCP TLS HTTP/2 (h2)
  8. X-FORWARDED-FOR ͕࢖͑ͳ͍ཧ༝ ➤ X-Forwarded-For ͸ HTTP ϔομͳͷͰɺHTTP (L7) ·Ͱ
 ղऍͰ͖Δ

    LB Ͱͳ͍ͱѻ͑ͳ͍ ➤ TCP Ͱϩʔυόϥϯγϯάͯ͠ TLS ͷऴ୺ॲཧΛόοΫΤϯ υͰߦ͏৔߹ɺ TLS ͷ payload ͸҉߸Խ͞Ε͍ͯΔͷͰಡΈ ॻ͖Ͱ͖ͳ͍
  9. PROXY PROTOCOL ઃఆྫ (NGINX) listen 443 ssl http2; proxy_set_header X-Forwarded-For

    $remote_addr; proxy_set_header X-Real-IP $remote_addr; listen 443 ssl http2 proxy_protocol; proxy_set_header X-Forwarded-For $proxy_protocol_addr; proxy_set_header X-Real-IP $proxy_protocol_addr; ELB: http://docs.aws.amazon.com/elasticloadbalancing/latest/classic/enable-proxy-protocol.html
  10. ݪҼ ➤ Google Chrome ͸ ALPN ͰϓϩτίϧωΰγΤʔγϣϯΛ
 ࢼΈΔ ➤ αʔό

    (nginx 1.9) ͸ NPN ͰωΰγΤʔγϣϯΛࢼΈΔ ➤ ૒ํͰ HTTP/2 ͷωΰγΤʔγϣϯํ͕ࣜҟͳΔҝɺ
 ωΰγΤʔγϣϯʹࣦഊͯ͠ HTTP/1.1 Ͱܨ͕Δ
  11. NPN ͱ ALPN ➤ SPDY Ͱ࢖ΘΕ͍ͯͨ NPN
 HTTP/2 ੍͕ఆ͞Εͯ ALPN

    Ͱஔ͖׵ΘΔ ➤ Chrome 51 Ͱ SPDY ͷαϙʔτऴྃɻHTTP/2 ׬શҠߦɻ
 http://blog.chromium.org/2016/02/transitioning-from-spdy- to-http2.html
  12. OWND ͰͷରԠ ➤ nginx 1.9 + openssl 1.0.1: NPN ʹͷΈରԠ


    ˠ Google Chrome 51 Ͱܨ͕Βͳ͘ͳͬͨݪҼ ➤ nginx 1.10 + openssl 1.0.2: ALPN ʹରԠ
 ˠ PPA Λ࢖͏ or Ubuntu Λ 16.04 LTS ΁ΞοϓάϨʔυ ➤ PPA (Personal Package Archive) Λ࢖͏͜ͱʹͳΓ·ͨ͠
  13. NGINX ͷΞοϓάϨʔυ͕Ͱ͖ͳ͍ ➤ nginx 1.9 ͷ package ͕ conf ϑΝΠϧΛ௫ΜͰ͍ͯ


    conflict Λىͯ͜͠ nginx 1.10 ͕ೖΒͳ͍ ➤ Ұ౓ uninstall ͕ඞཁ
  14. ANSIBLE Λ2ճྲྀ͞ͳ͍ͱ NGINX ͕ىಈ͠ͳ͍ ➤ ansible ͸ python ੡ͷߏ੒؅ཧπʔϧ ➤

    ansible Λ࢖ͬͯ΋ɺ
 ਓ͕ؒਖ਼͘͠ॻ͔ͳ͚Ε͹ႈ౳ʹͳͳΒͳ͍
  15. NGINX 1.9 Λ UNINSTALL ͢Δͱ LOG ͕ফ͑Δ ➤ nginx 1.10

    Ͱ͸࠶ݱ͠ͳ͍ ➤ apt remove ࣌ʹ log, cache ͷσΟϨΫτϦ͕ແ࣊൵ʹফ͑Δ ➤ ansible Ͱ apt remove લޙͰ log ͚ͩ͸όοΫΞοϓΛऔΔ ͜ͱͰରॲ ➤ લड़ͷݪҼ͸ओʹίϨͰͨ͠…
  16. ڭ܇ ➤ ຊ൪؀ڥͰ͸༧ظͤ͵ࣗମ͕ى͜Δ ➤ ӡ༻͍ͯ͠ΔαʔϏεͰ͸৻ॏʹ (ϢʔβӨڹ͸৴༻ʹڹ͘) ➤ ख٧·ΓʹͳͬͨΒ packet Λಡ΋͏

    ➤ ϓϩτίϧΛཧղ͠Α͏ ➤ ςετͷແ͍ίʔυ͸(ಛʹ)े෼ಡΜͰཧղ͢Δ
 (ansible playbook ؚΉ)