Skip to main content

Crate coqui_access_mtls

Crate coqui_access_mtls 

Source
Expand description

Maps peer certificates, verified by the transport, to directory identities.

The transport (see coqui-peer-tls) proves a peer holds the key of its certificate and hands the certificate’s fingerprint in [Attempt::certificate]. This provider keeps the fingerprints that were accepted in a [Table], each under a name and groups. A certificate nobody accepted is not authenticated and is kept for a while as waiting, in a second table, so whoever runs the service can accept it. Build the provider in code with MtlsAccounts::builder.

§coqui-access-mtls

Version Rust version License: MPL-2.0 Docs CI

Client certificates as accounts. The transport (see coqui-peer-tls) proves a client holds the key of its certificate and hands over the certificate; this provider trusts it pinned (an accepted fingerprint kept in a Table, mapped to a name and groups), signed by a CA, or either. A pinned certificate nobody accepted is not authenticated and is kept for a while as waiting, with the address it came from, in a second Table, so an operator can accept it. A CA-trusted one names its account by a field the deployment picks: an email or UPN SAN, the subject’s CN, the fingerprint.

§Features

  • Code first - MtlsAccounts::builder() works out of the box with in-memory tables.
  • Any source - an Arc<dyn Table<PeerRecord>> for the peers and an Arc<dyn Table<Unaccepted>> for the waiting list.
  • Waiting list - unaccepted fingerprints under coqui-peer’s WaitingQueue: one place per source (an IPv4 address or an IPv6 /64), 16 in all, the same certificate from one source written down at most once a minute; each bound is an option.
  • Any spelling - sha256:<hex>, bare hex, colon-separated hex or grouped base32.
  • Claims - a certificate is answered with everything it said (subject and issuer names, serial, UPN, email, DNS, URI and IP SANs, fingerprint, public key hash and the DER), and with no account picks as by: "claims", for the consumer’s matcher to tie to a directory account.
  • Pinned by fingerprint or by public key - a key pin (key:sha256:<hex> of the SubjectPublicKeyInfo) keeps signing in a certificate renewed on the same key, as a smartcard’s is; an account holds several pins, up to max_pins (4), and one is removed alone.
  • CA trust - TrustMode::Ca or PinnedOrCa with a CaPolicy (CA file, subject and SAN globs), and account picks over the certificate’s fields; an IP written as a DNS name counts as an IP by default.

§Installation

cargo add coqui-access-mtls --git https://github.com/Boriken-Dev/coqui-access

Build coqui-access-mtls-plugin for the loadable library.

§Quick start

use coqui_access::{Attempt, Authenticator, Verdict};
use coqui_access_mtls::{MtlsAccounts, default_waiting_limits};

let peers = MtlsAccounts::builder().waiting_limits(default_waiting_limits()).build().unwrap();
let verdict = peers
    .authenticate(Attempt { certificate: Some("not a fingerprint".into()), ..Attempt::default() })
    .unwrap();
assert_eq!(verdict, Verdict::Unknown);

MtlsAccounts of your own come from a table: MtlsAccounts::builder().table(table).build()?, where table is a MemoryTable::from_records([PeerRecord::new(id, name, &fingerprint)]) or your own Table<PeerRecord>; .waiting(table) keeps the waiting list somewhere else. The records derive guatiao’s value traits, so any table keeps them.

The loadable plugin (provider id coqui_access_mtls) is configured with a source, for example { "source": { "file": { "path": "peers.toml", "format": "toml" } } } (format is toml or json); the waiting list defaults to peers.toml.waiting beside a file source and can be given its own waiting source. With no source both live in memory.

§API overview

ItemPurpose
MtlsAccountsThe provider: builder() and the three kinds.
MtlsAccountsBuilderOptions: table, waiting, max_records, max_pins, waiting_limits, record_limits; build.
PeerRecord, UnacceptedThe records the two tables keep; guatiao value traits.
PinOne thing an account pins: a fingerprint or a key; key_of_certificate, parse, text.

§Development

cargo test -p coqui-access-mtls --all-features
cargo clippy -p coqui-access-mtls --all-targets --all-features -- -D warnings

§Releasing

This project follows Semantic Versioning and keeps a CHANGELOG.md. Pushing a tag matching v* triggers the release workflow of the repository.

§License

MPL-2.0 — see LICENSE.

Structs§

MtlsAccounts
MtlsAccounts as an Authenticator, Directory and Accounts implementation.
MtlsAccountsBuilder
Options for MtlsAccounts; every one has a default.
PeerRecord
One accepted peer as a [Table] keeps it, keyed by name.
Pin
One thing an account pins, as a record names it: a kind and a canonical value.
PinError
Text that is not a pin. It never quotes the text.
Unaccepted
A fingerprint shown to the service that nobody has accepted, keyed by fingerprint.

Enums§

TrustMode
How a client certificate is trusted.

Constants§

DEFAULT_MAX_CHAIN
The most certificates a client may send, leaf included, unless the builder says otherwise.
DEFAULT_MAX_PINS
The most pins (fingerprints and keys together) one account may hold unless the builder says otherwise.
DEFAULT_MAX_RECORDS
The most peers a table may hold unless the builder says otherwise.
DEFAULT_WAITING_PER_SOURCE
Places one source holds on the waiting list unless the builder says otherwise.
DEFAULT_WAITING_RERECORD
How soon one fingerprint from one source is written down again unless the builder says otherwise.
DEFAULT_WAITING_TOTAL
Places on the waiting list in all unless the builder says otherwise.

Functions§

default_account
The picks a CA-trusted certificate names its account by unless told otherwise: none. It is then answered by its claims (Lookup { by: "claims", .. }), and the consumer’s matcher ties it to a directory account.
default_waiting_limits
The bounds on the waiting list unless the builder says otherwise: one place per source (an IPv4 address, or an IPv6 /64), 16 in all, and a fingerprint from one source written down again at most once a minute.