Skip to content

Commit 9ed3d62

Browse files
Details on custom certs with worker pools (#1050)
* Details on custom certs with worker pools - adds details on how to use custom certs with worker pools using Kubernetes controller - also makes tabs for some assigning roles processes, and highlights a detail that could impact architecture security with the warning tag instead of important * Update kubernetes-workers.md
1 parent f0186ad commit 9ed3d62

File tree

2 files changed

+105
-23
lines changed

2 files changed

+105
-23
lines changed

docs/concepts/authorization/assigning-roles-stacks.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -258,30 +258,30 @@ List all stacks with `administrative = true` in your account. You can do this th
258258

259259
Attach the Space Admin role to the stack using the stack's own space as the binding space:
260260

261-
**Using the Terraform provider:**
261+
=== "Using the Terraform provider"
262262

263-
```hcl
264-
data "spacelift_role" "admin_role" {
265-
slug = "space-admin"
266-
}
267-
268-
resource "spacelift_role_attachment" "stack_admin" {
269-
stack_id = spacelift_stack.management.id
270-
space_id = spacelift_stack.management.space_id
271-
role_id = data.spacelift_role.admin_role.id
272-
}
273-
```
263+
```hcl
264+
data "spacelift_role" "admin_role" {
265+
slug = "space-admin"
266+
}
267+
268+
resource "spacelift_role_attachment" "stack_admin" {
269+
stack_id = spacelift_stack.management.id
270+
space_id = spacelift_stack.management.space_id
271+
role_id = data.spacelift_role.admin_role.id
272+
}
273+
```
274274

275-
**Using the Web UI:**
275+
=== "Using the Web UI"
276276

277-
1. Navigate to the stack's **Settings** page, then choose **Roles**
278-
2. Click **Manage Roles** on the top right
279-
3. In the drawer, select the **Space admin** role and the stack's own Space as the target
280-
4. Click **Add**
277+
1. Navigate to the stack's **Settings** page, then choose **Roles**.
278+
2. Click **Manage Roles** on the top right.
279+
3. In the drawer, select the **Space admin** role and the stack's own space as the target.
280+
4. Click **Add**.
281281

282-
Assuming your stack is in the `dev` [Space](../spaces/README.md), the role attachment will grant **Space admin** permissions in the `dev` space:
282+
Assuming your stack is in the `dev` [space](../spaces/README.md), the role attachment will grant **Space admin** permissions in the `dev` space:
283283

284-
![](../../assets/screenshots/role_stacks_migration.png)
284+
![](../../assets/screenshots/role_stacks_migration.png)
285285

286286
#### 3. Remove the administrative attribute
287287

@@ -294,7 +294,7 @@ resource "spacelift_stack" "management" {
294294
}
295295
```
296296

297-
!!! important
297+
!!! warning
298298
The administrative flag takes precedence over role attachments. If `administrative = true`, any attached roles will be ignored. You must either set `administrative = false`, or entirely remove the administrative attribute (recommended) for role attachments to take effect.
299299

300300
#### 4. Verify the role attachment
@@ -315,7 +315,7 @@ If any of your policies reference the `stack.administrative` field, update them
315315

316316
# Would become:
317317
deny contains "Administrative stacks are not allowed" if {
318-
some role in input.spacelift.stack.roles
318+
some role in input.stack.roles
319319
role.id == "space-admin" # (1)
320320
}
321321
```
@@ -330,7 +330,7 @@ If any of your policies reference the `stack.administrative` field, update them
330330

331331
# Would become:
332332
deny["Administrative stacks are not allowed"] {
333-
role := input.spacelift.stack.roles[_]
333+
role := input.stack.roles[_]
334334
role.id == "space-admin" # (1)
335335
}
336336
```

docs/concepts/worker-pools/kubernetes-workers.md

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ spec:
950950
951951
### Using VCS Agents with Kubernetes Workers
952952
953-
Using VCS Agents with Kubernetes workers is simple, and uses exactly the same approach outlined in the [VCS Agents](./README.md#vcs-agents) section. To configure your VCS Agent environment variables in a Kubernetes WorkerPool, add them to the `spec.pod.initContainer.env` section, like in the following example:
953+
Using VCS Agents with Kubernetes workers is simple, and uses exactly the same approach outlined in the [VCS Agents](../vcs-agent-pools.md#run-the-vcs-agent-inside-a-kubernetes-cluster) section. To configure your VCS Agent environment variables in a Kubernetes WorkerPool, add them to the `spec.pod.initContainer.env` section, like in the following example:
954954
955955
```yaml
956956
apiVersion: workers.spacelift.io/v1beta1
@@ -1176,6 +1176,88 @@ During the controller's startup, you should see the `FIPS 140 mode {"enabled": t
11761176
!!! note
11771177
This will only make the controller run in FIPS mode. The Spacelift worker pods are not affected by this setting - they are not compliant with FIPS 140-3 yet.
11781178
1179+
## Supply custom certificates to worker pools
1180+
1181+
You can add custom certificate authority (CA) certificates to your worker pools. We support adding them to the controller container and to the container that runs OpenTofu/Terraform.
1182+
1183+
### Add certificates to controller container
1184+
1185+
1. Ensure your custom certificate is pem-encoded **and** the file name ends in `.pem`.
1186+
2. Within the controller container, mount the certificate to `/ops/spacelift/certs`.
1187+
1188+
This example is for the controller Helm chart. If you're using a manifest, you will need to edit it directly.
1189+
1190+
``` yaml
1191+
controllerManager:
1192+
manager:
1193+
extraVolumeMounts:
1194+
- name: ca-secret-volume
1195+
mountPath: /opt/spacelift/certs
1196+
readOnly: true
1197+
extraVolumes:
1198+
- name: ca-secret-volume
1199+
secret:
1200+
secretName: my-amazing-secret-with-something-dot-pem-inside-it
1201+
```
1202+
1203+
### Add certificates to the OpenTofu/Terraform process
1204+
1205+
1. Prepare your **custom CA certificate**.
1206+
- Place your CA certificate in a directory on your computer (e.g., `custom-ca.pem`).
1207+
2. Create an **extended CA bundle**.
1208+
- Download the existing CA cert bundle from the container and append your custom certificate:
1209+
1210+
``` bash
1211+
docker run -it public.ecr.aws/spacelift/runner-terraform:latest cat /etc/ssl/certs/ca-certificates.crt > new-bundle.crt && cat custom-ca.pem >> new-bundle.crt
1212+
```
1213+
1214+
- Ensure `new-bundle.crt` has a newline at the end.
1215+
1216+
3. Create a **Kubernetes secret**.
1217+
1218+
``` bash
1219+
kubectl create secret generic extended-ca-bundle --from-file=bundle=new-bundle.crt
1220+
```
1221+
1222+
4. **Update** your WorkerPool.
1223+
- Delete your existing WorkerPool object (required due to immutable fields):
1224+
1225+
``` bash
1226+
kubectl delete workerpool workerpool -n spacelift-worker-pool-system
1227+
```
1228+
1229+
- Create a new WorkerPool with the updated configuration, adjusting your `poolSize` and credential secret names as needed:
1230+
1231+
``` yaml
1232+
apiVersion: workers.spacelift.io/v1beta1
1233+
kind: WorkerPool
1234+
metadata:
1235+
name: workerpool
1236+
namespace: spacelift-worker-pool-system
1237+
spec:
1238+
pod:
1239+
volumes:
1240+
- name: new-ca-bundle
1241+
secret:
1242+
secretName: extended-ca-bundle
1243+
items:
1244+
- key: bundle
1245+
path: ca-certificates.crt
1246+
workerContainer:
1247+
volumeMounts:
1248+
- name: new-ca-bundle
1249+
mountPath: /etc/ssl/certs
1250+
poolSize: 5
1251+
privateKey:
1252+
secretKeyRef:
1253+
key: privateKey
1254+
name: spacelift-worker-pool-credentials
1255+
token:
1256+
secretKeyRef:
1257+
key: token
1258+
name: spacelift-worker-pool-credentials
1259+
```
1260+
11791261
## Scaling a pool
11801262
11811263
To scale your WorkerPool, you can either edit the resource in Kubernetes, or use the `kubectl scale` command:

0 commit comments

Comments
 (0)