Skip to content

cornus config

管理用于访问远程 cornus server 的客户端侧 connection profile (context) ,其结构类似 kubectl config

概要

sh
cornus config <subcommand> [flags]

说明

cornus config 读写 cornus client config file;其中保存一个或多个命名 context (connection profile) 及 current-context pointer。文件位于 platform user config dir,或由全局 --config-file flag / CORNUS_CONFIG 指定的路径。 若需要引导式流程来选择部署场景、只询问相关问题、验证连接并给出设置说明,请使用交互式 cornus setup 向导;它是 set-context 的前端。

每个 context 描述如何访问 server: base URL、SSH 密钥会话、bearer token 或 ServiceAccount-minted auth、TLS material、到 in-cluster Service 的可选 automatic port-forward、direct-vs-proxy via-server toggle,以及 session conduit (port-forward 或 SOCKS5) 。完整 schema 见连接配置

客户端配置文件格式

文件为 YAML,以名称为 key 的 contexts: map 及 current-context: field,例如:

yaml
current-context: prod
contexts:
  prod:
    server: https://cornus.example.com:5000
    token: eyJhbGci...
  staging:
    namespace: cornus-system

view 默认 redact bearer token,除非给出 --show-tokens (或 --export) 。所有 field 见连接配置

cornus config get-contexts

以表格列出已配置 connection profile (* 标记 current context) 。

sh
cornus config get-contexts

cornus config current-context

打印当前 (默认) context name。没有设置时返回 error。

sh
cornus config current-context

cornus config use-context

设置当前 (默认) context。

sh
cornus config use-context <name>

cornus config set-context

创建或更新 context。

sh
cornus config set-context [flags] <name>

默认 set-context替换同名已有 context: 结果精确等于该次 invocation 指定的内容。分层顺序是 --from-file (base) 、各 individual flag、--from-file-override (top) 。使用 --merge 则将给定 setting 分层到已有 context,保留未设置 field——即 edit-in-place mode。

Config 尚无 context 且 terminal 为 interactive 时,新建 context 会被提示设为 default (current) context。--insecure-skip-verify 只会启用该 setting。

FlagEnv var默认值说明
--serverCornus server base URL (http(s)://host:port) 。
--token作为 Authorization: Bearer 发送的 bearer token / JWT。
--tls-ca-cert验证 server certificate 的 PEM CA bundle。
--tls-client-certmTLS 所用 PEM client certificate (需要 --tls-client-key) 。
--tls-client-keymTLS 所用 PEM client key (需要 --tls-client-cert) 。
--tls-server-name连接地址与证书身份不同时,覆盖要验证的证书主机名 (SNI) (例如通过 127.0.0.1 连接的 SSH 隧道端点) 。
--insecure-skip-verifyfalse禁用 server certificate verification (仅测试) 。
-n, --namespacecornus install 的 namespace;除非设置 --pf-service--no-detect,否则自动检测 Service 和 port。
--no-detectfalse保存 --namespace 而不联系 cluster 检测 Service。
--pf-kube-contextautomatic port-forward 所用 kubeconfig context。
--pf-namespace要 port-forward 的 in-cluster Service namespace (--namespace 的别名) 。
--pf-service要 port-forward 的 in-cluster Service 名称 (跳过 auto-detection) 。
--pf-remote-port要 port-forward 的 Service port。
--kube-auth-service-account通过 TokenRequest API 从此 cluster ServiceAccount 签发 bearer token (代替 static --token) 。
--kube-auth-audience签发 ServiceAccount token 的 audience;必须与 server CORNUS_JWT_AUDIENCE 匹配。
--kube-auth-namespaceServiceAccount namespace (默认 --pf-namespace) 。
--kube-auth-kube-context用于签发 token 的 kubeconfig context (默认 --pf-kube-context) 。
--kube-auth-expiration-seconds3600请求 token lifetime,单位秒 (0 = 默认 3600) 。
--key-auth-identity-file用于签发短期 Cornus 会话的 SSH 私钥路径。
--key-auth-fingerprintSSH_AUTH_SOCK 选择密钥或固定私钥文件的 SHA256 指纹。
--key-auth-name注册密钥时使用的易读名称。
--key-auth-scopeapiSSH 密钥会话请求的 scope。
--key-auth-ttl1hSSH 密钥会话请求的有效期 (最长 24h)。
--ssh-host通过到此目标的 SSH 隧道访问服务器: ssh_config Host 别名或 host[:port] (--pf-* 在 docker/containerd 主机上的对应项,且两者互斥) 。
--ssh-userSSH 登录用户 (默认依次来自 ssh_config 和当前用户) 。
--ssh-remote-addr127.0.0.1:5000从远程主机视角看,远程 Cornus 服务器监听的地址。
--ssh-identity-fileSSH 公钥认证所用 PEM 私钥 (默认使用 ssh-agent 和 ssh_config IdentityFile) 。
--ssh-no-agentfalse不使用本地 ssh-agent (主要用于“身份验证失败次数过多”的情况) 。
--ssh-known-hosts用于 SSH 主机密钥验证的 known_hosts 文件 (默认依次来自 ssh_config 和 ~/.ssh/known_hosts) 。
--ssh-host-key将单个 SSH 主机密钥固定为 authorized_keys 格式的一行。
--ssh-insecure-host-keyfalse跳过 SSH 主机密钥验证 (仅限开发) 。
--ssh-no-configfalse不读取 ~/.ssh/config/etc/ssh/ssh_config,仅使用 --ssh-* 标志。
--ssh-use-binaryfalse强制使用系统 ssh 二进制文件 (Unix socket 转发),以完整支持 ssh_config (ProxyCommandMatch) 。主机配置了 ProxyCommand 时会自动选择。
--ssh-tlsfalse由于远程服务器终止 TLS,通过 https:// 连接隧道端点 (通常与 --tls-server-name 配合使用) 。
--via-server / --no-via-server让 workload log/port-forward 经 cornus server proxy 路由,而非用 kubeconfig 直接访问 pod (仅 cluster profile) 。每次运行可由 CORNUS_VIA_SERVER 或 command --via-server flag 覆盖。
--conduit-modeClient session 暴露 port 的方式: port-forward (每 port local listener,默认) 、socks5 (一个按名称访问 service 的 split-tunnel proxy) ,或还会设置 proxy bind address 和 suffix 的 socks5://host:port[?suffix=SUFFIX] URL。每次运行可由 CORNUS_CONDUIT 或 command --conduit flag 覆盖。
--socks5-service-host-suffix.cornus.internalSOCKS5 CONNECT target 会 tunnel 至匹配 service 的 host suffix;其他 host 由 conduit 直接访问。
--socks5-resolve高级 SOCKS5 resolution rule PATTERN=REPLACE (可重复、有序、首个匹配获胜) ;替换 suffix 默认规则。
--ingress-conduitCORNUS_INGRESS_CONDUIT通过 SOCKS5 conduit 访问工作负载 ingress (x-cornus-ingress) : native (隧道连接真实集群 ingress controller) 、emulate (使用生成证书的客户端侧反向代理) 或 off。需要 --conduit-mode socks5。参见 Ingress
--ingress-controllernative 模式下要隧道连接的 ingress controller Service,格式为 <namespace>/<service>[:httpPort/httpsPort]。留空时从服务器获知 (GET /.cornus/v1/info) 。
--ingress-emulate-ca / --ingress-emulate-ca-keyemulate 模式下用于签署各主机 leaf certificate 的 PEM CA 证书/密钥。留空时自动检测本地信任的 mkcert CA (mkcert -install 后),否则生成持久化的 self-signed CA (~/.local/share/cornus/ingress-ca.pem) 。
--from-file加载 context definition (bare Context object、JSON/YAML) 作为 base layer,individual flag 覆盖它;可重复,后者获胜。
--from-file-override加载覆盖 individual flag 的 context definition;可重复,后者获胜。
--mergefalse将给定 setting merge 至已有 context 而非替换: 未设置 field 保留 stored value (edit-in-place) 。

cornus config delete-context

删除 context。若 current-context pointer 指向该 context,则一并清除。

sh
cornus config delete-context <name>

cornus config view

打印 client config file,默认 redact bearer token。

sh
cornus config view [flags]

--export 改为将单个 context 打印为 bare Context object (没有 contexts: wrapper) ,可 round-trip 回 set-context --from-file;该 mode 默认包含 token (目的就是 reusable export) ,除非 --redact。未使用 --export 时,export context 由全局 --context flag 选择,否则使用 current context。

FlagEnv var默认值说明
--show-tokensfalse打印 bearer token 而非 redact (whole-file view) 。
--exportfalse仅打印一个 context,作为可传回 set-context --from-file 的 bare Context object。
--redactfalse使用 --export 时,将 bearer token 替换为 REDACTED (export 默认包含真实 token) 。
-o, --output-filestdout写入此 file (以 0600 创建) 而非 stdout。

示例

创建直接访问 server 的 context 并设为 current:

sh
cornus config set-context prod --server https://cornus.example.com:5000 --token "$TOKEN"
cornus config use-context prod

创建自动检测 in-cluster Service 并签发 ServiceAccount token 的 cluster context:

sh
cornus config set-context staging \
  --namespace cornus-system \
  --kube-auth-service-account cornus-client \
  --kube-auth-audience cornus

原地编辑已有 context (保留未设置 field) :

sh
cornus config set-context prod --merge --conduit-mode socks5

导出一个 context (含其 token) ,以便在其他位置复用:

sh
cornus config view --export --context prod -o prod-context.yaml

Released under the Apache-2.0 License.