feat(server): add generate-certs subcommand; replace alpine PKI hook#1257
Open
TaylorMutch wants to merge 2 commits intomainfrom
Open
feat(server): add generate-certs subcommand; replace alpine PKI hook#1257TaylorMutch wants to merge 2 commits intomainfrom
TaylorMutch wants to merge 2 commits intomainfrom
Conversation
|
Label |
Collaborator
Author
|
/ok to test f7e72b0 |
5 tasks
Introduce `openshell-gateway generate-certs` modeled on envoyproxy/gateway's certgen pattern. The Helm pre-install/pre-upgrade hook now runs the gateway image instead of an alpine + openssl shell job — one image to mirror in air-gapped environments, one PKI implementation, real test coverage. Reuses `openshell_bootstrap::pki::generate_pki` for CA/server/client cert generation. Idempotency contract preserved: both Secrets exist → skip; one exists → fail with `kubectl delete` recovery hint; neither exists → POST both `kubernetes.io/tls` Secrets. The server CLI gains optional subcommand support: bare `openshell-gateway` still runs the gateway, `generate-certs` runs the new path. `--db-url` moved from clap-required to call-site validated to avoid the clap flatten + required-field landmine.
Presence of `--output-dir <DIR>` switches the subcommand from Kubernetes
Secret writes to filesystem writes, making the kube flags optional.
Local layout matches `deploy/rpm/init-pki.sh` exactly:
<dir>/{ca.crt, ca.key, server/tls.{crt,key}, client/tls.{crt,key}}
Stages writes to a sibling `<dir>.certgen.tmp` and renames into place for
atomic per-file installation. Sets 0o700 on directories and 0o600 on key
files. Reuses `openshell_bootstrap::mtls::store_pki_bundle` to populate
the CLI auto-discovery directory at $XDG_CONFIG_HOME/openshell/gateways/
openshell/mtls/, mirroring init-pki.sh's local-CLI UX.
Same idempotency contract as the Kubernetes path: all six files present →
skip (and self-heal the CLI mTLS copy if missing); partial → fail with a
recovery hint; nothing → generate and write.
Sets up the seam for a follow-up PR that swaps init-pki.sh for the Rust
command in the systemd unit. The shell script and unit are untouched here.
f7e72b0 to
e845d31
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces the alpine + openssl PKI hook with
openshell-gateway generate-certs. The command runs in two output modes — Kubernetes Secrets (default) and filesystem (--output-dir). The Helm chart's pre-install hook now uses the gateway image itself; the RPM systemd path will switch over in a follow-up PR.Changes
generate-certssubcommand onopenshell-gateway(crates/openshell-server/src/certgen.rs). Reusesopenshell_bootstrap::pki::generate_pkiandopenshell_bootstrap::mtls::store_pki_bundle— no new cert-generation code.kubernetes.io/tlsSecrets (tls.crt/tls.key/ca.crt) via kube-rs.--output-dir <DIR>): writes the 6-file layout used bydeploy/rpm/init-pki.sh(<dir>/{ca.crt, ca.key, server/tls.{crt,key}, client/tls.{crt,key}}); also copies client materials to$XDG_CONFIG_HOME/openshell/gateways/openshell/mtls/for CLI auto-discovery.openshell-gatewayinvocation still runs the gateway.--db-urlvalidated at the call site instead of clap-required to avoid the flatten + required-field interaction.templates/pki-hook.yamldeleted, replaced bytemplates/certgen.yaml.pkiInitJob.image.*,caValidityDays, andcertValidityDaysremoved fromvalues.yaml.serverDnsNames/serverIpAddressesdefaults emptied (the gateway binary already includes the cluster SANs); the values are now additive overrides.~/.configwas wiped.<dir>.certgen.tmpstaging directory; 0o700 dirs, 0o600 keys.Testing
mise run pre-commitpasses (clippy-D warnings, fmt, markdownlint, full unit suite).certgenandclimodules — k8s decision table, local decision table, layout, sibling temp path, write_local_bundle (incl. unix permission mode), CLI parse for both modes (with and without--db-url/ kube flags), stale-temp recovery.helm lintclean across all six CI overlays (values-{gateway,cert-manager,tls-disabled,skaffold,keycloak}.yamlplus default).kubernetes.io/tlstype and 3 keys (tls.crt/tls.key/ca.crt).openssl verifyvalidates the chain; server cert SANs include all 6 cluster defaults with no duplicates.PKI secrets already exist, skipping.; secret resourceVersions unchanged.× partial PKI state in namespace openshell: ... Recover with: kubectl delete secret -n openshell openshell-server-tls openshell-client-tls.openshell sandbox create -- /bin/echo ...runs end-to-end (compute allocate, image pull, supervisor mTLS callback, command output, auto-delete).drwx------on dirs,-rw-------on*.key).$XDG_CONFIG_HOME/openshell/gateways/openshell/mtls/.PKI files already exist, skipping.× partial PKI state ... Recover with: rm -rf <dir> ...Checklist
architecture/gateway.mdPKI Bootstrap subsection)deploy/helm/openshell/README.md)helm-dev-environmentskill updated to reflect the new hook descriptionFollow-up
A separate PR will swap
deploy/rpm/init-pki.shforopenshell-gateway generate-certs --output-dir %S/openshell/tlsinopenshell.spec'sExecStartPreand delete the shell script.