Skip to main content

Pluggable AuthorizedKeysCommand provider for OpenSSH (file/HTTP/LDAP sources, TTL cache, optional key server)

Project description

authkeys

PyPI version Python versions Documentation License: MIT

A pluggable OpenSSH AuthorizedKeysCommand provider. It resolves a user's authorized SSH keys from one or more configured sources — local key files, an HTTP endpoint, or LDAP-stored X.509 certificates — with optional TTL caching, user/group aliasing, and a small unattended HTTP key server for hosts that fetch keys centrally.

Built on the duho declarative CLI framework.

Install

pip install authkeys            # core (file source only)
pip install authkeys[http]      # + HTTP source (requests)
pip install authkeys[ldap]      # + LDAP cert source (ldap3, cryptography)
pip install authkeys[all]       # everything

authkeys targets POSIX systems (it reads the system user/group databases via pwd/grp). The package imports on any platform for testing, but resolution requires a POSIX host.

Usage

authkeys resolve alice          # print alice's authorized keys
authkeys alice                  # 'resolve' is the default command
authkeys serve --bind 0.0.0.0 --port 8090

Wire it into sshd_config:

AuthorizedKeysCommand /usr/bin/authkeys resolve %u
AuthorizedKeysCommandUser nobody

Configuration

authkeys reads (in order) /etc/authkeys.conf, /etc/authkeys/authkeys.conf, /etc/ssh/authkeys.conf, or a colon-separated list passed with --config. A per-user ~/.ssh/authkeys.conf may authorize additional users/groups. See examples/authkeys.conf for a fully commented example.

[cache]
backend = authkeys.cache.AuthKeysCacheMemBackend
expire = 3600
expired_on_error = 1

[source:files]
backend = authkeys.sources.authorizedkeys
paths =
    authorized_keys
    authorized_keys2

[source:ldap]
enabled = 1
backend = authkeys.sources.ldap
server = ldaps://ldap.example.com:636
basedn = o=Example,c=US

Sources

Alias (backend =) Reads keys from Extra dep
authkeys.sources.authorizedkeys ~/.ssh/authorized_keys* files
authkeys.sources.http an HTTP URL ({username} templated) requests
authkeys.sources.ldap X.509 certs in an LDAP directory ldap3, cryptography

Each [source:<name>] section supports enabled and cached (both default true) and an optional sanitize callable to rewrite/drop keys.

Caching

  • AuthKeysCacheMemBackend — per-process, in-memory (default).
  • AuthKeysCacheFileBackend — on-disk under path, shared across invocations.

With expired_on_error = 1, a source failure falls back to the last-known (expired) cached keys instead of returning nothing — useful when the SSH login must not be blocked by a transient LDAP/HTTP outage.

User / group aliasing

A per-user ~/.ssh/authkeys.conf may grant other principals' keys:

[authorized]
users =
    alice
    bob
groups =
    admins

HTTP key server (authkeys serve)

For hosts that can't run the command locally, authkeys serve exposes the same resolution over HTTP:

GET /keys?username=alice&apikey=<key>

Bind address, port, path, and API key come from the [serve] config section (or --bind/--port). The API key is compared in constant time; pull it from the environment with api_key = ${env:AUTHKEYS_APIKEY} to keep it off disk. If no API key is configured, authentication is disabled — only bind to a trusted interface in that case.

License

MIT — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

authkeys-0.4.0.tar.gz (45.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

authkeys-0.4.0-py3-none-any.whl (27.4 kB view details)

Uploaded Python 3

File details

Details for the file authkeys-0.4.0.tar.gz.

File metadata

  • Download URL: authkeys-0.4.0.tar.gz
  • Upload date:
  • Size: 45.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for authkeys-0.4.0.tar.gz
Algorithm Hash digest
SHA256 7a47ea04e309d904e6e282d41b22a4f4dc259391d8c4b76f27cfa0fd797e53d3
MD5 feef9e50efea62e618e8762d37865845
BLAKE2b-256 41d5581e97cb03f8323ab2b3c962c3a558246518af23fe91cbb0086cb6d6a9eb

See more details on using hashes here.

Provenance

The following attestation bundles were made for authkeys-0.4.0.tar.gz:

Publisher: release.yml on jose-pr/authkeys

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file authkeys-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: authkeys-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 27.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for authkeys-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9eb3c514781d09d0910cede86eacfba2e6d0170fc368de94495b525b3622bef4
MD5 3a53cfd95be1155dc5d3f52986fe15a7
BLAKE2b-256 cdf9e1e34a7c4f52157774b6be43d940e82e7448f160bb18ac0591320d057c07

See more details on using hashes here.

Provenance

The following attestation bundles were made for authkeys-0.4.0-py3-none-any.whl:

Publisher: release.yml on jose-pr/authkeys

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page