Skip to content

OCPBUGS-120802: fix(webhookcerts): prevent CA overwrite on transient API errors - #9507

Open
redhat-chai-bot wants to merge 2 commits into
openshift:release-4.22from
redhat-chai-bot:OCPBUGS-118883/webhook-tls-upgrade-stall
Open

redhat-chai-bot wants to merge 2 commits into
openshift:release-4.22from
redhat-chai-bot:OCPBUGS-118883/webhook-tls-upgrade-stall

Conversation

@redhat-chai-bot

Copy link
Copy Markdown
Contributor

Summary

  • Distinguish transient API errors from NotFound when checking webhook certificate secrets.
  • Preserve valid CA and serving certificate data during retries and multi-replica races.
  • Add regression coverage for transient errors, missing or empty serving certificates, and CA reuse.

Root Cause

During the operator upgrade, applying the CRDs can temporarily increase API server load. The certificate check previously treated any API error as if the secret were missing, which could regenerate and overwrite the CA while existing webhook configurations still referenced the previous CA bundle. The resulting certificate mismatch caused webhook TLS handshakes to fail and stalled the rollout.

Validation

  • Targeted webhook certificate tests: 17/17 passed
  • make test: 192 packages, 0 failures
  • make verify: passed

Scope

The pre-existing hasKeys issue in support/certs/tls.go is not changed by this pull request.


AI-generated. Review for accuracy.

@devguyio requested in Slack thread

…g upgrade

During operator upgrade, the install path applies 93 CRDs via SSA before
the new deployment rolls out. When the new operator pod starts, it calls
EnsureWebhookCerts to check whether webhook cert secrets exist. Under API
server load from the concurrent CRD apply, the Get call in certsExist
can fail with a transient error.

The old certsExist returned false on any error (not just NotFound),
causing EnsureWebhookCerts to generate a brand-new CA and serving cert
that overwrites the existing ones via CreateOrUpdate. This invalidates
the caBundle previously patched into CRDs and webhook configurations,
producing persistent "tls: bad certificate" errors from the API server
and stalling the deployment rollout until the 5-minute WaitUntilAvailable
timeout expires.

Fix certsExist to return an error on transient API failures so the
operator startup propagates the error instead of silently regenerating
certs. Fix EnsureWebhookCerts to guard each CreateOrUpdate callback
against overwriting a secret that already contains valid data (defending
against the replica-startup race where two pods bootstrap concurrently),
and to derive the serving cert from the existing CA when one is already
present rather than generating a mismatched pair.

Signed-off-by: Chai Bot <chai-bot@redhat.com>
Address pre-commit review findings for OCPBUGS-118883:

R1: Add transient-error tests for certsExist using fake client
interceptors. Two new subtests verify the core safety property
that distinguishes NotFound (safe to regenerate) from transient
API errors (must propagate to prevent silent CA corruption).

I2: Add subtests for serving-cert NotFound and empty-data paths
in certsExist to cover both legs of the function.

I3: Rename caObj/servingObj to caSecret/servingSecret in
EnsureWebhookCerts for naming consistency with the rest of the
file.

I6: Use requeueInterval constant in test assertions instead of
duplicating the literal 12h value.

I7: Fix misleading test name ("regenerate both" to "reuse
existing CA") and add assertion that CA data was not modified.

Signed-off-by: Chai Bot <chai-bot@redhat.com>
@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: LGTM mode

@coderabbitai

coderabbitai Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Team

Run ID: 78ebe973-45e5-4911-8469-d5322ece16fd

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Comment @coderabbitai help to get the list of available commands.

@openshift-ci
openshift-ci Bot requested review from devguyio and jparrill September 3, 2026 20:59
@openshift-ci openshift-ci Bot added area/hypershift-operator Indicates the PR includes changes for the hypershift operator and API - outside an OCP release and removed do-not-merge/needs-area labels Sep 3, 2026
@codecov

codecov Bot commented Sep 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.95652% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 36.73%. Comparing base (3004374) to head (ca79f50).

Files with missing lines Patch % Lines
...ontrollers/webhookcerts/webhookcerts_controller.go 86.95% 4 Missing and 2 partials ⚠️
Additional details and impacted files
@@               Coverage Diff                @@
##           release-4.22    #9507      +/-   ##
================================================
+ Coverage         36.71%   36.73%   +0.01%     
================================================
  Files               777      777              
  Lines             95484    95508      +24     
================================================
+ Hits              35061    35085      +24     
- Misses            57580    57582       +2     
+ Partials           2843     2841       -2     
Files with missing lines Coverage Δ
...ontrollers/webhookcerts/webhookcerts_controller.go 67.46% <86.95%> (+2.91%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@csrwng csrwng changed the title fix(webhookcerts): prevent CA overwrite on transient API errors OCPBUGS-120802: fix(webhookcerts): prevent CA overwrite on transient API errors Sep 4, 2026
@openshift-ci-robot openshift-ci-robot added jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. labels Sep 4, 2026
@openshift-ci-robot

Copy link
Copy Markdown

@redhat-chai-bot: This pull request references Jira Issue OCPBUGS-120802, which is invalid:

  • release note text must be set and not match the template OR release note type must be set to "Release Note Not Required". For more information you can reference the OpenShift Bug Process.
  • expected Jira Issue OCPBUGS-120802 to depend on a bug targeting a version in 5.0.0 and in one of the following states: MODIFIED, ON_QA, VERIFIED, RELEASE PENDING, CLOSED (ERRATA), CLOSED (CURRENT RELEASE), CLOSED (DONE), CLOSED (DONE-ERRATA), but no dependents were found

Comment /jira refresh to re-evaluate validity if changes to the Jira bug are made, or edit the title of this pull request to link to a different bug.

The bug has been updated to refer to the pull request using the external bug tracker.

Details

In response to this:

Summary

  • Distinguish transient API errors from NotFound when checking webhook certificate secrets.
  • Preserve valid CA and serving certificate data during retries and multi-replica races.
  • Add regression coverage for transient errors, missing or empty serving certificates, and CA reuse.

Root Cause

During the operator upgrade, applying the CRDs can temporarily increase API server load. The certificate check previously treated any API error as if the secret were missing, which could regenerate and overwrite the CA while existing webhook configurations still referenced the previous CA bundle. The resulting certificate mismatch caused webhook TLS handshakes to fail and stalled the rollout.

Validation

  • Targeted webhook certificate tests: 17/17 passed
  • make test: 192 packages, 0 failures
  • make verify: passed

Scope

The pre-existing hasKeys issue in support/certs/tls.go is not changed by this pull request.


AI-generated. Review for accuracy.

@devguyio requested in Slack thread

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 openshift-eng/jira-lifecycle-plugin repository.

@csrwng csrwng added jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. and removed jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. labels Sep 4, 2026
@csrwng csrwng added the backport-risk-assessed Indicates a PR to a release branch has been evaluated and considered safe to accept. label Sep 4, 2026
@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Sep 4, 2026
@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Scheduling tests matching the pipeline_run_if_changed or not excluded by pipeline_skip_if_only_changed parameters:
/test e2e-aks-4-21
/test e2e-aws-4-21
/test e2e-aks
/test e2e-aws
/test e2e-aws-upgrade-hypershift-operator
/test e2e-azure-aks-external-oidc
/test e2e-azure-self-managed
/test e2e-kubevirt-aws-ovn-reduced
/test e2e-v2-aws

@openshift-ci

openshift-ci Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: csrwng, redhat-chai-bot

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

The pull request process is described 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

@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 4, 2026
@csrwng

csrwng commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

/retest-required

@openshift-ci

openshift-ci Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

@redhat-chai-bot: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-azure-self-managed ca79f50 link true /test e2e-azure-self-managed
ci/prow/e2e-aws-4-21 ca79f50 link true /test e2e-aws-4-21
ci/prow/e2e-aks ca79f50 link true /test e2e-aks
ci/prow/e2e-v2-aws ca79f50 link true /test e2e-v2-aws
ci/prow/e2e-aws-upgrade-hypershift-operator ca79f50 link true /test e2e-aws-upgrade-hypershift-operator

Full PR test history. Your PR dashboard.

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. I understand the commands that are listed here.

@devguyio

Copy link
Copy Markdown
Contributor

/uncc @devguyio
I'm currently out of capacity to review this PR

@openshift-ci
openshift-ci Bot removed the request for review from devguyio September 29, 2026 23:00

This branch has not been deployed

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

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. area/hypershift-operator Indicates the PR includes changes for the hypershift operator and API - outside an OCP release backport-risk-assessed Indicates a PR to a release branch has been evaluated and considered safe to accept. jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants