Skip to content

Commit 5884cfc

Browse files
committed
Use spin.alt domain for service chaining
Signed-off-by: itowlson <[email protected]>
1 parent aa5d74c commit 5884cfc

File tree

10 files changed

+21
-15
lines changed

10 files changed

+21
-15
lines changed

crates/loader/src/local.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use spin_locked_app::{
1212
values::{ValuesMap, ValuesMapBuilder},
1313
};
1414
use spin_manifest::schema::v2::{self, AppManifest, KebabId, WasiFilesMount};
15-
use spin_outbound_networking::SERVICE_CHAINING_DOMAIN_SUFFIX;
15+
use spin_outbound_networking::SERVICE_CHAINING_DOMAIN_SUFFIXES;
1616
use tokio::{io::AsyncWriteExt, sync::Semaphore};
1717

1818
use crate::{cache::Cache, FilesMountStrategy};
@@ -661,12 +661,18 @@ fn is_chaining_host(pattern: &str) -> bool {
661661
match allowed.host() {
662662
HostConfig::List(hosts) => hosts
663663
.iter()
664-
.any(|h| h.ends_with(SERVICE_CHAINING_DOMAIN_SUFFIX)),
665-
HostConfig::AnySubdomain(domain) => domain == SERVICE_CHAINING_DOMAIN_SUFFIX,
664+
.any(|h| ends_with_any(h, SERVICE_CHAINING_DOMAIN_SUFFIXES)),
665+
HostConfig::AnySubdomain(domain) => {
666+
SERVICE_CHAINING_DOMAIN_SUFFIXES.contains(&domain.as_str())
667+
}
666668
_ => false,
667669
}
668670
}
669671

672+
fn ends_with_any(host: &str, suffixes: &[&str]) -> bool {
673+
suffixes.iter().any(|suffix| host.ends_with(suffix))
674+
}
675+
670676
const SLOTH_WARNING_DELAY_MILLIS: u64 = 1250;
671677

672678
fn warn_if_component_load_slothful() -> sloth::SlothGuard {

crates/loader/tests/ui/service-chaining.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"id": "four-lights",
5656
"metadata": {
5757
"allowed_outbound_hosts": [
58-
"http://old-test.spin.internal"
58+
"http://old-test.spin.alt"
5959
]
6060
},
6161
"source": {

crates/loader/tests/ui/service-chaining.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ component = "web"
2121

2222
[component.four-lights]
2323
source = "wasm/dummy.wasm"
24-
allowed_outbound_hosts = ["http://old-test.spin.internal"]
24+
allowed_outbound_hosts = ["http://old-test.spin.alt"]
2525
[component.four-lights.environment]
2626
env1 = "first"
2727
env2 = "second"

crates/locked-app/src/locked.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::{
1515
pub type LockedMap<T> = std::collections::BTreeMap<String, T>;
1616

1717
/// If present and required in `host_requirements`, the host must support
18-
/// local service chaining (*.spin.internal) or reject the app.
18+
/// local service chaining (*.spin.alt/.internal) or reject the app.
1919
pub const SERVICE_CHAINING_KEY: &str = "local_service_chaining";
2020

2121
/// Indicates that a host feature is optional. This is the default and is

crates/outbound-networking/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use spin_locked_app::MetadataKey;
55

66
pub const ALLOWED_HOSTS_KEY: MetadataKey<Vec<String>> = MetadataKey::new("allowed_outbound_hosts");
77

8-
pub const SERVICE_CHAINING_DOMAIN: &str = "spin.internal";
9-
pub const SERVICE_CHAINING_DOMAIN_SUFFIX: &str = ".spin.internal";
8+
pub const SERVICE_CHAINING_DOMAINS: &[&str] = &["spin.alt", "spin.internal"];
9+
pub const SERVICE_CHAINING_DOMAIN_SUFFIXES: &[&str] = &[".spin.alt", ".spin.internal"];
1010

1111
/// Checks address against allowed hosts
1212
///
@@ -453,7 +453,7 @@ fn parse_service_chaining_host(host: &str) -> Option<String> {
453453

454454
let (first, rest) = host.split_once('.')?;
455455

456-
if rest == SERVICE_CHAINING_DOMAIN {
456+
if SERVICE_CHAINING_DOMAINS.contains(&rest) {
457457
Some(first.to_owned())
458458
} else {
459459
None

crates/trigger-http/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1201,8 +1201,8 @@ mod tests {
12011201

12021202
#[test]
12031203
fn forbidden_headers_are_removed() {
1204-
let mut req = Request::get("http://test.spin.internal")
1205-
.header("Host", "test.spin.internal")
1204+
let mut req = Request::get("http://test.spin.alt")
1205+
.header("Host", "test.spin.alt")
12061206
.header("accept", "text/plain")
12071207
.body(Default::default())
12081208
.unwrap();

tests/runtime-tests/tests/internal-http-streaming/spin.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ component = "front-streaming"
1111

1212
[component.front-streaming]
1313
source = "%{source=internal-http-streaming-front}"
14-
allowed_outbound_hosts = ["http://*.spin.internal"]
14+
allowed_outbound_hosts = ["http://*.spin.alt"]
1515

1616
[[trigger.http]]
1717
route = "/back/..."

tests/runtime-tests/tests/internal-http/spin.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ component = "front"
1111

1212
[component.front]
1313
source = "%{source=internal-http-front}"
14-
allowed_outbound_hosts = ["http://middle.spin.internal"]
14+
allowed_outbound_hosts = ["http://middle.spin.alt"]
1515

1616
[[trigger.http]]
1717
route = { private = true }

tests/test-components/components/internal-http-front/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ async fn handle_front_impl(_req: Request) -> Result<impl IntoResponse, String> {
1515
let mut res: http::Response<String> = ensure_ok!(spin_sdk::http::send(
1616
spin_sdk::http::Request::new(
1717
spin_sdk::http::Method::Get,
18-
"http://middle.spin.internal/hello/from/front"
18+
"http://middle.spin.alt/hello/from/front"
1919
)
2020
)
2121
.await);

tests/test-components/components/internal-http-streaming-front/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async fn handle_front_impl(_req: Request) -> Result<impl IntoResponse, String> {
1717
spin_sdk::http::Fields::new()
1818
);
1919
out_req.set_method(&spin_sdk::http::Method::Post).unwrap();
20-
out_req.set_authority(Some("back-streaming.spin.internal")).unwrap();
20+
out_req.set_authority(Some("back-streaming.spin.alt")).unwrap();
2121
out_req.set_scheme(Some(&spin_sdk::http::Scheme::Http)).unwrap();
2222
out_req.set_path_with_query(Some("/")).unwrap();
2323

0 commit comments

Comments
 (0)