Skip to content

fix(pki): refuse to silently reissue or blank an existing kubernetes … - #18719

Open
ntmspavan wants to merge 1 commit into
kubernetes:masterfrom
ntmspavan:fix/pki-ca-keypair-silent-reissue
Open

fix(pki): refuse to silently reissue or blank an existing kubernetes …#18719
ntmspavan wants to merge 1 commit into
kubernetes:masterfrom
ntmspavan:fix/pki-ca-keypair-silent-reissue

Conversation

@ntmspavan

Copy link
Copy Markdown

…CA keypair

kops update cluster could propose creating a new kubernetes-ca keypair and blank ConfigServer.CACertificates in generated nodeup configs even when a valid CA already existed. If applied, this would break node bootstrap (empty CA bundle) or, worse, rotate the cluster's CA out from under it.

  • CreateKeyset() now re-checks the keystore immediately before minting a new "ca"-type certificate and refuses if one unexpectedly already exists there, protecting the dangerous real-apply outcome.
  • Keyset gains an IsPlaceholder() helper, and nodeup config rendering (loadCertificates) now emits an unambiguous placeholder marker instead of a bare empty string for an unresolved keyset, so a preview can never look like an existing CA cert was blanked.

Neither change affects a genuinely new cluster's first update cluster dry run, since nothing exists in the keystore to conflict with there.

Fixes #18680

@kubernetes-prow kubernetes-prow Bot added the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Aug 19, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

Welcome @ntmspavan!

It looks like this is your first PR to kubernetes/kops 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/kops has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@linux-foundation-easycla

linux-foundation-easycla Bot commented Aug 19, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: ntmspavan / name: Pavan Nalam (ece5172)

@kubernetes-prow kubernetes-prow Bot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 19, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

Hi @ntmspavan. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@kubernetes-prow kubernetes-prow Bot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Aug 19, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign zetaab for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubernetes-prow
kubernetes-prow Bot requested review from olemarkus and zetaab August 19, 2026 07:04
…CA keypair

kops update cluster could propose creating a new kubernetes-ca keypair and
blank ConfigServer.CACertificates in generated nodeup configs even when a
valid CA already existed. If applied, this would break node bootstrap
(empty CA bundle) or, worse, rotate the cluster's CA out from under it.

- CreateKeyset() now re-checks the keystore immediately before minting a
  new "ca"-type certificate and refuses if one unexpectedly already
  exists there, protecting the dangerous real-apply outcome.
- Keyset gains an IsPlaceholder() helper, and nodeup config rendering
  (loadCertificates) now emits an unambiguous placeholder marker instead
  of a bare empty string for an unresolved keyset, so a preview can never
  look like an existing CA cert was blanked.

Neither change affects a genuinely new cluster's first update cluster
dry run, since nothing exists in the keystore to conflict with there.

See kubernetes/kops issue 18680 for background.
@ntmspavan
ntmspavan force-pushed the fix/pki-ca-keypair-silent-reissue branch from 489fb43 to ece5172 Compare August 19, 2026 07:06
@kubernetes-prow kubernetes-prow Bot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Aug 19, 2026
@hakman

hakman commented Aug 19, 2026

Copy link
Copy Markdown
Member

Thanks for proposing this @ntmspavan. Did you manage to reproduce the issue and test the fix?

@ntmspavan

Copy link
Copy Markdown
Author

@hakman . yup reproduced and tested the fix

Bug Reproduction and Fix Verification

Tested on GCP with a single control-plane cluster (e2-medium, Gossip DNS).

Setup

  1. Create a working kOps cluster (any cloud provider) using kOps v1.36.2
  2. Confirm the CA exists and is healthy:
    kops get keypairs kubernetes-ca
    

Reproduce (kOps v1.36.2)

The bug triggers when Keypair.Find() cannot locate the existing CA in the state store.
To simulate this condition:

  1. Back up the CA keyset file:

    # GCS example (adjust path for S3/file:// state stores)
    gsutil cp \
        gs://<STATE_BUCKET>/<CLUSTER_NAME>/pki/private/kubernetes-ca/keyset.yaml \
        gs://<STATE_BUCKET>/<CLUSTER_NAME>/pki/private/kubernetes-ca/keyset.yaml.bak
  2. Temporarily remove the original so Find() returns nil:

    gsutil rm gs://<STATE_BUCKET>/<CLUSTER_NAME>/pki/private/kubernetes-ca/keyset.yaml
  3. Run a dry-run update with kOps v1.36.2 (unfixed):

    kops update cluster <CLUSTER_NAME>
  4. Observe the bug — control-plane nodeup config shows real certificate blanked to empty string:

    -   kubernetes-ca: |
    -     -----BEGIN CERTIFICATE-----
    -     MIIC+DCCAeCgAwIBAgIMGM7vay...
    -     -----END CERTIFICATE-----
    +   kubernetes-ca: ""

    And KeypairIDs show the real ID replaced with a placeholder:

    -   kubernetes-ca: "7677809576729311792494717359"
    +   kubernetes-ca: << TO BE GENERATED >>

    Output also shows Will create Keypair/kubernetes-ca — wants to recreate an existing CA.

  5. Restore immediately (DO NOT apply with --yes):

    gsutil cp \
        gs://<STATE_BUCKET>/<CLUSTER_NAME>/pki/private/kubernetes-ca/keyset.yaml.bak \
        gs://<STATE_BUCKET>/<CLUSTER_NAME>/pki/private/kubernetes-ca/keyset.yaml

Impact if applied with --yes

  • Nodes bootstrap with blank ConfigServer.CACertificates — cannot validate kops-controller
  • CreateKeyset() mints a new CA certificate, silently rotating the cluster's trust anchor
  • All previously issued certs become untrusted

Fix Verification (kOps v1.37.0-alpha.1, commit ece5172be4)

After restoring the CA file, repeat the same steps (hide keyset.yaml, run dry-run) using the fixed kOps binary built from this PR branch (fix/pki-ca-keypair-silent-reissue):

$ kops version
Client version: 1.37.0-alpha.1 (git-ece5172be4)

With the fix, the control-plane nodeup config diff now shows:

-   kubernetes-ca: |
-     -----BEGIN CERTIFICATE-----
-     MIIC+DCCAeCgAwIBAgIMGM7vay...
-     -----END CERTIFICATE-----
+   kubernetes-ca: << TO BE GENERATED >>

Key difference:

Control-plane CAs.kubernetes-ca
v1.36.2 (bug) "" — blank, silent data loss
This PR (fix) << TO BE GENERATED >> — unambiguous placeholder

The blank "" would silently break node bootstrap or rotate the CA if applied. The placeholder << TO BE GENERATED >> makes it immediately obvious that the keypair is unresolved, not that the CA was intentionally removed.

What this PR fixes

  1. loadCertificates() in nodeupconfigbuilder.go — detects placeholder keysets via IsPlaceholder() and refuses to write blank "". Writes the unambiguous marker << TO BE GENERATED >> instead.
  2. CreateKeyset() in keypair.go — re-checks the keystore before creating. If an existing CA certificate is found, returns a clear error instead of silently reissuing.
  3. PlaceholderKeypairID constant + IsPlaceholder() method in ca.go — shared sentinel so placeholder detection is consistent across the codebase.

Neither change affects new cluster creation (where no CA exists yet). Unit tests covering all three changes are included.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

kops 1.36.2: update cluster wants to create a new kubernetes-ca Keypair and blanks ConfigServer.CACertificates in nodeup config

2 participants