Skip to main content

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, a GitHub-style .keys 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

Alongside those, authkeys check resolves a user with per-source tracing on stderr (which source produced which key), authkeys cache show|purge|warm inspects and manages the on-disk cache, and authkeys completion bash|zsh|fish prints a shell completion script. resolve and check also take --format authorized_keys|json, where json emits one object per key with type, key, comment, and options for scripting. See the CLI guide for details.

resolve and check exit 0 on success — including when no keys were found, which sshd reads as "no keys" — and 3 on a config or internal error, never a traceback.

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.github a GitHub (or similar) .keys endpoint 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.

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.3.tar.gz (54.1 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.3-py3-none-any.whl (36.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for authkeys-0.4.3.tar.gz
Algorithm Hash digest
SHA256 bcc5bb71f4edfa7fc912da95f26c87b11256e5bba8a57b1ceaeb7d073817f124
MD5 692c791e51baaeda757efd360b535fad
BLAKE2b-256 874372e7f8599f0fafbaaaba20c799fff8aa16c9f5359edfa5a0b7bb2add0401

See more details on using hashes here.

Provenance

The following attestation bundles were made for authkeys-0.4.3.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.3-py3-none-any.whl.

File metadata

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

File hashes

Hashes for authkeys-0.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b86e52ef0a5fdd581df3b7f05b56d8263babdac11677dfad9d015a13f8565f68
MD5 d96794153f2716b89c9f65f6148fda0a
BLAKE2b-256 ae84296a59daf6933e438a8a35204b782cc645e2a468c2d045e479651993d345

See more details on using hashes here.

Provenance

The following attestation bundles were made for authkeys-0.4.3-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.

Release history Release notifications | RSS feed

This release

0.4.3 This release

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page