|
| 1 | +Just-In-Time Credential Leases |
| 2 | +============================== |
| 3 | + |
| 4 | +Long-lived secrets handed to automation are a standing liability. ``CredentialBroker`` |
| 5 | +applies **zero standing privilege**: a consumer takes a short-lived *lease* — a |
| 6 | +token bound to a secret name with an expiry — and the real value is fetched only |
| 7 | +at :meth:`redeem` time, only while the lease is valid, through a pluggable |
| 8 | +*resolver* (an unlocked ``SecretManager``'s ``get``, an environment lookup, a |
| 9 | +vault client). Expired or revoked leases yield nothing. |
| 10 | + |
| 11 | +Secret values never enter executor/MCP records: the executor and MCP surfaces |
| 12 | +manage the lease *lifecycle* only. :meth:`redeem`, which returns the real value, |
| 13 | +is a deliberate **Python-API-only** escape hatch for code that must handle the |
| 14 | +secret. The module is pure standard library and imports no ``PySide6``; the |
| 15 | +clock and resolver are injectable, so expiry is deterministically testable. |
| 16 | + |
| 17 | +Headless API |
| 18 | +------------ |
| 19 | + |
| 20 | +.. code-block:: python |
| 21 | +
|
| 22 | + from je_auto_control import CredentialBroker |
| 23 | +
|
| 24 | + broker = CredentialBroker(resolver=secret_manager.get) # resolver(name)->value |
| 25 | + token = broker.lease("db_password", ttl=120) # token, not the value |
| 26 | +
|
| 27 | + if broker.is_valid(token): |
| 28 | + password = broker.redeem(token) # fetched just in time, Python-only |
| 29 | + connect(password) |
| 30 | +
|
| 31 | + broker.revoke(token) # or let it expire after ttl seconds |
| 32 | +
|
| 33 | +``active()`` lists non-expired leases as ``{token, name, ttl_remaining}`` with no |
| 34 | +values. A module-level :data:`default_broker` backs the executor/MCP commands; |
| 35 | +configure its resolver once with ``set_secret_resolver(fn)``. |
| 36 | + |
| 37 | +Executor commands |
| 38 | +----------------- |
| 39 | + |
| 40 | +================================ =================================================== |
| 41 | +Command Effect |
| 42 | +================================ =================================================== |
| 43 | +``AC_lease_secret`` Issue a lease for ``name`` (``ttl`` s); ``{token, ttl}``. |
| 44 | +``AC_lease_valid`` Report ``{valid}`` for a lease token. |
| 45 | +``AC_revoke_lease`` Revoke a lease token; ``{revoked}``. |
| 46 | +``AC_lease_active`` List active leases (no secret values). |
| 47 | +================================ =================================================== |
| 48 | + |
| 49 | +There is intentionally **no** redeem command on the executor, MCP, or Script |
| 50 | +Builder surfaces — exposing the value there would leak it into run records. |
| 51 | +Redeeming is Python-only. The same lifecycle operations are exposed as MCP tools |
| 52 | +(``ac_lease_secret`` / ``ac_lease_valid`` / ``ac_revoke_lease`` / |
| 53 | +``ac_lease_active``) and as Script Builder commands under **Tools**. |
0 commit comments