Skip to content

Commit c26dc71

Browse files
authored
Merge pull request #144 from dfinity/igor/new-custom-domains
Add new custom domains system
2 parents 75d7fe9 + a386de6 commit c26dc71

File tree

13 files changed

+922
-638
lines changed

13 files changed

+922
-638
lines changed

Cargo.lock

Lines changed: 522 additions & 483 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@ clickhouse = { version = "0.13.1", features = [
3232
"rustls-tls-ring",
3333
"rustls-tls-webpki-roots",
3434
], optional = true }
35+
cloudflare = { version = "0.14.0", default-features = false, features = [
36+
"rustls-tls",
37+
] }
3538
console-subscriber = { version = "0.4.1", optional = true }
3639
ctrlc = { version = "3.4.5", features = ["termination"] }
40+
custom-domains-backend = { package = "backend", git = "https://github.com/dfinity/custom-domains", rev = "2113c19f3cc925b2b77f092e45daf5ed1dd3bda0" }
41+
custom-domains-base = { package = "base", git = "https://github.com/dfinity/custom-domains", rev = "2113c19f3cc925b2b77f092e45daf5ed1dd3bda0" }
3742
derive-new = "0.7.0"
3843
fqdn = { version = "0.4.1", features = ["serde"] }
3944
futures = "0.3.31"
@@ -48,7 +53,8 @@ http = "1.3.1"
4853
http-body = "1.0.1"
4954
http-body-util = "0.1.2"
5055
humantime = "2.2.0"
51-
ic-bn-lib = { git = "https://github.com/dfinity/ic-bn-lib", rev = "e23f4a8cf3bd7c06b8ef329d3c1e6117ea71b832", features = [
56+
ic-bn-lib = { git = "https://github.com/dfinity/ic-bn-lib", rev = "b5cd9d68c2c5ac3482c8a4f4a4dfb366f8ffdcff", features = [
57+
"acme",
5258
"vector",
5359
"cert-providers",
5460
"clients-hyper",
@@ -149,3 +155,11 @@ harness = false
149155
[[bench]]
150156
name = "http_gateway"
151157
harness = false
158+
159+
[[bin]]
160+
name = "create-acme-account"
161+
path = "tools/create_acme_account.rs"
162+
163+
[[bin]]
164+
name = "cloudflare-check"
165+
path = "tools/cloudflare_check.rs"

benches/domain_lookup.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ fn criterion_benchmark(c: &mut Criterion) {
3434
.map(|x| CustomDomain {
3535
name: x,
3636
canister_id: principal!("aaaaa-aa"),
37+
timestamp: 0,
3738
})
3839
.collect::<Vec<_>>();
3940

repro-env.lock

Lines changed: 136 additions & 112 deletions
Large diffs are not rendered by default.

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[toolchain]
2-
channel = "1.90.0"
2+
channel = "1.91.0"
33
targets = ["x86_64-unknown-linux-musl"]
44
profile = "default"

src/cli.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ pub struct Cli {
5555
#[command(flatten, next_help_heading = "Domains")]
5656
pub domain: Domain,
5757

58+
#[command(flatten, next_help_heading = "Custom Domains")]
59+
pub custom_domains: Option<custom_domains_base::cli::CustomDomainsCli>,
60+
5861
#[command(flatten, next_help_heading = "Policy")]
5962
pub policy: Policy,
6063

src/core.rs

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@ use std::{
55

66
use anyhow::{Context, Error, anyhow};
77
use axum::Router;
8+
use custom_domains_backend::setup;
89
use ic_bn_lib::{
910
custom_domains::{self, ProvidesCustomDomains},
10-
http::{self as bnhttp, dns::ApiBnResolver, middleware::waf::WafLayer, redirect_to_https},
11+
http::{
12+
self as bnhttp,
13+
dns::{ApiBnResolver, Options as DnsOptions},
14+
middleware::waf::WafLayer,
15+
redirect_to_https,
16+
},
1117
tasks::TaskManager,
1218
tls::{prepare_client_config, providers::ProvidesCertificates, verify::NoopServerCertVerifier},
1319
utils::health_manager::HealthManager,
@@ -92,7 +98,8 @@ pub async fn main(
9298
.context("unable to create Prometheus registry")?;
9399

94100
// DNS resolver
95-
let dns_resolver = bnhttp::dns::Resolver::new((&cli.dns).into());
101+
let dns_options: DnsOptions = (&cli.dns).into();
102+
let dns_resolver = bnhttp::dns::Resolver::new(dns_options.clone());
96103

97104
// HTTP client
98105
let mut http_client_opts: bnhttp::client::Options = (&cli.http_client).into();
@@ -173,6 +180,25 @@ pub async fn main(
173180
// HTTP server metrics
174181
let http_metrics = bnhttp::server::Metrics::new(&registry);
175182

183+
// Setup custom domains
184+
let custom_domains_router = if let Some(v) = &cli.custom_domains {
185+
let router = setup_custom_domains(
186+
v,
187+
dns_options,
188+
&registry,
189+
&mut tasks,
190+
&mut certificate_providers,
191+
&mut custom_domain_providers,
192+
)
193+
.await
194+
.context("unable to setup Custom Domains")?;
195+
196+
warn!("Custom Domains: initialized");
197+
Some(router)
198+
} else {
199+
None
200+
};
201+
176202
// Setup Certificate Issuers
177203
let issuers = setup_issuers(cli, &mut tasks, http_client.clone(), &registry);
178204

@@ -252,6 +278,7 @@ pub async fn main(
252278
shutdown_token.clone(),
253279
vector.clone(),
254280
waf_layer,
281+
custom_domains_router,
255282
#[cfg(feature = "clickhouse")]
256283
clickhouse.clone(),
257284
)
@@ -345,3 +372,32 @@ pub async fn main(
345372

346373
Ok(())
347374
}
375+
376+
async fn setup_custom_domains(
377+
cli: &custom_domains_base::cli::CustomDomainsCli,
378+
dns_options: DnsOptions,
379+
metrics_registry: &Registry,
380+
tasks: &mut TaskManager,
381+
certificate_providers: &mut Vec<Arc<dyn ProvidesCertificates>>,
382+
custom_domain_providers: &mut Vec<Arc<dyn ProvidesCustomDomains>>,
383+
) -> Result<Router, Error> {
384+
let token = tasks.token();
385+
let (workers, router, client) = setup(
386+
cli,
387+
dns_options,
388+
token,
389+
HOSTNAME.get().unwrap(),
390+
metrics_registry.clone(),
391+
)
392+
.await?;
393+
394+
for (i, worker) in workers.into_iter().enumerate() {
395+
tasks.add(&format!("custom_domains_worker_{i}"), Arc::new(worker));
396+
}
397+
tasks.add("custom_domains_canister_client", client.clone());
398+
399+
certificate_providers.push(client.clone());
400+
custom_domain_providers.push(client);
401+
402+
Ok(router)
403+
}

0 commit comments

Comments
 (0)