Skip to content

Commit 5c1281d

Browse files
authored
Merge pull request #142 from dfinity/igor/rl-bypass-token
Add rate limiter bypass token
2 parents b17d7d0 + 39496c4 commit 5c1281d

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ http = "1.3.1"
4848
http-body = "1.0.1"
4949
http-body-util = "0.1.2"
5050
humantime = "2.2.0"
51-
ic-bn-lib = { git = "https://github.com/dfinity/ic-bn-lib", rev = "3b99c44fae99d09cc6d78f0879d87dce0eb8768e", features = [
51+
ic-bn-lib = { git = "https://github.com/dfinity/ic-bn-lib", rev = "7f15e91888f76a6bfff9a59d478fdd11d76a5ff6", features = [
5252
"vector",
5353
"cert-providers",
5454
"clients-hyper",

src/cli.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ pub struct Cli {
8383
#[command(flatten, next_help_heading = "CORS")]
8484
pub cors: Cors,
8585

86+
#[command(flatten, next_help_heading = "Rate limiting")]
87+
pub rate_limit: RateLimit,
88+
8689
#[command(flatten, next_help_heading = "Cache")]
8790
pub cache: CacheConfig,
8891

@@ -557,6 +560,13 @@ pub struct Cors {
557560
pub cors_invalid_canisters_ttl: Duration,
558561
}
559562

563+
#[derive(Args)]
564+
pub struct RateLimit {
565+
/// Bypass token for rate-limiter that should be sent in `x-ratelimit-bypass-token` header
566+
#[clap(env, long)]
567+
pub rate_limit_bypass_token: Option<String>,
568+
}
569+
560570
#[cfg(test)]
561571
mod test {
562572
use super::*;

src/routing/mod.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,12 @@ pub async fn setup_router(
489489
])),
490490
)
491491
.route("/registrations", post(proxy::issuer_proxy).layer(cors_post))
492-
.layer(rate_limiter::layer_by_ip(1, 2, RateLimitCause::Normal)?)
492+
.layer(rate_limiter::layer_by_ip(
493+
1,
494+
2,
495+
RateLimitCause::Normal,
496+
cli.rate_limit.rate_limit_bypass_token.clone(),
497+
)?)
493498
.with_state(state);
494499

495500
Some(router)
@@ -590,7 +595,12 @@ pub async fn setup_router(
590595
)
591596
.context("unable to init SEV-SNP")?,
592597
)
593-
.layer(rate_limiter::layer_global(50, 100, RateLimitCause::Normal)?),
598+
.layer(rate_limiter::layer_global(
599+
50,
600+
100,
601+
RateLimitCause::Normal,
602+
cli.rate_limit.rate_limit_bypass_token.clone(),
603+
)?),
594604
);
595605

596606
router = router.merge(router_sev_snp)

0 commit comments

Comments
 (0)