labagent 0.1.0__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.
- labagent-0.1.0/CONTRIBUTING.md +15 -0
- labagent-0.1.0/LICENSE +202 -0
- labagent-0.1.0/MANIFEST.in +10 -0
- labagent-0.1.0/PKG-INFO +73 -0
- labagent-0.1.0/README.md +37 -0
- labagent-0.1.0/SECURITY.md +19 -0
- labagent-0.1.0/docs/account-cleanup.md +67 -0
- labagent-0.1.0/docs/e2e-test-plan.md +81 -0
- labagent-0.1.0/docs/examples/oidc-trust-policy.example.json +16 -0
- labagent-0.1.0/docs/examples/permissions-read.example.json +16 -0
- labagent-0.1.0/docs/examples/permissions-write.example.json +41 -0
- labagent-0.1.0/docs/examples/runner-workflow.example.yml +101 -0
- labagent-0.1.0/docs/job-contract.md +46 -0
- labagent-0.1.0/docs/state-and-secrets.md +60 -0
- labagent-0.1.0/examples/config.example.json +17 -0
- labagent-0.1.0/examples/rulesets/legacy-cleanup.example.json +16 -0
- labagent-0.1.0/labagent/__init__.py +3 -0
- labagent-0.1.0/labagent/audit.py +233 -0
- labagent-0.1.0/labagent/cleanup.py +67 -0
- labagent-0.1.0/labagent/cli.py +63 -0
- labagent-0.1.0/labagent/config.py +82 -0
- labagent-0.1.0/labagent/context.py +51 -0
- labagent-0.1.0/labagent/deleters.py +507 -0
- labagent-0.1.0/labagent/discovery.py +162 -0
- labagent-0.1.0/labagent/envelope.py +48 -0
- labagent-0.1.0/labagent/iam_ops.py +133 -0
- labagent-0.1.0/labagent/plan.py +40 -0
- labagent-0.1.0/labagent/rules.py +153 -0
- labagent-0.1.0/labagent/run.py +58 -0
- labagent-0.1.0/labagent/secrets_box.py +36 -0
- labagent-0.1.0/labagent/sweep.py +107 -0
- labagent-0.1.0/labagent/terraform/cohort_iam/.terraform.lock.hcl +29 -0
- labagent-0.1.0/labagent/terraform/cohort_iam/main.tf +101 -0
- labagent-0.1.0/labagent/terraform/cohort_iam/outputs.tf +21 -0
- labagent-0.1.0/labagent/terraform/cohort_iam/sandbox-policy.json.tftpl +33 -0
- labagent-0.1.0/labagent/terraform/cohort_iam/tests/cohort.tftest.hcl +63 -0
- labagent-0.1.0/labagent/terraform/cohort_iam/variables.tf +55 -0
- labagent-0.1.0/labagent/terraform/cohort_iam/versions.tf +15 -0
- labagent-0.1.0/labagent/terraform/state_backend/.terraform.lock.hcl +26 -0
- labagent-0.1.0/labagent/terraform/state_backend/main.tf +193 -0
- labagent-0.1.0/labagent/terraform/state_backend/tests/bootstrap.tftest.hcl +37 -0
- labagent-0.1.0/labagent/tf.py +118 -0
- labagent-0.1.0/labagent.egg-info/PKG-INFO +73 -0
- labagent-0.1.0/labagent.egg-info/SOURCES.txt +60 -0
- labagent-0.1.0/labagent.egg-info/dependency_links.txt +1 -0
- labagent-0.1.0/labagent.egg-info/entry_points.txt +3 -0
- labagent-0.1.0/labagent.egg-info/requires.txt +8 -0
- labagent-0.1.0/labagent.egg-info/top_level.txt +1 -0
- labagent-0.1.0/pyproject.toml +63 -0
- labagent-0.1.0/scripts/check_no_pii.py +48 -0
- labagent-0.1.0/scripts/make_test_job.py +45 -0
- labagent-0.1.0/setup.cfg +4 -0
- labagent-0.1.0/tests/__init__.py +0 -0
- labagent-0.1.0/tests/conftest.py +76 -0
- labagent-0.1.0/tests/test_classify.py +65 -0
- labagent-0.1.0/tests/test_cleanup.py +347 -0
- labagent-0.1.0/tests/test_cloudfront_and_cli.py +115 -0
- labagent-0.1.0/tests/test_iam_ops.py +176 -0
- labagent-0.1.0/tests/test_plan.py +35 -0
- labagent-0.1.0/tests/test_repo_hygiene.py +45 -0
- labagent-0.1.0/tests/test_sweep_moto.py +146 -0
- labagent-0.1.0/tests/test_tf_wrapper.py +145 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
- Fork, branch, open a PR. CI runs unit tests against mocked AWS (`moto`). It has no secrets and never touches real AWS.
|
|
4
|
+
- Add a deleter: implement it in `labagent/deleters.py` (idempotent, returns `Result`), register it in `REGISTRY` with an order,
|
|
5
|
+
add an ARN parse case in `labagent/discovery.py` and a moto test.
|
|
6
|
+
- Do not add organisation-specific values (account IDs, names, domains) to code or examples. Use `example.com` and `123456789012`.
|
|
7
|
+
- Run `python scripts/check_no_pii.py` and `pytest` before pushing.
|
|
8
|
+
- Changes under `labagent/`, `scripts/` and `.github/` need a maintainer review (see CODEOWNERS).
|
|
9
|
+
|
|
10
|
+
## Releasing (maintainers)
|
|
11
|
+
|
|
12
|
+
1. Bump `__version__` in `labagent/__init__.py` and update the changelog notes in the PR.
|
|
13
|
+
2. Merge, then tag `vX.Y.Z` on `main`. The `release` workflow builds, runs `twine check --strict`, verifies the tag matches
|
|
14
|
+
the version and publishes to PyPI via Trusted Publishing (no tokens). Use the manual run with `testpypi` first for a dry run.
|
|
15
|
+
3. One-time: on pypi.org add a (pending) publisher for `becloudready/labagent`, workflow `release.yml`, environment `pypi`.
|
labagent-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
include LICENSE README.md SECURITY.md CONTRIBUTING.md
|
|
2
|
+
recursive-include docs *.md *.yml *.json
|
|
3
|
+
recursive-include examples *.json
|
|
4
|
+
recursive-include scripts *.py
|
|
5
|
+
recursive-include tests *.py
|
|
6
|
+
recursive-include labagent/terraform *.tf *.tftpl *.hcl
|
|
7
|
+
# never ship operational data or state
|
|
8
|
+
global-exclude *.tfstate *.tfstate.* *.tfvars *.pem job*.json result*.json plan*.json lab.json *.pyc
|
|
9
|
+
prune .venv
|
|
10
|
+
prune build
|
labagent-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: labagent
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Provision, audit and safely tear down ephemeral AWS sandboxes for workshops, bootcamps and shared training accounts.
|
|
5
|
+
Author: BeCloudReady
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/becloudready/labagent
|
|
8
|
+
Project-URL: Source, https://github.com/becloudready/labagent
|
|
9
|
+
Project-URL: Issues, https://github.com/becloudready/labagent/issues
|
|
10
|
+
Project-URL: Documentation, https://github.com/becloudready/labagent/tree/main/docs
|
|
11
|
+
Keywords: aws,training,workshop,sandbox,cleanup,iam,terraform,finops,boto3
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Education
|
|
16
|
+
Classifier: Intended Audience :: System Administrators
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Topic :: Software Development :: Build Tools
|
|
24
|
+
Classifier: Topic :: System :: Systems Administration
|
|
25
|
+
Requires-Python: >=3.9
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
Requires-Dist: boto3>=1.34
|
|
29
|
+
Requires-Dist: cryptography>=42
|
|
30
|
+
Provides-Extra: dev
|
|
31
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
32
|
+
Requires-Dist: moto[all]>=5; extra == "dev"
|
|
33
|
+
Requires-Dist: build>=1.2; extra == "dev"
|
|
34
|
+
Requires-Dist: twine>=5; extra == "dev"
|
|
35
|
+
Dynamic: license-file
|
|
36
|
+
|
|
37
|
+
# labagent
|
|
38
|
+
|
|
39
|
+
Provision, audit and **safely tear down** ephemeral AWS sandboxes for workshops, bootcamps and shared training accounts.
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install labagent # Python 3.9+; Terraform or OpenTofu >= 1.11 for the cohort IAM layer
|
|
43
|
+
labagent --version
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Commands
|
|
47
|
+
|
|
48
|
+
| Command | What it does |
|
|
49
|
+
|---|---|
|
|
50
|
+
| `provision` | Terraform creates a cohort's IAM users, group, sandbox policy and Lambda role. Passwords are issued afterwards and returned **encrypted** to your public key, so state holds no secrets |
|
|
51
|
+
| `inventory`, `sweep` | List and delete what learners created. Plan first, then apply exactly that reviewed plan |
|
|
52
|
+
| `reset`, `offboard` | Rotate a learner's password; destroy a cohort (refuses while resources remain) |
|
|
53
|
+
| `audit`, `cleanup` | Clean an untagged, long-lived account from an explicit **ruleset** ([docs](docs/account-cleanup.md)) |
|
|
54
|
+
|
|
55
|
+
## Safety
|
|
56
|
+
|
|
57
|
+
- Plan, then apply: the plan is bound to the account, its items, an age limit and the hash a human approved.
|
|
58
|
+
- Only a `delete` rule can delete. `keep` rules always win; anything unmatched is reported, never removed.
|
|
59
|
+
- Refuses to run in an account that is not on your allow-list. Re-running is always safe.
|
|
60
|
+
- No plaintext secrets or emails in output or logs, and no PII in this repo (enforced by tests).
|
|
61
|
+
|
|
62
|
+
## Use
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
cp examples/config.example.json lab.json # set allowed_account_ids and the S3 state backend
|
|
66
|
+
labagent --config lab.json run --job job.json --output result.json
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Job and result formats: [docs/job-contract.md](docs/job-contract.md). State and secrets: [docs/state-and-secrets.md](docs/state-and-secrets.md).
|
|
70
|
+
Run it from a **private** CI repo with GitHub OIDC (examples in [docs/examples](docs/examples)), never from a public one.
|
|
71
|
+
Keep real configs, rosters, rulesets and job/result files out of this repo; `.gitignore` blocks the usual names.
|
|
72
|
+
|
|
73
|
+
Early release (v0.1), tested against mocked AWS: try a throwaway account first. Apache-2.0; see [SECURITY.md](SECURITY.md) and [CONTRIBUTING.md](CONTRIBUTING.md).
|
labagent-0.1.0/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# labagent
|
|
2
|
+
|
|
3
|
+
Provision, audit and **safely tear down** ephemeral AWS sandboxes for workshops, bootcamps and shared training accounts.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
pip install labagent # Python 3.9+; Terraform or OpenTofu >= 1.11 for the cohort IAM layer
|
|
7
|
+
labagent --version
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Commands
|
|
11
|
+
|
|
12
|
+
| Command | What it does |
|
|
13
|
+
|---|---|
|
|
14
|
+
| `provision` | Terraform creates a cohort's IAM users, group, sandbox policy and Lambda role. Passwords are issued afterwards and returned **encrypted** to your public key, so state holds no secrets |
|
|
15
|
+
| `inventory`, `sweep` | List and delete what learners created. Plan first, then apply exactly that reviewed plan |
|
|
16
|
+
| `reset`, `offboard` | Rotate a learner's password; destroy a cohort (refuses while resources remain) |
|
|
17
|
+
| `audit`, `cleanup` | Clean an untagged, long-lived account from an explicit **ruleset** ([docs](docs/account-cleanup.md)) |
|
|
18
|
+
|
|
19
|
+
## Safety
|
|
20
|
+
|
|
21
|
+
- Plan, then apply: the plan is bound to the account, its items, an age limit and the hash a human approved.
|
|
22
|
+
- Only a `delete` rule can delete. `keep` rules always win; anything unmatched is reported, never removed.
|
|
23
|
+
- Refuses to run in an account that is not on your allow-list. Re-running is always safe.
|
|
24
|
+
- No plaintext secrets or emails in output or logs, and no PII in this repo (enforced by tests).
|
|
25
|
+
|
|
26
|
+
## Use
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
cp examples/config.example.json lab.json # set allowed_account_ids and the S3 state backend
|
|
30
|
+
labagent --config lab.json run --job job.json --output result.json
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Job and result formats: [docs/job-contract.md](docs/job-contract.md). State and secrets: [docs/state-and-secrets.md](docs/state-and-secrets.md).
|
|
34
|
+
Run it from a **private** CI repo with GitHub OIDC (examples in [docs/examples](docs/examples)), never from a public one.
|
|
35
|
+
Keep real configs, rosters, rulesets and job/result files out of this repo; `.gitignore` blocks the usual names.
|
|
36
|
+
|
|
37
|
+
Early release (v0.1), tested against mocked AWS: try a throwaway account first. Apache-2.0; see [SECURITY.md](SECURITY.md) and [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Security
|
|
2
|
+
|
|
3
|
+
`labagent` deletes cloud resources and handles credentials. Please report vulnerabilities privately through
|
|
4
|
+
GitHub's "Report a vulnerability" (Security tab), not in a public issue.
|
|
5
|
+
|
|
6
|
+
## Design guarantees (and how they are tested)
|
|
7
|
+
|
|
8
|
+
- Destructive actions are plan-then-apply with an integrity hash (`tests/test_plan.py`, `tests/test_sweep_moto.py`).
|
|
9
|
+
- Account allow-list is mandatory (`test_account_guard`, `test_empty_allowlist_refuses`).
|
|
10
|
+
- Passwords are only emitted RSA-OAEP encrypted (`tests/test_iam_ops.py`) and never enter Terraform state (the module declares no login profile; `tests/test_tf_wrapper.py`).
|
|
11
|
+
- State lives in a private, versioned, KMS-encrypted S3 bucket created by the packaged `state_backend` module (`labagent bootstrap-path`); no backend values are committed.
|
|
12
|
+
- Logs contain no emails (`test_logs_contain_no_emails`). The repo contains no PII or secrets (`scripts/check_no_pii.py`).
|
|
13
|
+
|
|
14
|
+
## Operating it safely
|
|
15
|
+
|
|
16
|
+
- Run it from a private repo using GitHub OIDC (see `docs/examples/`). Never from a public repo: run logs are public.
|
|
17
|
+
- Pin the commit you run (`LABAGENT_SHA`) and move the pin by reviewed PR.
|
|
18
|
+
- Use a dedicated AWS account for labs. Use separate read-only and write roles.
|
|
19
|
+
- Never commit rosters, credentials, Terraform state or job/result files. `.gitignore` blocks the common names.
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Cleaning up an existing account
|
|
2
|
+
|
|
3
|
+
For accounts that were never tagged consistently (shared accounts, years of workshop leftovers). The tag-driven cohort
|
|
4
|
+
`sweep` cannot help there, because it only finds what carries your tag. `audit` and `cleanup` work from a **ruleset**:
|
|
5
|
+
an explicit, reviewable statement of what may be deleted.
|
|
6
|
+
|
|
7
|
+
## Safety model: delete only what a rule says
|
|
8
|
+
|
|
9
|
+
Decision order for every discovered resource:
|
|
10
|
+
|
|
11
|
+
1. a `keep` rule matches: **keep** (always wins, regardless of rule order)
|
|
12
|
+
2. built-in protected name prefixes (CloudTrail, Config, CDK, ...): **keep**
|
|
13
|
+
3. a `delete` rule matches **and** `labagent` has a deleter for the type: **delete**
|
|
14
|
+
4. anything else: **review**. It is reported and never deleted.
|
|
15
|
+
|
|
16
|
+
So a forgotten resource type or a typo makes labagent delete *less*, not more. Empty `match` blocks and `delete` rules
|
|
17
|
+
without a type are rejected when the ruleset is loaded. A rule with `"enabled": false` stays in the file but has no effect.
|
|
18
|
+
|
|
19
|
+
## Ruleset
|
|
20
|
+
|
|
21
|
+
```json
|
|
22
|
+
{
|
|
23
|
+
"version": 1, "name": "legacy-cleanup",
|
|
24
|
+
"rules": [
|
|
25
|
+
{"id": "keep-admin", "action": "keep", "match": {"type": ["iam/user"], "name": ["admin_*"]}},
|
|
26
|
+
{"id": "old-keys", "action": "delete", "match": {"type": ["ec2/key-pair"], "older_than_days": 30}}
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Match keys (all must match; a list means any entry): `type` (`service/type`), `region`, `name` (glob, case-insensitive),
|
|
32
|
+
`id`, `name_regex`, `tags` (`{"Key": "glob"}`), `tags_absent`, `older_than_days`, `unused_days`, `attrs` (exact match on
|
|
33
|
+
discovered attributes such as `enabled`, `attachments`, `aliases`). See `labagent/rules.py` for the full contract and
|
|
34
|
+
`examples/rulesets/legacy-cleanup.example.json` for a starting point.
|
|
35
|
+
|
|
36
|
+
**Keep your real rulesets out of this public repo.** They contain your resource names. Store them in the private runner
|
|
37
|
+
repo (or the orchestrator) and pass them to the job.
|
|
38
|
+
|
|
39
|
+
## Workflow
|
|
40
|
+
|
|
41
|
+
| Step | Command | Changes AWS? |
|
|
42
|
+
|---|---|---|
|
|
43
|
+
| 1. Audit | job `{"command":"audit","options":{"regions":["us-east-1"]}}` with your ruleset | no |
|
|
44
|
+
| 2. Plan | `{"command":"cleanup","mode":"plan"}` | no. Returns a plan with an id and hash |
|
|
45
|
+
| 3. Review | read `items`: `delete`, `keep`, `review`, each with the rule that decided it | no |
|
|
46
|
+
| 4. Apply | `{"command":"cleanup","mode":"apply","plan":<plan>,"approved_hash":"<hash>"}` | yes: exactly the plan |
|
|
47
|
+
| 5. Repeat | `pending` items (CloudFront, CloudFormation, throttled calls) return a `retry_after_s`. Re-run apply later | yes |
|
|
48
|
+
| 6. Re-audit | step 1 again. Remaining `review` items become new rules, or stay | no |
|
|
49
|
+
|
|
50
|
+
Locally: `labagent --config lab.json run --job job.json --ruleset rules.json --output result.json`.
|
|
51
|
+
In CI: the same job through the private runner workflow (`docs/examples/runner-workflow.example.yml`); the orchestrator
|
|
52
|
+
supplies the ruleset in the job.
|
|
53
|
+
|
|
54
|
+
## Supported deleters
|
|
55
|
+
|
|
56
|
+
CloudFormation stacks, CloudFront, API Gateway (REST, HTTP), Lambda, EC2 instances, Elastic IPs, volumes, key pairs,
|
|
57
|
+
security groups, S3 (versions included), DynamoDB, CloudWatch log groups, SNS, SQS, Secrets Manager (7 day recovery),
|
|
58
|
+
ECR (force), IAM users, groups, roles and policies (detached from everything first).
|
|
59
|
+
|
|
60
|
+
Discovered but not deletable yet (reported as `review`, even if a rule matches): VPCs, NAT gateways, load balancers,
|
|
61
|
+
RDS, EKS/ECS, KMS aliases, Route 53.
|
|
62
|
+
|
|
63
|
+
## Order and dependencies
|
|
64
|
+
|
|
65
|
+
Applied in dependency order: stacks, CloudFront, APIs, Lambda, EC2, key pairs, security groups, S3, DynamoDB,
|
|
66
|
+
logs, messaging, secrets, ECR, then IAM users, groups, roles, policies. In-use resources return `pending` and a retry
|
|
67
|
+
hint; they never fail the run.
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# End-to-end test plan: onboarding a cohort of 10
|
|
2
|
+
|
|
3
|
+
Use a **throwaway or dedicated AWS account**, never the shared one. Cost: 10 IAM users are free; test resources cost cents.
|
|
4
|
+
Put a $20 AWS Budget alarm on the account first.
|
|
5
|
+
|
|
6
|
+
All fake data: `e2e-student-01..10@example.com`, cohort `e2e-001`, date `01-Jan-2030`.
|
|
7
|
+
|
|
8
|
+
## Stage A: engine only (no GitHub, no LMS). About 2 hours. Can be done today.
|
|
9
|
+
|
|
10
|
+
Setup
|
|
11
|
+
```bash
|
|
12
|
+
cd labagent && python3 -m venv .venv && .venv/bin/pip install -e ".[dev]" && source .venv/bin/activate
|
|
13
|
+
cp examples/config.example.json lab.json # set allowed_account_ids to the TEST account id; keep lab.json out of git
|
|
14
|
+
export AWS_PROFILE=<admin profile for the test account>
|
|
15
|
+
openssl genrsa -out priv.pem 2048 && openssl rsa -in priv.pem -pubout -out pub.pem
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
### A0: bootstrap the state backend (once per account)
|
|
19
|
+
|
|
20
|
+
Follow `docs/state-and-secrets.md`: run the state backend module (`cd "$(labagent bootstrap-path)"`) with your own caller ARN in `admin_principal_arns` and
|
|
21
|
+
`runner_principal_arns`, then copy `terraform output backend_config` into `lab.json` under `"backend"`.
|
|
22
|
+
Also set `"name_prefix": "e2e"` so the test group, policy and role are `e2e-e2e-001-students` etc. and cannot collide with
|
|
23
|
+
anything real. Terraform >= 1.11 must be installed (`terraform version`).
|
|
24
|
+
|
|
25
|
+
| # | Action | Expected |
|
|
26
|
+
|---|---|---|
|
|
27
|
+
| A1 | `python scripts/make_test_job.py --command provision --mode dry-run --cohort e2e-001 --date 01-Jan-2030 --pubkey pub.pem > job.json`, then `labagent --config lab.json run --job job.json --output result.json` | exit 0, 10 items `planned` (a real `terraform plan`, read-only: no lock, no state write), nothing in IAM |
|
|
28
|
+
| A2 | Same with no `--mode` (apply) | exit 0, 10 `created`, 10 `secrets` with ciphertext only. IAM shows 10 users, the cohort group, policy and Lambda role. S3 shows `cohorts/e2e-001/terraform.tfstate`: download it and confirm it contains **no password** |
|
|
29
|
+
| A3 | Decrypt one: `jq -r '.secrets[0].ciphertext' result.json \| base64 -d > ct.bin; openssl pkeyutl -decrypt -inkey priv.pem -in ct.bin -pkeyopt rsa_padding_mode:oaep -pkeyopt rsa_oaep_md:sha256 -pkeyopt rsa_mgf1_md:sha256` | prints a 20 char password. `grep` the result file for that password: no match |
|
|
30
|
+
| A4 | Re-run A2 | 10 `exists`, **0 secrets** (no password re-issued), exit 0 |
|
|
31
|
+
| A5 | Sign in to the console as student 01 with the decrypted password | forced to set a new password. Then: create an S3 bucket and a t3.micro EC2 (allowed); try us-west-2 (denied); try an m5.large (denied by the new instance-type rule, which is untested on real AWS) |
|
|
32
|
+
| A6 | As students 01 and 02, create resources named `student-e2e-student-01-*`: a Lambda and an S3 bucket, tagged `workshop=full-stack`, `autodelete=true`, `date=01-Jan-2030`. Add: one tagged `autodelete=false`, one with **no tags**, and an Elastic IP tagged like the others | all created |
|
|
33
|
+
| A7 | `make_test_job.py --command inventory ...` and run | per-learner counts for 01 and 02, the EIP present, untagged resource absent (known gap W4), exit 0 |
|
|
34
|
+
| A8 | `--command sweep --mode plan`, run | read-only (nothing deleted). `items` show `delete` for tagged resources, `skip` with reason for the `autodelete=false` one. Save `result.json` |
|
|
35
|
+
| A9 | Tamper: change one `skip` to `delete` in the plan, run `sweep --mode apply` | **refused**, exit 2, `plan hash mismatch`, nothing deleted |
|
|
36
|
+
| A10 | Apply the untouched plan with `--approved-hash <plan.hash>` | tagged resources gone, `autodelete=false` and untagged remain, exit 0 |
|
|
37
|
+
| A11 | Create a resource after the plan, apply the same plan again | the new resource survives (apply never rediscovers) |
|
|
38
|
+
| A12 | `reset --learner-id 3` | new ciphertext, old password stops working |
|
|
39
|
+
| A13 | Account guard: put a wrong id in `allowed_account_ids`, run any command | exit 2, refuses |
|
|
40
|
+
| A14 | Leave one tagged resource, run `offboard` | **refused**. Sweep it, run `offboard` again | 10 users, the cohort group, policy and Lambda role deleted by `terraform destroy`; the state bucket remains |
|
|
41
|
+
| A15 | Run offboard once more | exit 0, no changes (idempotent) |
|
|
42
|
+
| A16 | Run two provision jobs at the same time for the same cohort | the second waits for the S3 lock (up to 5 min) or fails cleanly; state is not corrupted |
|
|
43
|
+
|
|
44
|
+
CloudFront: create one distribution tagged as above, plan, apply, expect `pending` ("disabling"), re-run after about 15 to 30 minutes, expect `deleted`. REST API: create 3, expect throttled waits then `deleted` or `pending` with retry time.
|
|
45
|
+
|
|
46
|
+
## Stage B: runner repo with a stand-in orchestrator. About half a day, needs lms-new L1 to L3.
|
|
47
|
+
|
|
48
|
+
Prerequisites: private `labagent-runner` repo with `lab-job.yml` from `docs/examples/`, `config/lab.json`, the four repo variables; AWS OIDC provider and the two roles (trust policy pinned to repo and `main`); lms-new dev worker with the job and callback endpoints, the RSA private key, and a GitHub token limited to the runner repo.
|
|
49
|
+
|
|
50
|
+
| # | Check | Expected |
|
|
51
|
+
|---|---|---|
|
|
52
|
+
| B1 | Dispatch a provision run from the Worker | workflow starts, fetches job, assumes the **write** role, posts result; run `success` |
|
|
53
|
+
| B2 | Dispatch a sweep **plan** | assumes the **read** role (confirm in the run log) |
|
|
54
|
+
| B3 | Fetch the same job twice | second fetch rejected |
|
|
55
|
+
| B4 | Call the job endpoint with a token from a different repo or branch | rejected (`repository`, `ref` claims) |
|
|
56
|
+
| B5 | Post the callback twice | second is a no-op (idempotent by run id) |
|
|
57
|
+
| B6 | Dispatch two runs at once | they serialise (concurrency group) |
|
|
58
|
+
| B7 | Read the run log and download any artifacts | **no emails, no passwords**, no artifacts; `job.json`/`result.json` removed |
|
|
59
|
+
| B8 | Apply with a plan whose hash was not approved | refused |
|
|
60
|
+
| B9 | Break `LABAGENT_SHA` to a wrong value | job fails before AWS is touched |
|
|
61
|
+
|
|
62
|
+
## Stage C: the 10-student dashboard flow. About half a day, needs lms-new L4 to L10.
|
|
63
|
+
|
|
64
|
+
1. Import 10 learners into a batch (bulk import).
|
|
65
|
+
2. Create the lab environment, run **provision dry-run**, review, approve, apply.
|
|
66
|
+
3. Each learner opens "My Lab": sees console URL and username, reveals the password **once**; a second reveal is blocked; the ciphertext is purged after the retention period.
|
|
67
|
+
4. Three learners really sign in and deploy a project; one hits a problem and uses reset.
|
|
68
|
+
5. Inventory view: per-learner counts, unattributed list.
|
|
69
|
+
6. Environment end date: sweep plan appears for approval, admin approves, apply runs, pending CloudFront items are retried by the dashboard, then offboard.
|
|
70
|
+
7. Audit log has one entry per action with actor and plan hash. Trainer role can view but not approve.
|
|
71
|
+
|
|
72
|
+
## Pass criteria
|
|
73
|
+
|
|
74
|
+
- Zero plaintext passwords anywhere (results, logs, artifacts, D1 rows).
|
|
75
|
+
- Zero resources deleted that were not in the approved plan.
|
|
76
|
+
- Account is clean afterwards: no users, no tagged resources, no Elastic IPs, no CloudFront.
|
|
77
|
+
- Every step is re-runnable without harm.
|
|
78
|
+
|
|
79
|
+
## Known gaps to expect
|
|
80
|
+
|
|
81
|
+
Untagged resources are not found (W4); no cost report; ECR, NAT, load balancers and IAM roles are not swept.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Version": "2012-10-17",
|
|
3
|
+
"Statement": [
|
|
4
|
+
{
|
|
5
|
+
"Effect": "Allow",
|
|
6
|
+
"Principal": { "Federated": "arn:aws:iam::123456789012:oidc-provider/token.actions.githubusercontent.com" },
|
|
7
|
+
"Action": "sts:AssumeRoleWithWebIdentity",
|
|
8
|
+
"Condition": {
|
|
9
|
+
"StringEquals": {
|
|
10
|
+
"token.actions.githubusercontent.com:aud": "sts.amazonaws.com",
|
|
11
|
+
"token.actions.githubusercontent.com:sub": "repo:YOUR-ORG/YOUR-PRIVATE-RUNNER-REPO:ref:refs/heads/main"
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
]
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Version": "2012-10-17",
|
|
3
|
+
"Statement": [
|
|
4
|
+
{
|
|
5
|
+
"Sid": "ReadOnlyDiscovery",
|
|
6
|
+
"Effect": "Allow",
|
|
7
|
+
"Action": [
|
|
8
|
+
"sts:GetCallerIdentity",
|
|
9
|
+
"tag:GetResources",
|
|
10
|
+
"ec2:DescribeAddresses", "ec2:DescribeVolumes", "ec2:DescribeSecurityGroups", "ec2:DescribeInstances",
|
|
11
|
+
"cloudfront:GetDistribution", "cloudfront:GetDistributionConfig", "cloudfront:ListDistributions"
|
|
12
|
+
],
|
|
13
|
+
"Resource": "*"
|
|
14
|
+
}
|
|
15
|
+
]
|
|
16
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Version": "2012-10-17",
|
|
3
|
+
"Statement": [
|
|
4
|
+
{
|
|
5
|
+
"Sid": "Discovery",
|
|
6
|
+
"Effect": "Allow",
|
|
7
|
+
"Action": ["sts:GetCallerIdentity", "tag:GetResources", "ec2:Describe*", "cloudfront:GetDistribution", "cloudfront:GetDistributionConfig"],
|
|
8
|
+
"Resource": "*"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"Sid": "DeleteLabResources",
|
|
12
|
+
"Effect": "Allow",
|
|
13
|
+
"Action": [
|
|
14
|
+
"lambda:DeleteFunction",
|
|
15
|
+
"s3:ListBucket", "s3:ListBucketVersions", "s3:DeleteObject", "s3:DeleteObjectVersion", "s3:DeleteBucket",
|
|
16
|
+
"dynamodb:DeleteTable",
|
|
17
|
+
"logs:DeleteLogGroup",
|
|
18
|
+
"ec2:TerminateInstances", "ec2:ReleaseAddress", "ec2:DisassociateAddress", "ec2:DeleteSecurityGroup", "ec2:DeleteVolume",
|
|
19
|
+
"apigateway:DELETE",
|
|
20
|
+
"cloudfront:UpdateDistribution", "cloudfront:DeleteDistribution"
|
|
21
|
+
],
|
|
22
|
+
"Resource": "*"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"Sid": "CohortIamLifecycle",
|
|
26
|
+
"Effect": "Allow",
|
|
27
|
+
"Action": [
|
|
28
|
+
"iam:CreateUser", "iam:DeleteUser", "iam:GetUser", "iam:TagUser", "iam:ListUsers",
|
|
29
|
+
"iam:CreateLoginProfile", "iam:UpdateLoginProfile", "iam:DeleteLoginProfile",
|
|
30
|
+
"iam:ListAccessKeys", "iam:DeleteAccessKey", "iam:ListMFADevices", "iam:DeactivateMFADevice", "iam:DeleteVirtualMFADevice",
|
|
31
|
+
"iam:ListSigningCertificates", "iam:DeleteSigningCertificate", "iam:ListSSHPublicKeys", "iam:DeleteSSHPublicKey",
|
|
32
|
+
"iam:ListUserPolicies", "iam:DeleteUserPolicy", "iam:ListAttachedUserPolicies", "iam:DetachUserPolicy",
|
|
33
|
+
"iam:ListGroupsForUser", "iam:AddUserToGroup", "iam:RemoveUserFromGroup",
|
|
34
|
+
"iam:GetPolicy", "iam:GetPolicyVersion", "iam:CreatePolicy", "iam:CreatePolicyVersion", "iam:DeletePolicyVersion", "iam:ListPolicyVersions",
|
|
35
|
+
"iam:CreateGroup", "iam:AttachGroupPolicy",
|
|
36
|
+
"iam:CreateRole", "iam:AttachRolePolicy", "iam:PutRolePolicy", "iam:TagRole", "iam:TagPolicy"
|
|
37
|
+
],
|
|
38
|
+
"Resource": "*"
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
}
|