rdeploy 0.5.7__tar.gz → 0.6.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.
Files changed (30) hide show
  1. {rdeploy-0.5.7/rdeploy.egg-info → rdeploy-0.6.0}/PKG-INFO +92 -4
  2. {rdeploy-0.5.7 → rdeploy-0.6.0}/README.md +91 -3
  3. rdeploy-0.6.0/VERSION +1 -0
  4. rdeploy-0.6.0/rdeploy/main.py +44 -0
  5. rdeploy-0.6.0/rdeploy/secret_manager.py +504 -0
  6. {rdeploy-0.5.7 → rdeploy-0.6.0}/rdeploy/tasks.py +24 -4
  7. {rdeploy-0.5.7 → rdeploy-0.6.0/rdeploy.egg-info}/PKG-INFO +92 -4
  8. {rdeploy-0.5.7 → rdeploy-0.6.0}/rdeploy.egg-info/SOURCES.txt +1 -2
  9. {rdeploy-0.5.7 → rdeploy-0.6.0}/tests/test_tasks.py +480 -0
  10. rdeploy-0.5.7/CHANGES.txt +0 -313
  11. rdeploy-0.5.7/VERSION +0 -1
  12. rdeploy-0.5.7/rdeploy/main.py +0 -18
  13. rdeploy-0.5.7/requirements.txt +0 -7
  14. {rdeploy-0.5.7 → rdeploy-0.6.0}/LICENSE +0 -0
  15. {rdeploy-0.5.7 → rdeploy-0.6.0}/pyproject.toml +0 -0
  16. {rdeploy-0.5.7 → rdeploy-0.6.0}/rdeploy/__init__.py +0 -0
  17. {rdeploy-0.5.7 → rdeploy-0.6.0}/rdeploy/exceptions.py +0 -0
  18. {rdeploy-0.5.7 → rdeploy-0.6.0}/rdeploy/gke_auth.py +0 -0
  19. {rdeploy-0.5.7 → rdeploy-0.6.0}/rdeploy/helm_chart.py +0 -0
  20. {rdeploy-0.5.7 → rdeploy-0.6.0}/rdeploy/utils.py +0 -0
  21. {rdeploy-0.5.7 → rdeploy-0.6.0}/rdeploy.egg-info/dependency_links.txt +0 -0
  22. {rdeploy-0.5.7 → rdeploy-0.6.0}/rdeploy.egg-info/entry_points.txt +0 -0
  23. {rdeploy-0.5.7 → rdeploy-0.6.0}/rdeploy.egg-info/requires.txt +0 -0
  24. {rdeploy-0.5.7 → rdeploy-0.6.0}/rdeploy.egg-info/top_level.txt +0 -0
  25. {rdeploy-0.5.7 → rdeploy-0.6.0}/setup.cfg +0 -0
  26. {rdeploy-0.5.7 → rdeploy-0.6.0}/tests/test_exceptions.py +0 -0
  27. {rdeploy-0.5.7 → rdeploy-0.6.0}/tests/test_gke_auth.py +0 -0
  28. {rdeploy-0.5.7 → rdeploy-0.6.0}/tests/test_helm_chart.py +0 -0
  29. {rdeploy-0.5.7 → rdeploy-0.6.0}/tests/test_main.py +0 -0
  30. {rdeploy-0.5.7 → rdeploy-0.6.0}/tests/test_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rdeploy
3
- Version: 0.5.7
3
+ Version: 0.6.0
4
4
  Summary: CLI that makes it easy to build and deploy an application to k8s.
5
5
  Author-email: Rehive <info@rehive.com>
6
6
  License: MIT
@@ -74,7 +74,7 @@ rdeploy git-release patch
74
74
  | `kubectl-login` | Sign kubectl in to GKE under certificate-based access (see [kubectl under certificate-based access](#kubectl-under-certificate-based-access)) |
75
75
  | `activate` | Fetch and set project, cluster, and namespace |
76
76
  | `install` | Install a Helm chart deployment |
77
- | `upgrade` | Upgrade a Helm deployment to a new image tag (atomic by default: waits for the rollout and rolls back on failure; use `--no-atomic` to skip, `--timeout` to adjust the wait, default `15m`) |
77
+ | `upgrade` | Upgrade a Helm deployment to a new image tag (atomic by default: waits for the rollout and rolls back on failure; use `--no-atomic` to skip, `--timeout` to adjust the wait, default `15m`). With `secretManager.enabled`, checks the secrets first (`--no-secret-check` skips it) |
78
78
  | `helm` | Run arbitrary Helm commands |
79
79
  | `helm-setup` | Download and configure a local Helm binary |
80
80
  | `git-release` | Bump version and push a git tag |
@@ -86,8 +86,13 @@ rdeploy git-release patch
86
86
  | `shell` | Exec into a management container |
87
87
  | `manage` | Run a Django management command in-cluster |
88
88
  | `create-namespace` | Create a Kubernetes namespace |
89
- | `upload-secrets` | Upload secrets from an env file to Kubernetes |
90
- | `decode-secret` | Print decoded values of a Kubernetes secret |
89
+ | `secret list` | List a service's Secret Manager secrets and their newest version, never values (see [Secrets in Secret Manager](#secrets-in-secret-manager)) |
90
+ | `secret set` | Add a new version of a secret, from a hidden prompt or stdin |
91
+ | `secret check` | Check every key in `secretManager.keys` has an enabled version |
92
+ | `secret restart` | Restart the release's deployments so pods read new values |
93
+ | `secret migrate` | Copy values from the namespace's Kubernetes Secrets into Secret Manager |
94
+ | `upload-secrets` | Deprecated: upload secrets from an env file to a Kubernetes Secret |
95
+ | `decode-secret` | Deprecated: print decoded values of a Kubernetes Secret |
91
96
  | `upload-static` | Upload static files to a GCS bucket |
92
97
  | `create-bucket` | Create a private GCS bucket |
93
98
  | `create-public-bucket` | Create a public GCS bucket |
@@ -199,6 +204,89 @@ app's session control, keep the control plane on a private endpoint behind
199
204
  your access gateway, and leave CBA enforced for everything else.
200
205
  rdeploy doesn't contain any organisation's client ID, project or cluster names.
201
206
 
207
+ ## Secrets in Secret Manager
208
+
209
+ The `rehive-service` chart (1.4.0+) loads a service's secrets from Google
210
+ Secret Manager instead of a Kubernetes Secret. Each key under
211
+ `secretManager.keys` in the values file is one regional secret named
212
+ `<environment>--<service>--<KEY>`, which the pods read at startup through
213
+ Workload Identity:
214
+
215
+ ```yaml
216
+ # etc/helm/staging/values.yaml
217
+ secretManager:
218
+ enabled: true
219
+ environment: staging
220
+ keys: [DJANGO_SECRET, POSTGRES_PASSWORD]
221
+ ```
222
+
223
+ `rdeploy secret` manages those secrets. Each command takes the rdeploy config
224
+ and reads everything else from the config's `helm_values_path`, the way the
225
+ chart does: `secretManager.environment`, `service` (default: `project_name`)
226
+ and `prefix`. The secrets' `project` and `location` come from
227
+ `secretManager.project` and `secretManager.location`, or else from
228
+ `cloud_provider.project` and `cloud_provider.region` in `rdeploy.yaml`. A
229
+ `zone` isn't used. The chart has its own defaults for these two, so if they
230
+ differ from your `cloud_provider`, set them in the values file.
231
+
232
+ ```bash
233
+ rdeploy secret list staging # names and newest version, never values
234
+ rdeploy secret set staging DJANGO_SECRET # value from a hidden prompt
235
+ rdeploy secret set staging DJANGO_SECRET --generate # new random value
236
+ <command that prints the value> | rdeploy secret set staging SENTRY_DSN_KEY
237
+ rdeploy secret check staging # every key has an enabled version
238
+ rdeploy secret restart staging # pods read the new values
239
+ ```
240
+
241
+ `rdeploy secret <action>` is short for invoke's `rdeploy secret.<action>`;
242
+ `rdeploy --help secret.set` shows each command's options.
243
+
244
+ `set` creates the secret if it's missing (labelled `env`, `service` and
245
+ `managed-by=rdeploy`) and adds a version. Values never go on the command line,
246
+ to the terminal or to disk: rdeploy passes them to gcloud on stdin. Pods read
247
+ values once, at startup, so run `restart` after `set`. `restart` restarts the
248
+ deployments labelled `app.kubernetes.io/instance=<project_name>` and waits
249
+ for each rollout.
250
+
251
+ `upgrade` runs the same check as `secret check` when the values file has
252
+ `secretManager.enabled: true`, and stops before helm if a key has no enabled
253
+ version. Otherwise new pods would wait in `ContainerCreating` until the atomic
254
+ upgrade times out. `--no-secret-check` skips it, for example if you can add
255
+ versions but not list them.
256
+
257
+ ### Moving from Kubernetes Secrets
258
+
259
+ `rdeploy secret migrate` copies each key's value from the namespace's
260
+ Kubernetes Secrets into Secret Manager, then runs `secret check`. By default a
261
+ key comes from the field of the same name in the Secret named after the
262
+ release (`project_name`); `--map` points a key elsewhere:
263
+
264
+ ```bash
265
+ rdeploy kubectl-login
266
+ rdeploy secret migrate staging --dry-run \
267
+ --map POSTGRES_PASSWORD=postgres/postgres-password \
268
+ --map RABBITMQ_PASSWORD=rabbitmq/rabbitmq-password
269
+ ```
270
+
271
+ Drop `--dry-run` to copy. Values go from kubectl to gcloud in memory and are
272
+ never printed. Keys whose Secret or field doesn't exist are skipped. It stops
273
+ straight away if kubectl can't read the namespace, for example once the
274
+ `rdeploy kubectl-login` session has expired. It's safe to rerun: each run adds
275
+ a new version with the same value.
276
+
277
+ ### Certificate-based access
278
+
279
+ Regional secrets are served from a regional endpoint, and under
280
+ certificate-based access from its mTLS form. rdeploy sets
281
+ `CLOUDSDK_API_ENDPOINT_OVERRIDES_SECRETMANAGER` to
282
+ `https://secretmanager.<location>.rep.mtls.googleapis.com/` when
283
+ `GOOGLE_API_USE_CLIENT_CERTIFICATE=true` or gcloud's
284
+ `context_aware/use_client_certificate` is on, and to
285
+ `https://secretmanager.<location>.rep.googleapis.com/` otherwise. Without
286
+ this, gcloud fails with `ACCESS_TOKEN_TYPE_UNSUPPORTED` or "Project ID ...
287
+ does not match the expected format". An override already in your environment
288
+ wins.
289
+
202
290
  ## Configuration
203
291
 
204
292
  rdeploy is configured via an `rdeploy.yaml` file in your project root. The file supports versioned schemas (v1, v2, v3).
@@ -37,7 +37,7 @@ rdeploy git-release patch
37
37
  | `kubectl-login` | Sign kubectl in to GKE under certificate-based access (see [kubectl under certificate-based access](#kubectl-under-certificate-based-access)) |
38
38
  | `activate` | Fetch and set project, cluster, and namespace |
39
39
  | `install` | Install a Helm chart deployment |
40
- | `upgrade` | Upgrade a Helm deployment to a new image tag (atomic by default: waits for the rollout and rolls back on failure; use `--no-atomic` to skip, `--timeout` to adjust the wait, default `15m`) |
40
+ | `upgrade` | Upgrade a Helm deployment to a new image tag (atomic by default: waits for the rollout and rolls back on failure; use `--no-atomic` to skip, `--timeout` to adjust the wait, default `15m`). With `secretManager.enabled`, checks the secrets first (`--no-secret-check` skips it) |
41
41
  | `helm` | Run arbitrary Helm commands |
42
42
  | `helm-setup` | Download and configure a local Helm binary |
43
43
  | `git-release` | Bump version and push a git tag |
@@ -49,8 +49,13 @@ rdeploy git-release patch
49
49
  | `shell` | Exec into a management container |
50
50
  | `manage` | Run a Django management command in-cluster |
51
51
  | `create-namespace` | Create a Kubernetes namespace |
52
- | `upload-secrets` | Upload secrets from an env file to Kubernetes |
53
- | `decode-secret` | Print decoded values of a Kubernetes secret |
52
+ | `secret list` | List a service's Secret Manager secrets and their newest version, never values (see [Secrets in Secret Manager](#secrets-in-secret-manager)) |
53
+ | `secret set` | Add a new version of a secret, from a hidden prompt or stdin |
54
+ | `secret check` | Check every key in `secretManager.keys` has an enabled version |
55
+ | `secret restart` | Restart the release's deployments so pods read new values |
56
+ | `secret migrate` | Copy values from the namespace's Kubernetes Secrets into Secret Manager |
57
+ | `upload-secrets` | Deprecated: upload secrets from an env file to a Kubernetes Secret |
58
+ | `decode-secret` | Deprecated: print decoded values of a Kubernetes Secret |
54
59
  | `upload-static` | Upload static files to a GCS bucket |
55
60
  | `create-bucket` | Create a private GCS bucket |
56
61
  | `create-public-bucket` | Create a public GCS bucket |
@@ -162,6 +167,89 @@ app's session control, keep the control plane on a private endpoint behind
162
167
  your access gateway, and leave CBA enforced for everything else.
163
168
  rdeploy doesn't contain any organisation's client ID, project or cluster names.
164
169
 
170
+ ## Secrets in Secret Manager
171
+
172
+ The `rehive-service` chart (1.4.0+) loads a service's secrets from Google
173
+ Secret Manager instead of a Kubernetes Secret. Each key under
174
+ `secretManager.keys` in the values file is one regional secret named
175
+ `<environment>--<service>--<KEY>`, which the pods read at startup through
176
+ Workload Identity:
177
+
178
+ ```yaml
179
+ # etc/helm/staging/values.yaml
180
+ secretManager:
181
+ enabled: true
182
+ environment: staging
183
+ keys: [DJANGO_SECRET, POSTGRES_PASSWORD]
184
+ ```
185
+
186
+ `rdeploy secret` manages those secrets. Each command takes the rdeploy config
187
+ and reads everything else from the config's `helm_values_path`, the way the
188
+ chart does: `secretManager.environment`, `service` (default: `project_name`)
189
+ and `prefix`. The secrets' `project` and `location` come from
190
+ `secretManager.project` and `secretManager.location`, or else from
191
+ `cloud_provider.project` and `cloud_provider.region` in `rdeploy.yaml`. A
192
+ `zone` isn't used. The chart has its own defaults for these two, so if they
193
+ differ from your `cloud_provider`, set them in the values file.
194
+
195
+ ```bash
196
+ rdeploy secret list staging # names and newest version, never values
197
+ rdeploy secret set staging DJANGO_SECRET # value from a hidden prompt
198
+ rdeploy secret set staging DJANGO_SECRET --generate # new random value
199
+ <command that prints the value> | rdeploy secret set staging SENTRY_DSN_KEY
200
+ rdeploy secret check staging # every key has an enabled version
201
+ rdeploy secret restart staging # pods read the new values
202
+ ```
203
+
204
+ `rdeploy secret <action>` is short for invoke's `rdeploy secret.<action>`;
205
+ `rdeploy --help secret.set` shows each command's options.
206
+
207
+ `set` creates the secret if it's missing (labelled `env`, `service` and
208
+ `managed-by=rdeploy`) and adds a version. Values never go on the command line,
209
+ to the terminal or to disk: rdeploy passes them to gcloud on stdin. Pods read
210
+ values once, at startup, so run `restart` after `set`. `restart` restarts the
211
+ deployments labelled `app.kubernetes.io/instance=<project_name>` and waits
212
+ for each rollout.
213
+
214
+ `upgrade` runs the same check as `secret check` when the values file has
215
+ `secretManager.enabled: true`, and stops before helm if a key has no enabled
216
+ version. Otherwise new pods would wait in `ContainerCreating` until the atomic
217
+ upgrade times out. `--no-secret-check` skips it, for example if you can add
218
+ versions but not list them.
219
+
220
+ ### Moving from Kubernetes Secrets
221
+
222
+ `rdeploy secret migrate` copies each key's value from the namespace's
223
+ Kubernetes Secrets into Secret Manager, then runs `secret check`. By default a
224
+ key comes from the field of the same name in the Secret named after the
225
+ release (`project_name`); `--map` points a key elsewhere:
226
+
227
+ ```bash
228
+ rdeploy kubectl-login
229
+ rdeploy secret migrate staging --dry-run \
230
+ --map POSTGRES_PASSWORD=postgres/postgres-password \
231
+ --map RABBITMQ_PASSWORD=rabbitmq/rabbitmq-password
232
+ ```
233
+
234
+ Drop `--dry-run` to copy. Values go from kubectl to gcloud in memory and are
235
+ never printed. Keys whose Secret or field doesn't exist are skipped. It stops
236
+ straight away if kubectl can't read the namespace, for example once the
237
+ `rdeploy kubectl-login` session has expired. It's safe to rerun: each run adds
238
+ a new version with the same value.
239
+
240
+ ### Certificate-based access
241
+
242
+ Regional secrets are served from a regional endpoint, and under
243
+ certificate-based access from its mTLS form. rdeploy sets
244
+ `CLOUDSDK_API_ENDPOINT_OVERRIDES_SECRETMANAGER` to
245
+ `https://secretmanager.<location>.rep.mtls.googleapis.com/` when
246
+ `GOOGLE_API_USE_CLIENT_CERTIFICATE=true` or gcloud's
247
+ `context_aware/use_client_certificate` is on, and to
248
+ `https://secretmanager.<location>.rep.googleapis.com/` otherwise. Without
249
+ this, gcloud fails with `ACCESS_TOKEN_TYPE_UNSUPPORTED` or "Project ID ...
250
+ does not match the expected format". An override already in your environment
251
+ wins.
252
+
165
253
  ## Configuration
166
254
 
167
255
  rdeploy is configured via an `rdeploy.yaml` file in your project root. The file supports versioned schemas (v1, v2, v3).
rdeploy-0.6.0/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.6.0
@@ -0,0 +1,44 @@
1
+ import shlex
2
+ import sys
3
+ from importlib.metadata import version as get_version
4
+
5
+ from invoke import Argument, Collection, Program
6
+
7
+ import rdeploy
8
+ from rdeploy import secret_manager
9
+
10
+
11
+ def secret_argv(argv):
12
+ """
13
+ Let `rdeploy secret <action> ...` stand for invoke's
14
+ `rdeploy secret.<action> ...`.
15
+ """
16
+ argv = shlex.split(argv) if isinstance(argv, str) else list(argv)
17
+ for i in range(1, len(argv) - 1):
18
+ if argv[i] == 'secret' and argv[i + 1] in secret_manager.ACTIONS:
19
+ return argv[:i] + ['secret.' + argv[i + 1]] + argv[i + 2:]
20
+ return argv
21
+
22
+
23
+ class MainProgram(Program):
24
+ def core_args(self):
25
+ core_args = super(MainProgram, self).core_args()
26
+ extra_args = [
27
+ Argument(names=('project', 'n'), help="The project/package name being build"),
28
+ ]
29
+ return core_args + extra_args
30
+
31
+ def run(self, argv=None, exit=True):
32
+ return super(MainProgram, self).run(
33
+ secret_argv(sys.argv if argv is None else argv), exit)
34
+
35
+
36
+ def build_namespace():
37
+ namespace = Collection.from_module(rdeploy)
38
+ namespace.add_collection(
39
+ Collection.from_module(secret_manager, name='secret'))
40
+ return namespace
41
+
42
+
43
+ version = get_version("rdeploy")
44
+ program = MainProgram(namespace=build_namespace(), version=version)