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

proxy-wasm-rust-sdkについて

 proxy-wasm-rust-sdkについて

Tomohide Takao

December 07, 2020
Tweet

More Decks by Tomohide Takao

Other Decks in Technology

Transcript

  1. 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ʹΑΔ֦ு͕Ͱ͖ΔΑ͏ʹͳͬͨΒ͍͠
  2. 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ͱ͍͏ϓϩδΣΫτ͕ݩʹͳ͍ͬͯΔ
 (ޙड़)
  3. 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ͷ࣮૷Λ࡞੒
  4. 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"]
  5. ೚ҙͷ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 } .. . }
  6. • 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ϑΝΠϧ͕Ͳ͏ݺͼग़͞ΕΔ͔
  7. WebAssembly for Proxies͕࡞੒͞ΕͨܦҢ - 1 • envoy੩తͳόΠφϦ • ͦͷͨΊɺenvoyͷ֦ு΋ಉ͡λΠϛϯάͰίϯύΠϧ͠ͳ͍ͱ͍͚ ͳ͔ͬͨ

    • ͦͷͨΊɺenvoyͷ֦ுΛ͢Δͱ΋Εͳࣗ͘લͷenvoyόΠφϦΛӡ ༻͢Δ͜ͱ͕ඞਢͩͬͨ(ཪΛฦ͢ͱެࣜͷenvoyόΠφϦ΍ૉͷঢ় ଶͷenvoyόΠφϦ͕ར༻Ͱ͖ͳ͘ͳͬͯ͠·͏੍໿͕͋ͬͨ)
  8. 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ͰͷΈ্هͷमਖ਼͕ར༻Ͱ͖Δ
  9. 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
  10. 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 " ] } }
  11. 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
  12. wasmeʹ͍ͭͯ • Solo.io ͕ఏڙ͢ΔCL I • WebAssemblyHubͱ͍͏Envoy WebAssebly FilterΛొ࿥͢Δ DockerHubͷΑ͏ͳ৔ॴʹpush

    ΋͘͠͸ pull ͢ΔͨΊͷπʔϧ • wasme Λ࢖Θͳͯ͘΋wasm-filterΛར༻Ͱ͖Δ͕ wasme Λ࢖ͬͨ ։ൃͷ΄͏͕ΑΓ༰қ
  13. 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͚ͭͩ
  14. The WASM OCI Artifactʹ͍ͭͯ - 2 • runtime-config.jsonͷઃఆ஋ ◦ typ

    e ▪ envoy_proxyݻఆ ◦ abiVersion s ▪ v0.2.1ͳͲ࢖༻͢ΔAVIόʔδϣϯΛ഑ྻͰࢦఆ ◦ root_Id s ▪ ఏڙ͞ΕͨϑΟϧλʔͰ࢖༻Ͱ͖ΔrootId
  15. 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͸೚ҙͷ΋ͷʹมߋͰ͖Δ
  16. ͓·͚(ࣗલͰ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Λ༻ҙ͢Ε͹ ࣗલͰ΋ࣗྗͰಈ࡞֬ೝͰ͖·͢
  17. ࢀߟ৘ใ • 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