Skip to content

Decode all CAs in the activator's routing secret - #16707

Merged
knative-prow[bot] merged 5 commits into
knative:mainfrom
cvas22:fix/13877-activator-decode-all-cas
Nov 25, 2026
Merged

knative-prow[bot] merged 5 commits into
knative:mainfrom
cvas22:fix/13877-activator-decode-all-cas

Conversation

@cvas22

@cvas22 cvas22 commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #13877

Proposed Changes

  • The activator now adds every PEM-encoded CA found in ca.crt of the routing-serving-certs secret to its upstream trust pool (via x509.CertPool.AppendCertsFromPEM), instead of only the first PEM block. This allows multiple CAs to be trusted at once, e.g. during CA rotation or with a bring-your-own CA bundle.
  • Fixes a nil pointer dereference: if ca.crt contained non-PEM data, pem.Decode returned a nil block and block.Bytes panicked in the informer handler. Now a warning is logged and the CA is ignored, matching the existing handling of invalid trust-bundle ConfigMaps.
  • Adds TestReconcile cases "Multiple CAs in secret" and "Invalid CA in secret". Both fail without the fix (the first times out because only one CA ends up in the pool; the second panics at cache.go:146) and pass with it.

Tests run locally (Windows, Go 1.26): gofmt -l, go vet ./pkg/activator/certificate/, go test ./pkg/activator/certificate/ -count=1, go build ./pkg/activator/... ./cmd/activator/. Not run locally: -race, the full unit test suite, linters beyond go vet, and e2e tests; I'm relying on CI for those.

Disclosure: I prepared this change with the help of an AI coding assistant. I reviewed the diff and tests and take responsibility for them.

Release Note

The activator now trusts all CA certificates contained in the `ca.crt` field of the `routing-serving-certs` secret, not just the first one, and no longer panics if that field holds invalid data.

@knative-prow

knative-prow Bot commented Oct 17, 2026

Copy link
Copy Markdown

Welcome @cvas22! It looks like this is your first PR to knative/serving 🎉

@knative-prow knative-prow Bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Oct 17, 2026
@knative-prow

knative-prow Bot commented Oct 17, 2026

Copy link
Copy Markdown

Hi @cvas22. Thanks for your PR.

I'm waiting for a knative 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.

@knative-prow
knative-prow Bot requested review from dprotaso, matzew and skonto October 17, 2026 09:59
@cvas22

cvas22 commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

Could someone with access add /ok-to-test here, and on #16708 too? Both are small activator fixes waiting on that. thx

@dprotaso

Copy link
Copy Markdown
Member

/ok-to-test

@knative-prow knative-prow Bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 11, 2026
@codecov

codecov Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.32%. Comparing base (7eea605) to head (eab1691).
⚠️ Report is 31 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16707      +/-   ##
==========================================
- Coverage   80.32%   80.32%   -0.01%     
==========================================
  Files         217      217              
  Lines       13701    13690      -11     
==========================================
- Hits        11006    10997       -9     
+ Misses       2327     2325       -2     
  Partials      368      368              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dprotaso

Copy link
Copy Markdown
Member

One thing we need to cover is that the docs say AppendCertsFromPEM will return true when one of the certs is added to the pool. So if you have an invalid cert it wouldn't be added which is a silent error.

https://pkg.go.dev/crypto/x509#CertPool.AppendCertsFromPEM

I'm debating validating this when we update the config map

@dprotaso

Copy link
Copy Markdown
Member

I'd close and open this PR so it refreshed HEAD

The activator only decoded the first PEM block of ca.crt in the
routing-serving-certs secret, so any additional CAs (e.g. during a CA
rotation or with a bring-your-own CA bundle) were silently ignored. If
the field did not contain PEM data at all, pem.Decode returned a nil
block and the activator panicked with a nil pointer dereference.

Use x509.CertPool.AppendCertsFromPEM to add every CA in the field and
log a warning when no valid certificate is found.

Fixes knative#13877

Signed-off-by: cvas22 <[email protected]>
@cvas22
cvas22 force-pushed the fix/13877-activator-decode-all-cas branch from d134f4b to 6ed5cf6 Compare November 11, 2026 23:53
@cvas22

cvas22 commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

Good point, thx. 6ed5cf6 decodes the bundle one PEM block at a time instead of using AppendCertsFromPEM, so each invalid cert or non-certificate block gets its own warning, plus one if nothing valid is left. Added a test with a valid and a corrupt cert in the same bundle. I rebased on main rather than closing and reopening, so HEAD should be fresh now.

@dprotaso

Copy link
Copy Markdown
Member

/retest

@dprotaso

Copy link
Copy Markdown
Member

Good point, thx. 6ed5cf6 decodes the bundle one PEM block at a time instead of using AppendCertsFromPEM, so each invalid cert or non-certificate block gets its own warning, plus one if nothing valid is left.

I guess to be clear - the operator who configures a bad cert won't know that it doesn't work until something breaks.

So my comment wasn't regarding the test - but the flow from setting the config map -> processing it in the activator.

@cvas22

cvas22 commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

Ah ok, got it. The logs only help if someone goes looking. For the trust-bundle ConfigMaps I could add a validating webhook that rejects a labeled ConfigMap when any block in it doesn't parse, so the apply fails right away. The secret's ca.crt is usually written by cert-manager rather than by hand, so I'd leave that to the activator warning. Want that in this PR or as a follow-up?

The istio-latest-no-mesh failure looks unrelated btw, the API server refused connections and TestBYOCertificate panicked in its cleanup.

@cvas22

cvas22 commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

/retest

@dprotaso

Copy link
Copy Markdown
Member

Want that in this PR or as a follow-up?

Let's have it in this PR

@cvas22

cvas22 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Sure, I'll add it here. One question before I do: the config webhook only validates ConfigMaps by fixed name, and the trust bundles are picked by the knative-ca-trust-bundle label with any name. So I'd add a small admission controller with its own ValidatingWebhookConfiguration that selects on that label and rejects a bundle that has a block that doesn't parse. Is that the shape you had in mind, or would you rather I do something lighter?

@dprotaso

dprotaso commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Actually we should probably skip the webhook. Long term we want to migrate to ClusterTrustBundles since they are GA in v1.37.

@dprotaso dprotaso left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's skip the ConfigMap admission for this PR. The multi-CA and panic fixes look good, but malformed PEM can still be silently skipped. Left comments inline.

Comment thread pkg/activator/certificate/cache.go Resolved
Comment thread pkg/activator/certificate/cache_test.go Resolved
@knative-prow knative-prow Bot removed the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Nov 25, 2026
@knative-prow knative-prow Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 25, 2026
@cvas22

cvas22 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Sounds good, I'll skip the webhook here. thx for the pointer on ClusterTrustBundles.

@knative-prow knative-prow Bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 25, 2026
@dprotaso

Copy link
Copy Markdown
Member

/lgtm
/approve

I decided to go back to AppendCertsFromPEM for now. I found the parsing logic to much for an alpha feature.

@knative-prow knative-prow Bot added the lgtm Indicates that a PR is ready to be merged. label Nov 25, 2026
@knative-prow

knative-prow Bot commented Nov 25, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cvas22, dprotaso

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

@knative-prow knative-prow Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 25, 2026
@dprotaso

Copy link
Copy Markdown
Member

/retest

@knative-prow
knative-prow Bot merged commit db25364 into knative:main Nov 25, 2026
105 of 110 checks passed
@dprotaso

Copy link
Copy Markdown
Member

/cherry-pick release-1.24
/cherry-pick release-1.23

@knative-prow-robot

Copy link
Copy Markdown
Contributor

@dprotaso: new pull request created: #16863

Details

In response to this:

/cherry-pick release-1.24
/cherry-pick release-1.23

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.

@knative-prow-robot

Copy link
Copy Markdown
Contributor

@dprotaso: new pull request created: #16864

Details

In response to this:

/cherry-pick release-1.24
/cherry-pick release-1.23

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.

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. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Decode all CAs in secret for activator

3 participants