From 8c6a1376d044417ae07841ab9066cd33814c801e Mon Sep 17 00:00:00 2001 From: Andreas Bergmeier Date: Tue, 14 Jan 2025 19:38:29 +0000 Subject: [PATCH] Add initial authentication OpenAPI Currently only contains basic auth definitions to keep it simple stupid. Mostly just following https://swagger.io/docs/specification/v3_0/authentication/basic-authentication/ Document can be printed via new command: openapi print --- Cargo.lock | 445 ++++++++++++++++++++++++++------ Cargo.toml | 4 + api/openapi/authentication.yaml | 19 ++ bffhd/lib.rs | 2 + bffhd/rest/authentication.rs | 25 ++ bffhd/rest/mod.rs | 2 + bffhd/rest/security.rs | 24 ++ bin/bffhd/main.rs | 14 +- rust-toolchain.toml | 2 +- 9 files changed, 457 insertions(+), 80 deletions(-) create mode 100644 api/openapi/authentication.yaml create mode 100644 bffhd/rest/authentication.rs create mode 100644 bffhd/rest/mod.rs create mode 100644 bffhd/rest/security.rs diff --git a/Cargo.lock b/Cargo.lock index 2fe2470..e718333 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -28,7 +28,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "939d59666dd9a7964a3a5312b9d24c9c107630752ee64f2dd5038189a23fe331" dependencies = [ "abnf", - "indexmap", + "indexmap 1.9.2", "itertools 0.10.5", "pretty", ] @@ -309,7 +309,7 @@ checksum = "10f203db73a71dfa2fb6dd22763990fa26f3d2625a6da2da900d23b87d26be27" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -326,7 +326,7 @@ checksum = "1cd7fce9ba8c3c042128ce72d8b2ddbf3a05747efb67ea0313c635e10bda47a2" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -359,28 +359,62 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acee9fd5073ab6b045a275b3e709c163dd36c90685219cb21804a147b58dba43" dependencies = [ "async-trait", - "axum-core", + "axum-core 0.2.9", "bitflags", "bytes", "futures-util", - "http", - "http-body", - "hyper", + "http 0.2.8", + "http-body 0.4.5", + "hyper 0.14.24", "itoa 1.0.5", - "matchit", + "matchit 0.5.0", "memchr", "mime", "percent-encoding", "pin-project-lite", "serde", - "sync_wrapper", + "sync_wrapper 0.1.2", "tokio", - "tower", + "tower 0.4.13", "tower-http", "tower-layer", "tower-service", ] +[[package]] +name = "axum" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d6fd624c75e18b3b4c6b9caf42b1afe24437daaee904069137d8bab077be8b8" +dependencies = [ + "axum-core 0.5.0", + "bytes", + "form_urlencoded", + "futures-util", + "http 1.2.0", + "http-body 1.0.1", + "http-body-util", + "hyper 1.5.2", + "hyper-util", + "itoa 1.0.5", + "matchit 0.8.4", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "rustversion", + "serde", + "serde_json", + "serde_path_to_error", + "serde_urlencoded", + "sync_wrapper 1.0.2", + "tokio", + "tower 0.5.2", + "tower-layer", + "tower-service", + "tracing", +] + [[package]] name = "axum-core" version = "0.2.9" @@ -390,13 +424,33 @@ dependencies = [ "async-trait", "bytes", "futures-util", - "http", - "http-body", + "http 0.2.8", + "http-body 0.4.5", "mime", "tower-layer", "tower-service", ] +[[package]] +name = "axum-core" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df1362f362fd16024ae199c1970ce98f9661bf5ef94b9808fee734bc3698b733" +dependencies = [ + "bytes", + "futures-util", + "http 1.2.0", + "http-body 1.0.1", + "http-body-util", + "mime", + "pin-project-lite", + "rustversion", + "sync_wrapper 1.0.2", + "tower-layer", + "tower-service", + "tracing", +] + [[package]] name = "backtrace" version = "0.3.67" @@ -540,7 +594,7 @@ checksum = "13e576ebe98e605500b3c8041bb888e966653577172df6dd97398714eb30b9bf" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -551,9 +605,9 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "bytes" -version = "1.4.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" +checksum = "325918d6fe32f23b19878fe4b34794ae41fc19ddbe53b10571a4874d44ffd39b" [[package]] name = "capnp" @@ -657,7 +711,7 @@ dependencies = [ "atty", "bitflags", "clap_lex", - "indexmap", + "indexmap 1.9.2", "once_cell", "strsim", "termcolor", @@ -706,7 +760,7 @@ dependencies = [ "crossbeam-utils", "futures-util", "hdrhistogram", - "hyper", + "hyper 0.14.24", "prost-types", "thread_local", "tokio", @@ -931,7 +985,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d2301688392eb071b0bf1a37be05c469d3cc4dbbd95df672fe28ab021e6a096" dependencies = [ "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -958,7 +1012,7 @@ dependencies = [ "proc-macro2", "quote", "scratch", - "syn", + "syn 1.0.107", ] [[package]] @@ -975,7 +1029,7 @@ checksum = "81bbeb29798b407ccd82a3324ade1a7286e0d29851475990b612670f6f5124d2" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -1037,11 +1091,11 @@ checksum = "f64ba6f41d9b223e2e1d7c97a1145a1aa03e57d65e1c9c2baa29f194caf322c9" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] -name = "diflouroborane" +name = "difluoroborane" version = "0.4.2" dependencies = [ "api", @@ -1052,6 +1106,7 @@ dependencies = [ "async-oneshot", "async-process", "async-trait", + "axum 0.8.1", "backtrace", "capnp", "capnp-rpc", @@ -1068,6 +1123,7 @@ dependencies = [ "futures-test", "futures-util", "hex", + "http 1.2.0", "inventory", "lazy_static", "libc", @@ -1102,7 +1158,9 @@ dependencies = [ "tracing-futures", "tracing-subscriber", "url", - "uuid", + "utoipa", + "utoipa-axum", + "uuid 0.8.2", ] [[package]] @@ -1171,6 +1229,12 @@ dependencies = [ "stable_deref_trait", ] +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + [[package]] name = "erased-serde" version = "0.3.24" @@ -1320,7 +1384,7 @@ checksum = "95a73af87da33b5acf53acfebdc339fe592ecf5357ac7c0a7734ab9d8c876a70" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -1440,7 +1504,7 @@ checksum = "41973d4c45f7a35af8753ba3457cc99d406d863941fd7f52663cff54a5ab99b3" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -1491,8 +1555,8 @@ dependencies = [ "futures-core", "futures-sink", "futures-util", - "http", - "indexmap", + "http 0.2.8", + "indexmap 1.9.2", "slab", "tokio", "tokio-util", @@ -1514,6 +1578,12 @@ dependencies = [ "ahash", ] +[[package]] +name = "hashbrown" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" + [[package]] name = "hdrhistogram" version = "7.5.2" @@ -1566,6 +1636,17 @@ dependencies = [ "itoa 1.0.5", ] +[[package]] +name = "http" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f16ca2af56261c99fba8bac40a10251ce8188205a4c448fbb745a2e4daa76fea" +dependencies = [ + "bytes", + "fnv", + "itoa 1.0.5", +] + [[package]] name = "http-body" version = "0.4.5" @@ -1573,7 +1654,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" dependencies = [ "bytes", - "http", + "http 0.2.8", + "pin-project-lite", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http 1.2.0", +] + +[[package]] +name = "http-body-util" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http 1.2.0", + "http-body 1.0.1", "pin-project-lite", ] @@ -1606,8 +1710,8 @@ dependencies = [ "futures-core", "futures-util", "h2", - "http", - "http-body", + "http 0.2.8", + "http-body 0.4.5", "httparse", "httpdate", "itoa 1.0.5", @@ -1619,18 +1723,53 @@ dependencies = [ "want", ] +[[package]] +name = "hyper" +version = "1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "256fb8d4bd6413123cc9d91832d78325c48ff41677595be797d90f42969beae0" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http 1.2.0", + "http-body 1.0.1", + "httparse", + "httpdate", + "itoa 1.0.5", + "pin-project-lite", + "smallvec", + "tokio", +] + [[package]] name = "hyper-timeout" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1" dependencies = [ - "hyper", + "hyper 0.14.24", "pin-project-lite", "tokio", "tokio-io-timeout", ] +[[package]] +name = "hyper-util" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df2dcfbe0677734ab2f3ffa7fa7bfd4706bfdc1ef393f2ee30184aed67e631b4" +dependencies = [ + "bytes", + "futures-util", + "http 1.2.0", + "http-body 1.0.1", + "hyper 1.5.2", + "pin-project-lite", + "tokio", + "tower-service", +] + [[package]] name = "iana-time-zone" version = "0.1.53" @@ -1672,7 +1811,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" dependencies = [ "autocfg", - "hashbrown", + "hashbrown 0.12.3", +] + +[[package]] +name = "indexmap" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62f822373a4fe84d4bb149bf54e584a7f4abec90e072ed49cda0edea5b95471f" +dependencies = [ + "equivalent", + "hashbrown 0.15.2", + "serde", ] [[package]] @@ -1703,7 +1853,7 @@ checksum = "7e41b53715c6f0c4be49510bb82dee2c1e51c8586d885abe65396e82ed518548" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -1852,7 +2002,7 @@ checksum = "73fd9dc7072de7168cbdaba9125e8f742cd3a965aa12bde994b4611a174488d8" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -1913,6 +2063,12 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73cbba799671b762df5a175adf59ce145165747bb891505c43d09aefbbf38beb" +[[package]] +name = "matchit" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3" + [[package]] name = "memchr" version = "2.5.0" @@ -1965,7 +2121,7 @@ checksum = "6b5bc45b761bcf1b5e6e6c4128cd93b84c218721a8d9b894aa0aff4ed180174c" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -2042,7 +2198,7 @@ checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -2154,6 +2310,12 @@ dependencies = [ "windows-sys 0.45.0", ] +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + [[package]] name = "percent-encoding" version = "2.2.0" @@ -2189,7 +2351,7 @@ checksum = "9d8630a7a899cb344ec1c16ba0a6b24240029af34bdc0a21f84e411d7f793f29" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -2212,7 +2374,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -2243,7 +2405,7 @@ checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -2332,9 +2494,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.51" +version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6" +checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99" dependencies = [ "unicode-ident", ] @@ -2359,7 +2521,7 @@ dependencies = [ "itertools 0.10.5", "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -2389,14 +2551,14 @@ checksum = "16b845dbfca988fa33db069c0e230574d15a3088f147a87b64c7589eb662c9ac" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] name = "quote" -version = "1.0.23" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" dependencies = [ "proc-macro2", ] @@ -2539,7 +2701,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cec2b3485b07d96ddfd3134767b8a447b45ea4eb91448d0a35180ec0ffd5ed15" dependencies = [ "bytecheck", - "hashbrown", + "hashbrown 0.12.3", "ptr_meta", "rend", "rkyv_derive", @@ -2554,7 +2716,7 @@ checksum = "6eaedadc88b53e36dd32d940ed21ae4d850d5916f2581526921f553a72ac34c4" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -2579,7 +2741,7 @@ checksum = "f298184c1603a4e5114ab0147c4a7d47c1b4f7a78720e6211d02aea16cd6c04f" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -2599,7 +2761,7 @@ checksum = "27a570b78b72542588a1f3ecaa8d109b5332e61465c729e96941adafb81fc6eb" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -2623,7 +2785,7 @@ checksum = "29fa50cc13f4c9c4962d925c3f99f822fb19995cc527ec1d556ee7635dfa2e3d" dependencies = [ "async-channel", "bytes", - "http", + "http 0.2.8", "log", "pollster", "rustls-pemfile 0.3.0", @@ -2693,6 +2855,12 @@ dependencies = [ "base64 0.21.0", ] +[[package]] +name = "rustversion" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7c45b9784283f1b2e7fb61b42047c2fd678ef0960d4f6f1eba131594cc369d4" + [[package]] name = "ryu" version = "1.0.12" @@ -2743,7 +2911,7 @@ dependencies = [ name = "sdk" version = "0.1.0" dependencies = [ - "diflouroborane", + "difluoroborane", "futures-util", "sdk-proc", ] @@ -2754,7 +2922,7 @@ version = "0.1.0" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", "trybuild", ] @@ -2789,9 +2957,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.152" +version = "1.0.217" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" +checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" dependencies = [ "serde_derive", ] @@ -2808,13 +2976,13 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.152" +version = "1.0.217" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e" +checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.96", ] [[package]] @@ -2841,6 +3009,41 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_path_to_error" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af99884400da37c88f5e9146b7f1fd0fbcae8f6eec4e9da38b67d05486f814a6" +dependencies = [ + "itoa 1.0.5", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa 1.0.5", + "ryu", + "serde", +] + +[[package]] +name = "serde_yaml" +version = "0.9.34+deprecated" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" +dependencies = [ + "indexmap 2.7.0", + "itoa 1.0.5", + "ryu", + "serde", + "unsafe-libyaml", +] + [[package]] name = "sha2" version = "0.9.9" @@ -2934,9 +3137,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.10.0" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "smawk" @@ -3021,12 +3224,29 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn" +version = "2.0.96" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5d0adab1ae378d7f53bdebc67a39f1f151407ef230f0ce2883572f5d8985c80" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "sync_wrapper" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" +[[package]] +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" + [[package]] name = "tempfile" version = "3.3.0" @@ -3103,7 +3323,7 @@ checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -3186,7 +3406,7 @@ checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -3242,15 +3462,15 @@ checksum = "5be9d60db39854b30b835107500cf0aca0b0d14d6e1c3de124217c23a29c2ddb" dependencies = [ "async-stream", "async-trait", - "axum", + "axum 0.5.17", "base64 0.13.1", "bytes", "futures-core", "futures-util", "h2", - "http", - "http-body", - "hyper", + "http 0.2.8", + "http-body 0.4.5", + "hyper 0.14.24", "hyper-timeout", "percent-encoding", "pin-project", @@ -3259,7 +3479,7 @@ dependencies = [ "tokio", "tokio-stream", "tokio-util", - "tower", + "tower 0.4.13", "tower-layer", "tower-service", "tracing", @@ -3274,7 +3494,7 @@ checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" dependencies = [ "futures-core", "futures-util", - "indexmap", + "indexmap 1.9.2", "pin-project", "pin-project-lite", "rand", @@ -3286,6 +3506,22 @@ dependencies = [ "tracing", ] +[[package]] +name = "tower" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d039ad9159c98b70ecfd540b2573b97f7f52c3e8d9f8ad57a24b916a536975f9" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper 1.0.2", + "tokio", + "tower-layer", + "tower-service", + "tracing", +] + [[package]] name = "tower-http" version = "0.3.5" @@ -3296,26 +3532,26 @@ dependencies = [ "bytes", "futures-core", "futures-util", - "http", - "http-body", + "http 0.2.8", + "http-body 0.4.5", "http-range-header", "pin-project-lite", - "tower", + "tower 0.4.13", "tower-layer", "tower-service", ] [[package]] name = "tower-layer" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" [[package]] name = "tower-service" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" [[package]] name = "tracing" @@ -3338,7 +3574,7 @@ checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -3449,7 +3685,7 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c5faade31a542b8b35855fff6e8def199853b2da8da256da52f52f1316ee3137" dependencies = [ - "hashbrown", + "hashbrown 0.12.3", "regex", ] @@ -3480,6 +3716,12 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" +[[package]] +name = "unsafe-libyaml" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" + [[package]] name = "untrusted" version = "0.7.1" @@ -3497,6 +3739,44 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "utoipa" +version = "5.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "435c6f69ef38c9017b4b4eea965dfb91e71e53d869e896db40d1cf2441dd75c0" +dependencies = [ + "indexmap 2.7.0", + "serde", + "serde_json", + "serde_yaml", + "utoipa-gen", +] + +[[package]] +name = "utoipa-axum" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c25bae5bccc842449ec0c5ddc5cbb6a3a1eaeac4503895dc105a1138f8234a0" +dependencies = [ + "axum 0.8.1", + "paste", + "tower-layer", + "tower-service", + "utoipa", +] + +[[package]] +name = "utoipa-gen" +version = "5.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a77d306bc75294fd52f3e99b13ece67c02c1a2789190a6f31d32f736624326f7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.96", + "uuid 1.12.0", +] + [[package]] name = "uuid" version = "0.8.2" @@ -3507,6 +3787,15 @@ dependencies = [ "serde", ] +[[package]] +name = "uuid" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "744018581f9a3454a9e15beb8a33b017183f1e7c0cd170232a2d1453b23a51c4" +dependencies = [ + "serde", +] + [[package]] name = "valuable" version = "0.1.0" @@ -3595,7 +3884,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn", + "syn 1.0.107", "wasm-bindgen-shared", ] @@ -3629,7 +3918,7 @@ checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", "wasm-bindgen-backend", "wasm-bindgen-shared", ] diff --git a/Cargo.toml b/Cargo.toml index d368a90..b74d778 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -111,6 +111,10 @@ url = "2.2.2" rustls-native-certs = "0.6.1" shadow-rs = "0.11" +utoipa = { version = "5.3.1", features = ["uuid", "yaml"] } +http = "1.2.0" +axum = "0.8.1" +utoipa-axum = "0.2.0" [dependencies.rsasl] version = "2.0.0" diff --git a/api/openapi/authentication.yaml b/api/openapi/authentication.yaml new file mode 100644 index 0000000..ed9fa13 --- /dev/null +++ b/api/openapi/authentication.yaml @@ -0,0 +1,19 @@ +openapi: 3.1.0 +info: + title: difluoroborane + description: FabAccess Auth API + contact: + name: dequbed + email: me@dequbed.space + license: + name: GPL-3.0 + identifier: GPL-3.0 + version: 0.4.2 +paths: {} +components: + securitySchemes: + basicAuth: + type: http + scheme: basic +security: +- basicAuth: [] diff --git a/bffhd/lib.rs b/bffhd/lib.rs index 6ce37b1..5ed046c 100644 --- a/bffhd/lib.rs +++ b/bffhd/lib.rs @@ -33,6 +33,8 @@ pub mod sensors; pub mod capnp; +pub mod rest; + pub mod utils; // Store build information in the `env` module. diff --git a/bffhd/rest/authentication.rs b/bffhd/rest/authentication.rs new file mode 100644 index 0000000..f5056cf --- /dev/null +++ b/bffhd/rest/authentication.rs @@ -0,0 +1,25 @@ +use utoipa::{self}; + +#[derive(utoipa::ToSchema)] +pub struct AuthenticationMethod(String); + +pub mod responses { + + #[derive(utoipa::ToResponse)] + pub struct Unauthorized { + pub www_authenticate: Option, + } +} + +#[derive(utoipa::OpenApi)] +#[openapi( + info(description = "FabAccess Auth API"), + modifiers(&SecurityAddon), + components(schemas(AuthenticationMethod), responses(responses::Unauthorized)), + security( + ("basicAuth" = []), + ), +)] +pub struct ApiDoc; + +include!("./security.rs"); diff --git a/bffhd/rest/mod.rs b/bffhd/rest/mod.rs new file mode 100644 index 0000000..9096a40 --- /dev/null +++ b/bffhd/rest/mod.rs @@ -0,0 +1,2 @@ +pub mod authentication; +mod security; diff --git a/bffhd/rest/security.rs b/bffhd/rest/security.rs new file mode 100644 index 0000000..a82e25d --- /dev/null +++ b/bffhd/rest/security.rs @@ -0,0 +1,24 @@ +use utoipa::openapi; +use utoipa::openapi::security::HttpAuthScheme; +use utoipa::openapi::security::HttpBuilder; +use utoipa::openapi::security::SecurityScheme; +use utoipa::Modify; + +pub(crate) struct SecurityAddon; + +impl Modify for SecurityAddon { + fn modify(&self, openapi: &mut openapi::OpenApi) { + openapi.components = Some( + utoipa::openapi::ComponentsBuilder::new() + .security_scheme( + "basicAuth", + SecurityScheme::Http( + HttpBuilder::new() + .scheme(HttpAuthScheme::Basic) + .build(), + ), + ) + .build(), + ) + } +} diff --git a/bin/bffhd/main.rs b/bin/bffhd/main.rs index 727a1a8..a609184 100644 --- a/bin/bffhd/main.rs +++ b/bin/bffhd/main.rs @@ -1,5 +1,6 @@ use clap::{Arg, Command, ValueHint}; -use difluoroborane::{config, Difluoroborane}; +use difluoroborane::{config, rest, Difluoroborane}; +use utoipa::OpenApi; use std::str::FromStr; use std::{env, io, io::Write, path::PathBuf}; @@ -89,6 +90,10 @@ fn main() -> miette::Result<()> { .max_values(1) .min_values(0) .default_missing_value("")) + .arg(Arg::new("openapi") + .help("Handle OpenAPI") + ) + .subcommand(Command::new("print")) .try_get_matches(); let matches = match matches { @@ -96,6 +101,13 @@ fn main() -> miette::Result<()> { Err(error) => error.exit(), }; + if matches.is_present("openapi") { + if matches.subcommand_name() == Some("print") { + println!("{}", rest::authentication::ApiDoc::openapi().to_yaml().unwrap()); + } + return Ok(()); + } + let configpath = matches .value_of("config") .unwrap_or("/etc/difluoroborane.dhall"); diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 99c6e11..8cca5be 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "1.66" +channel = "1.80"