release / validate (push) Successful in 5s
test / test (push) Successful in 1m6s
release / build (, macos-arm64, macos-arm64) (push) Successful in 1m20s
release / build (amd64, linux-amd64, linux-amd64) (push) Successful in 1m7s
release / build (arm64, linux-arm64, linux-arm64) (push) Successful in 2m2s
release / release (push) Successful in 26s
New OpenBao credential engines (database/PostgreSQL, aws, approle, ssh) backed by a POST-capable BaoClient. Queries can set cache = true on dynamic database and aws roles to reuse the credential until near lease expiry (file store by default, optional keychain), revoking the old lease on refresh. Adds [cache] store and --clear-cache. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
49 lines
1.9 KiB
Python
49 lines
1.9 KiB
Python
"""AWS secrets engine (dynamic IAM users or STS credentials)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from collections.abc import Mapping
|
|
from typing import Any
|
|
|
|
from envbao.client import BaoClient
|
|
from envbao.engines import _common as c
|
|
from envbao.errors import ConfigError
|
|
|
|
_OPTIONS = {"mount", "role", "kind", "ttl"}
|
|
_FIELDS = ("access_key", "secret_key", "security_token")
|
|
|
|
|
|
class AwsEngine:
|
|
"""Reads AWS credentials for a role.
|
|
|
|
Options: ``role`` (required), ``mount`` (default ``"aws"``), ``kind`` (``"creds"`` or
|
|
``"sts"``, default ``"creds"``), ``ttl`` (optional duration string such as ``"15m"``).
|
|
Returns ``access_key``, ``secret_key`` and, for STS, ``security_token``.
|
|
"""
|
|
|
|
def validate(self, options: Mapping[str, Any]) -> None:
|
|
c.check_options("aws", options, _OPTIONS)
|
|
c.get_str("aws", options, "role")
|
|
c.get_str("aws", options, "mount", default="aws")
|
|
c.get_choice("aws", options, "kind", ("creds", "sts"), "creds")
|
|
ttl = options.get("ttl")
|
|
if ttl is not None and (not isinstance(ttl, str) or not ttl):
|
|
raise ConfigError("aws option 'ttl' must be a non-empty string such as \"15m\"")
|
|
|
|
def cacheable(self, options: Mapping[str, Any]) -> bool:
|
|
return True
|
|
|
|
def fetch(self, client: BaoClient, options: Mapping[str, Any]) -> dict[str, Any]:
|
|
return self.fetch_leased(client, options)[0]
|
|
|
|
def fetch_leased(
|
|
self, client: BaoClient, options: Mapping[str, Any]
|
|
) -> tuple[dict[str, Any], c.Lease | None]:
|
|
mount = c.get_str("aws", options, "mount", default="aws")
|
|
role = c.get_str("aws", options, "role")
|
|
kind = c.get_choice("aws", options, "kind", ("creds", "sts"), "creds")
|
|
ttl = options.get("ttl")
|
|
where = f"{mount}/{kind}/{role}"
|
|
body = client.get(where, {"ttl": ttl} if ttl else None)
|
|
return c.pick(c.response_data(body, where), _FIELDS, where), c.lease_of(body)
|