Skip to content

Commit a598135

Browse files
committed
config: Add TRUSTPUB_AUDIENCE setting
This defaults to the domain name (crates.io / staging.crates.io) and controls the expected `aud` claim of the OIDC JWT in the Trusted Publishing token exchange.
1 parent afb3438 commit a598135

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/config/server.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ pub struct Server {
8787
pub html_render_cache_max_capacity: u64,
8888

8989
pub content_security_policy: Option<HeaderValue>,
90+
91+
/// The expected audience claim (`aud`) for the Trusted Publishing
92+
/// token exchange.
93+
pub trustpub_audience: String,
9094
}
9195

9296
impl Server {
@@ -186,6 +190,9 @@ impl Server {
186190
.unwrap_or_default()
187191
);
188192

193+
let domain_name = dotenvy::var("DOMAIN_NAME").unwrap_or_else(|_| "crates.io".into());
194+
let trustpub_audience = var("TRUSTPUB_AUDIENCE")?.unwrap_or_else(|| domain_name.clone());
195+
189196
Ok(Server {
190197
db: DatabasePools::full_from_environment(&base)?,
191198
storage,
@@ -210,7 +217,7 @@ impl Server {
210217
page_offset_ua_blocklist,
211218
page_offset_cidr_blocklist,
212219
excluded_crate_names,
213-
domain_name: dotenvy::var("DOMAIN_NAME").unwrap_or_else(|_| "crates.io".into()),
220+
domain_name,
214221
allowed_origins,
215222
downloads_persist_interval: var_parsed("DOWNLOADS_PERSIST_INTERVAL_MS")?
216223
.map(Duration::from_millis)
@@ -233,6 +240,7 @@ impl Server {
233240
og_image_base_url: var_parsed("OG_IMAGE_BASE_URL")?,
234241
html_render_cache_max_capacity: var_parsed("HTML_RENDER_CACHE_CAP")?.unwrap_or(1024),
235242
content_security_policy: Some(content_security_policy.parse()?),
243+
trustpub_audience,
236244
})
237245
}
238246
}

src/tests/util/test_app.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use crates_io_index::testing::UpstreamIndex;
1717
use crates_io_index::{Credentials, RepositoryConfig};
1818
use crates_io_team_repo::MockTeamRepo;
1919
use crates_io_test_db::TestDatabase;
20+
use crates_io_trustpub::github::test_helpers::AUDIENCE;
2021
use crates_io_worker::Runner;
2122
use diesel_async::AsyncPgConnection;
2223
use futures_util::TryStreamExt;
@@ -491,6 +492,7 @@ fn simple_config() -> config::Server {
491492
og_image_base_url: None,
492493
html_render_cache_max_capacity: 1024,
493494
content_security_policy: None,
495+
trustpub_audience: AUDIENCE.to_string(),
494496
}
495497
}
496498

0 commit comments

Comments
 (0)