Skip to content

Commit fe16328

Browse files
committed
Richer support for 'allowed_outbound_hosts'
Signed-off-by: Ryan Levick <[email protected]>
1 parent 0b1f3de commit fe16328

File tree

15 files changed

+333
-18
lines changed

15 files changed

+333
-18
lines changed

Cargo.lock

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/loader/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ itertools = "0.10.3"
1616
lazy_static = "1.4.0"
1717
mime_guess = { version = "2.0" }
1818
outbound-http = { path = "../outbound-http", default-features = false }
19+
spin-outbound-networking = { path = "../outbound-networking" }
1920
path-absolutize = "3.0.11"
2021
regex = "1.5.4"
2122
reqwest = "0.11.9"
@@ -30,7 +31,7 @@ spin-manifest = { path = "../manifest" }
3031
tempfile = "3.8.0"
3132
terminal = { path = "../terminal" }
3233
thiserror = "1.0.49"
33-
tokio = { version = "1.23", features = [ "full" ] }
34+
tokio = { version = "1.23", features = ["full"] }
3435
tokio-util = "0.6"
3536
toml = "0.8.2"
3637
tracing = { workspace = true }
@@ -43,4 +44,4 @@ ui-testing = { path = "../ui-testing" }
4344
[[test]]
4445
name = "ui"
4546
path = "tests/ui.rs"
46-
harness = false
47+
harness = false

crates/loader/src/local.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ impl LocalLoader {
111111
component: v2::Component,
112112
) -> Result<LockedComponent> {
113113
outbound_http::allowed_http_hosts::parse_allowed_http_hosts(&component.allowed_http_hosts)?;
114+
if let Some(hosts) = &component.allowed_outbound_hosts {
115+
spin_outbound_networking::AllowedHosts::parse(hosts)
116+
.context("`allowed_outbound_hosts` is malformed")?;
117+
}
114118
let metadata = ValuesMapBuilder::new()
115119
.string("description", component.description)
116120
.string_array("allowed_http_hosts", component.allowed_http_hosts)

crates/loader/tests/ui/insecure-allow-all-with-invalid-url.lock

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"allowed_http_hosts": [
2929
"insecure:allow-all",
3030
"random-data-api.fermyon.app"
31-
]
31+
],
32+
"allowed_outbound_hosts": null
3233
},
3334
"source": {
3435
"content_type": "application/wasm",

crates/loader/tests/ui/invalid-manifest-duplicate-id.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
"components": [
3333
{
3434
"id": "hello",
35+
"metadata": {
36+
"allowed_outbound_hosts": null
37+
},
3538
"source": {
3639
"content_type": "application/wasm",
3740
"source": "file://<test-dir>/wasm/dummy.wasm"

crates/loader/tests/ui/valid-manifest.lock

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
"components": [
5050
{
5151
"id": "four-lights",
52+
"metadata": {
53+
"allowed_outbound_hosts": null
54+
},
5255
"source": {
5356
"content_type": "application/wasm",
5457
"source": "file://<test-dir>/wasm/dummy.wasm"
@@ -60,13 +63,19 @@
6063
},
6164
{
6265
"id": "old-test",
66+
"metadata": {
67+
"allowed_outbound_hosts": null
68+
},
6369
"source": {
6470
"content_type": "application/wasm",
6571
"source": "file://<test-dir>/wasm/dummy.wasm"
6672
}
6773
},
6874
{
6975
"id": "web",
76+
"metadata": {
77+
"allowed_outbound_hosts": null
78+
},
7079
"source": {
7180
"content_type": "application/wasm",
7281
"source": "file://<cache-dir>/spin/registry/wasm/sha256:0000000000000000000000000000000000000000000000000000000000000000"

crates/loader/tests/ui/valid-with-files/spin.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
"components": [
3131
{
3232
"id": "fs",
33+
"metadata": {
34+
"allowed_outbound_hosts": null
35+
},
3336
"source": {
3437
"content_type": "application/wasm",
3538
"source": "file://<test-dir>/spin-fs.wasm"

crates/loader/tests/ui/wagi-custom-entrypoint.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
"components": [
3232
{
3333
"id": "fs",
34+
"metadata": {
35+
"allowed_outbound_hosts": null
36+
},
3437
"source": {
3538
"content_type": "application/wasm",
3639
"source": "file://<test-dir>/wasm/dummy.wasm"

crates/manifest/src/schema/v2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ pub struct Component {
121121

122122
/// Used to skip serializing if the value is either `None` or `Some(v)` where `v` is empty
123123
fn is_none_or_empty<T>(value: &Option<Vec<T>>) -> bool {
124-
value.as_ref().map(|s| !s.is_empty()).unwrap_or_default()
124+
value.as_ref().map(|s| s.is_empty()).unwrap_or(true)
125125
}
126126

127127
mod one_or_many {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "spin-outbound-networking"
3+
version.workspace = true
4+
authors.workspace = true
5+
edition.workspace = true
6+
7+
[dependencies]
8+
anyhow = "1.0"
9+
url = "2.4.1"

0 commit comments

Comments
 (0)