diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..7494d25 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,76 @@ +name: CI + +on: + pull_request: + push: + branches: + - main + +permissions: + contents: read + +env: + CARGO_TERM_COLOR: always + RUST_BACKTRACE: 1 + +jobs: + format: + name: Format + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@1.97.0 + with: + components: rustfmt + - name: Check formatting + run: cargo fmt --all -- --check + + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@1.97.0 + with: + components: clippy + - uses: Swatinem/rust-cache@v2 + - name: Run Clippy + run: cargo clippy --locked --all-targets --all-features -- + + build: + name: Build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@1.97.0 + - uses: Swatinem/rust-cache@v2 + - name: Build debug + run: cargo build --locked --verbose + - name: Build release + run: cargo build --locked --release --verbose + + test: + name: Test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@1.97.0 + - uses: Swatinem/rust-cache@v2 + - name: Run tests + run: cargo test --locked --all --verbose + + deny: + name: Cargo deny + runs-on: ubuntu-latest + strategy: + matrix: + checks: + - advisories + - bans licenses sources + continue-on-error: ${{ matrix.checks == 'advisories' }} + steps: + - uses: actions/checkout@v4 + - uses: EmbarkStudios/cargo-deny-action@v2 + with: + command: check ${{ matrix.checks }} + rust-version: 1.97.0 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..216cf26 --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +# Rust +target/ +**/*.rs.bk + +# IDE +.idea/ +.vscode/ +*.swp +*.swo + +# OS +.DS_Store +Thumbs.db + +# Environment +.env +.env.local diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..6052106 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,682 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "aho-corasick" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" +dependencies = [ + "memchr", +] + +[[package]] +name = "anyhow" +version = "1.0.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a4385e2e34eb35d6b3efe798b9eb88096925d87726c0798709bf56d9ed84af3" + +[[package]] +name = "api" +version = "0.1.0" +dependencies = [ + "anyhow", + "axum", + "tokio", + "tower", + "tower-http", + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "axum" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31b698c5f9a010f6573133b09e0de5408834d0c82f8d7475a89fc1867a71cd90" +dependencies = [ + "axum-core", + "bytes", + "form_urlencoded", + "futures-util", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-util", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "serde_core", + "serde_json", + "serde_path_to_error", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "axum-core" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08c78f31d7b1291f7ee735c1c6780ccde7785daae9a9206026862dab7d8792d1" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "http-body-util", + "mime", + "pin-project-lite", + "sync_wrapper", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "bitflags" +version = "2.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4388bee8683e3d04af747c73422af53102d2bd24d9eadb6cbc100baef4b43f8" + +[[package]] +name = "bytes" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04" + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures-channel" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" + +[[package]] +name = "futures-task" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393" + +[[package]] +name = "futures-util" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "slab", +] + +[[package]] +name = "http" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6970f50e31d6fc17d3fa27329444bfa74e196cf62e95052a3f6fee181dba6425" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "hyper" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55281c53a1894c864990125767da440a4e630446785086f52523b20033b74498" +dependencies = [ + "atomic-waker", + "bytes", + "futures-channel", + "futures-core", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", +] + +[[package]] +name = "hyper-util" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0" +dependencies = [ + "bytes", + "http", + "http-body", + "hyper", + "pin-project-lite", + "tokio", + "tower-service", +] + +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.186" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66" + +[[package]] +name = "log" +version = "0.4.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ceec5bc11778974d1bcb055b18002eba7f4b3518b6a0081b3af5f21666da9ad" + +[[package]] +name = "matchers" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1525a2a28c7f4fa0fc98bb91ae755d1e2d1505079e05539e35bc876b5d65ae9" +dependencies = [ + "regex-automata", +] + +[[package]] +name = "matchit" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3" + +[[package]] +name = "memchr" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mio" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02bd0af71c67b473010cbbc60715ee815645a4dc942899111f494b4b737d6fda" +dependencies = [ + "libc", + "wasi", + "windows-sys", +] + +[[package]] +name = "nu-ansi-term" +version = "0.50.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "proc-macro2" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfbc457d0c7a0759a614551b11a6409e5951f6c7537be1f1b7682b9ae9230368" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "regex-automata" +version = "0.4.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f388202e4b80542a0921078cc23b6333bcf1409c1e3f86404cae4766a6131db" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4" + +[[package]] +name = "ryu" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" + +[[package]] +name = "secure-enclave" +version = "0.1.0" +dependencies = [ + "anyhow", + "tokio", + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.150" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8014e44b4736ed0538adeecded0fce2a272f22dc9578a7eb6b2d9993c74cfb9" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_path_to_error" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10a9ff822e371bb5403e391ecd83e182e0e77ba7f6fe0160b795797109d1b457" +dependencies = [ + "itoa", + "serde", + "serde_core", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "signal-hook-registry" +version = "1.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" +dependencies = [ + "errno", + "libc", +] + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "smallvec" +version = "1.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ed6a63f02c8539c91a8685a86f4099661ba3da017932f6ebbea6de3f0fa7c90" + +[[package]] +name = "socket2" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52d1cfed4120b4d927bf7c0f86d2087a4a7d6027c906d9f9d525a80573b9be51" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "syn" +version = "2.0.118" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9ae57f904213ebb649ce6895b8a66c66f0203b9319718f69a5612a065b1422" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" + +[[package]] +name = "thread_local" +version = "1.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ad99c4c6d32803332c548b1af0540b357b3f5fc0be8f6c6bfe8b2e6ae784070" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "tokio" +version = "1.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc7f01b389ac15039e4dc9531aa973a135d7a4135281b12d7c1bc79fd57fffe" +dependencies = [ + "libc", + "mio", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys", +] + +[[package]] +name = "tokio-macros" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "385a6cb71ab9ab790c5fe8d67f1645e6c450a7ce006a33de03daa956cf70a496" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tower" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper", + "tokio", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-http" +version = "0.6.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cfcf7e2740e6fc6d4d688b4ef00650406bb94adf4731e43c096c3a19fe40840" +dependencies = [ + "bitflags", + "bytes", + "http", + "http-body", + "pin-project-lite", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "log", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7f578e5945fb242538965c2d0b04418d38ec25c79d160cd279bf0731c8d319" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex-automata", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", +] + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + +[[package]] +name = "valuable" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "zmij" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..ed1bee2 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,19 @@ +[workspace] +members = ["api", "secure-enclave"] +resolver = "3" + +[workspace.package] +edition = "2024" +rust-version = "1.97.0" +version = "0.1.0" +license = "MIT" +publish = false + +[workspace.dependencies] +anyhow = "1.0" +axum = "0.8" +tokio = { version = "1.48", features = ["macros", "net", "rt-multi-thread", "signal"] } +tower = { version = "0.5", features = ["util"] } +tower-http = { version = "0.6", features = ["trace"] } +tracing = "0.1" +tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/README.md b/README.md index 78048be..e2745ce 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,86 @@ -# embedding-verifier -embedding-verifier repository +# Embedding Verifier + +Rust workspace for the embedding verifier API and secure enclave. + +## Structure + +```text +embedding-verifier/ +├── api/ # Axum HTTP API +└── secure-enclave/ # Secure enclave process +``` + +## Development + +```bash +# Run formatting and lint checks +cargo fmt --all -- --check +cargo clippy --all-targets --all-features -- + +# Build and test the workspace +cargo build +cargo test --all + +# Run the API on http://localhost:8000 +RUST_LOG=info cargo run --bin api +curl http://localhost:8000/health + +# Run the secure enclave placeholder +RUST_LOG=info cargo run --bin secure-enclave +``` + +## Nitro-enabled development host + +Use an Amazon Linux 2023 EC2 instance type that supports Nitro Enclaves and launch it with +Nitro Enclaves enabled. Limit inbound SSH access to your current public IP. + +On the instance, install the development tools and Nitro Enclaves runtime: + +```bash +sudo dnf install -y \ + git wget jq tmux tree unzip tar gzip \ + gcc gcc-c++ make cmake clang pkgconf-pkg-config openssl-devel \ + bubblewrap docker aws-nitro-enclaves-cli aws-nitro-enclaves-cli-devel + +sudo usermod -aG ne "$USER" +sudo usermod -aG docker "$USER" +sudo systemctl enable --now nitro-enclaves-allocator.service +sudo systemctl enable --now docker +``` + +These commands follow the [AWS Nitro Enclaves setup for Amazon Linux 2023](https://docs.aws.amazon.com/enclaves/latest/user/nitro-enclave-cli-install.html). + +The allocator defaults to 2 vCPUs and 512 MiB. Adjust +`/etc/nitro_enclaves/allocator.yaml` before starting the service when the enclave needs more. +Log out and reconnect after changing group membership, then verify the host: + +```bash +nitro-cli --version +nitro-cli describe-enclaves +docker version +``` + +Install Rust and the components used by this workspace: + +```bash +curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y +source "$HOME/.cargo/env" +rustup component add rustfmt clippy +cargo test --all +``` + +For private repository access, install and authenticate the GitHub CLI using its +[official RPM instructions](https://github.com/cli/cli/blob/trunk/docs/install_linux.md#dnf4). + +Optionally install Codex for development on the remote host: + +```bash +curl -fsSL https://chatgpt.com/codex/install.sh | sh +exec "$SHELL" -l +codex login --device-auth +codex doctor +``` + +To use the Codex desktop app, add a concrete host alias to your local `~/.ssh/config`, confirm +`ssh ` works, then select the host and repository path under **Settings > Connections**. +See the [Codex remote connection guide](https://learn.chatgpt.com/docs/remote-connections#connect-to-an-ssh-host). diff --git a/api/Cargo.toml b/api/Cargo.toml new file mode 100644 index 0000000..f065e28 --- /dev/null +++ b/api/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "api" +version.workspace = true +edition.workspace = true +rust-version.workspace = true +license.workspace = true +publish.workspace = true + +[[bin]] +name = "api" +path = "src/main.rs" + +[dependencies] +anyhow.workspace = true +axum.workspace = true +tokio.workspace = true +tower-http.workspace = true +tracing.workspace = true +tracing-subscriber.workspace = true + +[dev-dependencies] +tower.workspace = true diff --git a/api/src/lib.rs b/api/src/lib.rs new file mode 100644 index 0000000..c7751a8 --- /dev/null +++ b/api/src/lib.rs @@ -0,0 +1,13 @@ +//! HTTP API for the embedding verifier. + +#![deny( + clippy::all, + clippy::pedantic, + clippy::nursery, + missing_docs, + dead_code +)] + +pub mod routes; +pub mod server; +pub mod types; diff --git a/api/src/main.rs b/api/src/main.rs new file mode 100644 index 0000000..de7f7c6 --- /dev/null +++ b/api/src/main.rs @@ -0,0 +1,15 @@ +use tracing_subscriber::EnvFilter; + +use api::types::Environment; + +#[tokio::main] +async fn main() -> anyhow::Result<()> { + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); + + let environment = Environment::from_env(); + tracing::info!(?environment, "Starting API"); + + api::server::start(environment).await +} diff --git a/api/src/routes/health.rs b/api/src/routes/health.rs new file mode 100644 index 0000000..7856ad5 --- /dev/null +++ b/api/src/routes/health.rs @@ -0,0 +1,8 @@ +use axum::{extract::State, http::StatusCode}; + +use crate::types::Environment; + +/// Handles API health checks. +pub async fn handler(State(_environment): State) -> StatusCode { + StatusCode::OK +} diff --git a/api/src/routes/mod.rs b/api/src/routes/mod.rs new file mode 100644 index 0000000..b98e1de --- /dev/null +++ b/api/src/routes/mod.rs @@ -0,0 +1,12 @@ +//! HTTP route definitions. + +mod health; + +use axum::{Router, routing::get}; + +use crate::types::Environment; + +/// Builds the router with all API routes. +pub fn handler() -> Router { + Router::new().route("/health", get(health::handler)) +} diff --git a/api/src/server.rs b/api/src/server.rs new file mode 100644 index 0000000..809802c --- /dev/null +++ b/api/src/server.rs @@ -0,0 +1,44 @@ +//! Axum server setup and lifecycle. + +use std::net::SocketAddr; + +use anyhow::Context; +use tokio::net::TcpListener; +use tower_http::trace::TraceLayer; + +use crate::{routes, types::Environment}; + +const DEFAULT_PORT: u16 = 8000; + +/// Starts the API server. +/// +/// # Errors +/// +/// Returns an error when the configured port is invalid, the listener cannot bind, or the server +/// exits unexpectedly. +pub async fn start(environment: Environment) -> anyhow::Result<()> { + let port = std::env::var("PORT").map_or(Ok(DEFAULT_PORT), |value| value.parse())?; + let address = SocketAddr::from(([0, 0, 0, 0], port)); + let listener = TcpListener::bind(address) + .await + .with_context(|| format!("failed to bind API to {address}"))?; + + tracing::info!(%address, "API listening"); + + axum::serve( + listener, + routes::handler() + .with_state(environment) + .layer(TraceLayer::new_for_http()) + .into_make_service(), + ) + .with_graceful_shutdown(shutdown_signal()) + .await + .context("API server failed") +} + +async fn shutdown_signal() { + if let Err(error) = tokio::signal::ctrl_c().await { + tracing::error!(%error, "failed to install shutdown signal handler"); + } +} diff --git a/api/src/types/environment.rs b/api/src/types/environment.rs new file mode 100644 index 0000000..346c08a --- /dev/null +++ b/api/src/types/environment.rs @@ -0,0 +1,36 @@ +//! Runtime environment configuration. + +/// Runtime environment for the API. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Environment { + /// Production environment. + Production, + /// Staging environment. + Staging, + /// Local development environment. + Development, +} + +impl Environment { + /// Resolves the runtime environment from `APP_ENV`. + /// + /// Defaults to development when `APP_ENV` is unset. + /// + /// # Panics + /// + /// Panics when `APP_ENV` is not `development`, `staging`, or `production`. + #[must_use] + pub fn from_env() -> Self { + let environment = std::env::var("APP_ENV") + .unwrap_or_else(|_| "development".to_owned()) + .trim() + .to_lowercase(); + + match environment.as_str() { + "production" => Self::Production, + "staging" => Self::Staging, + "development" => Self::Development, + _ => panic!("invalid APP_ENV: {environment}"), + } + } +} diff --git a/api/src/types/mod.rs b/api/src/types/mod.rs new file mode 100644 index 0000000..304d995 --- /dev/null +++ b/api/src/types/mod.rs @@ -0,0 +1,5 @@ +//! API types. + +mod environment; + +pub use environment::Environment; diff --git a/api/tests/health.rs b/api/tests/health.rs new file mode 100644 index 0000000..4aec248 --- /dev/null +++ b/api/tests/health.rs @@ -0,0 +1,19 @@ +use api::{routes, types::Environment}; +use axum::{body::Body, http::Request}; +use tower::ServiceExt; + +#[tokio::test] +async fn health_returns_ok() { + let response = routes::handler() + .with_state(Environment::Development) + .oneshot( + Request::builder() + .uri("/health") + .body(Body::empty()) + .expect("health request should be valid"), + ) + .await + .expect("health request should succeed"); + + assert_eq!(response.status(), axum::http::StatusCode::OK); +} diff --git a/deny.toml b/deny.toml new file mode 100644 index 0000000..92798dd --- /dev/null +++ b/deny.toml @@ -0,0 +1,27 @@ +[graph] +all-features = true +targets = ["x86_64-unknown-linux-gnu"] + +[advisories] + +[bans] +multiple-versions = "allow" +deny = [ + { name = "openssl" }, + { name = "openssl-sys" }, + { name = "openssl-src" }, +] + +[licenses] +version = 2 +confidence-threshold = 1.0 +allow = [ + "Apache-2.0", + "BSD-3-Clause", + "MIT", + "Unicode-3.0", +] + +[sources] +unknown-registry = "deny" +unknown-git = "deny" diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..c10b12e --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "1.97.0" +profile = "minimal" +components = ["clippy", "rustfmt"] diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..f216078 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1 @@ +edition = "2024" diff --git a/secure-enclave/Cargo.toml b/secure-enclave/Cargo.toml new file mode 100644 index 0000000..9573852 --- /dev/null +++ b/secure-enclave/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "secure-enclave" +version.workspace = true +edition.workspace = true +rust-version.workspace = true +license.workspace = true +publish.workspace = true + +[[bin]] +name = "secure-enclave" +path = "src/main.rs" + +[dependencies] +anyhow.workspace = true +tokio.workspace = true +tracing.workspace = true +tracing-subscriber.workspace = true diff --git a/secure-enclave/src/main.rs b/secure-enclave/src/main.rs new file mode 100644 index 0000000..a1480b1 --- /dev/null +++ b/secure-enclave/src/main.rs @@ -0,0 +1,15 @@ +use tracing::info; +use tracing_subscriber::EnvFilter; + +#[tokio::main] +async fn main() -> anyhow::Result<()> { + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); + + info!("Secure enclave started"); + tokio::signal::ctrl_c().await?; + info!("Secure enclave shutting down"); + + Ok(()) +}