docker-tests: initial integration tests (#55)

Scripts that demonstrate building a network of docker containers, doubling as an integration test for innernet.

Includes a number of improvements to the recent non-interactive CLI changes as well.
This commit is contained in:
Jake McGinty 2021-04-19 21:56:18 +09:00 committed by GitHub
parent 849cc4cd4f
commit e2ea2ddded
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 325 additions and 226 deletions

1
.dockerignore Normal file
View file

@ -0,0 +1 @@
target/

243
Cargo.lock generated
View file

@ -57,9 +57,9 @@ checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
[[package]]
name = "bindgen"
version = "0.57.0"
version = "0.58.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd4865004a46a0aafb2a0a5eb19d3c9fc46ee5f063a6cfc605c69ac9ecf5263d"
checksum = "0f8523b410d7187a43085e7e064416ea32ded16bd0a4e6fc025e21616d01258f"
dependencies = [
"bitflags",
"cexpr",
@ -89,12 +89,6 @@ dependencies = [
"generic-array",
]
[[package]]
name = "bumpalo"
version = "3.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63396b8a4b9de3f4fdfb320ab6080762242f66a8ef174c49d8e19b674db4cdbe"
[[package]]
name = "byteorder"
version = "1.4.3"
@ -136,9 +130,9 @@ checksum = "fff857943da45f546682664a79488be82e69e43c1a7a2307679ab9afb3a66d2e"
[[package]]
name = "clang-sys"
version = "1.1.1"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f54d78e30b388d4815220c8dd03fea5656b6c6d32adb59e89061552a102f8da1"
checksum = "853eda514c284c2287f4bf20ae614f8781f40a81d32ecda6e91449304dfe077c"
dependencies = [
"glob",
"libc",
@ -228,9 +222,9 @@ dependencies = [
[[package]]
name = "crossbeam-channel"
version = "0.5.0"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dca26ee1f8d361640700bde38b2c37d8c22b3ce2d360e1fc1c74ea4b0aa7d775"
checksum = "06ed27e177f16d65f0f0c22a213e17c696ace5dd64b14258b52f9417ccb52db4"
dependencies = [
"cfg-if",
"crossbeam-utils",
@ -373,9 +367,9 @@ dependencies = [
[[package]]
name = "futures"
version = "0.3.13"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f55667319111d593ba876406af7c409c0ebb44dc4be6132a783ccf163ea14c1"
checksum = "a9d5813545e459ad3ca1bff9915e9ad7f1a47dc6a91b627ce321d5863b7dd253"
dependencies = [
"futures-channel",
"futures-core",
@ -387,9 +381,9 @@ dependencies = [
[[package]]
name = "futures-channel"
version = "0.3.13"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c2dd2df839b57db9ab69c2c9d8f3e8c81984781937fe2807dc6dcf3b2ad2939"
checksum = "ce79c6a52a299137a6013061e0cf0e688fce5d7f1bc60125f520912fdb29ec25"
dependencies = [
"futures-core",
"futures-sink",
@ -397,33 +391,33 @@ dependencies = [
[[package]]
name = "futures-core"
version = "0.3.13"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "15496a72fabf0e62bdc3df11a59a3787429221dd0710ba8ef163d6f7a9112c94"
checksum = "098cd1c6dda6ca01650f1a37a794245eb73181d0d4d4e955e2f3c37db7af1815"
[[package]]
name = "futures-io"
version = "0.3.13"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d71c2c65c57704c32f5241c1223167c2c3294fd34ac020c807ddbe6db287ba59"
checksum = "365a1a1fb30ea1c03a830fdb2158f5236833ac81fa0ad12fe35b29cddc35cb04"
[[package]]
name = "futures-sink"
version = "0.3.13"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85754d98985841b7d4f5e8e6fbfa4a4ac847916893ec511a2917ccd8525b8bb3"
checksum = "5c5629433c555de3d82861a7a4e3794a4c40040390907cfbfd7143a92a426c23"
[[package]]
name = "futures-task"
version = "0.3.13"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa189ef211c15ee602667a6fcfe1c1fd9e07d42250d2156382820fba33c9df80"
checksum = "ba7aa51095076f3ba6d9a1f702f74bd05ec65f555d70d2033d55ba8d69f581bc"
[[package]]
name = "futures-util"
version = "0.3.13"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1812c7ab8aedf8d6f2701a43e1243acdbcc2b36ab26e2ad421eb99ac963d96d1"
checksum = "3c144ad54d60f23927f0a6b6d816e4271278b64f005ad65e4e35291d2de9c025"
dependencies = [
"futures-core",
"futures-sink",
@ -554,9 +548,9 @@ dependencies = [
[[package]]
name = "http"
version = "0.2.3"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7245cd7449cc792608c3c8a9eaf69bd4eabbabf802713748fd739c98b82f0747"
checksum = "527e8c9ac747e28542699a951517aa9a6945af506cd1f2e1b53a576c17b6cc11"
dependencies = [
"bytes",
"fnv",
@ -576,9 +570,9 @@ dependencies = [
[[package]]
name = "httparse"
version = "1.3.5"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "615caabe2c3160b313d52ccc905335f4ed5f10881dd63dc5699d47e90be85691"
checksum = "4a1ce40d6fc9764887c2fdc7305c3dcc429ba11ff981c1509416afd5697e4437"
[[package]]
name = "httpdate"
@ -621,9 +615,9 @@ dependencies = [
[[package]]
name = "idna"
version = "0.2.2"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89829a5d69c23d348314a7ac337fe39173b61149a9864deabd260983aed48c21"
checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8"
dependencies = [
"matches",
"unicode-bidi",
@ -672,15 +666,6 @@ version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736"
[[package]]
name = "js-sys"
version = "0.3.50"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d99f9e3e84b8f67f846ef5b4cbbc3b1c29f6c759fcbce6f01aa0e73d932a24c"
dependencies = [
"wasm-bindgen",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
@ -695,9 +680,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
[[package]]
name = "libc"
version = "0.2.92"
version = "0.2.93"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56d855069fafbb9b344c0f962150cd2c1187975cb1c22c1522c240d8c4986714"
checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41"
[[package]]
name = "libsqlite3-sys"
@ -866,18 +851,18 @@ checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
[[package]]
name = "pin-project"
version = "1.0.6"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc174859768806e91ae575187ada95c91a29e96a98dc5d2cd9a1fed039501ba6"
checksum = "c7509cc106041c40a4518d2af7a61530e1eed0e6285296a3d8c5472806ccc4a4"
dependencies = [
"pin-project-internal",
]
[[package]]
name = "pin-project-internal"
version = "1.0.6"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a490329918e856ed1b083f244e3bfe2d8c4f336407e4ea9e1a9f479ff09049e5"
checksum = "48c950132583b500556b1efd71d45b319029f2b71518d979fcc208e16b42426f"
dependencies = [
"proc-macro2",
"quote",
@ -1008,9 +993,9 @@ dependencies = [
[[package]]
name = "redox_syscall"
version = "0.2.5"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94341e4e44e24f6b591b59e47a8a027df12e008d73fd5672dbea9cc22f4507d9"
checksum = "8270314b5ccceb518e7e578952f0b72b88222d02e8f77f5ecf7abbb673539041"
dependencies = [
"bitflags",
]
@ -1041,21 +1026,6 @@ dependencies = [
"winapi",
]
[[package]]
name = "ring"
version = "0.16.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc"
dependencies = [
"cc",
"libc",
"once_cell",
"spin",
"untrusted",
"web-sys",
"winapi",
]
[[package]]
name = "rusqlite"
version = "0.25.0"
@ -1077,19 +1047,6 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "rustls"
version = "0.19.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "35edb675feee39aec9c99fa5ff985081995a06d594114ae14cbe797ad7b7a6d7"
dependencies = [
"base64",
"log",
"ring",
"sct",
"webpki",
]
[[package]]
name = "ryu"
version = "1.0.5"
@ -1108,16 +1065,6 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "sct"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b362b83898e0e69f38515b82ee15aa80636befe47c3b6d3d89a911e78fc228ce"
dependencies = [
"ring",
"untrusted",
]
[[package]]
name = "serde"
version = "1.0.125"
@ -1227,9 +1174,9 @@ dependencies = [
[[package]]
name = "shlex"
version = "0.1.1"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2"
checksum = "42a568c8f2cd051a4d283bd6eb0343ac214c1b0f1ac19f93e1175b2dee38c73d"
[[package]]
name = "slab"
@ -1253,12 +1200,6 @@ dependencies = [
"winapi",
]
[[package]]
name = "spin"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
[[package]]
name = "strsim"
version = "0.8.0"
@ -1297,9 +1238,9 @@ checksum = "1e81da0851ada1f3e9d4312c704aa4f8806f0f9d69faaf8df2f3464b4a9437c2"
[[package]]
name = "syn"
version = "1.0.68"
version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ce15dd3ed8aa2f8eeac4716d6ef5ab58b6b9256db41d7e1a0224c2788e8fd87"
checksum = "48fe99c6bd8b1cc636890bcc071842de909d902c81ac7dab53ba33c421ab8ffb"
dependencies = [
"proc-macro2",
"quote",
@ -1407,9 +1348,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
[[package]]
name = "tokio"
version = "1.4.0"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "134af885d758d645f0f0505c9a8b3f9bf8a348fd822e112ab5248138348f1722"
checksum = "83f0c8e7c0addab50b663055baf787d0af7f413a46e6e7fb9559a4e4db7137a5"
dependencies = [
"autocfg",
"bytes",
@ -1445,9 +1386,9 @@ dependencies = [
[[package]]
name = "tokio-util"
version = "0.6.5"
version = "0.6.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5143d049e85af7fbc36f5454d990e62c2df705b3589f123b71f441b6b59f443f"
checksum = "940a12c99365c31ea8dd9ba04ec1be183ffe4920102bb7122c2f515437601e8e"
dependencies = [
"bytes",
"futures-core",
@ -1516,9 +1457,9 @@ dependencies = [
[[package]]
name = "unicode-bidi"
version = "0.3.4"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5"
checksum = "eeb8be209bb1c96b7c177c7420d26e04eccacb0eeae6b980e35fcb74678107e0"
dependencies = [
"matches",
]
@ -1556,12 +1497,6 @@ version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f14ee04d9415b52b3aeab06258a3f07093182b88ba0f9b8d203f211a7a7d41c7"
[[package]]
name = "untrusted"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a"
[[package]]
name = "ureq"
version = "2.1.0"
@ -1572,12 +1507,9 @@ dependencies = [
"chunked_transfer",
"log",
"once_cell",
"rustls",
"serde",
"serde_json",
"url",
"webpki",
"webpki-roots",
]
[[package]]
@ -1594,9 +1526,9 @@ dependencies = [
[[package]]
name = "vcpkg"
version = "0.2.11"
version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b00bca6106a5e23f3eee943593759b7fcddb00554332e856d990c893966879fb"
checksum = "cbdbff6266a24120518560b5dc983096efb98462e51d0d68169895b237be3e5d"
[[package]]
name = "vec_map"
@ -1652,89 +1584,6 @@ version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
[[package]]
name = "wasm-bindgen"
version = "0.2.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "83240549659d187488f91f33c0f8547cbfef0b2088bc470c116d1d260ef623d9"
dependencies = [
"cfg-if",
"wasm-bindgen-macro",
]
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae70622411ca953215ca6d06d3ebeb1e915f0f6613e3b495122878d7ebec7dae"
dependencies = [
"bumpalo",
"lazy_static",
"log",
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e734d91443f177bfdb41969de821e15c516931c3c3db3d318fa1b68975d0f6f"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
]
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d53739ff08c8a68b0fdbcd54c372b8ab800b1449ab3c9d706503bc7dd1621b2c"
dependencies = [
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9a543ae66aa233d14bb765ed9af4a33e81b8b58d1584cf1b47ff8cd0b9e4489"
[[package]]
name = "web-sys"
version = "0.3.50"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a905d57e488fec8861446d3393670fb50d27a262344013181c2cdf9fff5481be"
dependencies = [
"js-sys",
"wasm-bindgen",
]
[[package]]
name = "webpki"
version = "0.21.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8e38c0608262c46d4a56202ebabdeb094cef7e560ca7a226c6bf055188aa4ea"
dependencies = [
"ring",
"untrusted",
]
[[package]]
name = "webpki-roots"
version = "0.21.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aabe153544e473b775453675851ecc86863d2a81d786d741f6b76778f2a48940"
dependencies = [
"webpki",
]
[[package]]
name = "wgctrl"
version = "1.1.0"

View file

@ -3,9 +3,9 @@ use dialoguer::{Confirm, Input};
use hostsfile::HostsBuilder;
use indoc::printdoc;
use shared::{
interface_config::InterfaceConfig, prompts, AddCidrOpts, AddPeerOpts, Association,
AssociationContents, Cidr, CidrTree, EndpointContents, InstallOpts, Interface, IoErrorContext,
Peer, RedeemContents, State, CLIENT_CONFIG_PATH, REDEEM_TRANSITION_WAIT,
interface_config::InterfaceConfig, prompts, AddAssociationOpts, AddCidrOpts, AddPeerOpts,
Association, AssociationContents, Cidr, CidrTree, EndpointContents, InstallOpts, Interface,
IoErrorContext, Peer, RedeemContents, State, CLIENT_CONFIG_PATH, REDEEM_TRANSITION_WAIT,
};
use std::{
fmt,
@ -109,6 +109,11 @@ enum Command {
Down { interface: Interface },
/// Add a new peer.
///
/// By default, you'll be prompted interactively to create a peer, but you can
/// also specify all the options in the command, eg:
///
/// --name "person" --cidr "humans" --admin false --auto-ip --save-config "person.toml" --yes
AddPeer {
interface: Interface,
@ -131,7 +136,12 @@ enum Command {
EnablePeer { interface: Interface },
/// Add an association between CIDRs.
AddAssociation { interface: Interface },
AddAssociation {
interface: Interface,
#[structopt(flatten)]
opts: AddAssociationOpts,
},
/// Delete an association between CIDRs.
DeleteAssociation { interface: Interface },
@ -560,25 +570,38 @@ fn enable_or_disable_peer(interface: &InterfaceName, enable: bool) -> Result<(),
Ok(())
}
fn add_association(interface: &InterfaceName) -> Result<(), Error> {
fn add_association(interface: &InterfaceName, opts: AddAssociationOpts) -> Result<(), Error> {
let InterfaceConfig { server, .. } = InterfaceConfig::from_interface(interface)?;
let api = Api::new(&server);
println!("Fetching CIDRs");
let cidrs: Vec<Cidr> = api.http("GET", "/admin/cidrs")?;
if let Some((cidr1, cidr2)) = prompts::add_association(&cidrs[..])? {
let association = if let (Some(ref cidr1), Some(ref cidr2)) = (opts.cidr1, opts.cidr2) {
let cidr1 = cidrs
.iter()
.find(|c| &c.name == cidr1)
.ok_or(format!("can't find cidr '{}'", cidr1))?;
let cidr2 = cidrs
.iter()
.find(|c| &c.name == cidr2)
.ok_or(format!("can't find cidr '{}'", cidr2))?;
(cidr1, cidr2)
} else if let Some((cidr1, cidr2)) = prompts::add_association(&cidrs[..])? {
(cidr1, cidr2)
} else {
println!("exited without adding association.");
return Ok(());
};
api.http_form(
"POST",
"/admin/associations",
AssociationContents {
cidr_id_1: cidr1.id,
cidr_id_2: cidr2.id,
cidr_id_1: association.0.id,
cidr_id_2: association.1.id,
},
)?;
} else {
println!("exited without adding association.");
}
Ok(())
}
@ -870,7 +893,7 @@ fn run(opt: Opt) -> Result<(), Error> {
Command::AddCidr { interface, opts } => add_cidr(&interface, opts)?,
Command::DisablePeer { interface } => enable_or_disable_peer(&interface, false)?,
Command::EnablePeer { interface } => enable_or_disable_peer(&interface, true)?,
Command::AddAssociation { interface } => add_association(&interface)?,
Command::AddAssociation { interface, opts } => add_association(&interface, opts)?,
Command::DeleteAssociation { interface } => delete_association(&interface)?,
Command::ListAssociations { interface } => list_associations(&interface)?,
Command::SetListenPort { interface, unset } => set_listen_port(&interface, unset)?,

View file

@ -0,0 +1,40 @@
####################################################################################################
## Builder
####################################################################################################
FROM rust as planner
RUN apt update && apt install -y build-essential musl-tools musl-dev clang libclang-dev libsqlite3-dev
RUN update-ca-certificates
WORKDIR /app
RUN cargo install cargo-chef
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
FROM rust as cacher
RUN apt update && apt install -y build-essential musl-tools musl-dev clang libclang-dev libsqlite3-dev
RUN update-ca-certificates
WORKDIR /app
RUN cargo install cargo-chef
COPY --from=planner /app/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json
FROM rust as builder
RUN apt update && apt install -y build-essential musl-tools musl-dev clang libclang-dev libsqlite3-dev
RUN update-ca-certificates
WORKDIR /app
COPY . .
COPY --from=cacher /app/target target
RUN cargo build --release --bin innernet
####################################################################################################
## Final image
####################################################################################################
FROM ubuntu:latest
RUN apt-get update && apt-get install -y libsqlite3-dev iproute2 iputils-ping && rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY ./docker-tests/start-client.sh ./
COPY --from=builder /app/target/release/innernet /usr/bin/
CMD ["/app/start-client.sh"]

View file

@ -0,0 +1,40 @@
####################################################################################################
## Builder
####################################################################################################
FROM rust as planner
RUN apt update && apt install -y build-essential musl-tools musl-dev clang libclang-dev libsqlite3-dev
RUN update-ca-certificates
WORKDIR /app
RUN cargo install cargo-chef
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
FROM rust as cacher
RUN apt update && apt install -y build-essential musl-tools musl-dev clang libclang-dev libsqlite3-dev
RUN update-ca-certificates
WORKDIR /app
RUN cargo install cargo-chef
COPY --from=planner /app/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json
FROM rust as builder
RUN apt update && apt install -y build-essential musl-tools musl-dev clang libclang-dev libsqlite3-dev
RUN update-ca-certificates
WORKDIR /app
COPY . .
COPY --from=cacher /app/target target
RUN cargo build --release --bin innernet-server
####################################################################################################
## Final image
####################################################################################################
FROM ubuntu:latest
RUN apt-get update && apt-get install -y libsqlite3-dev iproute2 iputils-ping && rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY ./docker-tests/start-server.sh ./
COPY --from=builder /app/target/release/innernet-server /usr/bin/
EXPOSE 51820/udp
CMD ["/app/start-server.sh"]

View file

@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -ex
SELF_DIR="$(dirname "$0")"
cd "$SELF_DIR/.."
docker build -t innernet-server -f "$SELF_DIR/Dockerfile.innernet-server" .
docker build -t innernet -f "$SELF_DIR/Dockerfile.innernet" .

View file

@ -0,0 +1,96 @@
#!/usr/bin/env bash
set -e
SELF_DIR="$(dirname "$0")"
cd "$SELF_DIR/.."
cmd() {
echo "[#] $*" >&2
"$@"
}
info() {
TERM=${TERM:-dumb} echo -e "$(tput setaf 4)- $@$(tput sgr0)" 1>&2
}
tmp_dir=$(mktemp -d -t innernet-tests-XXXXXXXXXX)
cleanup() {
info "Cleaning up."
rm -rf "$tmp_dir"
cmd docker stop $(docker ps -q) || true
cmd docker network remove innernet
}
trap cleanup EXIT
if [[ "$OSTYPE" == "darwin"* ]]; then
info "Loading wireguard kernel module in Docker VM."
# ensure the wireguard kernel module is loaded in the macOS docker VM.
cmd docker run --rm --pid=host --privileged justincormack/nsenter1 /sbin/modprobe wireguard
fi
info "Creating network."
NETWORK=$(cmd docker network create -d bridge --subnet=172.18.0.0/16 innernet)
info "Starting server."
SERVER_CONTAINER=$(cmd docker run -itd --rm \
--network "$NETWORK" \
--ip 172.18.1.1 \
--cap-add NET_ADMIN \
innernet-server)
info "Waiting for server to initialize."
cmd sleep 10
info "Starting first peer."
cmd docker cp "$SERVER_CONTAINER:/app/peer1.toml" "$tmp_dir"
PEER1_CONTAINER=$(cmd docker create --rm -it \
--network "$NETWORK" \
--ip 172.18.1.2 \
--env INTERFACE=evilcorp \
--cap-add NET_ADMIN \
innernet)
cmd docker cp "$tmp_dir/peer1.toml" "$PEER1_CONTAINER:/app/invite.toml"
cmd docker start "$PEER1_CONTAINER"
sleep 5
info "Creating a new CIDR from first peer."
cmd docker exec "$PEER1_CONTAINER" innernet \
add-cidr evilcorp \
--name "robots" \
--cidr "10.66.2.0/24" \
--parent "evilcorp" \
--yes
info "Creating association between CIDRs."
cmd docker exec "$PEER1_CONTAINER" innernet \
add-association evilcorp \
humans \
robots
info "Creating invitation for second peer from first peer."
cmd docker exec "$PEER1_CONTAINER" innernet \
add-peer evilcorp \
--name "peer2" \
--cidr "robots" \
--admin false \
--auto-ip \
--save-config "/app/peer2.toml" \
--yes
cmd docker cp "$PEER1_CONTAINER:/app/peer2.toml" "$tmp_dir"
info "Starting second peer."
PEER2_CONTAINER=$(docker create --rm -it \
--network "$NETWORK" \
--ip 172.18.1.3 \
--cap-add NET_ADMIN \
--env INTERFACE=evilcorp \
innernet)
cmd docker cp "$tmp_dir/peer2.toml" "$PEER2_CONTAINER:/app/invite.toml"
cmd docker start "$PEER2_CONTAINER"
sleep 10
# read -p "Press enter to continue. " -n 1 -r
info "Checking connectivity betweeen peers."
cmd docker exec "$PEER2_CONTAINER" ping -c3 10.66.0.1
cmd docker exec "$PEER2_CONTAINER" ping -c3 10.66.1.1

14
docker-tests/start-client.sh Executable file
View file

@ -0,0 +1,14 @@
#!/bin/bash
set -e
INTERFACE="${INTERFACE:-innernet}"
innernet install \
--name "$INTERFACE" \
--delete-invite \
--no-write-hosts \
/app/invite.toml
while true; do
innernet up --no-write-hosts "$INTERFACE"
sleep 1
done

14
docker-tests/start-server.sh Executable file
View file

@ -0,0 +1,14 @@
#!/bin/bash
set -e
innernet-server new \
--network-name "evilcorp" \
--network-cidr "10.66.0.0/16" \
--external-endpoint "172.18.1.1:51820" \
--listen-port 51820
innernet-server add-cidr evilcorp --name "humans" --cidr "10.66.1.0/24" --parent "evilcorp" --yes
innernet-server add-peer evilcorp --name "admin" --cidr "humans" --admin true --auto-ip --save-config "peer1.toml" --yes
innernet-server serve evilcorp

View file

@ -33,7 +33,7 @@ shared = { path = "../shared" }
subtle = "2"
structopt = "0.3"
thiserror = "1"
ureq = "2"
ureq = { version = "2", default-features = false }
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
toml = "0.5"
warp = { git = "https://github.com/tonarino/warp", default-features = false } # pending https://github.com/seanmonstar/warp/issues/830

View file

@ -35,9 +35,9 @@ mod initialize;
use db::{DatabaseCidr, DatabasePeer};
pub use endpoints::Endpoints;
pub use error::ServerError;
use initialize::InitializeOpts;
use shared::{prompts, wg, CidrTree, Error, Interface, SERVER_CONFIG_DIR, SERVER_DATABASE_DIR};
pub use shared::{Association, AssociationContents};
use initialize::InitializeOpts;
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
@ -54,7 +54,7 @@ enum Command {
#[structopt(alias = "init")]
New {
#[structopt(flatten)]
opts: InitializeOpts
opts: InitializeOpts,
},
/// Permanently uninstall a created network, rendering it unusable. Use with care.

View file

@ -61,7 +61,7 @@ pub fn add_cidr(cidrs: &[Cidr], request: &AddCidrOpts) -> Result<Option<CidrCont
};
Ok(
if request.force
if request.yes
|| Confirm::with_theme(&*THEME)
.with_prompt(&format!("Create CIDR \"{}\"?", cidr_request.name))
.default(false)
@ -228,7 +228,7 @@ pub fn add_peer(
};
Ok(
if args.force
if args.yes
|| Confirm::with_theme(&*THEME)
.with_prompt(&format!("Create peer {}?", peer_request.name.yellow()))
.default(false)

View file

@ -199,31 +199,45 @@ pub struct AddPeerOpts {
#[structopt(long)]
pub cidr: Option<String>,
/// Make new peer an admin
/// Make new peer an admin?
#[structopt(long)]
pub admin: Option<bool>,
/// Force confirmation
#[structopt(short, long)]
pub force: bool,
/// Bypass confirmation
#[structopt(long)]
pub yes: bool,
/// Save the config to the given location
#[structopt(long)]
pub save_config: Option<String>,
}
#[derive(Debug, Clone, PartialEq, StructOpt)]
pub struct AddCidrOpts {
/// The CIDR name (eg. "engineers")
#[structopt(long)]
pub name: Option<String>,
/// The CIDR network (eg. "10.42.5.0/24")
#[structopt(long)]
pub cidr: Option<IpNetwork>,
/// The CIDR parent name
#[structopt(long)]
pub parent: Option<String>,
#[structopt(short, long)]
pub force: bool,
/// Bypass confirmation
#[structopt(long)]
pub yes: bool,
}
#[derive(Debug, Clone, PartialEq, StructOpt)]
pub struct AddAssociationOpts {
/// The first cidr to associate
pub cidr1: Option<String>,
/// The second cidr to associate
pub cidr2: Option<String>,
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]

View file

@ -13,5 +13,5 @@ version = "1.1.0"
libc = "0.2"
[build-dependencies]
bindgen = { version = "0.57", default-features = false }
bindgen = { version = "0.58", default-features = false }
cc = "1.0"

View file

@ -8,7 +8,7 @@ mod linux {
.derive_default(true)
.header("c/wireguard.h")
.impl_debug(true)
.whitelist_function("wg_.*")
.allowlist_function("wg_.*")
.bitfield_enum("wg_peer_flags")
.bitfield_enum("wg_device_flags");