fix(certgen): use POD_NAMESPACE for default server SANs instead of hardcoded namespace
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 8.7k
- Forks
- 1.3k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 253
Description
Problem Statement
The Rust constant DEFAULT_SERVER_SANS in crates/openshell-bootstrap/src/pki.rs:32-42 hardcodes openshell.openshell.svc and openshell.openshell.svc.cluster.local. When the Helm chart passes explicit --server-san args (as in PR #2062), the certgen binary still prepends these hardcoded SANs, resulting in duplicate and incorrect entries in the certificate.
PR #2062 fixes the Helm side (option B from #2060), but the Rust binary should also be namespace-aware so that the hardcoded defaults don't leak into certificates for non-openshell namespaces.
Proposed Design
Read the POD_NAMESPACE environment variable (already available via the downward API in certgen.yaml:91-94) and use it to generate namespace-aware default SANs:
fn default_server_sans(namespace: &str) -> Vec<String> {
let name = "openshell";
vec![
name.to_string(),
format!("{name}.{namespace}.svc"),
format!("{name}.{namespace}.svc.cluster.local"),
"localhost".to_string(),
format!("{name}.localhost"),
format!("*.{name}.localhost"),
"host.docker.internal".to_string(),
"host.containers.internal".to_string(),
]
}
When --server-san args are provided, skip the defaults entirely — the caller (Helm template or user) has full control over the SAN list.
Changes required
crates/openshell-bootstrap/src/pki.rs— replace theDEFAULT_SERVER_SANSconstant with a function that readsPOD_NAMESPACEcrates/openshell-server/src/certgen.rs:91— pass the namespace togenerate_pki()when no--server-sanargs are provided- Update tests that reference
DEFAULT_SERVER_SANS
Alternatives Considered
-
Helm-only fix (PR #2062, option B from #2060): Already implemented. Fixes the Helm path but the Rust defaults still produce duplicate SANs in the cert. Works but not clean.
-
Remove
DEFAULT_SERVER_SANSentirely: Would break localopenshell gateway generate-certsinvocations that don't pass--server-sanargs (e.g., Docker/Podman installs where there is no Helm). -
Condition defaults on
--server-sanpresence only: Skip defaults when any--server-sanis passed. Simpler than readingPOD_NAMESPACEbut loses the fallback for non-Helm installs where namespace matters.
Agent Investigation
- Explored
crates/openshell-bootstrap/src/pki.rs:32-42— confirmed the constant is used unconditionally inbuild_server_sans()at line 134. - Explored
crates/openshell-server/src/certgen.rs:91— the certgen binary receivesserver_sansfrom CLI args and passes them togenerate_pki(). ThePOD_NAMESPACEenv var is available (set incertgen.yaml:91-94) but not read. - Verified by deploying in
openshell-system: the generated cert contains bothopenshell.openshell.svc.cluster.local(from Rust defaults) andopenshell.openshell-system.svc.cluster.local(from Helm--server-sanargs). Duplicates are harmless but messy.
Related
- #2060 — original issue
- #2062 — Helm-side fix (option B)
- I've reviewed existing issues and the architecture docs
- This is a design proposal, not a "please build this" request
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in crates/openshell-bootstrap/src/pki.rs:32-42 and inspect build_server_sans() around line 134, then trace the server_sans flow from crates/openshell-server/src/certgen.rs:91. Check the existing tests that reference DEFAULT_SERVER_SANS and certgen.yaml:91-94 for the environment variable setup. Done means namespace-aware defaults are used when no --server-san args are supplied, explicit SANs replace defaults, and the affected tests pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- cryptography, security
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100