Skip to main content

vault-approle-toolkit

Short-lived, least-privilege credentials from Vault — without ever passing a Vault token across a process boundary.

It replaces a long-lived VAULT_TOKEN stored as a CI secret, or a setup job that logs in and exports one for every later step to inherit, with a single wrapped command.

Quick start

Push to AWS ECR with a credential that exists only while docker push runs.

pip install 'vault-approle-toolkit[aws]'

Describe your Vault once, in vault-approle.json in the working directory or in ~/.config/vault-approle/config.json:

{
  "version": 1,
  "profiles": {
    "default": {
      "vault": {
        "addr": "https://vault.example.com:8200",
        "auth_path": "approle",
        "role_id": "your-role-id"
      },
      "provider": {
        "name": "aws.ecr",
        "role": "ci-ecr-readwrite",
        "region": "us-east-2"
      }
    }
  }
}

Then supply the SecretID and run:

export VAULT_SECRET_ID=...                 # from your CI secret store
vault-approle doctor                       # checks every layer, names the one that fails
vault-approle run -- docker push "$IMAGE"

run logs in with the AppRole, issues an ECR credential, runs the command against an isolated docker config, and revokes everything on the way out. The Vault token never leaves the process, and VAULT_* is stripped from the child.

Field Meaning
vault.addr your Vault server
vault.auth_path where the AppRole auth method is enabled (approle unless you chose otherwise)
vault.role_id the AppRole's RoleID. An identifier rather than a secret, so it can live in the file
provider.role the role in Vault's AWS secrets engine
provider.region the registry's AWS region

Optional: vault.namespace (Vault Enterprise), provider.engine_mount (default aws), provider.registry_id (default: the account of the assumed role).

The SecretID is the only secret, and the file rejects one if you put it there. It can also come from --secret-id-file or a response-wrapping token; see identity.md.

More examples

Each is a complete, runnable file:

Example Shows
Jenkinsfile replacing a stored VAULT_TOKEN in a pipeline
.gitlab-ci.yml the same, plus a wrapped SecretID as a deploy trigger
build-and-push.sh run versus credentials in the current shell, and branching on exit codes
push_image.py the Python API: with scoping and typed errors
playbook.yml the Ansible role, plus five other shapes
Dockerfile adding the toolkit to an image with no pip at build time

They use the built-in example-ecr profile, whose addresses are placeholders. With the file above in place, drop --profile example-ecr (in Ansible, set vault_approle_profile: default).

Install

The CLI and Python library

pip install 'vault-approle-toolkit[aws]'

Python ≥ 3.8. Drop [aws] if you only need Vault-side commands such as doctor: the core has no dependencies at all. [aws] adds boto3.

The Ansible collection

On the controller only; managed targets need nothing but docker or podman. Install the Python package first, with the [ansible] extra, so that ansible-galaxy is the one in your virtualenv rather than a system install:

V=0.2.1
pip install "vault-approle-toolkit[aws,ansible]==$V"
ansible-galaxy collection install \
    "https://github.com/liozzazhang/vault-approle-toolkit/releases/download/vault-approle-toolkit.v$V/ops-vault-$V.tar.gz"
vault-approle version                # core, collection and ansible-core, side by side

The two are released together and only tested as a pair, so keep them on the same version; vault-approle version --check exits non-zero if they differ. ansible-core must be 2.14 or newer. The collection README covers Execution Environments and what to check when a play complains.

Every release also carries the wheel, the collection tarball and SHA256SUMS, for offline or verified installs.

How it works

The chain is AppRole → Vault token → secrets engine role → short-lived credential. The Vault token in the middle is an intermediate value, not an interface: the client holds a RoleID and a SecretID of its own, and the Vault token is born, used and revoked inside a single process.

A SecretID is issued per consumer, with its own TTL, use count and CIDR binding, and can be revoked without disturbing anyone else.

You have You use Docs
a shell script or CI job vault-approle run -- <cmd> shell
Python code with approle_session(...) as s: python
an Ansible playbook role: ops.vault.aws_ecr_login ansible
a Dockerfile, no pip at build time COPY --from=vak /opt/vault-approle image

All four are the same core. Behaviour, exit codes and guarantees are identical, which is what contract.md pins down.

When something breaks

Run vault-approle doctor. It walks the chain left to right — config, AppRole login, Vault policy, AWS — prints PASS/FAIL with a hint for each layer, and exits with the code of the first one that fails. Exit codes are the supported interface for wrappers; troubleshooting.md has one section per code.

Configuration precedence is CLI flag > environment variable > config file > built-in profile. A VAULT_ADDR left over in your shell silently outranks the file, so doctor shows where every field came from and warns when something was overridden.

What it guarantees

Four invariants, asserted by tests/contract/scenarios.yaml rather than promised in prose:

  1. The token never leaves memory — not disk, not an environment variable, not argv, not a log line, not any --format output.
  2. Inherited credential material is actively stripped from child environments, not merely not added.
  3. The scope is the lifetime: normal return, exception, SIGINT and SIGTERM all clean up. (SIGKILL cannot be caught; short TTLs are the answer.)
  4. Only what we created gets revoked. A caller-supplied token is never revoked.

Documentation

Development

$ make dev          # venv + editable install with dev extras
$ make lint         # ruff, shellcheck, ansible-lint, ansible-test sanity
$ make test         # pytest (unit + contract) and bats
$ make image-verify # build the artifact and run it under python 3.8/3.9/3.12

Status

Phase one: AWS ECR. aws.sts and aws.ecr are implemented; other providers are registered as placeholders that fail with exit code 50 and a clear message rather than an import error. Adding one means implementing issue() and registering it — see architecture.md.

Metadata

Release files for vault-approle-toolkit 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for vault-approle-toolkit 0.2.1
File Size Uploaded Provenance Actions
vault_approle_toolkit-0.2.1.tar.gz 68.7 kB Without provenance Details for vault_approle_toolkit-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for vault-approle-toolkit 0.2.1
File Interpreter ABI Platform Actions
vault_approle_toolkit-0.2.1-py3-none-any.whl Python 3 none any Details for vault_approle_toolkit-0.2.1-py3-none-any.whl

Total release size: 152.4 kB

Release files / vault_approle_toolkit-0.2.1.tar.gz

Download URL vault_approle_toolkit-0.2.1.tar.gz
Size 68.7 kB
Tags Source
SHA-256 checksum
How to use checksums
00b2f8b2a140177bbb20032755adc04af0f14012bf3a1d42e3465bbf7fa08e6f
BLAKE2b-256 checksum
How to use checksums
454dc2ce71683f3dab62bc03f635dba66cab20451cc78470b53f447df19a0b67
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.2

Release files / vault_approle_toolkit-0.2.1-py3-none-any.whl

Download URL vault_approle_toolkit-0.2.1-py3-none-any.whl
Size 83.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
197b1a96988605a2f2d716aa463368b290177e6b32633195e05bc7743c60af7e
BLAKE2b-256 checksum
How to use checksums
54ec3fc9a846e6f9d913e283fcf4ea54d7ec32e6227bd5934bfdb859c96c7221
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.2

Security for vault-approle-toolkit 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files No provenance

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