Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async #94

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ serde_derive = "1"
serde_json = "1"
openssl = "0"
base64 = "0"
acme-lib = { git = 'https://github.com/DBCDK/acme-lib', branch = 'dbc-fork' }
acme-lib = { git = 'https://github.com/DBCDK/acme-lib', branch = 'dbc-fork-merge-upstream' }
regex = "1"
lazy_static = "1"
walkdir = "2"
trust-dns-resolver = "0"
trust-dns-resolver = { version = "0", features = ["tokio-runtime"] }
env_logger = "0"
prometheus_exporter_base = { version = "=1.4.0", features = ["hyper_server"] }
tokio = { version = "1", features = [ "full" ] }
Expand Down
27 changes: 14 additions & 13 deletions nixos/vault-test.nix
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,16 @@ nixos-lib.runTest (
}
];
}
# Multiple vaultmonitorconfigs break faythe currently, commented out
# {
# inherit role_id_path secret_id_path vault_addr;
# key_prefix = "path2";
# specs = [
# {
# name = "path2-test";
# cn = "path2.${domain}";
# }
# ];
# }
{
inherit role_id_path secret_id_path vault_addr;
key_prefix = "path2";
specs = [
{
name = "path2-test";
cn = "path2.${domain}";
}
];
}
];
lets_encrypt_url = "https://${nodes.acme.test-support.acme.caDomain}/dir";
lets_encrypt_email = "test_mail@${domain}";
Expand Down Expand Up @@ -131,6 +130,7 @@ nixos-lib.runTest (
dnsutils
vault
getent
lsof
];

environment.variables.VAULT_ADDR = vault_addr;
Expand Down Expand Up @@ -215,6 +215,8 @@ nixos-lib.runTest (
dnsutils
dig
];
environment.RUST_BACKTRACE = "full";
environment.RUST_LOG = "warn,acme_lib=debug";
wantedBy = [ "multi-user.target" ];
wants = [ "vault-provision.service" ];
after = [ "vault-provision.service" ];
Expand All @@ -241,8 +243,7 @@ nixos-lib.runTest (

with subtest("Can get certs"):
client.wait_until_succeeds("""
vault kv get kv/path1/path1-test/cert
# vault kv get kv/path2/path2-test/cert
vault kv get kv/path1/path1-test/cert && vault kv get kv/path2/path2-test/cert
""")

with subtest("No failed dispatch in vaultrs"):
Expand Down
10 changes: 5 additions & 5 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl CertSpec {
}

pub trait Persistable {
fn persist(&self, cert: Certificate) -> Result<(), PersistError>;
async fn persist(&self, cert: Certificate) -> Result<(), PersistError>;
}

#[derive(Debug, Clone, Serialize)]
Expand All @@ -183,11 +183,11 @@ pub enum PersistSpec {
}

impl Persistable for CertSpec {
fn persist(&self, cert: Certificate) -> Result<(), PersistError> {
async fn persist(&self, cert: Certificate) -> Result<(), PersistError> {
match &self.persist_spec {
PersistSpec::KUBERNETES(spec) => Ok(kube::persist(&spec, &cert)?),
PersistSpec::FILE(spec) => Ok(file::persist(&spec, &cert)?),
PersistSpec::VAULT(spec) => Ok(vault::persist(&spec, cert)?),
PersistSpec::VAULT(spec) => Ok(vault::persist(&spec, cert).await?),
//PersistSpec::FILE(_spec) => { unimplemented!() },
PersistSpec::DONTPERSIST => { Ok(()) }
}
Expand Down Expand Up @@ -325,8 +325,8 @@ pub trait ValidityVerifier {

pub trait CertSpecable: IssueSource {
fn to_cert_spec(&self, config: &ConfigContainer) -> Result<CertSpec, SpecError>;
fn touch(&self, config: &ConfigContainer) -> Result<(), TouchError>;
fn should_retry(&self, config: &ConfigContainer) -> bool;
async fn touch(&self, config: &ConfigContainer) -> Result<(), TouchError>;
async fn should_retry(&self, config: &ConfigContainer) -> bool;
}

pub trait IssueSource {
Expand Down
6 changes: 3 additions & 3 deletions src/dns/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::convert::From;
use crate::log;
use crate::common::{CertSpec, DNSName, SpecError};
use crate::config::Zone;
use self::trust_dns_resolver::Resolver;
use self::trust_dns_resolver::TokioAsyncResolver;
use self::trust_dns_resolver::error::{ResolveError,ResolveErrorKind};
use std::string::String;

Expand Down Expand Up @@ -77,9 +77,9 @@ pub fn delete(config: &FaytheConfig, spec: &CertSpec) -> Result<(), DNSError> {
Ok(())
}

pub fn query(resolver: &Resolver, host: &DNSName, proof: &String) -> Result<(), DNSError> {
pub async fn query(resolver: &TokioAsyncResolver, host: &DNSName, proof: &String) -> Result<(), DNSError> {
let challenge_host = challenge_host(host, None);
match resolver.txt_lookup(&challenge_host) {
match resolver.txt_lookup(&challenge_host).await {
Ok(res) => {
let trim_chars: &[_] = &['"', '\n'];
res.iter().find(|record_set|
Expand Down
5 changes: 3 additions & 2 deletions src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl CertSpecable for FileSpec {
})
}

fn touch(&self, config: &ConfigContainer) -> Result<(), TouchError> {
async fn touch(&self, config: &ConfigContainer) -> Result<(), TouchError> {
let monitor_config = config.get_file_monitor_config()?;
let names = default_file_names(&self);
let sub_dir = absolute_dir_path(&monitor_config, names.sub_directory.as_ref());
Expand All @@ -164,7 +164,7 @@ impl CertSpecable for FileSpec {
Ok(())
}

fn should_retry(&self, config: &ConfigContainer) -> bool {
async fn should_retry(&self, config: &ConfigContainer) -> bool {
use std::time::Duration;

match || -> Result<(), TouchError> {
Expand Down Expand Up @@ -212,6 +212,7 @@ impl FileNames {
}
}

#[derive(Debug)]
pub enum FileError {
IO
}
Expand Down
Loading