Skip to content
Skip to Content
Coder Docs

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 begin

You 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
  1. Rebuild the workspace image so it installs the patched package version.

  2. Push the image to your registry under a new tag.

  3. If you reference the image by digest, copy the digest that the push prints.

  4. 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 version

Publish 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.

  1. Open the template.
  2. From the template's more-options menu (the vertical ellipsis), select Edit files.
  3. Update the image reference.
  4. Select Build.
  5. When the build succeeds, select Publish.
  6. In the Publish new version dialog, keep Promote to active version selected.
  7. Select Publish.

To promote a version that you already published:

  1. Open the template's Versions tab.
  2. On the version, select Promote….
  3. Select Promote.

For pipelines that push template versions, refer to Change management.

Make future starts use the active version

Make future starts use the active version

Promotion 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 start

Note

Template update policies are a Premium feature.

  1. Open the template.
  2. From the template's more-options menu (the vertical ellipsis), select Settings.
  3. On the General page, under Operations, select Require workspaces automatically update when started.
  4. 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-version

Refer to Template update policies.

Enforce regular restarts

Enforce regular restarts

Note

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 updates

Without 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 workspaces

Update 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 -y

The 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.

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 version

On 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.

To 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-certificates

The output shows the package name, then the installed version:

ca-certificates    <version>

Other places to update

Other places to update

A 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.json in 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.
  • envbuilder caches: 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 the envbuilder caching 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.

Learn more

Learn more