botmaro-secrets-manager 0.1.0__py3-none-any.whl

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.
@@ -0,0 +1,578 @@
1
+ Metadata-Version: 2.4
2
+ Name: botmaro-secrets-manager
3
+ Version: 0.1.0
4
+ Summary: A standalone secret management tool for multi-environment deployments with Google Secret Manager
5
+ Author: Botmaro Team
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/B9ice/botmaro-gcp-secret-manager
8
+ Project-URL: Repository, https://github.com/B9ice/botmaro-gcp-secret-manager
9
+ Project-URL: Issues, https://github.com/B9ice/botmaro-gcp-secret-manager/issues
10
+ Keywords: secrets,gsm,google-secret-manager,environment,deployment
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.8
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Requires-Python: >=3.8
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: google-cloud-secret-manager>=2.16.0
23
+ Requires-Dist: typer[all]>=0.9.0
24
+ Requires-Dist: pyyaml>=6.0
25
+ Requires-Dist: pydantic>=2.0.0
26
+ Requires-Dist: python-dotenv>=1.0.0
27
+ Requires-Dist: rich>=13.0.0
28
+ Provides-Extra: dev
29
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
30
+ Requires-Dist: black>=23.0.0; extra == "dev"
31
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
32
+ Requires-Dist: types-PyYAML>=6.0.0; extra == "dev"
33
+ Dynamic: license-file
34
+
35
+ # Botmaro Secrets Manager
36
+
37
+ A standalone, environment-aware secret management tool built on Google Secret Manager (GSM). Designed for multi-environment deployments with support for both GitHub Actions workflows and local development.
38
+
39
+ ## Features
40
+
41
+ - 🔐 **Multi-environment support** - Manage secrets across staging, prod, dev, and custom environments
42
+ - 🎯 **Project scoping** - Organize secrets by project within environments
43
+ - 🔄 **Version control** - Leverage GSM's built-in versioning
44
+ - 🚀 **CI/CD ready** - Bootstrap secrets in GitHub Actions or any CI/CD pipeline
45
+ - 🛠️ **CRUD operations** - Full create, read, update, delete support via CLI
46
+ - 📦 **Pip installable** - Install as a standalone package
47
+ - 🎨 **Rich CLI** - Beautiful, user-friendly command-line interface
48
+ - 🔒 **IAM integration** - Automatic service account access management
49
+
50
+ ## Installation
51
+
52
+ ### From source (development)
53
+
54
+ ```bash
55
+ # Clone the repository
56
+ git clone https://github.com/B9ice/botmaro-gcp-secret-manager.git
57
+ cd botmaro-gcp-secret-manager
58
+
59
+ # Install in development mode
60
+ pip install -e .
61
+ ```
62
+
63
+ ### From PyPI (when published)
64
+
65
+ ```bash
66
+ pip install botmaro-secrets-manager
67
+ ```
68
+
69
+ ## Quick Start
70
+
71
+ ### 1. Create a configuration file
72
+
73
+ Create a `secrets.yml` file defining your environments and secrets:
74
+
75
+ ```yaml
76
+ version: "1.0"
77
+
78
+ environments:
79
+ staging:
80
+ name: staging
81
+ gcp_project: your-gcp-project-staging
82
+ global_secrets:
83
+ - name: API_KEY
84
+ required: true
85
+ - name: DATABASE_URL
86
+ required: true
87
+ ```
88
+
89
+ See [secrets.example.yml](secrets.example.yml) for a complete example.
90
+
91
+ ### 2. Bootstrap your environment
92
+
93
+ ```bash
94
+ # Load all secrets for staging environment
95
+ secrets-manager bootstrap staging
96
+
97
+ # Bootstrap with project scope
98
+ secrets-manager bootstrap staging --project myapp
99
+
100
+ # Export to a .env file
101
+ secrets-manager bootstrap staging --output .env.staging
102
+ ```
103
+
104
+ ### 3. Manage secrets
105
+
106
+ ```bash
107
+ # Set a secret
108
+ secrets-manager set staging.API_KEY --value "sk-123456"
109
+
110
+ # Set a project-scoped secret
111
+ secrets-manager set staging.myapp.DATABASE_URL --value "postgres://..."
112
+
113
+ # Get a secret
114
+ secrets-manager get staging.API_KEY --reveal
115
+
116
+ # List all secrets
117
+ secrets-manager list staging
118
+
119
+ # Delete a secret
120
+ secrets-manager delete staging.OLD_KEY --force
121
+ ```
122
+
123
+ ## Usage
124
+
125
+ ### Command-Line Interface
126
+
127
+ #### Bootstrap Command
128
+
129
+ Load all secrets for an environment:
130
+
131
+ ```bash
132
+ secrets-manager bootstrap <environment> [OPTIONS]
133
+
134
+ Options:
135
+ --project, -p TEXT Project name to scope secrets
136
+ --config, -c TEXT Path to secrets config file
137
+ --export/--no-export Export secrets to environment variables [default: True]
138
+ --runtime-sa TEXT Runtime service account to grant access
139
+ --deployer-sa TEXT Deployer service account to grant access
140
+ --output, -o TEXT Output file for .env format
141
+ --verbose, -v Verbose output
142
+ ```
143
+
144
+ **Examples:**
145
+
146
+ ```bash
147
+ # Bootstrap staging
148
+ secrets-manager bootstrap staging
149
+
150
+ # Bootstrap with service account access grants
151
+ secrets-manager bootstrap staging \
152
+ --runtime-sa bot@project.iam.gserviceaccount.com \
153
+ --deployer-sa deploy@project.iam.gserviceaccount.com
154
+
155
+ # Save to .env file
156
+ secrets-manager bootstrap prod --output .env.production
157
+ ```
158
+
159
+ #### Set Command
160
+
161
+ Create or update a secret:
162
+
163
+ ```bash
164
+ secrets-manager set <target> [OPTIONS]
165
+
166
+ Target format:
167
+ - env.SECRET_NAME (environment-scoped)
168
+ - env.project.SECRET_NAME (project-scoped)
169
+
170
+ Options:
171
+ --value, -v TEXT Secret value (or read from stdin)
172
+ --config, -c TEXT Path to secrets config file
173
+ --grant, -g TEXT Service account to grant access (can be repeated)
174
+ ```
175
+
176
+ **Examples:**
177
+
178
+ ```bash
179
+ # Set an environment-scoped secret
180
+ secrets-manager set staging.API_KEY --value "sk-123456"
181
+
182
+ # Set a project-scoped secret
183
+ secrets-manager set staging.orchestrator.DATABASE_URL --value "postgres://..."
184
+
185
+ # Read from stdin
186
+ echo "secret-value" | secrets-manager set staging.MY_SECRET
187
+
188
+ # Grant access to service accounts
189
+ secrets-manager set staging.API_KEY --value "sk-123" \
190
+ --grant bot@project.iam.gserviceaccount.com \
191
+ --grant deploy@project.iam.gserviceaccount.com
192
+ ```
193
+
194
+ #### Get Command
195
+
196
+ Retrieve a secret value:
197
+
198
+ ```bash
199
+ secrets-manager get <target> [OPTIONS]
200
+
201
+ Options:
202
+ --version TEXT Secret version to retrieve [default: latest]
203
+ --config, -c TEXT Path to secrets config file
204
+ --reveal Show the full secret value
205
+ ```
206
+
207
+ **Examples:**
208
+
209
+ ```bash
210
+ # Get latest version (masked by default)
211
+ secrets-manager get staging.API_KEY
212
+
213
+ # Reveal full value
214
+ secrets-manager get staging.API_KEY --reveal
215
+
216
+ # Get specific version
217
+ secrets-manager get staging.API_KEY --version 2 --reveal
218
+ ```
219
+
220
+ #### List Command
221
+
222
+ List all secrets in an environment:
223
+
224
+ ```bash
225
+ secrets-manager list <environment> [OPTIONS]
226
+
227
+ Options:
228
+ --project, -p TEXT Project name to filter by
229
+ --config, -c TEXT Path to secrets config file
230
+ --reveal Show secret values
231
+ ```
232
+
233
+ **Examples:**
234
+
235
+ ```bash
236
+ # List all staging secrets
237
+ secrets-manager list staging
238
+
239
+ # List project-specific secrets
240
+ secrets-manager list staging --project orchestrator
241
+
242
+ # Show values (masked by default)
243
+ secrets-manager list staging --reveal
244
+ ```
245
+
246
+ #### Delete Command
247
+
248
+ Delete a secret:
249
+
250
+ ```bash
251
+ secrets-manager delete <target> [OPTIONS]
252
+
253
+ Options:
254
+ --config, -c TEXT Path to secrets config file
255
+ --force, -f Skip confirmation
256
+ ```
257
+
258
+ **Examples:**
259
+
260
+ ```bash
261
+ # Delete with confirmation prompt
262
+ secrets-manager delete staging.OLD_API_KEY
263
+
264
+ # Force delete
265
+ secrets-manager delete staging.OLD_API_KEY --force
266
+ ```
267
+
268
+ #### Grant Access Command
269
+
270
+ Grant access to all secrets in an environment or project:
271
+
272
+ ```bash
273
+ secrets-manager grant-access <target> [OPTIONS]
274
+
275
+ Target format:
276
+ - env (all environment-level secrets)
277
+ - env.project (all project-scoped secrets)
278
+
279
+ Options:
280
+ --sa TEXT Service account email to grant access (can be repeated)
281
+ --config, -c TEXT Path to secrets config file
282
+ --force, -f Skip confirmation prompt
283
+ ```
284
+
285
+ **Examples:**
286
+
287
+ ```bash
288
+ # Grant access to all staging secrets
289
+ secrets-manager grant-access staging \
290
+ --sa bot@project.iam.gserviceaccount.com
291
+
292
+ # Grant to multiple service accounts
293
+ secrets-manager grant-access staging \
294
+ --sa bot@project.iam.gserviceaccount.com \
295
+ --sa deployer@project.iam.gserviceaccount.com
296
+
297
+ # Grant access to all project-specific secrets
298
+ secrets-manager grant-access staging.myapp \
299
+ --sa myapp-runtime@project.iam.gserviceaccount.com
300
+
301
+ # Skip confirmation
302
+ secrets-manager grant-access staging --sa bot@project.iam.gserviceaccount.com --force
303
+ ```
304
+
305
+ **Note:** This command grants the `secretmanager.secretAccessor` role, allowing the service account to read secret values.
306
+
307
+ ## GitHub Actions Integration
308
+
309
+ ### Example Workflow
310
+
311
+ ```yaml
312
+ name: Deploy
313
+
314
+ on:
315
+ push:
316
+ branches: [main]
317
+
318
+ jobs:
319
+ deploy:
320
+ runs-on: ubuntu-latest
321
+
322
+ steps:
323
+ - uses: actions/checkout@v3
324
+
325
+ - name: Set up Python
326
+ uses: actions/setup-python@v4
327
+ with:
328
+ python-version: '3.11'
329
+
330
+ - name: Install secrets manager
331
+ run: pip install -e .
332
+
333
+ - name: Authenticate to Google Cloud
334
+ uses: google-github-actions/auth@v1
335
+ with:
336
+ credentials_json: ${{ secrets.GCP_SA_KEY }}
337
+
338
+ - name: Bootstrap secrets
339
+ run: |
340
+ secrets-manager bootstrap staging \
341
+ --runtime-sa botmaro-runner@project.iam.gserviceaccount.com \
342
+ --config secrets.yml
343
+
344
+ - name: Deploy application
345
+ run: |
346
+ # Your deployment commands here
347
+ # All secrets are now available as environment variables
348
+ echo "Deploying with SUPABASE_URL=$SUPABASE_URL"
349
+ ```
350
+
351
+ ### Setting up initial secrets
352
+
353
+ Before running in GitHub Actions, you need to populate secrets using this tool's CLI.
354
+
355
+ **Note:** This tool is your interface to Google Secret Manager. You only need `gcloud` for authentication, not for managing secrets.
356
+
357
+ ```bash
358
+ # 1. Authenticate to GCP (required for API access)
359
+ gcloud auth application-default login
360
+
361
+ # 2. Use secrets-manager CLI to create and manage secrets
362
+ secrets-manager set staging.SUPABASE_URL --value "https://xxx.supabase.co"
363
+ secrets-manager set staging.SUPABASE_ANON_KEY --value "eyJxxx..."
364
+ secrets-manager set staging.SUPABASE_SERVICE_ROLE_KEY --value "eyJxxx..."
365
+
366
+ # 3. Verify secrets were created
367
+ secrets-manager list staging --reveal
368
+ ```
369
+
370
+ The `secrets-manager` CLI automatically creates secrets in Google Secret Manager with proper naming conventions and IAM permissions.
371
+
372
+ ## Configuration Reference
373
+
374
+ ### Environment Configuration
375
+
376
+ ```yaml
377
+ environments:
378
+ <env-name>:
379
+ name: string # Environment name
380
+ gcp_project: string # GCP project ID
381
+ prefix: string # Optional: secret name prefix (default: botmaro-{env})
382
+
383
+ global_secrets: # Environment-level secrets
384
+ - name: string # Secret name
385
+ description: string # Optional description
386
+ required: boolean # Whether secret is required (default: true)
387
+ default: string # Optional default value
388
+
389
+ projects: # Project-specific secrets
390
+ <project-name>:
391
+ project_id: string
392
+ secrets:
393
+ - name: string
394
+ description: string
395
+ required: boolean
396
+ default: string
397
+ ```
398
+
399
+ ## Secret Naming Convention
400
+
401
+ Secrets are stored in GSM using a **double-hyphen (`--`) convention** for hierarchical separation, while single hyphens (`-`) or underscores (`_`) are used within component names:
402
+
403
+ - **Environment-scoped**: `{prefix}--{SECRET_NAME}`
404
+ - Example: `botmaro-staging--API_KEY`
405
+ - Example: `my-longer-prefix--SUPABASE_URL`
406
+
407
+ - **Project-scoped**: `{prefix}--{project}--{SECRET_NAME}`
408
+ - Example: `botmaro-staging--orchestrator--DATABASE_URL`
409
+ - Example: `my-company-prod--my-service--API_KEY`
410
+
411
+ Where `{prefix}` defaults to `botmaro-{environment}` but can be customized.
412
+
413
+ **Why double-hyphen?**
414
+ - Provides clear, unambiguous hierarchical separation
415
+ - Easy to parse: `secret_id.split('--')`
416
+ - GSM-compliant (only allows letters, numbers, `-`, and `_`)
417
+ - Visually distinct from naming hyphens
418
+
419
+ ## Local Development
420
+
421
+ ### Setup
422
+
423
+ ```bash
424
+ # Install dependencies
425
+ pip install -e ".[dev]"
426
+
427
+ # Set up secrets config
428
+ cp secrets.example.yml secrets.yml
429
+ # Edit secrets.yml with your configuration
430
+
431
+ # Authenticate to GCP
432
+ gcloud auth application-default login
433
+ ```
434
+
435
+ ### Running locally
436
+
437
+ ```bash
438
+ # Bootstrap local environment
439
+ secrets-manager bootstrap dev
440
+
441
+ # Or use a custom config
442
+ secrets-manager bootstrap dev --config ./my-secrets.yml
443
+ ```
444
+
445
+ ## Python API
446
+
447
+ You can also use the library programmatically:
448
+
449
+ ```python
450
+ from secrets_manager import SecretsManager, SecretsConfig
451
+
452
+ # Load from config file
453
+ config = SecretsConfig.from_file("secrets.yml")
454
+ manager = SecretsManager(config)
455
+
456
+ # Bootstrap environment
457
+ secrets = manager.bootstrap(env="staging", export_to_env=True)
458
+
459
+ # Set a secret
460
+ manager.set_secret(
461
+ env="staging",
462
+ secret="API_KEY",
463
+ value="sk-123456",
464
+ grant_to=["bot@project.iam.gserviceaccount.com"]
465
+ )
466
+
467
+ # Get a secret
468
+ value = manager.get_secret(env="staging", secret="API_KEY")
469
+
470
+ # List secrets
471
+ secrets = manager.list_secrets(env="staging", project="myapp")
472
+
473
+ # Grant access to all secrets in an environment
474
+ result = manager.grant_access_bulk(
475
+ env="staging",
476
+ service_accounts=["bot@project.iam.gserviceaccount.com", "deployer@project.iam.gserviceaccount.com"]
477
+ )
478
+ ```
479
+
480
+ ## IAM Permissions
481
+
482
+ The service account running the secrets manager needs:
483
+
484
+ - `secretmanager.admin` - To create/update/delete secrets
485
+ - `iam.serviceAccountUser` - To grant access to other service accounts
486
+
487
+ Grant these roles:
488
+
489
+ ```bash
490
+ gcloud projects add-iam-policy-binding PROJECT_ID \
491
+ --member="serviceAccount:YOUR_SA@PROJECT.iam.gserviceaccount.com" \
492
+ --role="roles/secretmanager.admin"
493
+ ```
494
+
495
+ Runtime service accounts need:
496
+
497
+ - `secretmanager.secretAccessor` - To read secrets (granted automatically by the tool)
498
+
499
+ ## Troubleshooting
500
+
501
+ ### Authentication errors
502
+
503
+ Make sure you're authenticated to GCP:
504
+
505
+ ```bash
506
+ gcloud auth application-default login
507
+ ```
508
+
509
+ For CI/CD, use service account key or Workload Identity.
510
+
511
+ ### Secret not found
512
+
513
+ Check that:
514
+ 1. The secret exists in GSM: `gcloud secrets list --project PROJECT_ID`
515
+ 2. Your config file matches the environment name
516
+ 3. The GCP project ID is correct
517
+
518
+ ### Permission denied
519
+
520
+ Ensure your service account has the required IAM roles listed above.
521
+
522
+ ## Releasing
523
+
524
+ This project uses tag-based releases. When you're ready to publish a new version:
525
+
526
+ ### 1. Update version and changelog
527
+
528
+ ```bash
529
+ # Update version in pyproject.toml
530
+ vim pyproject.toml # Change version = "0.1.0" to "0.1.1"
531
+
532
+ # Update CHANGELOG.md
533
+ vim CHANGELOG.md # Add release notes under [Unreleased]
534
+ ```
535
+
536
+ ### 2. Commit changes
537
+
538
+ ```bash
539
+ git add pyproject.toml CHANGELOG.md
540
+ git commit -m "Bump version to 0.1.1"
541
+ git push origin main
542
+ ```
543
+
544
+ ### 3. Create and push tag
545
+
546
+ ```bash
547
+ # Create an annotated tag
548
+ git tag -a v0.1.1 -m "Release v0.1.1: Description of changes"
549
+
550
+ # Push the tag (this triggers PyPI publish!)
551
+ git push origin v0.1.1
552
+ ```
553
+
554
+ ### What happens automatically:
555
+
556
+ 1. **Version verification** - Ensures tag matches pyproject.toml version
557
+ 2. **Build package** - Creates wheel and source distribution
558
+ 3. **Publish to PyPI** - Uploads to PyPI (requires PYPI_API_TOKEN secret)
559
+ 4. **Create GitHub Release** - Creates release page with changelog and assets
560
+
561
+ ### Manual publish (if needed)
562
+
563
+ You can also manually trigger the publish workflow from GitHub Actions UI:
564
+ - Go to Actions → Publish to PyPI → Run workflow
565
+
566
+ ## Contributing
567
+
568
+ Contributions are welcome! Please feel free to submit a Pull Request.
569
+
570
+ ## License
571
+
572
+ MIT License - see LICENSE file for details.
573
+
574
+ ## Support
575
+
576
+ For issues and questions:
577
+ - GitHub Issues: https://github.com/B9ice/botmaro-gcp-secret-manager/issues
578
+ - Documentation: https://github.com/B9ice/botmaro-gcp-secret-manager
@@ -0,0 +1,11 @@
1
+ botmaro_secrets_manager-0.1.0.dist-info/licenses/LICENSE,sha256=sdHlzbWaWwCagG6KDQ6pNlGZ-PNbe53cK1wyzqXVwmI,1068
2
+ secrets_manager/__init__.py,sha256=Hi7v6f28oLV9sZEBGo2kqkvxivAhNFEpMk3zMHL6xNM,307
3
+ secrets_manager/cli.py,sha256=7GvzMmX9m8w-d2cWvzcxRiMVDqqQKPrMFtMFZf3JnTI,15816
4
+ secrets_manager/config.py,sha256=e_aGLZbmC9bdmXKizJ_5jHxcKD4hwkW09Um01_wr2c4,2699
5
+ secrets_manager/core.py,sha256=l6HJNPfiXxVcynUzKV35qiIqJlt8xygNWePYAlc6K9c,10575
6
+ secrets_manager/gsm.py,sha256=J4ADduyokEWlOR8w-zjmeW4U6MBFwGd5OhhJ53LCBFw,5564
7
+ botmaro_secrets_manager-0.1.0.dist-info/METADATA,sha256=HSD-mBSiMCnEJWJQvS4VlkNrpXbR-LCM9WTKRvSM1g4,15248
8
+ botmaro_secrets_manager-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
+ botmaro_secrets_manager-0.1.0.dist-info/entry_points.txt,sha256=mbYrJiLkaejv4ATJZjikDWZS179YLv2M_88-_kwGezU,60
10
+ botmaro_secrets_manager-0.1.0.dist-info/top_level.txt,sha256=niW1V8PBYVHgVPND01EaqbHUrnAuRGi_3nUSSRz2SLo,16
11
+ botmaro_secrets_manager-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ secrets-manager = secrets_manager.cli:app
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Botmaro Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ secrets_manager
@@ -0,0 +1,13 @@
1
+ """
2
+ Botmaro Secrets Manager
3
+
4
+ A standalone secret management tool for multi-environment deployments
5
+ with Google Secret Manager.
6
+ """
7
+
8
+ __version__ = "0.1.0"
9
+
10
+ from .core import SecretsManager
11
+ from .config import SecretConfig, EnvironmentConfig
12
+
13
+ __all__ = ["SecretsManager", "SecretConfig", "EnvironmentConfig"]