Skip to content

Commit 5bce940

Browse files
committed
feat(toml): Allow interpolation in allowed_host.pattern
1 parent 551b8a6 commit 5bce940

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

DEVELOPMENT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ cargo test --package obelisk grpc_server::tests
6666

6767
| Task | Files |
6868
|------|-------|
69-
| TOML | `src/config/toml.rs`, `obelisk-help-server.toml`, `obelisk-help-deployment.toml` |
69+
| TOML | `src/config/toml.rs`, `obelisk-help-server.toml`, `obelisk-help-deployment.toml` — update the `obelisk-help-*.toml` files when changing TOML config |
7070
| Database schema/queries | `crates/db-sqlite/src/sqlite_dao.rs`, `crates/db-postgres/src/postgres_dao.rs` |
7171
| Storage traits | `crates/concepts/src/storage.rs` |
7272
| gRPC API | `proto/obelisk.proto`, `src/server/grpc_server.rs`,`crates/grpc/src/grpc_mapping.rs` |

obelisk-help-deployment.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
## Environment variables: Set to a specific value, use ${VAR} interpolation, or forward from the host. Default is empty.
3838
## Bash-style defaults are supported: ${VAR:-default} uses default when VAR is unset or empty, ${VAR-default} when unset only.
3939
## Defaults can themselves contain ${...} interpolations.
40+
## Note: only `${VAR}` triggers interpolation; `$VAR` (no braces) is treated as a literal string.
41+
## Forwarded vars ("ENV1") fail startup if missing; value strings with unresolved `${VAR}` also fail.
4042
# env_vars = ["ENV1", {key = "ENV2", value = "somevalue"}, {key = "ENV3", value = "${HOST_VAR}"}, {key = "ENV4", value = "prefix ${HOST_VAR}"}, {key = "ENV5", value = "${OPTIONAL:-fallback}"}]
4143

4244
## Outgoing HTTP host allowlist.
@@ -57,6 +59,7 @@
5759
## - Omitting `methods` entirely allows nothing (config warning)
5860
##
5961
## Multiple entries can match the same request; they form a union (secrets are merged).
62+
## The `pattern` field supports `${VAR}` and `${VAR:-default}` env var interpolation.
6063
# [[activity_wasm.allowed_host]]
6164
# pattern = "api.github.com"
6265
# methods = "*"
@@ -258,6 +261,8 @@
258261
## Environment variables: Set to a specific value, use ${VAR} interpolation, or forward from the host. Default is empty.
259262
## Bash-style defaults are supported: ${VAR:-default} uses default when VAR is unset or empty, ${VAR-default} when unset only.
260263
## Defaults can themselves contain ${...} interpolations.
264+
## Note: only `${VAR}` triggers interpolation; `$VAR` (no braces) is treated as a literal string.
265+
## Forwarded vars ("ENV1") fail startup if missing; value strings with unresolved `${VAR}` also fail.
261266
# env_vars = ["ENV1", {key = "ENV2", value = "somevalue"}, {key = "ENV3", value = "${HOST_VAR}"}, {key = "ENV4", value = "prefix ${HOST_VAR}"}, {key = "ENV5", value = "${OPTIONAL:-fallback}"}]
262267
# backtrace.sources = {"frame symbol file path" = "path to the source file", ".../src/lib.rs" = "path to source file"}
263268
## Outgoing HTTP host allowlist - same syntax as activity_wasm.allowed_host.
@@ -286,6 +291,8 @@
286291
## Environment variables: Set to a specific value, use ${VAR} interpolation, or forward from the host. Default is empty.
287292
## Bash-style defaults are supported: ${VAR:-default} uses default when VAR is unset or empty, ${VAR-default} when unset only.
288293
## Defaults can themselves contain ${...} interpolations.
294+
## Note: only `${VAR}` triggers interpolation; `$VAR` (no braces) is treated as a literal string.
295+
## Forwarded vars ("ENV1") fail startup if missing; value strings with unresolved `${VAR}` also fail.
289296
# env_vars = ["ENV1", {key = "ENV2", value = "somevalue"}, {key = "ENV3", value = "${HOST_VAR}"}, {key = "ENV4", value = "prefix ${HOST_VAR}"}, {key = "ENV5", value = "${OPTIONAL:-fallback}"}]
290297
## Outgoing HTTP host allowlist - same syntax as activity_wasm.allowed_host.
291298
# [[webhook_endpoint_js.allowed_host]]

src/config/toml.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2974,7 +2974,22 @@ fn resolve_allowed_hosts(
29742974
}
29752975
};
29762976

2977-
let pattern = match HostPattern::parse_with_methods(&entry.pattern, methods) {
2977+
let pattern_str = match interpolate_env_vars_plaintext(&entry.pattern) {
2978+
Ok(s) => s,
2979+
Err(EnvVarMissing(var)) => {
2980+
if ignore_missing_env_vars {
2981+
warn!(
2982+
"allowed_host pattern `{}` references missing env var `{var}`, skipping",
2983+
entry.pattern
2984+
);
2985+
return None;
2986+
}
2987+
return Some(Err(ResolveAllowedHostsError::EnvVarsMissing(
2988+
EnvVarsMissing(vec![var]),
2989+
)));
2990+
}
2991+
};
2992+
let pattern = match HostPattern::parse_with_methods(&pattern_str, methods) {
29782993
Ok(p) => p,
29792994
Err(e) => return Some(Err(e.into())),
29802995
};

0 commit comments

Comments
 (0)