Skip to content

Commit 8d768ee

Browse files
committed
impl: prompt user when running unsigned binaries
A pop-up dialog is displayed asking the user if he wants to run an unsigned cli version. The pop-up can be skipped if the user configures the `Allow unsigned binary execution without prompt`
1 parent 6754300 commit 8d768ee

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/main/kotlin/com/coder/toolbox/cli/CoderCLIManager.kt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ package com.coder.toolbox.cli
33
import com.coder.toolbox.CoderToolboxContext
44
import com.coder.toolbox.cli.downloader.CoderDownloadApi
55
import com.coder.toolbox.cli.downloader.CoderDownloadService
6+
import com.coder.toolbox.cli.downloader.DownloadResult.Downloaded
67
import com.coder.toolbox.cli.ex.MissingVersionException
78
import com.coder.toolbox.cli.ex.SSHConfigFormatException
9+
import com.coder.toolbox.cli.ex.UnsignedBinaryExecutionDeniedException
810
import com.coder.toolbox.sdk.v2.models.Workspace
911
import com.coder.toolbox.sdk.v2.models.WorkspaceAgent
1012
import com.coder.toolbox.util.CoderHostnameVerifier
@@ -27,6 +29,7 @@ import retrofit2.Retrofit
2729
import java.io.EOFException
2830
import java.io.FileNotFoundException
2931
import java.net.URL
32+
import java.nio.file.Files
3033
import java.nio.file.Path
3134
import javax.net.ssl.X509TrustManager
3235

@@ -170,6 +173,31 @@ class CoderCLIManager(
170173
singatureDownloadResult = downloader.downloadReleasesSignature(showTextProgress)
171174
}
172175

176+
// if we could not find any signature and the user wants to explicitly
177+
// confirm whether we run an unsigned cli
178+
if (cliDownloadResult.isNotDownloaded()) {
179+
val cli = cliDownloadResult as Downloaded
180+
if (context.settingsStore.allowUnsignedBinaryWithoutPrompt) {
181+
context.logger.warn("Running unsigned CLI from ${cli.source}")
182+
} else {
183+
val acceptsUnsignedBinary = context.ui.showYesNoPopup(
184+
context.i18n.ptrl("Security Warning"),
185+
context.i18n.pnotr("Can't verify the integrity of the Coder CLI pulled from ${cli.source}"),
186+
context.i18n.ptrl("Accept"),
187+
context.i18n.ptrl("Abort"),
188+
)
189+
190+
if (acceptsUnsignedBinary) {
191+
return true
192+
} else {
193+
// remove the cli, otherwise next time the user tries to login the cached cli is picked up
194+
// and we don't verify cached cli signatures
195+
Files.delete(cli.dst)
196+
throw UnsignedBinaryExecutionDeniedException("Running unsigned CLI from ${cli.source} was denied by the user")
197+
}
198+
}
199+
}
200+
173201
return cliDownloadResult.isDownloaded()
174202
}
175203

src/main/kotlin/com/coder/toolbox/cli/ex/Exceptions.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ class ResponseException(message: String, val code: Int) : Exception(message)
55
class SSHConfigFormatException(message: String) : Exception(message)
66

77
class MissingVersionException(message: String) : Exception(message)
8+
9+
class UnsignedBinaryExecutionDeniedException(message: String) : Exception(message)

0 commit comments

Comments
 (0)