diff --git a/.env.example b/.env.example index fec4bee..199e535 100644 --- a/.env.example +++ b/.env.example @@ -5,39 +5,39 @@ # You may also want to change other configuration settings, # like the user agent or the database URL. # -# You probably would want to reassign the folder of `RELAY__AUTH__PEM_PATH` +# You probably would want to reassign the folder of `CBRIDGE__AUTH__PEM_PATH` # if you're not running on a container. # Server -RELAY__SERVER__ADDRESS=0.0.0.0:3000 -RELAY__SERVER__USER_AGENT=nilirad-relay-server -RELAY__SERVER__IN_REQUEST_TIMEOUT=30s -RELAY__SERVER__OUT_REQUEST_TIMEOUT=30s +CBRIDGE__SERVER__ADDRESS=0.0.0.0:3000 +CBRIDGE__SERVER__USER_AGENT=nilirad-commit-bridge +CBRIDGE__SERVER__IN_REQUEST_TIMEOUT=30s +CBRIDGE__SERVER__OUT_REQUEST_TIMEOUT=30s # Database -RELAY__DATABASE__URL=sqlite://relay.db?mode=rwc -RELAY__DATABASE__TIMEOUT=3s -RELAY__DATABASE__POLLING_DB_BUFFER_SIZE=3 -RELAY__DATABASE__POLLING_DB_ERROR_COOLDOWN=300s -RELAY__DATABASE__SUBSCRIPTIONS_LIST_LIMIT=50 -RELAY__DATABASE__SUBSCRIPTIONS_LIST_LIMIT_CAP=100 +CBRIDGE__DATABASE__URL=sqlite://commit-bridge.db?mode=rwc +CBRIDGE__DATABASE__TIMEOUT=3s +CBRIDGE__DATABASE__POLLING_DB_BUFFER_SIZE=3 +CBRIDGE__DATABASE__POLLING_DB_ERROR_COOLDOWN=300s +CBRIDGE__DATABASE__SUBSCRIPTIONS_LIST_LIMIT=50 +CBRIDGE__DATABASE__SUBSCRIPTIONS_LIST_LIMIT_CAP=100 # GitHub API -RELAY__GITHUB_API__BASE_URL=https://api.github.com -RELAY__GITHUB_API__VERSION=2026-03-10 -RELAY__GITHUB_API__ACCEPT_HEADER=application/vnd.github+json +CBRIDGE__GITHUB_API__BASE_URL=https://api.github.com +CBRIDGE__GITHUB_API__VERSION=2026-03-10 +CBRIDGE__GITHUB_API__ACCEPT_HEADER=application/vnd.github+json # Engine -RELAY__ENGINE__POLLING_SLEEP=300s -RELAY__ENGINE__TRIGGER_QUEUE_POLLING_INTERVAL=5s -RELAY__ENGINE__TRIGGER_RETRY_MAX_ATTEMPTS=10 -RELAY__ENGINE__TRIGGER_RETRY_BACKOFF_BASE=10s -RELAY__ENGINE__STUCK_TASK_THRESHOLD=300s +CBRIDGE__ENGINE__POLLING_SLEEP=300s +CBRIDGE__ENGINE__TRIGGER_QUEUE_POLLING_INTERVAL=5s +CBRIDGE__ENGINE__TRIGGER_RETRY_MAX_ATTEMPTS=10 +CBRIDGE__ENGINE__TRIGGER_RETRY_BACKOFF_BASE=10s +CBRIDGE__ENGINE__STUCK_TASK_THRESHOLD=300s # Auth -RELAY__AUTH__CLOCK_DRIFT_BUFFER=60s -RELAY__AUTH__TOKEN_VALIDITY=300s -# RELAY__AUTH__API_KEY=YOUR_API_KEY -# RELAY__AUTH__ALLOW_UNAUTHENTICATED=true -RELAY__AUTH__CLIENT_ID=YOUR_GITHUB_CLIENT_ID -RELAY__AUTH__PEM_PATH=/app/data/YOUR_PEM_FILE.pem +CBRIDGE__AUTH__CLOCK_DRIFT_BUFFER=60s +CBRIDGE__AUTH__TOKEN_VALIDITY=300s +# CBRIDGE__AUTH__API_KEY=YOUR_API_KEY +# CBRIDGE__AUTH__ALLOW_UNAUTHENTICATED=true +CBRIDGE__AUTH__CLIENT_ID=YOUR_GITHUB_CLIENT_ID +CBRIDGE__AUTH__PEM_PATH=/app/data/YOUR_PEM_FILE.pem diff --git a/AGENTS.md b/AGENTS.md index d425f10..c626a40 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,4 +1,4 @@ -# Agent Instructions for `relay` +# Agent Instructions for `commit-bridge` This file contains crucial context for AI agents working in this repository. diff --git a/Cargo.lock b/Cargo.lock index 8a16cb5..3b6c886 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -122,6 +122,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5ec2f1fc3ec205783a5da9a7e6c1509cc69dedf09a1949e412c1e18469326d00" dependencies = [ "aws-lc-sys", + "untrusted 0.7.1", "zeroize", ] @@ -347,6 +348,41 @@ dependencies = [ "memchr", ] +[[package]] +name = "commit-bridge" +version = "0.1.0" +dependencies = [ + "async-trait", + "axum", + "chrono", + "config", + "dotenvy", + "dudect-bencher", + "futures", + "http", + "humantime-serde", + "jsonwebtoken", + "rand 0.10.1", + "reqwest", + "rovo", + "schemars", + "serde", + "serde_json", + "sqlx", + "subtle", + "thiserror", + "tokio", + "tokio-test", + "tokio-util", + "tower", + "tower-http", + "tracing", + "tracing-subscriber", + "url", + "validator", + "wiremock", +] + [[package]] name = "concurrent-queue" version = "2.5.0" @@ -493,9 +529,9 @@ checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" [[package]] name = "crypto-common" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" dependencies = [ "generic-array", "typenum", @@ -874,9 +910,9 @@ dependencies = [ [[package]] name = "generic-array" -version = "0.14.9" +version = "0.14.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bb6743198531e02858aeaea5398fcc883e71851fcbcb5a2f773e2fb6cb1edf2" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", @@ -1411,6 +1447,7 @@ version = "10.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eba32bfb4ffdeaca3e34431072faf01745c9b26d25504aa7a6cf5684334fc4fc" dependencies = [ + "aws-lc-rs", "base64", "getrandom 0.2.17", "js-sys", @@ -2089,41 +2126,6 @@ version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4" -[[package]] -name = "relay" -version = "0.1.0" -dependencies = [ - "async-trait", - "axum", - "chrono", - "config", - "dotenvy", - "dudect-bencher", - "futures", - "http", - "humantime-serde", - "jsonwebtoken", - "rand 0.10.1", - "reqwest", - "rovo", - "schemars", - "serde", - "serde_json", - "sqlx", - "subtle", - "thiserror", - "tokio", - "tokio-test", - "tokio-util", - "tower", - "tower-http", - "tracing", - "tracing-subscriber", - "url", - "validator", - "wiremock", -] - [[package]] name = "reqwest" version = "0.13.4" @@ -2174,7 +2176,7 @@ dependencies = [ "cfg-if", "getrandom 0.2.17", "libc", - "untrusted", + "untrusted 0.9.0", "windows-sys 0.52.0", ] @@ -2335,7 +2337,7 @@ dependencies = [ "aws-lc-rs", "ring", "rustls-pki-types", - "untrusted", + "untrusted 0.9.0", ] [[package]] @@ -3345,6 +3347,12 @@ version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + [[package]] name = "untrusted" version = "0.9.0" @@ -3604,7 +3612,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.61.2", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 08f22ca..433b1e9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "relay" +name = "commit-bridge" version = "0.1.0" edition = "2024" license = "MIT OR Apache-2.0" @@ -13,7 +13,7 @@ dotenvy = "0.15.7" futures = "0.3.32" http = "1.4.2" humantime-serde = "1.1.1" -jsonwebtoken = { version = "10.4.0" } +jsonwebtoken = { version = "10.4.0", features = ["aws_lc_rs"] } reqwest = { version = "0.13.4", features = ["json"] } rovo = { version = "0.4.8", features = ["scalar"] } schemars = { version = "0.9", features = ["chrono04"] } diff --git a/Dockerfile b/Dockerfile index 19b2ad2..1eed854 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,16 +13,16 @@ COPY --from=planner /app/recipe.json recipe.json ENV SQLX_OFFLINE=true RUN cargo chef cook --release --recipe-path recipe.json COPY . . -RUN cargo build --release --bin relay +RUN cargo build --release --bin commit-bridge FROM debian:bookworm-slim AS final RUN apt-get update && apt-get install -y --no-install-recommends \ git \ ca-certificates \ && rm -rf /var/lib/apt/lists/* -COPY --from=builder /app/target/release/relay /usr/local/bin/relay -ENV RELAY__DATABASE__URL="sqlite:///app/data/relay.db?mode=rwc" +COPY --from=builder /app/target/release/commit-bridge /usr/local/bin/commit-bridge +ENV CBRIDGE__DATABASE__URL="sqlite:///app/data/commit-bridge.db?mode=rwc" VOLUME ["/app/data"] EXPOSE 3000 WORKDIR /app/data -CMD ["relay"] +CMD ["commit-bridge"] diff --git a/README.md b/README.md index e56c7ea..d868988 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,22 @@ -# Relay Server +
+ Seamless workflow dispatch for remote git dependencies. +
+ + + + + +--- Triggering a repository workflow in response to a commit on a different repository is not a trivial problem. @@ -49,7 +67,7 @@ from other `repository_dispatch` events. Clone this repository: ```shell -git clone https://github.com/Nilirad/relay.git +git clone https://github.com/Nilirad/commit-bridge.git ``` Then, @@ -96,8 +114,8 @@ cp .env.example .env ``` Then, -edit the `.env` file to add your GitHub App's client id (`RELAY__AUTH__CLIENT_ID`) -and prepare the necessary paths for your GitHub App private key (`RELAY__AUTH__PEM_PATH`). +edit the `.env` file to add your GitHub App's client id (`CBRIDGE__AUTH__CLIENT_ID`) +and prepare the necessary paths for your GitHub App private key (`CBRIDGE__AUTH__PEM_PATH`). Finally, follow one of the three options below. @@ -176,7 +194,7 @@ cargo run --release By default, this server mandates authentication for all `/subscriptions` endpoints. -1. **Configure:** Set the `RELAY__AUTH__API_KEY` environment variable to a secure value in your `.env` file. +1. **Configure:** Set the `CBRIDGE__AUTH__API_KEY` environment variable to a secure value in your `.env` file. 2. **Authenticate:** Include the key in the `X-API-KEY` header for all requests: ```shell @@ -192,7 +210,7 @@ Note that while this protects against key content discovery, an attacker may still be able to infer the length of the API key by measuring response times. For maximum security, -ensure that your `RELAY__AUTH__API_KEY` is long +ensure that your `CBRIDGE__AUTH__API_KEY` is long and generated using a cryptographically secure random source. ### Disabling Authentication (Not Recommended) @@ -206,7 +224,7 @@ If you require an unauthenticated setup for rapid local prototyping, you can explicitly opt-in by setting the following environment variable: ```text -RELAY__AUTH__ALLOW_UNAUTHENTICATED=true +CBRIDGE__AUTH__ALLOW_UNAUTHENTICATED=true ``` ## License diff --git a/docker-compose.yaml.example b/docker-compose.yaml.example index f95c4b3..135aaa8 100644 --- a/docker-compose.yaml.example +++ b/docker-compose.yaml.example @@ -1,15 +1,15 @@ services: - relay: + commit-bridge: build: context: . dockerfile: Dockerfile - image: nilirad/relay:latest - container_name: relay-server + image: nilirad/commit-bridge:latest + container_name: commit-bridge-server restart: unless-stopped ports: - "3000:3000" volumes: - - relay_data:/app/data + - commit_bridge_data:/app/data - ./YOUR_PEM_FILE.pem:/app/data/YOUR_PEM_FILE.pem:ro env_file: - .env @@ -23,4 +23,4 @@ services: path: Cargo.lock volumes: - relay_data: + commit_bridge_data: diff --git a/examples/timing_attack_check.rs b/examples/timing_attack_check.rs index 58a68fb..90e3308 100644 --- a/examples/timing_attack_check.rs +++ b/examples/timing_attack_check.rs @@ -1,9 +1,9 @@ use dudect_bencher::{BenchRng, Class, CtRunner, ctbench_main}; +use commit_bridge::domain::NonEmptyString; +use commit_bridge::verify_api_key; use dudect_bencher::rand::RngExt; use rand::distr::{Alphanumeric, SampleString}; -use relay::domain::NonEmptyString; -use relay::verify_api_key; fn bench_verify_api_key(runner: &mut CtRunner, rng: &mut BenchRng) { const SET_SIZE: usize = 100_000; diff --git a/flake.nix b/flake.nix index 3f7a815..98a1339 100644 --- a/flake.nix +++ b/flake.nix @@ -103,11 +103,11 @@ shellHook = '' echo "Rust dev shell ready (Rust $(rustc --version))" - export DATABASE_URL="sqlite://relay.db?mode=rwc" + export DATABASE_URL="sqlite://commit-bridge.db?mode=rwc" ''; }; packages.default = pkgs.rustPlatform.buildRustPackage { - pname = "relay"; + pname = "commit-bridge"; version = "0.1.0"; src = ./.; cargoLock = { diff --git a/src/config.rs b/src/config.rs index ffccca9..f06f023 100644 --- a/src/config.rs +++ b/src/config.rs @@ -48,7 +48,7 @@ impl Config { ); } - let environment = Environment::with_prefix("RELAY") + let environment = Environment::with_prefix("CBRIDGE") .separator("__") .try_parsing(true); @@ -62,7 +62,7 @@ impl Config { if config.auth.allow_unauthenticated { tracing::warn!( "API AUTHENTICATION DISABLED. \ - Please do not set `RELAY__AUTH__ALLOW_UNAUTHENTICATED=true` \ + Please do not set `CBRIDGE__AUTH__ALLOW_UNAUTHENTICATED=true` \ on production environments." ); } diff --git a/src/lib.rs b/src/lib.rs index ae84aea..31bad48 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -210,7 +210,7 @@ mod health_handler { use super::*; #[rovo] pub async fn health_check(State(_state): State