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

proxy-wasm-rust-sdkについて

 proxy-wasm-rust-sdkについて

Dd307cfc553fa838357daa26f3f02f84?s=128

Tomohide Takao

December 07, 2020
Tweet

Transcript

  1. proxy-wasm-rust-sdkʹ͍ͭͯ 2020-12-07 RustLT Online #2 dorayakikun ։ൃํ๏ͱ֎؍

  2. whoami • dorayakiku n • Rust.Tokyo΍Rust LTͷӡӦ͍ͯ͠·͢ • Rust͕޷͖

  3. browserҎ֎Ͱಈ͘wasmͷ࿩

  4. Redefining extensibility in proxies - introducing WebAssembly to Envoy and

    Isti o A new interface for extending proxy servers allows moving Istio extensibility from the control plane into the sidecar proxies themselve s https://istio.io/latest/blog/2020/wasm-announce/ envoyͱIstioͰwasmʹΑΔ֦ு͕Ͱ͖ΔΑ͏ʹͳͬͨΒ͍͠
  5. wasmͰenvoyΛ֦ுͯ͠Έ͍ͨ...
 Ͳ͏͢Ε͹

  6. ͦ͜Ͱग़ͯ͘Δͷ͕.. . proxy-wasm-sdk

  7. proxy-wasm-sdk • wasmͰ؆୯ʹenvoyͷϑΟϧλʔΛ࡞੒Ͱ͖ΔϥΠϒϥϦ • ݱࡏC++/Rust/AssemblyScript/TinyGo ͳͲͷSDK͕ଘࡏ͢Δ ◦ https://github.com/proxy-wasm/proxy-wasm-cpp-sdk ◦ https://github.com/proxy-wasm/proxy-wasm-rust-sdk

    ◦ https://github.com/solo-io/proxy-runtime ◦ https://github.com/tetratelabs/proxy-wasm-go-sdk • ΋ͱ΋ͱ͸envoy-wasmͱ͍͏ϓϩδΣΫτ͕ݩʹͳ͍ͬͯΔ
 (ޙड़)
  8. proxy-wasm-sdkͷ࢖͍ํ(Rust൛) • cargo.tomlͷdependenciesʹ proxy-wasm Λ௥Ճ • lib.rsʹ_start()Λ࡞੒ ◦ ಺෦Ͱset_xxx_context() Λίʔϧ

    ▪ set_xxx_context()͸ҎԼͷ3͕ͭ͋Δ • set_root_context( ) • set_stream_context( ) • set_http_context( ) • ೚ҙͷcontextͷ࣮૷Λ࡞੒
  9. cargo.tomlͷdependenciesʹ log / proxy-was m Λ௥Ճ [dependencies ] log =

    "0.4.8 " proxy-wasm = "0.1.0" # The Rust SDK for proxy-was m [lib ] path = "src/lib.rs " crate-type = ["cdylib"]
  10. lib.rsʹ_start()Λ࡞੒ #[no_mangle ] pub fn _start() { proxy_wasm::set_log_level(LogLevel::Trace) ; proxy_wasm::set_root_context(|_|

    -> Box<dyn RootContext> { Box::new(HelloWorld) }) ; }
  11. ೚ҙͷcontextͷ࣮૷Λ࡞੒ struct HelloWorld ; impl Context for HelloWorld { }

    impl RootContext for HelloWorld { fn on_vm_start(&mut self, _: usize) -> bool { info!("ka23 dayo") ; self.set_tick_period(Duration::from_secs(5)) ; tru e } .. . }
  12. buildͷ࢓ํΛݟΔલʹ...

  13. WebAssembly for Proxies(ABI ) Λগ͠ਂງΓ

  14. proxy-wasm-rust-sdkͷߏ੒

  15. • proxy-wasmΛΠϯλʔϑΣʔεͱͯ͠envoy Λ֦ு͍ͯ͠Δ
 • ͜ΕΒ͸WebAssembly for Proxiesͱ͍͏ABI ͱͯ͠ఆٛ͞Ε͍ͯΔ΋ͷ
 • ͜ͷ࢓༷͸GitHubʹެ։͞Ε͓ͯΓɺͦΕʹ

    ै͑͹޷͖ͳݴޠͰenvoyͷwasm-filter͕࡞ ੒Ͱ͖Δ
 ◦ spec: https://github.com/proxy-wasm/ spec/blob/master/abi-versions/vNEXT/ README.md https://github.com/proxy-wasm/spec/blob/master/docs/WebAssembly-in-Envoy.md wasmϑΝΠϧ͕Ͳ͏ݺͼग़͞ΕΔ͔
  16. WebAssembly for Proxies͕࡞੒͞ΕͨܦҢ - 1 • envoy੩తͳόΠφϦ • ͦͷͨΊɺenvoyͷ֦ு΋ಉ͡λΠϛϯάͰίϯύΠϧ͠ͳ͍ͱ͍͚ ͳ͔ͬͨ

    • ͦͷͨΊɺenvoyͷ֦ுΛ͢Δͱ΋Εͳࣗ͘લͷenvoyόΠφϦΛӡ ༻͢Δ͜ͱ͕ඞਢͩͬͨ(ཪΛฦ͢ͱެࣜͷenvoyόΠφϦ΍ૉͷঢ় ଶͷenvoyόΠφϦ͕ར༻Ͱ͖ͳ͘ͳͬͯ͠·͏੍໿͕͋ͬͨ)
  17. WebAssembly for Proxies͕࡞੒͞ΕͨܦҢ - 2 • ಈతʹϩʔυ͞ΕΔC++Ͱͷ֦ு΋ߟ͑ΒΕ͕ͨɺ׆ൃͳenvoyͷ։ ൃεϐʔυͱ͸͏·͘Ϛον͠ͳ͔ͬͨ • ͦ͜Ͱ

    WebAssemblyͱ҆ఆͨ͠ABIͷఏڙͰ͜ͷ໰୊Λղܾ͠Α͏ ͱ͍͏ӡͼʹͳͬͨ
  18. WebAssembly for Proxies͕࡞੒͞ΕͨܦҢ - 3 • ݩʑ͸ɺhttps://github.com/envoyproxy/envoy-wasm ͱͯ͠ελʔτ
 • ͦͷޙ2020/03/05ʹʰRedefining

    extensibility in proxies - introducing WebAssembly to Envoy and IstioʱͰWebAssembly for Proxies͕ެ։͞ΕΔ
 • 2020/10/10ʹ͜ͷP/RͰenvoy-wasm͕envoyຊମʹऔΓࠐ·Εͨ ◦ https://github.com/envoyproxy/envoy/pull/12546 ◦ 2020/12/02࣌఺ͰupstreamͰͷΈ্هͷमਖ਼͕ར༻Ͱ͖Δ
  19. build & ಈ࡞֬ೝ ʹ໭Γ·͢

  20. build & ಈ࡞֬ೝ - 1 # wasmϑΝΠϧͷϏϧυ $ cargo build

    --target wasm32-unknown-unknown --releas e # wasmeͷΠϯετʔϧ $ curl -sL https://run.solo.io/wasme/install | s h $ export PATH=$HOME/.wasme/bin:$PATH
  21. build & ಈ࡞֬ೝ- 2 # runtime-config.jsonͷ࡞੒ $ vi runtime-config.jso n

    { "type": "envoy_proxy" , "abiVersions": ["v0-097b7f2e4cc1fb490cc1943d0d633655ac3c522f", "v0- 4689a30309abf31aee9ae36e73d34b1bb182685f", "v0.2.1"] , "config": { "rootIds": [ "hello_world " ] } }
  22. build & ಈ࡞֬ೝ - 3 # wasmeΛ࢖ͬͯwasm imageͷ࡞੒ $ wasme

    build precompiled target/wasm32-unknown-unknown/release/hello_world.wasm --tag hello_world:v0. 1 # wasmeΛ࢖ͬͯlocalͰಈ࡞֬ೝ $ wasme deploy envoy hello_world:v0.1
  23. wasmeʹ͍ͭͯ • Solo.io ͕ఏڙ͢ΔCL I • WebAssemblyHubͱ͍͏Envoy WebAssebly FilterΛొ࿥͢Δ DockerHubͷΑ͏ͳ৔ॴʹpush

    ΋͘͠͸ pull ͢ΔͨΊͷπʔϧ • wasme Λ࢖Θͳͯ͘΋wasm-filterΛར༻Ͱ͖Δ͕ wasme Λ࢖ͬͨ ։ൃͷ΄͏͕ΑΓ༰қ
  24. The WASM OCI Artifactʹ͍ͭͯ - 1 • ҎԼ2ͭͷlayer͔Βߏ੒͞ΕΔ ◦ application/vnd.module.wasm.config.v1+jso

    n ◦ application/vnd.module.wasm.content.layer.v1+was m • application/vnd.module.wasm.config.v1+jsonͷઃఆ஋͸runtime- config.jsonʹఆٛ͢Δඞཁ͕͋Δ ◦ ઃఆ஋͸࣍ͷϖʔδͰ঺հ • ؆ུԽͷͨΊɺҰͭͷOCI imageʹొ࿥Ͱ͖Δmodule͸1͚ͭͩ
  25. The WASM OCI Artifactʹ͍ͭͯ - 2 • runtime-config.jsonͷઃఆ஋ ◦ typ

    e ▪ envoy_proxyݻఆ ◦ abiVersion s ▪ v0.2.1ͳͲ࢖༻͢ΔAVIόʔδϣϯΛ഑ྻͰࢦఆ ◦ root_Id s ▪ ఏڙ͞ΕͨϑΟϧλʔͰ࢖༻Ͱ͖ΔrootId
  26. The WASM OCI Artifactʹ͍ͭͯ - 3 • imageΛpull΍build͢Δͱ~/.wasme/store ʹҎԼͷܗࣜͰϩʔΧϧ Ωϟογϡ͕࡞੒͞ΕΔ

    ◦ descriptor.jso n ◦ filter.was m ◦ image_re f ◦ runtime-config.json
  27. wasme deploy envoyʹ͍ͭͯ • Ϣʔβ͕ࢦఆͨ͠wasmϑΟϧλʔͷΠϝʔδ(~/.wasme/store഑Լʹ͋Δ)Λऔಘ • envoyͷconfig ʹϢʔβ͕ࢦఆͨ͠wasmϑΟϧλʔ·ͰͷઈରύεΛ௥Ճ • docker

    Λར༻ͯ͠ envoy Λ࣮ߦ ◦ σϑΥϧτͰར༻͞ΕΔΠϝʔδ͸ docker.io/istio/proxyv2:1.5.1 (2020/12/02࣌ ఺ ) ◦ σϑΥϧτͰར༻͞ΕΔenvoyͷconfig͸jsonplaceholder.typicode.com΁ͷϦΫ ΤετΛϑΟϧλʔ͢Δ΋ͷ • ࢖༻͢ΔenvoyͷΠϝʔδ΍config͸೚ҙͷ΋ͷʹมߋͰ͖Δ
  28. ͓·͚(ࣗલͰenvoyʹ௥Ճ͢Δ৔߹) admin : accessLogPath: /dev/nul l address : socketAddress :

    address: 0.0.0. 0 portValue: 1900 0 staticResources : clusters : - connectTimeout: 0.250 s dnsLookupFamily: V4_ONL Y hosts : - socketAddress : address: jsonplaceholder.typicode.co m ipv4Compat: tru e portValue: 44 3 name: static-cluste r tlsContext : sni: jsonplaceholder.typicode.co m type: LOGICAL_DN S listeners : - address : socketAddress : address: 0.0.0. 0 portValue: 808 0 filterChains : - filters : - config : httpFilters : - config : config : name: hello_worl d rootId: hello_worl d vmConfig : code : local : filename: /Users/kanisan/.wasme/store/99634fb1dd2d0e534a1760741f4fbd19/filter.was m runtime: envoy.wasm.runtime.v 8 vmId: hello_worl d name: envoy.filters.http.was m - name: envoy.route r routeConfig : name: tes t virtualHosts : - domains : - '* ' name: jsonplaceholde r routes : - match : prefix: / route : autoHostRewrite: tru e cluster: static-cluste r statPrefix: ingress_htt p name: envoy.http_connection_manage r name: listener_0 ͜Μͳײ͡ͷconfig.yamlΛ༻ҙ͢Ε͹ ࣗલͰ΋ࣗྗͰಈ࡞֬ೝͰ͖·͢
  29. ࠓ೔࿩ͤͳ͔ͬͨ(ௐ΂͖Εͳ͔ͬͨ)͜ͱ • wasmeͷৄࡉ • GetEnvoy Extension Toolkitʹ͍ͭͯ ◦ envoy୯ମͰͷར༻ͳΒɺͪ͜Βͷ΄͏͕ྑͦ͞͏

  30. GetEnvoy Extension Toolki t ΋ௐ΂ͯΈ·͢

  31. ࢀߟ৘ใ • Extending Envoy with WASM and Rust • Redefining

    extensibility in proxies - introducing WebAssembly to Envoy and Istio • Extending Istio with Rust and WebAssembly • Envoy Ͱͷ WebAssembly αϙʔτͱ WebAssembly Hub, WASM OCI Image Specification ʹ͍ͭͯ • WebAssembly ͕ωοτϫʔΫ ϓϩΩγʹ΋ͨΒ֦͢ுੑ • Introducing the WebAssembly Hub, a service for building, deploying, sharing, and discovering Wasm extensions for Envoy Proxy • Extension Toolkit Reference • Proxy-wasm and its landscape • WASM Artifact Image Specification v0.0.0