Skip to content

Commit b14654d

Browse files
authored
Merge pull request #1933 from fermyon/require-allow-listed-host-redis
Require user to add redis host to list of allowed listed hosts
2 parents 9ae9308 + fe16328 commit b14654d

File tree

20 files changed

+423
-9
lines changed

20 files changed

+423
-9
lines changed

Cargo.lock

Lines changed: 13 additions & 0 deletions
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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,14 @@ 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)
121+
.string_array_option("allowed_outbound_hosts", component.allowed_outbound_hosts)
117122
.string_array("key_value_stores", component.key_value_stores)
118123
.string_array("databases", component.sqlite_databases)
119124
.string_array("ai_models", component.ai_models)

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/locked-app/src/values.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,20 @@ impl ValuesMapBuilder {
5858
self.entry(key, entries)
5959
}
6060

61+
/// Inserts an optional list of strings
62+
pub fn string_array_option(
63+
&mut self,
64+
key: impl Into<String>,
65+
value: Option<impl IntoIterator<Item = impl Into<String>>>,
66+
) -> &mut Self {
67+
if let Some(value) = value {
68+
let entries = value.into_iter().map(|s| s.into()).collect::<Vec<_>>();
69+
self.entry(key, entries)
70+
} else {
71+
self.entry(key, Value::Null)
72+
}
73+
}
74+
6175
/// Inserts an entry into the map using the value's `impl Into<Value>`.
6276
pub fn entry(&mut self, key: impl Into<String>, value: impl Into<Value>) -> &mut Self {
6377
self.0.insert(key.into(), value.into());

crates/manifest/src/compat.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ pub fn v1_to_v2_app(manifest: v1::AppManifestV1) -> Result<v2::AppManifest, Erro
6969
sqlite_databases,
7070
ai_models,
7171
build: component.build,
72+
allowed_outbound_hosts: component.allowed_outbound_hosts,
7273
},
7374
);
7475
triggers

0 commit comments

Comments
 (0)