1
0
mirror of https://github.com/vbrandl/bind9-api.git synced 2025-04-21 01:57:00 +02:00

Compare commits

..

No commits in common. "master" and "v0.1.1" have entirely different histories.

13 changed files with 3184 additions and 1923 deletions

View File

@ -1,5 +1,4 @@
sudo: required
language: rust
services:
- docker
script:

3067
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -7,19 +7,6 @@
This is an attempt to implement an API to create, update or delete DNS records
on a BIND9 DNS server.
## Building
To compile the code, you first need to [install Rust](https://rustup.rs/). Then
you can run
```
cargo build --release
```
in the project root. The server and client binary will be located in
`./target/release/bind9-api` and `./target/release/bind9-api-client`
respectively.
## Server
The server will wait for incoming requests and uses the `nsupdate` command to

View File

@ -3,13 +3,13 @@
set -ex
main() {
local src=$(pwd)
local stage=$src/deploy
local src=$(pwd) \
stage=$src/deploy
mkdir -p $stage
mkdir -p $deploy
cp target/x86_64-unknown-linux-musl/release/bind9-api $stage/bind9-api-${TRAVIS_TAG:1}-x86_64-musl
cp target/x86_64-unknown-linux-musl/release/bind9-api-client $stage/bind9-api-client-${TRAVIS_TAG:1}-x86_64-musl
}
test -f Cargo.lock || cargo generate-lockfile
main
cp target/x86_64-unknown-linux-musl/release/bind9-api $stage/bind9-api-${TRAVIS-TAG:1}-x86_64-musl
cp target/x86_64-unknown-linux-musl/release/bind9-api-client $stage/bind9-api-client-${TRAVIS-TAG:1}-x86_64-musl
}

194
client/Cargo.lock generated Normal file
View File

@ -0,0 +1,194 @@
[[package]]
name = "ansi_term"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "atty"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
"termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "bind9-api-client"
version = "0.1.0"
dependencies = [
"clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.69 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.69 (registry+https://github.com/rust-lang/crates.io-index)",
"toml 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "bitflags"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "clap"
version = "2.32.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"atty 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "libc"
version = "0.2.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "proc-macro2"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "quote"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "redox_syscall"
version = "0.1.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "redox_termios"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serde"
version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde_derive"
version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.14.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "strsim"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "syn"
version = "0.14.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "termion"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "textwrap"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "toml"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"serde 1.0.69 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "unicode-width"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "unicode-xid"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "vec_map"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
"checksum atty 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "2fc4a1aa4c24c0718a250f0681885c1af91419d242f29eb8f2ab28502d80dbd1"
"checksum bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d0c54bb8f454c567f21197eefcdbf5679d0bd99f2ddbe52e84c77061952e6789"
"checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e"
"checksum libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "b685088df2b950fccadf07a7187c8ef846a959c142338a48f9dc0b94517eb5f1"
"checksum proc-macro2 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "effdb53b25cdad54f8f48843d67398f7ef2e14f12c1b4cb4effc549a6462a4d6"
"checksum quote 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e44651a0dc4cdd99f71c83b561e221f714912d11af1a4dff0631f923d53af035"
"checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1"
"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
"checksum serde 1.0.69 (registry+https://github.com/rust-lang/crates.io-index)" = "210e5a3b159c566d7527e9b22e44be73f2e0fcc330bb78fef4dbccb56d2e74c8"
"checksum serde_derive 1.0.69 (registry+https://github.com/rust-lang/crates.io-index)" = "dd724d68017ae3a7e63600ee4b2fdb3cad2158ffd1821d44aff4580f63e2b593"
"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550"
"checksum syn 0.14.4 (registry+https://github.com/rust-lang/crates.io-index)" = "2beff8ebc3658f07512a413866875adddd20f4fd47b2a4e6c9da65cd281baaea"
"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"
"checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6"
"checksum toml 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a0263c6c02c4db6c8f7681f9fd35e90de799ebd4cfdeab77a38f4ff6b3d8c0d9"
"checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526"
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a"
"checksum winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "773ef9dcc5f24b7d850d0ff101e542ff24c3b090a9768e03ff889fdef41f00fd"
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

View File

@ -1,21 +1,21 @@
[package]
name = "bind9-api-client"
version = "0.1.3"
version = "0.1.1"
authors = ["Valentin Brandl <vbrandl@riseup.net>"]
description = "Client for the BIND9 API"
license = "MIT/Apache-2.0"
[dependencies]
clap = "2.33.0"
clap = "2.32.0"
crypto = { path = "../crypto" }
data = { path = "../data" }
failure = "0.1.7"
hyper = "0.12.35"
log = "0.4.8"
failure = "0.1.1"
hyper = "0.11"
log = "0.4.3"
openssl-probe = "0.1.2"
pretty_env_logger = "0.4.0"
reqwest = "0.9.24"
serde = "1.0.104"
serde_derive = "1.0.104"
serde_json = "1.0.50"
toml = "0.5.6"
pretty_env_logger = "0.2.3"
reqwest = "0.8.6"
serde = "1.0.69"
serde_derive = "1.0.69"
serde_json = "1.0.22"
toml = "0.4.6"

View File

@ -42,6 +42,7 @@ extern crate clap;
extern crate crypto;
extern crate data;
extern crate failure;
#[macro_use]
extern crate hyper;
#[macro_use]
extern crate log;
@ -64,6 +65,8 @@ use std::borrow::Cow;
type Result<T> = std::result::Result<T, Error>;
header! { (XApiToken, data::TOKEN_HEADER) => [String] }
#[derive(Eq, PartialEq, Clone, Copy)]
enum Method {
POST,
@ -106,17 +109,16 @@ fn call_api<D: serde::Serialize>(
let data_s = serde_json::to_string(&data)?;
info!("body: {}", data_s);
let signature = crypto::sign(config.secret.as_bytes(), data_s.as_bytes());
let signature = crypto::bytes_to_hex_str(&signature);
let signature = crypto::bytes_to_hex_str(&signature)?;
let client = reqwest::Client::new();
let url = format!("{}/record", config.host);
Ok(if method == Method::POST {
client.post(&url)
} else {
client.delete(&url)
}
.header("X-Api-Token", signature)
.json(&data)
.send()?)
}.header(XApiToken(signature))
.json(&data)
.send()?)
}
fn main() -> Result<()> {

View File

@ -5,9 +5,9 @@ authors = ["Valentin Brandl <vbrandl@riseup.net>"]
license = "MIT/Apache-2.0"
[dependencies]
failure = "0.1.7"
hex = "0.4.0"
ring = "0.13.5"
failure = "0.1.1"
hex = "0.3.2"
ring = "0.12.1"
[dev-dependencies]
proptest = "0.9.5"
proptest = "0.8.1"

View File

@ -55,8 +55,10 @@ use ring::{digest, hmac};
type Result<T> = std::result::Result<T, Error>;
/// Converts a byte slice to a lowercase hex string.
pub fn bytes_to_hex_str(bytes: &[u8]) -> String {
bytes.encode_hex::<String>()
pub fn bytes_to_hex_str(bytes: &[u8]) -> Result<String> {
let mut output = String::new();
bytes.write_hex(&mut output)?;
Ok(output)
}
/// Converts a hey string to a vec of bytes.

View File

@ -5,6 +5,6 @@ authors = ["Valentin Brandl <vbrandl@riseup.net>"]
license = "MIT/Apache-2.0"
[dependencies]
failure = "0.1.7"
serde = "1.0.104"
serde_derive = "1.0.104"
failure = "0.1.1"
serde = "1.0.69"
serde_derive = "1.0.69"

1741
server/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,18 +1,18 @@
[package]
name = "bind9-api"
version = "0.1.3"
version = "0.1.1"
authors = ["Valentin Brandl <vbrandl@riseup.net>"]
description = "Web API to create, update and remove DNS entries in bind9"
license = "MIT/Apache-2.0"
[dependencies]
actix-web = "0.7.19"
clap = "2.33.0"
actix-web = "0.6.14"
clap = "2.31.2"
crypto = { path = "../crypto" }
data = { path = "../data" }
failure = "0.1.7"
futures = "0.1.29"
log = "0.4.8"
pretty_env_logger = "0.4.0"
serde = "1.0.104"
serde_json = "1.0.50"
failure = "0.1.1"
futures = "0.1.21"
log = "0.4.3"
pretty_env_logger = "0.2.3"
serde = "1.0.69"
serde_json = "1.0.22"

View File

@ -104,7 +104,7 @@ pub struct Validated<T>(T);
impl<T: 'static + ::serde::de::DeserializeOwned> FromRequest<Arc<Config>> for Validated<T> {
type Config = ();
type Result = Box<dyn Future<Item = Self, Error = Error>>;
type Result = Box<Future<Item = Self, Error = Error>>;
fn from_request(req: &HttpRequest<Arc<Config>>, _: &Self::Config) -> Self::Result {
let state = req.state().clone();
@ -134,8 +134,7 @@ impl<T> Deref for Validated<T> {
}
fn extract_signature<S>(req: &HttpRequest<S>) -> Result<Vec<u8>> {
Ok(req
.headers()
Ok(req.headers()
.get(::data::TOKEN_HEADER)
.as_ref()
.ok_or_else(|| ErrorUnauthorized(ParseError::Header))?