Skip to content

Commit 7559bef

Browse files
committed
impl: add new configurable option to disable CLI signature verification
These options are configurable from the Settings page, there is no available shortcut on the main plugin page to discourage the quick disable of CLI verification
1 parent 82eee1f commit 7559bef

File tree

5 files changed

+41
-3
lines changed

5 files changed

+41
-3
lines changed

src/main/kotlin/com/coder/toolbox/settings/ReadOnlyCoderSettings.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ interface ReadOnlyCoderSettings {
2929
val binaryDirectory: String?
3030

3131
/**
32-
* Controls whether we fall back release.coder.com
32+
* Controls whether we verify the cli signature
33+
*/
34+
val disableSignatureVerification: Boolean
35+
36+
/**
37+
* Controls whether we fall back on release.coder.com for signatures if signature validation is enabled
3338
*/
3439
val fallbackOnCoderForSignatures: SignatureFallbackStrategy
3540

src/main/kotlin/com/coder/toolbox/store/CoderSettingsStore.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class CoderSettingsStore(
3838
override val defaultURL: String get() = store[DEFAULT_URL] ?: "https://dev.coder.com"
3939
override val binarySource: String? get() = store[BINARY_SOURCE]
4040
override val binaryDirectory: String? get() = store[BINARY_DIRECTORY]
41+
override val disableSignatureVerification: Boolean
42+
get() = store[DISABLE_SIGNATURE_VALIDATION]?.toBooleanStrictOrNull() ?: false
4143
override val fallbackOnCoderForSignatures: SignatureFallbackStrategy
4244
get() = SignatureFallbackStrategy.fromValue(store[FALLBACK_ON_CODER_FOR_SIGNATURES])
4345
override val defaultCliBinaryNameByOsAndArch: String get() = getCoderCLIForOS(getOS(), getArch())
@@ -166,6 +168,10 @@ class CoderSettingsStore(
166168
store[ENABLE_DOWNLOADS] = shouldEnableDownloads.toString()
167169
}
168170

171+
fun updateDisableSignatureVerification(shouldDisableSignatureVerification: Boolean) {
172+
store[DISABLE_SIGNATURE_VALIDATION] = shouldDisableSignatureVerification.toString()
173+
}
174+
169175
fun updateSignatureFallbackStrategy(fallback: Boolean) {
170176
store[FALLBACK_ON_CODER_FOR_SIGNATURES] = when (fallback) {
171177
true -> SignatureFallbackStrategy.ALLOW.toString()

src/main/kotlin/com/coder/toolbox/store/StoreKeys.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ internal const val BINARY_SOURCE = "binarySource"
1010

1111
internal const val BINARY_DIRECTORY = "binaryDirectory"
1212

13+
internal const val DISABLE_SIGNATURE_VALIDATION = "disableSignatureValidation"
14+
1315
internal const val FALLBACK_ON_CODER_FOR_SIGNATURES = "signatureFallbackStrategy"
1416

1517
internal const val BINARY_NAME = "binaryName"

src/main/kotlin/com/coder/toolbox/views/CoderSettingsPage.kt

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.jetbrains.toolbox.api.ui.components.CheckboxField
66
import com.jetbrains.toolbox.api.ui.components.TextField
77
import com.jetbrains.toolbox.api.ui.components.TextType
88
import com.jetbrains.toolbox.api.ui.components.UiField
9+
import kotlinx.coroutines.Job
910
import kotlinx.coroutines.channels.Channel
1011
import kotlinx.coroutines.channels.ClosedSendChannelException
1112
import kotlinx.coroutines.flow.MutableStateFlow
@@ -20,7 +21,7 @@ import kotlinx.coroutines.launch
2021
* TODO@JB: There is no scroll, and our settings do not fit. As a consequence,
2122
* I have not been able to test this page.
2223
*/
23-
class CoderSettingsPage(context: CoderToolboxContext, triggerSshConfig: Channel<Boolean>) :
24+
class CoderSettingsPage(private val context: CoderToolboxContext, triggerSshConfig: Channel<Boolean>) :
2425
CoderPage(MutableStateFlow(context.i18n.ptrl("Coder Settings")), false) {
2526
private val settings = context.settingsStore.readOnly()
2627

@@ -33,6 +34,11 @@ class CoderSettingsPage(context: CoderToolboxContext, triggerSshConfig: Channel<
3334
TextField(context.i18n.ptrl("Data directory"), settings.dataDirectory ?: "", TextType.General)
3435
private val enableDownloadsField =
3536
CheckboxField(settings.enableDownloads, context.i18n.ptrl("Enable downloads"))
37+
38+
private val disableSignatureVerificationField = CheckboxField(
39+
settings.disableSignatureVerification,
40+
context.i18n.ptrl("Disable Coder CLI signature verification")
41+
)
3642
private val signatureFallbackStrategyField =
3743
CheckboxField(
3844
settings.fallbackOnCoderForSignatures.isAllowed(),
@@ -65,13 +71,14 @@ class CoderSettingsPage(context: CoderToolboxContext, triggerSshConfig: Channel<
6571
private val networkInfoDirField =
6672
TextField(context.i18n.ptrl("SSH network metrics directory"), settings.networkInfoDir, TextType.General)
6773

68-
74+
private lateinit var visibilityUpdateJob: Job
6975
override val fields: StateFlow<List<UiField>> = MutableStateFlow(
7076
listOf(
7177
binarySourceField,
7278
enableDownloadsField,
7379
binaryDirectoryField,
7480
enableBinaryDirectoryFallbackField,
81+
disableSignatureVerificationField,
7582
signatureFallbackStrategyField,
7683
dataDirectoryField,
7784
headerCommandField,
@@ -94,6 +101,7 @@ class CoderSettingsPage(context: CoderToolboxContext, triggerSshConfig: Channel<
94101
context.settingsStore.updateBinaryDirectory(binaryDirectoryField.contentState.value)
95102
context.settingsStore.updateDataDirectory(dataDirectoryField.contentState.value)
96103
context.settingsStore.updateEnableDownloads(enableDownloadsField.checkedState.value)
104+
context.settingsStore.updateDisableSignatureVerification(disableSignatureVerificationField.checkedState.value)
97105
context.settingsStore.updateSignatureFallbackStrategy(signatureFallbackStrategyField.checkedState.value)
98106
context.settingsStore.updateBinaryDirectoryFallback(enableBinaryDirectoryFallbackField.checkedState.value)
99107
context.settingsStore.updateHeaderCommand(headerCommandField.contentState.value)
@@ -182,5 +190,19 @@ class CoderSettingsPage(context: CoderToolboxContext, triggerSshConfig: Channel<
182190
networkInfoDirField.contentState.update {
183191
settings.networkInfoDir
184192
}
193+
194+
visibilityUpdateJob = context.cs.launch {
195+
disableSignatureVerificationField.checkedState.collect { state ->
196+
signatureFallbackStrategyField.visibility.update {
197+
// the fallback checkbox should not be visible
198+
// if signature verification is disabled
199+
!state
200+
}
201+
}
202+
}
203+
}
204+
205+
override fun afterHide() {
206+
visibilityUpdateJob.cancel()
185207
}
186208
}

src/main/resources/localization/defaultMessages.po

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,7 @@ msgid "Abort"
164164
msgstr ""
165165

166166
msgid "Run anyway"
167+
msgstr ""
168+
169+
msgid "Disable Coder CLI signature verification"
167170
msgstr ""

0 commit comments

Comments
 (0)