Roll out a security update to every workspace
Roll out a patched image to every new and existing workspace by publishing a template version and updating outdated workspaces.
On this page
This guide is for template admins and Coder deployment administrators who need to patch a package inside every workspace, such as an updated ca-certificates package after a certificate authority is compromised.
It covers the image, the template version, new workspaces, and existing workspaces, in the order you apply them.
For general image practices, refer to Image management.
A workspace build uses the template version it was started with. When the template references the patched image by a new tag or digest, the image reaches a workspace only when the workspace builds on a template version with that reference. A running workspace keeps its current container or VM until it stops and starts again.
Before you begin
Before you beginYou need:
- The Template Admin or Organization Template Admin role to push and promote template versions.
- The Owner or Organization Admin role to update workspaces that other users own. Template Admins can view other users' workspaces, but can't start, stop, or update them.
- A Premium license for template update policies and the autostop requirement. The rest of this guide works without Premium.
Rebuild the image with the patched package
Rebuild the image with the patched package-
Rebuild the workspace image so it installs the patched package version.
-
Push the image to your registry under a new tag.
-
If you reference the image by digest, copy the digest that the push prints.
-
In the template, reference the new tag or the digest:
resource "docker_container" "workspace" { # Pin the digest so every build uses the patched image. image = "registry.example.com/workspace-base@sha256:<digest>" # ... }
A reference that changes makes the fix explicit and traceable to a template version.
If you push the patched image under the same mutable tag, such as ubuntu, a host or node that already has the old image can keep using it.
Docker reuses a local image with the same name and tag.
Kubernetes pulls a cached tag again only when the container's imagePullPolicy is Always, the default for latest and untagged images.
Refer to the Kubernetes image pull policy documentation for details.
Publish and promote a new template version
Publish and promote a new template versionPublish the template change from Step 1 as a new version and make it the active version. By default, new workspaces start on the active version.
Keep the parameters of a security release the same as the previous version. If the new version adds a required parameter without a default, updates fail until each user enters a value, and autostart stops for those workspaces.
- Open the template.
- From the template's more-options menu (the vertical ellipsis), select Edit files.
- Update the image reference.
- Select Build.
- When the build succeeds, select Publish.
- In the Publish new version dialog, keep Promote to active version selected.
- Select Publish.
To promote a version that you already published:
- Open the template's Versions tab.
- On the version, select Promote….
- Select Promote.
From the template directory, push the new version:
coder templates push <template-name> --directory . --name <version-name>coder templates push makes the new version active by default.
If you pushed it with --activate=false, promote it afterward:
coder templates versions promote --template=<template-name> --template-version=<version-name>For pipelines that push template versions, refer to Change management.
Make future starts use the active version
Make future starts use the active versionPromotion doesn't change existing workspaces. By default, a workspace that stops and starts again stays on its current template version. Choose how workspaces move to the active version on their next start. You can combine these options.
Require the active version for every start
Require the active version for every startNote
Template update policies are a Premium feature.
- Open the template.
- From the template's more-options menu (the vertical ellipsis), select Settings.
- On the General page, under Operations, select Require workspaces automatically update when started.
- Select Save.
Manual starts and autostarts then use the active version. The policy doesn't apply to users who can edit the template, such as Owners and template admins, who can still start a workspace on an older version.
From the CLI, run:
coder templates edit <template-name> --require-active-versionRefer to Template update policies.
Enforce regular restarts
Enforce regular restartsNote
The autostop requirement is a Premium feature.
A workspace that never stops never picks up a new version on start. Set the template's autostop requirement so workspaces stop on a regular schedule, even when a connection is open. Combine it with the template update policy, so those workspaces start on the active version.
Ask users to turn on automatic updates
Ask users to turn on automatic updatesWithout a Premium license, ask users to turn on automatic updates for their workspaces. In the workspace's Settings > General page, the user sets Update Policy to Always. The workspace then updates to the active version whenever it starts. Refer to Automatic updates.
Update existing workspaces
Update existing workspacesUpdate the workspaces that already exist, so the fix doesn't wait for each user to restart their workspace.
Warning
Updating a running workspace stops it and starts it on the active version. Anyone connected to the workspace is disconnected, unsaved work is lost, and data outside persistent storage is deleted. Tell users before you update their workspaces.
coder update stops a running workspace and starts it on the active version.
It also starts a stopped workspace.
To update every outdated workspace of one template, one at a time, run:
coder list --search "template:<template-name> outdated:true" --output json \
| jq -r '.[] | select(.dormant_at == null) | "\(.owner_name)/\(.name)"' \
| xargs -n 1 coder update -yThe select filter skips dormant workspaces, like the dashboard.
Without it, coder update activates and starts each dormant workspace.
coder list ignores --search when you also pass --all, so the command uses --search alone.
Refer to Update workspaces for the other coder update options.
The Workspaces page shows 25 workspaces at a time, and bulk actions apply only to the workspaces you select on the current page. For more than a few pages of workspaces, use the CLI.
-
Open the Workspaces page.
-
Replace the filter with
template:<template-name> outdated:true. -
Select the checkbox in the table header to select every workspace on the page.
-
Select Bulk actions > Update….
-
If the dialog shows Running workspaces detected, select I acknowledge these risks.
-
Select Update.
If a selected workspace is starting or stopping, Update is unavailable until that build finishes.
-
Repeat these steps until the filter shows no workspaces, or only dormant ones.
The dialog lists the workspaces it updates and skips the ones already on the active version. Bulk update also starts selected workspaces that are stopped, and it skips dormant workspaces.
Use Update…, not Stop followed by Start. Bulk Start starts each workspace on the version it already uses, so it doesn't apply the new image.
Dormant workspaces stay on their current version. When a user activates one, update it, or turn on the template update policy so it starts on the active version.
Confirm every workspace is on the active version
Confirm every workspace is on the active versionOn the Workspaces page, filter by template:<template-name> outdated:true.
An empty list, or a list of only dormant workspaces, means every active workspace of the template is on the active version.
Each outdated workspace also shows an outdated indicator next to its name.
List the workspaces that are still outdated:
coder list --search "template:<template-name> outdated:true" --column workspace,status,"current version",outdatedWhen every workspace is updated, the command prints No workspaces found! Create one: instead of a table.
Otherwise, it prints one row for each outdated workspace:
WORKSPACE STATUS CURRENT VERSION OUTDATED
<owner>/<workspace-name> Started <version-name> trueTo check the package itself, connect to an updated workspace that you own and query the package version, for example on a Debian-based image:
coder ssh <workspace-name> -- dpkg-query -W ca-certificatesThe output shows the package name, then the installed version:
ca-certificates <version>Other places to update
Other places to updateA new template version replaces the image, but not files that live outside it. Update these separately:
- Dev containers: a dev container builds from the
devcontainer.jsonin the project repository, not from the template's image. Change the image reference in the repository's dev container configuration to the new tag or digest, then have developers select Rebuild on the dev container. Refer to Rebuild dev containers. envbuildercaches: a template that uses a cache repository can start from a previously built image instead of building again. Change the base image reference in the dev container configuration, for example to a new digest, so the build doesn't reuse the cached image. Refer to Layer and image caching and theenvbuildercaching documentation.- Persistent home volumes: files in a persistent home directory survive updates. A copy of a certificate bundle or a tool installed under the home directory, such as in a language virtual environment, keeps the old version until the user updates it.
- Persistent disks and VMs: templates that keep a VM or its boot disk across stops don't get a new image on start. Patch those workspaces with the operating system's package manager, for example in the startup script, or change the template so the boot disk is recreated. Refer to Resource persistence.
Prebuilt workspaces follow the active version. When you promote a new version, Coder deletes prebuilt workspaces for older versions and creates new ones on the active version. If you change an image without a new template version, invalidate the prebuilds instead.