vault-approle-toolkit 0.2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. vault_approle_toolkit-0.2.1/LICENSE +201 -0
  2. vault_approle_toolkit-0.2.1/PKG-INFO +247 -0
  3. vault_approle_toolkit-0.2.1/README.md +213 -0
  4. vault_approle_toolkit-0.2.1/VERSION +1 -0
  5. vault_approle_toolkit-0.2.1/pyproject.toml +102 -0
  6. vault_approle_toolkit-0.2.1/setup.cfg +4 -0
  7. vault_approle_toolkit-0.2.1/src/vault_approle/VERSION +1 -0
  8. vault_approle_toolkit-0.2.1/src/vault_approle/__init__.py +72 -0
  9. vault_approle_toolkit-0.2.1/src/vault_approle/auth/__init__.py +9 -0
  10. vault_approle_toolkit-0.2.1/src/vault_approle/auth/approle.py +68 -0
  11. vault_approle_toolkit-0.2.1/src/vault_approle/auth/base.py +53 -0
  12. vault_approle_toolkit-0.2.1/src/vault_approle/auth/token_passthrough.py +70 -0
  13. vault_approle_toolkit-0.2.1/src/vault_approle/bootstrap/__init__.py +19 -0
  14. vault_approle_toolkit-0.2.1/src/vault_approle/bootstrap/base.py +58 -0
  15. vault_approle_toolkit-0.2.1/src/vault_approle/bootstrap/env.py +108 -0
  16. vault_approle_toolkit-0.2.1/src/vault_approle/bootstrap/file.py +103 -0
  17. vault_approle_toolkit-0.2.1/src/vault_approle/bootstrap/wrapped.py +101 -0
  18. vault_approle_toolkit-0.2.1/src/vault_approle/cli/__init__.py +5 -0
  19. vault_approle_toolkit-0.2.1/src/vault_approle/cli/approle.py +313 -0
  20. vault_approle_toolkit-0.2.1/src/vault_approle/cli/aws.py +58 -0
  21. vault_approle_toolkit-0.2.1/src/vault_approle/cli/common.py +130 -0
  22. vault_approle_toolkit-0.2.1/src/vault_approle/cli/config_cmd.py +130 -0
  23. vault_approle_toolkit-0.2.1/src/vault_approle/cli/doctor.py +53 -0
  24. vault_approle_toolkit-0.2.1/src/vault_approle/cli/ecr.py +108 -0
  25. vault_approle_toolkit-0.2.1/src/vault_approle/cli/main.py +92 -0
  26. vault_approle_toolkit-0.2.1/src/vault_approle/cli/run.py +95 -0
  27. vault_approle_toolkit-0.2.1/src/vault_approle/cli/session_cmd.py +127 -0
  28. vault_approle_toolkit-0.2.1/src/vault_approle/cli/version_cmd.py +102 -0
  29. vault_approle_toolkit-0.2.1/src/vault_approle/config.py +267 -0
  30. vault_approle_toolkit-0.2.1/src/vault_approle/delivery/__init__.py +24 -0
  31. vault_approle_toolkit-0.2.1/src/vault_approle/delivery/docker_config.py +234 -0
  32. vault_approle_toolkit-0.2.1/src/vault_approle/delivery/dotenv.py +28 -0
  33. vault_approle_toolkit-0.2.1/src/vault_approle/delivery/json_out.py +22 -0
  34. vault_approle_toolkit-0.2.1/src/vault_approle/delivery/shell_export.py +55 -0
  35. vault_approle_toolkit-0.2.1/src/vault_approle/delivery/subprocess_env.py +96 -0
  36. vault_approle_toolkit-0.2.1/src/vault_approle/errors.py +115 -0
  37. vault_approle_toolkit-0.2.1/src/vault_approle/http.py +215 -0
  38. vault_approle_toolkit-0.2.1/src/vault_approle/logging.py +128 -0
  39. vault_approle_toolkit-0.2.1/src/vault_approle/policy.py +356 -0
  40. vault_approle_toolkit-0.2.1/src/vault_approle/profiles/builtin.json +32 -0
  41. vault_approle_toolkit-0.2.1/src/vault_approle/providers/__init__.py +37 -0
  42. vault_approle_toolkit-0.2.1/src/vault_approle/providers/aws/__init__.py +6 -0
  43. vault_approle_toolkit-0.2.1/src/vault_approle/providers/aws/ecr.py +125 -0
  44. vault_approle_toolkit-0.2.1/src/vault_approle/providers/aws/helpers.py +106 -0
  45. vault_approle_toolkit-0.2.1/src/vault_approle/providers/aws/sts.py +103 -0
  46. vault_approle_toolkit-0.2.1/src/vault_approle/providers/base.py +140 -0
  47. vault_approle_toolkit-0.2.1/src/vault_approle/providers/registry.py +80 -0
  48. vault_approle_toolkit-0.2.1/src/vault_approle/redact.py +112 -0
  49. vault_approle_toolkit-0.2.1/src/vault_approle/session.py +325 -0
  50. vault_approle_toolkit-0.2.1/src/vault_approle/table.py +28 -0
  51. vault_approle_toolkit-0.2.1/src/vault_approle/token.py +198 -0
  52. vault_approle_toolkit-0.2.1/src/vault_approle/vault/__init__.py +5 -0
  53. vault_approle_toolkit-0.2.1/src/vault_approle/vault/client.py +200 -0
  54. vault_approle_toolkit-0.2.1/src/vault_approle/versions.py +295 -0
  55. vault_approle_toolkit-0.2.1/src/vault_approle_toolkit.egg-info/PKG-INFO +247 -0
  56. vault_approle_toolkit-0.2.1/src/vault_approle_toolkit.egg-info/SOURCES.txt +58 -0
  57. vault_approle_toolkit-0.2.1/src/vault_approle_toolkit.egg-info/dependency_links.txt +1 -0
  58. vault_approle_toolkit-0.2.1/src/vault_approle_toolkit.egg-info/entry_points.txt +2 -0
  59. vault_approle_toolkit-0.2.1/src/vault_approle_toolkit.egg-info/requires.txt +19 -0
  60. vault_approle_toolkit-0.2.1/src/vault_approle_toolkit.egg-info/top_level.txt +1 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,247 @@
1
+ Metadata-Version: 2.4
2
+ Name: vault-approle-toolkit
3
+ Version: 0.2.1
4
+ Summary: Obtain short-lived, least-privilege credentials from Vault via AppRole without ever passing a Vault token across a process boundary
5
+ Author-email: liozzazhang <liozza@163.com>
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/liozzazhang/vault-approle-toolkit
8
+ Project-URL: Changelog, https://github.com/liozzazhang/vault-approle-toolkit/blob/main/CHANGELOG.md
9
+ Project-URL: Issues, https://github.com/liozzazhang/vault-approle-toolkit/issues
10
+ Project-URL: Releases, https://github.com/liozzazhang/vault-approle-toolkit/releases
11
+ Keywords: vault,approle,aws,ecr,credentials
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.8
14
+ Classifier: Topic :: Security
15
+ Requires-Python: >=3.8
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Provides-Extra: aws
19
+ Requires-Dist: boto3>=1.26; extra == "aws"
20
+ Provides-Extra: yaml
21
+ Requires-Dist: PyYAML>=5.1; extra == "yaml"
22
+ Provides-Extra: ansible
23
+ Requires-Dist: ansible-core>=2.14; extra == "ansible"
24
+ Provides-Extra: dev
25
+ Requires-Dist: pytest>=7.0; extra == "dev"
26
+ Requires-Dist: pytest-cov; extra == "dev"
27
+ Requires-Dist: moto[ecr,sts]>=4.0; extra == "dev"
28
+ Requires-Dist: boto3>=1.26; extra == "dev"
29
+ Requires-Dist: PyYAML>=5.1; extra == "dev"
30
+ Requires-Dist: ruff; extra == "dev"
31
+ Requires-Dist: twine; extra == "dev"
32
+ Requires-Dist: ansible-core>=2.15; extra == "dev"
33
+ Dynamic: license-file
34
+
35
+ # vault-approle-toolkit
36
+
37
+ Short-lived, least-privilege credentials from Vault — without ever passing a
38
+ Vault token across a process boundary.
39
+
40
+ It replaces a long-lived `VAULT_TOKEN` stored as a CI secret, or a setup job
41
+ that logs in and exports one for every later step to inherit, with a single
42
+ wrapped command.
43
+
44
+ ## Quick start
45
+
46
+ Push to AWS ECR with a credential that exists only while `docker push` runs.
47
+
48
+ ```bash
49
+ pip install 'vault-approle-toolkit[aws]'
50
+ ```
51
+
52
+ Describe your Vault once, in `vault-approle.json` in the working directory or
53
+ in `~/.config/vault-approle/config.json`:
54
+
55
+ ```json
56
+ {
57
+ "version": 1,
58
+ "profiles": {
59
+ "default": {
60
+ "vault": {
61
+ "addr": "https://vault.example.com:8200",
62
+ "auth_path": "approle",
63
+ "role_id": "your-role-id"
64
+ },
65
+ "provider": {
66
+ "name": "aws.ecr",
67
+ "role": "ci-ecr-readwrite",
68
+ "region": "us-east-2"
69
+ }
70
+ }
71
+ }
72
+ }
73
+ ```
74
+
75
+ Then supply the SecretID and run:
76
+
77
+ ```bash
78
+ export VAULT_SECRET_ID=... # from your CI secret store
79
+ vault-approle doctor # checks every layer, names the one that fails
80
+ vault-approle run -- docker push "$IMAGE"
81
+ ```
82
+
83
+ `run` logs in with the AppRole, issues an ECR credential, runs the command
84
+ against an isolated docker config, and revokes everything on the way out. The
85
+ Vault token never leaves the process, and `VAULT_*` is stripped from the child.
86
+
87
+ | Field | Meaning |
88
+ | --- | --- |
89
+ | `vault.addr` | your Vault server |
90
+ | `vault.auth_path` | where the AppRole auth method is enabled (`approle` unless you chose otherwise) |
91
+ | `vault.role_id` | the AppRole's RoleID. An identifier rather than a secret, so it can live in the file |
92
+ | `provider.role` | the role in Vault's AWS secrets engine |
93
+ | `provider.region` | the registry's AWS region |
94
+
95
+ Optional: `vault.namespace` (Vault Enterprise), `provider.engine_mount` (default
96
+ `aws`), `provider.registry_id` (default: the account of the assumed role).
97
+
98
+ The SecretID is the only secret, and the file rejects one if you put it there.
99
+ It can also come from `--secret-id-file` or a response-wrapping token; see
100
+ [identity.md][identity].
101
+
102
+ ## More examples
103
+
104
+ Each is a complete, runnable file:
105
+
106
+ | Example | Shows |
107
+ | --- | --- |
108
+ | [Jenkinsfile][ex-jenkins] | replacing a stored `VAULT_TOKEN` in a pipeline |
109
+ | [.gitlab-ci.yml][ex-gitlab] | the same, plus a wrapped SecretID as a deploy trigger |
110
+ | [build-and-push.sh][ex-shell] | `run` versus credentials in the current shell, and branching on exit codes |
111
+ | [push_image.py][ex-python] | the Python API: `with` scoping and typed errors |
112
+ | [playbook.yml][ex-ansible] | the Ansible role, plus five other shapes |
113
+ | [Dockerfile][ex-docker] | adding the toolkit to an image with no pip at build time |
114
+
115
+ They use the built-in `example-ecr` profile, whose addresses are placeholders.
116
+ With the file above in place, drop `--profile example-ecr` (in Ansible, set
117
+ `vault_approle_profile: default`).
118
+
119
+ ## Install
120
+
121
+ ### The CLI and Python library
122
+
123
+ ```bash
124
+ pip install 'vault-approle-toolkit[aws]'
125
+ ```
126
+
127
+ Python ≥ 3.8. Drop `[aws]` if you only need Vault-side commands such as
128
+ `doctor`: the core has no dependencies at all. `[aws]` adds boto3.
129
+
130
+ ### The Ansible collection
131
+
132
+ On the **controller** only; managed targets need nothing but `docker` or
133
+ `podman`. Install the Python package first, with the `[ansible]` extra, so that
134
+ `ansible-galaxy` is the one in your virtualenv rather than a system install:
135
+
136
+ ```bash
137
+ V=0.2.1
138
+ pip install "vault-approle-toolkit[aws,ansible]==$V"
139
+ ansible-galaxy collection install \
140
+ "https://github.com/liozzazhang/vault-approle-toolkit/releases/download/vault-approle-toolkit.v$V/ops-vault-$V.tar.gz"
141
+ vault-approle version # core, collection and ansible-core, side by side
142
+ ```
143
+
144
+ The two are released together and only tested as a pair, so keep them on the
145
+ same version; `vault-approle version --check` exits non-zero if they differ.
146
+ ansible-core must be 2.14 or newer. The [collection README][collection] covers
147
+ Execution Environments and what to check when a play complains.
148
+
149
+ Every [release][releases] also carries the wheel, the collection tarball and
150
+ `SHA256SUMS`, for offline or verified installs.
151
+
152
+ ## How it works
153
+
154
+ The chain is **AppRole → Vault token → secrets engine role → short-lived
155
+ credential**. The Vault token in the middle is an intermediate value, not an
156
+ interface: the client holds a RoleID and a SecretID of its own, and the Vault
157
+ token is born, used and revoked inside a single process.
158
+
159
+ A SecretID is issued per consumer, with its own TTL, use count and CIDR
160
+ binding, and can be revoked without disturbing anyone else.
161
+
162
+ | You have | You use | Docs |
163
+ | --- | --- | --- |
164
+ | a shell script or CI job | `vault-approle run -- <cmd>` | [shell][int-shell] |
165
+ | Python code | `with approle_session(...) as s:` | [python][int-python] |
166
+ | an Ansible playbook | `role: ops.vault.aws_ecr_login` | [ansible][int-ansible] |
167
+ | a Dockerfile, no pip at build time | `COPY --from=vak /opt/vault-approle` | [image][int-image] |
168
+
169
+ All four are the same core. Behaviour, exit codes and guarantees are
170
+ identical, which is what [contract.md][contract] pins down.
171
+
172
+ ## When something breaks
173
+
174
+ Run `vault-approle doctor`. It walks the chain left to right — config, AppRole
175
+ login, Vault policy, AWS — prints `PASS`/`FAIL` with a hint for each layer, and
176
+ exits with the code of the first one that fails. Exit codes are the supported
177
+ interface for wrappers; [troubleshooting.md][troubleshooting] has one section
178
+ per code.
179
+
180
+ Configuration precedence is **CLI flag > environment variable > config file >
181
+ built-in profile**. A `VAULT_ADDR` left over in your shell silently outranks the
182
+ file, so `doctor` shows where every field came from and warns when something
183
+ was overridden.
184
+
185
+ ## What it guarantees
186
+
187
+ Four invariants, asserted by `tests/contract/scenarios.yaml` rather than
188
+ promised in prose:
189
+
190
+ 1. The token never leaves memory — not disk, not an environment variable, not
191
+ argv, not a log line, not any `--format` output.
192
+ 2. Inherited credential material is actively **stripped** from child
193
+ environments, not merely not added.
194
+ 3. The scope is the lifetime: normal return, exception, `SIGINT` and `SIGTERM`
195
+ all clean up. (`SIGKILL` cannot be caught; short TTLs are the answer.)
196
+ 4. Only what we created gets revoked. A caller-supplied token is never revoked.
197
+
198
+ ## Documentation
199
+
200
+ - [design/proposal.md][d-proposal] — why AppRole-issued, short-lived credentials, and who owns which layer
201
+ - [design/aws-ecr-detailed-design.md][d-ecr] — the ECR reference case end to end: objects, runtime sequence, permission layers, Vault configuration
202
+ - [contract.md][contract] — invariants, exit codes, profile schema, output formats
203
+ - [architecture.md][d-architecture] — layout and the decisions behind it
204
+ - [identity.md][identity] — RoleID and SecretID: where each comes from, and why not rotation
205
+ - [troubleshooting.md][troubleshooting] — one section per exit code
206
+ - [releasing.md][d-releasing] — one product, three delivery vehicles, and how their versions stay aligned
207
+ - [ansible-design.md][d-ansible] — why all Vault work is controller-side, and what Ansible's forking model rules out
208
+ - [vault-policy-recommendations.md][d-policy] — two policy issues that need the Vault owners
209
+
210
+ ## Development
211
+
212
+ ```console
213
+ $ make dev # venv + editable install with dev extras
214
+ $ make lint # ruff, shellcheck, ansible-lint, ansible-test sanity
215
+ $ make test # pytest (unit + contract) and bats
216
+ $ make image-verify # build the artifact and run it under python 3.8/3.9/3.12
217
+ ```
218
+
219
+ ## Status
220
+
221
+ Phase one: AWS ECR. `aws.sts` and `aws.ecr` are implemented; other providers
222
+ are registered as placeholders that fail with exit code 50 and a clear message
223
+ rather than an import error. Adding one means implementing `issue()` and
224
+ registering it — see [architecture.md][d-architecture].
225
+
226
+ <!-- Absolute links: this file is also the PyPI project page. -->
227
+ [releases]: https://github.com/liozzazhang/vault-approle-toolkit/releases
228
+ [collection]: https://github.com/liozzazhang/vault-approle-toolkit/blob/main/ansible_collections/ops/vault/README.md
229
+ [ex-jenkins]: https://github.com/liozzazhang/vault-approle-toolkit/blob/main/examples/jenkins/Jenkinsfile
230
+ [ex-gitlab]: https://github.com/liozzazhang/vault-approle-toolkit/blob/main/examples/gitlab/.gitlab-ci.yml
231
+ [ex-shell]: https://github.com/liozzazhang/vault-approle-toolkit/blob/main/examples/shell/build-and-push.sh
232
+ [ex-python]: https://github.com/liozzazhang/vault-approle-toolkit/blob/main/examples/python/push_image.py
233
+ [ex-ansible]: https://github.com/liozzazhang/vault-approle-toolkit/blob/main/examples/ansible/playbook.yml
234
+ [ex-docker]: https://github.com/liozzazhang/vault-approle-toolkit/blob/main/examples/dockerfile/Dockerfile
235
+ [int-shell]: https://github.com/liozzazhang/vault-approle-toolkit/blob/main/docs/integration-shell.md
236
+ [int-python]: https://github.com/liozzazhang/vault-approle-toolkit/blob/main/docs/integration-python.md
237
+ [int-ansible]: https://github.com/liozzazhang/vault-approle-toolkit/blob/main/docs/integration-ansible.md
238
+ [int-image]: https://github.com/liozzazhang/vault-approle-toolkit/blob/main/docs/integration-image.md
239
+ [contract]: https://github.com/liozzazhang/vault-approle-toolkit/blob/main/docs/contract.md
240
+ [identity]: https://github.com/liozzazhang/vault-approle-toolkit/blob/main/docs/identity.md
241
+ [troubleshooting]: https://github.com/liozzazhang/vault-approle-toolkit/blob/main/docs/troubleshooting.md
242
+ [d-proposal]: https://github.com/liozzazhang/vault-approle-toolkit/blob/main/docs/design/proposal.md
243
+ [d-ecr]: https://github.com/liozzazhang/vault-approle-toolkit/blob/main/docs/design/aws-ecr-detailed-design.md
244
+ [d-architecture]: https://github.com/liozzazhang/vault-approle-toolkit/blob/main/docs/architecture.md
245
+ [d-releasing]: https://github.com/liozzazhang/vault-approle-toolkit/blob/main/docs/releasing.md
246
+ [d-ansible]: https://github.com/liozzazhang/vault-approle-toolkit/blob/main/docs/ansible-design.md
247
+ [d-policy]: https://github.com/liozzazhang/vault-approle-toolkit/blob/main/docs/vault-policy-recommendations.md
@@ -0,0 +1,213 @@
1
+ # vault-approle-toolkit
2
+
3
+ Short-lived, least-privilege credentials from Vault — without ever passing a
4
+ Vault token across a process boundary.
5
+
6
+ It replaces a long-lived `VAULT_TOKEN` stored as a CI secret, or a setup job
7
+ that logs in and exports one for every later step to inherit, with a single
8
+ wrapped command.
9
+
10
+ ## Quick start
11
+
12
+ Push to AWS ECR with a credential that exists only while `docker push` runs.
13
+
14
+ ```bash
15
+ pip install 'vault-approle-toolkit[aws]'
16
+ ```
17
+
18
+ Describe your Vault once, in `vault-approle.json` in the working directory or
19
+ in `~/.config/vault-approle/config.json`:
20
+
21
+ ```json
22
+ {
23
+ "version": 1,
24
+ "profiles": {
25
+ "default": {
26
+ "vault": {
27
+ "addr": "https://vault.example.com:8200",
28
+ "auth_path": "approle",
29
+ "role_id": "your-role-id"
30
+ },
31
+ "provider": {
32
+ "name": "aws.ecr",
33
+ "role": "ci-ecr-readwrite",
34
+ "region": "us-east-2"
35
+ }
36
+ }
37
+ }
38
+ }
39
+ ```
40
+
41
+ Then supply the SecretID and run:
42
+
43
+ ```bash
44
+ export VAULT_SECRET_ID=... # from your CI secret store
45
+ vault-approle doctor # checks every layer, names the one that fails
46
+ vault-approle run -- docker push "$IMAGE"
47
+ ```
48
+
49
+ `run` logs in with the AppRole, issues an ECR credential, runs the command
50
+ against an isolated docker config, and revokes everything on the way out. The
51
+ Vault token never leaves the process, and `VAULT_*` is stripped from the child.
52
+
53
+ | Field | Meaning |
54
+ | --- | --- |
55
+ | `vault.addr` | your Vault server |
56
+ | `vault.auth_path` | where the AppRole auth method is enabled (`approle` unless you chose otherwise) |
57
+ | `vault.role_id` | the AppRole's RoleID. An identifier rather than a secret, so it can live in the file |
58
+ | `provider.role` | the role in Vault's AWS secrets engine |
59
+ | `provider.region` | the registry's AWS region |
60
+
61
+ Optional: `vault.namespace` (Vault Enterprise), `provider.engine_mount` (default
62
+ `aws`), `provider.registry_id` (default: the account of the assumed role).
63
+
64
+ The SecretID is the only secret, and the file rejects one if you put it there.
65
+ It can also come from `--secret-id-file` or a response-wrapping token; see
66
+ [identity.md][identity].
67
+
68
+ ## More examples
69
+
70
+ Each is a complete, runnable file:
71
+
72
+ | Example | Shows |
73
+ | --- | --- |
74
+ | [Jenkinsfile][ex-jenkins] | replacing a stored `VAULT_TOKEN` in a pipeline |
75
+ | [.gitlab-ci.yml][ex-gitlab] | the same, plus a wrapped SecretID as a deploy trigger |
76
+ | [build-and-push.sh][ex-shell] | `run` versus credentials in the current shell, and branching on exit codes |
77
+ | [push_image.py][ex-python] | the Python API: `with` scoping and typed errors |
78
+ | [playbook.yml][ex-ansible] | the Ansible role, plus five other shapes |
79
+ | [Dockerfile][ex-docker] | adding the toolkit to an image with no pip at build time |
80
+
81
+ They use the built-in `example-ecr` profile, whose addresses are placeholders.
82
+ With the file above in place, drop `--profile example-ecr` (in Ansible, set
83
+ `vault_approle_profile: default`).
84
+
85
+ ## Install
86
+
87
+ ### The CLI and Python library
88
+
89
+ ```bash
90
+ pip install 'vault-approle-toolkit[aws]'
91
+ ```
92
+
93
+ Python ≥ 3.8. Drop `[aws]` if you only need Vault-side commands such as
94
+ `doctor`: the core has no dependencies at all. `[aws]` adds boto3.
95
+
96
+ ### The Ansible collection
97
+
98
+ On the **controller** only; managed targets need nothing but `docker` or
99
+ `podman`. Install the Python package first, with the `[ansible]` extra, so that
100
+ `ansible-galaxy` is the one in your virtualenv rather than a system install:
101
+
102
+ ```bash
103
+ V=0.2.1
104
+ pip install "vault-approle-toolkit[aws,ansible]==$V"
105
+ ansible-galaxy collection install \
106
+ "https://github.com/liozzazhang/vault-approle-toolkit/releases/download/vault-approle-toolkit.v$V/ops-vault-$V.tar.gz"
107
+ vault-approle version # core, collection and ansible-core, side by side
108
+ ```
109
+
110
+ The two are released together and only tested as a pair, so keep them on the
111
+ same version; `vault-approle version --check` exits non-zero if they differ.
112
+ ansible-core must be 2.14 or newer. The [collection README][collection] covers
113
+ Execution Environments and what to check when a play complains.
114
+
115
+ Every [release][releases] also carries the wheel, the collection tarball and
116
+ `SHA256SUMS`, for offline or verified installs.
117
+
118
+ ## How it works
119
+
120
+ The chain is **AppRole → Vault token → secrets engine role → short-lived
121
+ credential**. The Vault token in the middle is an intermediate value, not an
122
+ interface: the client holds a RoleID and a SecretID of its own, and the Vault
123
+ token is born, used and revoked inside a single process.
124
+
125
+ A SecretID is issued per consumer, with its own TTL, use count and CIDR
126
+ binding, and can be revoked without disturbing anyone else.
127
+
128
+ | You have | You use | Docs |
129
+ | --- | --- | --- |
130
+ | a shell script or CI job | `vault-approle run -- <cmd>` | [shell][int-shell] |
131
+ | Python code | `with approle_session(...) as s:` | [python][int-python] |
132
+ | an Ansible playbook | `role: ops.vault.aws_ecr_login` | [ansible][int-ansible] |
133
+ | a Dockerfile, no pip at build time | `COPY --from=vak /opt/vault-approle` | [image][int-image] |
134
+
135
+ All four are the same core. Behaviour, exit codes and guarantees are
136
+ identical, which is what [contract.md][contract] pins down.
137
+
138
+ ## When something breaks
139
+
140
+ Run `vault-approle doctor`. It walks the chain left to right — config, AppRole
141
+ login, Vault policy, AWS — prints `PASS`/`FAIL` with a hint for each layer, and
142
+ exits with the code of the first one that fails. Exit codes are the supported
143
+ interface for wrappers; [troubleshooting.md][troubleshooting] has one section
144
+ per code.
145
+
146
+ Configuration precedence is **CLI flag > environment variable > config file >
147
+ built-in profile**. A `VAULT_ADDR` left over in your shell silently outranks the
148
+ file, so `doctor` shows where every field came from and warns when something
149
+ was overridden.
150
+
151
+ ## What it guarantees
152
+
153
+ Four invariants, asserted by `tests/contract/scenarios.yaml` rather than
154
+ promised in prose:
155
+
156
+ 1. The token never leaves memory — not disk, not an environment variable, not
157
+ argv, not a log line, not any `--format` output.
158
+ 2. Inherited credential material is actively **stripped** from child
159
+ environments, not merely not added.
160
+ 3. The scope is the lifetime: normal return, exception, `SIGINT` and `SIGTERM`
161
+ all clean up. (`SIGKILL` cannot be caught; short TTLs are the answer.)
162
+ 4. Only what we created gets revoked. A caller-supplied token is never revoked.
163
+
164
+ ## Documentation
165
+
166
+ - [design/proposal.md][d-proposal] — why AppRole-issued, short-lived credentials, and who owns which layer
167
+ - [design/aws-ecr-detailed-design.md][d-ecr] — the ECR reference case end to end: objects, runtime sequence, permission layers, Vault configuration
168
+ - [contract.md][contract] — invariants, exit codes, profile schema, output formats
169
+ - [architecture.md][d-architecture] — layout and the decisions behind it
170
+ - [identity.md][identity] — RoleID and SecretID: where each comes from, and why not rotation
171
+ - [troubleshooting.md][troubleshooting] — one section per exit code
172
+ - [releasing.md][d-releasing] — one product, three delivery vehicles, and how their versions stay aligned
173
+ - [ansible-design.md][d-ansible] — why all Vault work is controller-side, and what Ansible's forking model rules out
174
+ - [vault-policy-recommendations.md][d-policy] — two policy issues that need the Vault owners
175
+
176
+ ## Development
177
+
178
+ ```console
179
+ $ make dev # venv + editable install with dev extras
180
+ $ make lint # ruff, shellcheck, ansible-lint, ansible-test sanity
181
+ $ make test # pytest (unit + contract) and bats
182
+ $ make image-verify # build the artifact and run it under python 3.8/3.9/3.12
183
+ ```
184
+
185
+ ## Status
186
+
187
+ Phase one: AWS ECR. `aws.sts` and `aws.ecr` are implemented; other providers
188
+ are registered as placeholders that fail with exit code 50 and a clear message
189
+ rather than an import error. Adding one means implementing `issue()` and
190
+ registering it — see [architecture.md][d-architecture].
191
+
192
+ <!-- Absolute links: this file is also the PyPI project page. -->
193
+ [releases]: https://github.com/liozzazhang/vault-approle-toolkit/releases
194
+ [collection]: https://github.com/liozzazhang/vault-approle-toolkit/blob/main/ansible_collections/ops/vault/README.md
195
+ [ex-jenkins]: https://github.com/liozzazhang/vault-approle-toolkit/blob/main/examples/jenkins/Jenkinsfile
196
+ [ex-gitlab]: https://github.com/liozzazhang/vault-approle-toolkit/blob/main/examples/gitlab/.gitlab-ci.yml
197
+ [ex-shell]: https://github.com/liozzazhang/vault-approle-toolkit/blob/main/examples/shell/build-and-push.sh
198
+ [ex-python]: https://github.com/liozzazhang/vault-approle-toolkit/blob/main/examples/python/push_image.py
199
+ [ex-ansible]: https://github.com/liozzazhang/vault-approle-toolkit/blob/main/examples/ansible/playbook.yml
200
+ [ex-docker]: https://github.com/liozzazhang/vault-approle-toolkit/blob/main/examples/dockerfile/Dockerfile
201
+ [int-shell]: https://github.com/liozzazhang/vault-approle-toolkit/blob/main/docs/integration-shell.md
202
+ [int-python]: https://github.com/liozzazhang/vault-approle-toolkit/blob/main/docs/integration-python.md
203
+ [int-ansible]: https://github.com/liozzazhang/vault-approle-toolkit/blob/main/docs/integration-ansible.md
204
+ [int-image]: https://github.com/liozzazhang/vault-approle-toolkit/blob/main/docs/integration-image.md
205
+ [contract]: https://github.com/liozzazhang/vault-approle-toolkit/blob/main/docs/contract.md
206
+ [identity]: https://github.com/liozzazhang/vault-approle-toolkit/blob/main/docs/identity.md
207
+ [troubleshooting]: https://github.com/liozzazhang/vault-approle-toolkit/blob/main/docs/troubleshooting.md
208
+ [d-proposal]: https://github.com/liozzazhang/vault-approle-toolkit/blob/main/docs/design/proposal.md
209
+ [d-ecr]: https://github.com/liozzazhang/vault-approle-toolkit/blob/main/docs/design/aws-ecr-detailed-design.md
210
+ [d-architecture]: https://github.com/liozzazhang/vault-approle-toolkit/blob/main/docs/architecture.md
211
+ [d-releasing]: https://github.com/liozzazhang/vault-approle-toolkit/blob/main/docs/releasing.md
212
+ [d-ansible]: https://github.com/liozzazhang/vault-approle-toolkit/blob/main/docs/ansible-design.md
213
+ [d-policy]: https://github.com/liozzazhang/vault-approle-toolkit/blob/main/docs/vault-policy-recommendations.md
@@ -0,0 +1 @@
1
+ 0.2.1