feat(openshell): connect to a gateway that requires mutual TLS (#1864)

This commit is contained in:
sam committed 2026-11-14 03:41:24 +11:00
1 parent e784adbd7a
commit 5c02207d48
5 files changed
+71 -2

No files matched your search

+5 -1
View File
@@ -446,11 +446,15 @@ func (b *boot) refuseRuntimeChange(ctx context.Context) error {
// egress hosts are read per task.
type openShellBoot struct {
address, workspace, servicesHost string
caFile, certFile, keyFile string
token config.SecretRef
}
func bootOnlyOpenShell(c config.OpenShellConfig) openShellBoot {
return openShellBoot{address: c.Address, workspace: c.Workspace, servicesHost: c.ServicesHost, token: c.Token}
return openShellBoot{
address: c.Address, workspace: c.Workspace, servicesHost: c.ServicesHost,
caFile: c.CAFile, certFile: c.CertFile, keyFile: c.KeyFile, token: c.Token,
}
}
// runtimeName is runtime with the empty default spelled out.
+5 -1
View File
@@ -31,7 +31,11 @@ func startOpenShell(ctx context.Context, cfgHolder *config.Holder, secrets *secr
}
auth = v1.StaticToken(token)
}
client, err := v1.NewClient(v1.Config{Address: settings.Address, Auth: auth})
var tls *v1.TLSConfig
if settings.CAFile != "" || settings.CertFile != "" || settings.KeyFile != "" {
tls = &v1.TLSConfig{CAFile: settings.CAFile, CertFile: settings.CertFile, KeyFile: settings.KeyFile}
}
client, err := v1.NewClient(v1.Config{Address: settings.Address, Auth: auth, TLS: tls})
if err != nil {
return nil, nil, nil, fmt.Errorf("openshell gateway %s: %w", settings.Address, err)
}
+7
View File
@@ -712,6 +712,13 @@ type OpenShellConfig struct {
// Token resolves to the gateway's bearer token. Zero sends none, which
// only a gateway allowing unauthenticated users accepts.
Token SecretRef `toml:"token" yaml:"token" json:"token"`
// CAFile, CertFile and KeyFile are PEM files for a gateway that requires
// mutual TLS: the CA its server certificate is checked against, and the
// client certificate and key archie presents. Empty uses no client
// certificate.
CAFile string `toml:"ca_file" yaml:"ca_file" json:"ca_file"`
CertFile string `toml:"cert_file" yaml:"cert_file" json:"cert_file"`
KeyFile string `toml:"key_file" yaml:"key_file" json:"key_file"`
// ServicesHost is the DNS name sandboxes reach this host's NATS and State
// Store by when those are addressed by IP or loopback: sandbox policy
// admits TCP only to DNS names, and never to loopback.
@@ -133,6 +133,9 @@ func validateRuntime(settings config.ContainerConfig) error {
default:
return fmt.Errorf("runtime must be docker or openshell")
}
if (settings.OpenShell.CertFile == "") != (settings.OpenShell.KeyFile == "") {
return fmt.Errorf("the openshell client certificate and key go together")
}
if (settings.OpenShell.Token.Engine == "") != (settings.OpenShell.Token.Key == "") {
return fmt.Errorf("the openshell token reference needs both an engine and a key")
}
+51
View File
@@ -51,6 +51,9 @@ interface ContainerRuntime {
address: string;
workspace: string;
token: { engine: string; key: string };
ca_file: string;
cert_file: string;
key_file: string;
services_host: string;
egress_hosts: string[];
};
@@ -176,6 +179,54 @@ function formatHours(seconds: number): string {
</Field>
</form.Field>
<form.Field v-slot="{ field }" name="openshell.ca_file">
<Field orientation="responsive">
<FieldContent><FieldLabel for="cr-os-ca-file">CA file</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Input
id="cr-os-ca-file"
:model-value="field.state.value"
class="max-w-sm font-mono"
@blur="field.handleBlur"
@update:model-value="field.handleChange"
/>
<DraftHint :kind="KIND" path="openshell.ca_file" />
</div>
</Field>
</form.Field>
<form.Field v-slot="{ field }" name="openshell.cert_file">
<Field orientation="responsive">
<FieldContent><FieldLabel for="cr-os-cert-file">Client certificate</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Input
id="cr-os-cert-file"
:model-value="field.state.value"
class="max-w-sm font-mono"
@blur="field.handleBlur"
@update:model-value="field.handleChange"
/>
<DraftHint :kind="KIND" path="openshell.cert_file" />
</div>
</Field>
</form.Field>
<form.Field v-slot="{ field }" name="openshell.key_file">
<Field orientation="responsive">
<FieldContent><FieldLabel for="cr-os-key-file">Client key</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Input
id="cr-os-key-file"
:model-value="field.state.value"
class="max-w-sm font-mono"
@blur="field.handleBlur"
@update:model-value="field.handleChange"
/>
<DraftHint :kind="KIND" path="openshell.key_file" />
</div>
</Field>
</form.Field>
<form.Field v-slot="{ field }" name="openshell.services_host">
<Field orientation="responsive">
<FieldContent><FieldLabel for="cr-os-services-host">Services host</FieldLabel></FieldContent>