Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

- the header command falls back to the `CODER_HEADER_COMMAND` environment variable when the setting is blank, matching the Coder CLI and the VS Code extension

### Changed

- the Coder CLI is now verified with Coder's new release signing key; the previous key is no longer trusted
- the plugin ships with new signatures for Coder 2.29.0 to 2.39.4
- a CLI from a deployment older than 2.29.0 can no longer be verified, and asks for confirmation before it runs

## 2.23.1 - 2026-01-21

### Changed
Expand Down
18 changes: 12 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,23 @@ running potentially malicious or tampered binaries.
1. **Binary Download**: When connecting to a Coder deployment, the plugin downloads the appropriate Coder CLI binary for
the user's operating system and architecture from the deployment's `/bin/` endpoint.

2. **Signature Download**: After downloading the binary, the plugin attempts to download the corresponding `.asc`
2. **Signature Download**: After downloading the binary, the plugin attempts to download the corresponding `.v2.asc`
signature file from the same location. The signature file is named according to the binary (e.g.,
`coder-linux-amd64.asc` for `coder-linux-amd64`).
`coder-linux-amd64.v2.asc` for `coder-linux-amd64`).

3. **Fallback Signature Sources**: If the signature is not available from the deployment, the plugin can optionally fall
back to downloading signatures from `releases.coder.com`. This is controlled by the `fallbackOnCoderForSignatures`
3. **Bundled Signatures**: Deployments released before Coder's current release signing key have no `.v2.asc` signature.
If the signature is not available from the deployment, the plugin uses the signature that ships with the plugin for
the release of the deployment's version. Coder made these signatures with the current key for the releases from
2.29.0 to 2.39.4. They are the signatures that `releases.coder.com` serves for those releases.

4. **Fallback Signature Sources**: If the plugin has no signature for the release, it can optionally fall back to
downloading signatures from `releases.coder.com`. This is controlled by the `fallbackOnCoderForSignatures`
setting.

4. **GPG Verification**: The plugin uses the BouncyCastle library shipped with Gateway app to verify the detached GPG
5. **GPG Verification**: The plugin uses the BouncyCastle library shipped with Gateway app to verify the detached GPG
signature against the downloaded binary using Coder's trusted public key.

5. **User Interaction**: If signature verification fails or signatures are unavailable, the plugin presents security
6. **User Interaction**: If signature verification fails or signatures are unavailable, the plugin presents security
warnings
to users, allowing them to accept the risk and continue or abort the operation.

Expand All @@ -64,6 +69,7 @@ Users can control signature verification behavior through plugin settings:
### Security Considerations

- The plugin embeds Coder's trusted public key in the plugin resources
- The plugin embeds the signatures that Coder made with that key for the releases published before it
- Verification uses detached signatures, which are more secure than attached signatures
- Users are warned about security risks when verification fails
- The system gracefully handles cases where signatures are unavailable
Expand Down
6 changes: 6 additions & 0 deletions src/main/kotlin/com/coder/gateway/cli/CoderCLIManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@
downloader.downloadSignature(showTextProgress)
}

if (signatureResult.isNotDownloaded()) {
signatureResult = withContext(Dispatchers.IO) {
downloader.bundledSignature(buildVersion)
}
}

if (signatureResult.isNotDownloaded()) {
if (settings.fallbackOnCoderForSignatures) {
logger.info("Trying to download signature file from releases.coder.com")
Expand Down Expand Up @@ -273,7 +279,7 @@

else -> {
val failure = result as VerificationResult.Failed
UnsignedBinaryExecutionDeniedException(result.error.message)

Check warning on line 282 in src/main/kotlin/com/coder/gateway/cli/CoderCLIManager.kt

View workflow job for this annotation

GitHub Actions / Build

Throwable not thrown

Throwable instance 'UnsignedBinaryExecutionDeniedException' is not thrown
logger.error("Failed to verify signature for ${cliResult.dst}", failure.error)
}
}
Expand Down Expand Up @@ -570,7 +576,7 @@
coderConfigPath.toString(),
"start",
"--yes",
workspaceOwner + "/" + workspaceName

Check notice on line 579 in src/main/kotlin/com/coder/gateway/cli/CoderCLIManager.kt

View workflow job for this annotation

GitHub Actions / Build

String concatenation that can be converted to string template

'String' concatenation can be converted to a template
)

if (feats.buildReason) {
Expand Down Expand Up @@ -668,7 +674,7 @@
}
// non-wildcard case
if (parts[0] == "coder-jetbrains") {
return hostname + "--bg"

Check notice on line 677 in src/main/kotlin/com/coder/gateway/cli/CoderCLIManager.kt

View workflow job for this annotation

GitHub Actions / Build

String concatenation that can be converted to string template

'String' concatenation can be converted to a template
}
// wildcard case
parts[0] += "-bg"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package com.coder.gateway.cli.downloader
import com.coder.gateway.cli.ex.ResponseException
import com.coder.gateway.settings.CoderSettings
import com.coder.gateway.util.OS
import com.coder.gateway.util.SemVer
import com.coder.gateway.util.getHeaders
import com.coder.gateway.util.getOS
import com.coder.gateway.util.sha1
import com.intellij.openapi.diagnostic.Logger
import com.squareup.moshi.Moshi
import com.squareup.moshi.Types
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import okhttp3.ResponseBody
Expand All @@ -25,6 +26,10 @@ import java.nio.file.StandardOpenOption
import java.util.zip.GZIPInputStream
import kotlin.io.path.name
import kotlin.io.path.notExists
import kotlin.io.path.writeText

private const val BUNDLED_SIGNATURES = "/META-INF/release-signatures.json"
private val RELEASE_BUILD = Regex("""v?(\d+\.\d+\.\d+)(\+.*)?""")

/**
* Handles the download steps of Coder CLI
Expand Down Expand Up @@ -225,14 +230,45 @@ class CoderDownloadService(
buildVersion: String,
showTextProgress: ((t: String) -> Unit)? = null
): DownloadResult {
val semVer = SemVer.parse(buildVersion)
val release = releaseVersion(buildVersion)
if (release == null) {
logger.info("No signature is published on releases.coder.com for $buildVersion")
return DownloadResult.NotFound
}
return downloadSignature(
URI.create("https://releases.coder.com/coder-cli/${semVer.major}.${semVer.minor}.${semVer.patch}/").toURL(),
URI.create("https://releases.coder.com/coder-cli/$release/").toURL(),
showTextProgress
)
}

fun bundledSignature(buildVersion: String): DownloadResult {
val source = javaClass.getResource(BUNDLED_SIGNATURES) ?: return DownloadResult.NotFound
val signature = releaseVersion(buildVersion)
?.let { bundledSignatures(source)[it] }
?.get(settings.defaultCliBinaryNameByOsAndArch)
if (signature == null) {
logger.info("No signature is bundled with the plugin for $buildVersion")
return DownloadResult.NotFound
}
val localSignaturePath = cliFinalDst.parent.resolve(settings.defaultSignatureNameByOsAndArch)
logger.info("Using the signature bundled with the plugin for the $buildVersion release")
localSignaturePath.writeText(signature)
return DownloadResult.Downloaded(source, localSignaturePath)
}

companion object {
val logger = Logger.getInstance(CoderDownloadService::class.java.simpleName)
}
}

private fun releaseVersion(buildVersion: String): String? =
RELEASE_BUILD.matchEntire(buildVersion)?.groupValues?.get(1)

internal fun bundledSignatures(source: URL): Map<String, Map<String, String>> {
val type = Types.newParameterizedType(
Map::class.java,
String::class.java,
Types.newParameterizedType(Map::class.java, String::class.java, String::class.java),
)
return Moshi.Builder().build().adapter<Map<String, Map<String, String>>>(type).fromJson(source.readText()).orEmpty()
}
4 changes: 2 additions & 2 deletions src/main/kotlin/com/coder/gateway/settings/CoderSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -447,11 +447,11 @@ open class CoderSettings(
}

/**
* Returns the name of the signature file (.asc) for the provided OS and architecture.
* Returns the name of the signature file (.v2.asc) for the provided OS and architecture.
*/
private fun getCoderSignatureForOS(os: OS?, arch: Arch?): String {
logger.debug("Resolving signature for $os $arch")
return "${getCoderCLIForOS(os, arch)}.asc"
return "${getCoderCLIForOS(os, arch)}.v2.asc"
}

companion object {
Expand Down
Loading
Loading