Skip to content

Commit d0dafe6

Browse files
authored
Merge pull request #302 from supabase/bo/feat/package-checksum
feat(wasm): add `fdw_package_checksum` server option
2 parents 3ecda9e + 69e3af1 commit d0dafe6

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

docs/paddle.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ The Paddle API uses JSON formatted data, please refer to [Paddle docs](https://d
2626

2727
## Available Versions
2828

29-
| Version | Wasm Package URL |
30-
| --------| ---------------- |
31-
| 0.1.0 | https://github.com/supabase/wrappers/releases/download/wasm_paddle_fdw_v0.1.0/paddle_fdw.wasm |
29+
| Version | Wasm Package URL | Checksum |
30+
| --------| ---------------- | -------- |
31+
| 0.1.0 | `https://github.com/supabase/wrappers/releases/download/wasm_paddle_fdw_v0.1.0/paddle_fdw.wasm` | `7d0b902440ac2ef1af85d09807145247f14d1d8fd4d700227e5a4d84c8145409` |
3232

3333
## Preparation
3434

@@ -73,6 +73,7 @@ We need to provide Postgres with the credentials to access Paddle, and any addit
7373
fdw_package_url 'https://github.com/supabase/wrappers/releases/download/wasm_paddle_fdw_v0.1.0/paddle_fdw.wasm',
7474
fdw_package_name 'supabase:paddle-fdw',
7575
fdw_package_version '0.1.0',
76+
fdw_package_checksum '7d0b902440ac2ef1af85d09807145247f14d1d8fd4d700227e5a4d84c8145409',
7677
api_url 'https://sandbox-api.paddle.com', -- Use https://api.paddle.com for live account
7778
api_key_id '<key_ID>' -- The Key ID from above.
7879
);
@@ -87,6 +88,7 @@ We need to provide Postgres with the credentials to access Paddle, and any addit
8788
fdw_package_url 'https://github.com/supabase/wrappers/releases/download/wasm_paddle_fdw_v0.1.0/paddle_fdw.wasm',
8889
fdw_package_name 'supabase:paddle-fdw',
8990
fdw_package_version '0.1.0',
91+
fdw_package_checksum '7d0b902440ac2ef1af85d09807145247f14d1d8fd4d700227e5a4d84c8145409',
9092
api_url 'https://sandbox-api.paddle.com', -- Use https://api.paddle.com for live account
9193
api_key 'bb4e69088ea07a98a90565ac610c63654423f8f1e2d48b39b5'
9294
);

docs/snowflake.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ The Snowflake Wrapper is a WebAssembly(Wasm) foreign data wrapper which allows y
2424

2525
## Available Versions
2626

27-
| Version | Wasm Package URL |
28-
| --------| ---------------- |
29-
| 0.1.0 | https://github.com/supabase/wrappers/releases/download/wasm_snowflake_fdw_v0.1.0/snowflake_fdw.wasm |
27+
| Version | Wasm Package URL | Checksum |
28+
| --------| ---------------- | -------- |
29+
| 0.1.0 | `https://github.com/supabase/wrappers/releases/download/wasm_snowflake_fdw_v0.1.0/snowflake_fdw.wasm` | `2fb46fd8afa63f3975dadf772338106b609b131861849356e0c09dde032d1af8` |
3030

3131
## Preparation
3232

@@ -73,6 +73,7 @@ We need to provide Postgres with the credentials to connect to Snowflake, and an
7373
fdw_package_url 'https://github.com/supabase/wrappers/releases/download/wasm_snowflake_fdw_v0.1.0/snowflake_fdw.wasm',
7474
fdw_package_name 'supabase:snowflake-fdw',
7575
fdw_package_version '0.1.0',
76+
fdw_package_checksum '2fb46fd8afa63f3975dadf772338106b609b131861849356e0c09dde032d1af8',
7677
account_identifier 'MYORGANIZATION-MYACCOUNT',
7778
user 'MYUSER',
7879
public_key_fingerprint 'SizgPofeFX0jwC8IhbOfGFyOggFgo8oTOS1uPLZhzUQ=',
@@ -89,6 +90,7 @@ We need to provide Postgres with the credentials to connect to Snowflake, and an
8990
fdw_package_url 'https://github.com/supabase/wrappers/releases/download/wasm_snowflake_fdw_v0.1.0/snowflake_fdw.wasm',
9091
fdw_package_name 'supabase:snowflake-fdw',
9192
fdw_package_version '0.1.0',
93+
fdw_package_checksum '2fb46fd8afa63f3975dadf772338106b609b131861849356e0c09dde032d1af8',
9294
account_identifier 'MYORGANIZATION-MYACCOUNT',
9395
user 'MYUSER',
9496
public_key_fingerprint 'SizgPofeFX0jwC8IhbOfGFyOggFgo8oTOS1uPLZhzUQ=',

wrappers/src/fdw/wasm_fdw/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This is Wasm foreign data wrapper host, please visit each Wasm foreign data wrap
66

77
| Version | Date | Notes |
88
| ------- | ---------- | ---------------------------------------------------- |
9+
| 0.1.2 | 2024-07-07 | Add fdw_package_checksum server option |
910
| 0.1.1 | 2024-07-05 | Fix missing wasm package cache dir issue |
1011
| 0.1.0 | 2024-07-03 | Initial version |
1112

wrappers/src/fdw/wasm_fdw/wasm_fdw.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ fn download_component(
4141
url: &str,
4242
name: &str,
4343
version: &str,
44+
checksum: Option<&str>,
4445
) -> WasmFdwResult<Component> {
4546
if let Some(file_path) = url.strip_prefix("file://") {
4647
return Ok(Component::from_file(engine, file_path)?);
@@ -87,9 +88,18 @@ fn download_component(
8788
path.set_extension("wasm");
8889

8990
if !path.exists() {
90-
// download component wasm from remote and save it to local cache
91+
// package checksum must be specified
92+
let option_checksum = checksum.ok_or("pacakge checksum option not specified".to_owned())?;
93+
94+
// download component wasm from remote and check its checksum
9195
let resp = rt.block_on(reqwest::get(url))?;
9296
let bytes = rt.block_on(resp.bytes())?;
97+
let bytes_checksum = hex::encode(Sha256::digest(&bytes));
98+
if bytes_checksum != option_checksum {
99+
return Err("pacakge checksum not match".to_string().into());
100+
}
101+
102+
// save the component wasm to local cache
93103
if let Some(parent) = path.parent() {
94104
// create all parent directories if they do not exist
95105
fs::create_dir_all(parent)?;
@@ -105,7 +115,7 @@ fn download_component(
105115
}
106116

107117
#[wrappers_fdw(
108-
version = "0.1.1",
118+
version = "0.1.2",
109119
author = "Supabase",
110120
website = "https://github.com/supabase/wrappers/tree/main/wrappers/src/fdw/wasm_fdw",
111121
error_type = "WasmFdwError"
@@ -126,14 +136,16 @@ impl ForeignDataWrapper<WasmFdwError> for WasmFdw {
126136
let pkg_url = require_option("fdw_package_url", options)?;
127137
let pkg_name = require_option("fdw_package_name", options)?;
128138
let pkg_version = require_option("fdw_package_version", options)?;
139+
let pkg_checksum = options.get("fdw_package_checksum").map(|t| t.as_str());
129140

130141
let rt = create_async_runtime()?;
131142

132143
let mut config = Config::new();
133144
config.wasm_component_model(true);
134145
let engine = Engine::new(&config)?;
135146

136-
let component = download_component(&rt, &engine, pkg_url, pkg_name, pkg_version)?;
147+
let component =
148+
download_component(&rt, &engine, pkg_url, pkg_name, pkg_version, pkg_checksum)?;
137149

138150
let mut linker = Linker::new(&engine);
139151
Wrappers::add_to_linker(&mut linker, |host: &mut FdwHost| host)?;

0 commit comments

Comments
 (0)