Skip to content

feat: Add CA certificate bundle support for builds - #3751

Open
Itx-Psycho0 wants to merge 2 commits into
knative:mainfrom
Itx-Psycho0:feat/ca-bundle-support
Open

Itx-Psycho0 wants to merge 2 commits into
knative:mainfrom
Itx-Psycho0:feat/ca-bundle-support

Conversation

@Itx-Psycho0

@Itx-Psycho0 Itx-Psycho0 commented May 15, 2026 •

Copy link
Copy Markdown
Contributor

This lets a custom CA be trusted during pack builds. It's for builds behind a TLS-intercepting proxy, where buildpacks fail to download dependencies with x509: certificate signed by unknown authority (#3721).

Fixes #3721

Usage
func build --builder pack --build-cafile ./corp-ca.pem
It also works as FUNC_BUILD_CAFILE or in func.yaml:

build:
caFile: corp-ca.pem
The flag is available on func build, func deploy and func run.

A relative path is resolved against the function directory, and an absolute path is used as is. The file can be outside the project. It can hold one or more PEM certificates.

How it works
The certificates are written into a temporary service binding of type ca-certificates, one certificate per file as Paketo requires. The binding is mounted read-only under SERVICE_BINDING_ROOT (the user's value if set, otherwise /platform/bindings). The Paketo CA Certificates buildpack then adds them to the trust store for the rest of the build. They are used at build time only and are not added to the image. The temp directory is removed after the build.

Errors:

a missing file, or a file without valid certificates, fails before the build starts
--build-cafile with a builder other than pack fails with a clear error
--build-cafile with --remote fails with a clear error (not supported yet)
Testing
New integration test TestInt_PackBuildTrustsCAFile. It runs a Go module proxy over TLS with a certificate signed by a CA created in the test, and builds a Go function that depends on a module from it, using the stock ghcr.io/knative/builder-jammy-tiny:v2 builder:

with the CA file: the build succeeds and the module is downloaded from the proxy
without it: same image, the build fails on the TLS handshake
a bundle where the right CA is the second cert: the build succeeds
TestInt_PrivateGitRepository still uses the patched builder. git in the jammy image uses gnutls, which doesn't read SSL_CERT_DIR, so the Paketo buildpack can't make git trust the CA. There's a comment about this in the test.

Unit tests cover:

the binding layout (type plus one file per cert)
a custom SERVICE_BINDING_ROOT next to existing mounts
relative and absolute paths
a missing file and a file without certs
cleanup of the temp directory
the flag, env var and func.yaml for build and deploy, including the non-pack and remote errors
make check, make check-schema and hack/verify-codegen.sh pass. Docs and schema are regenerated.

@knative-prow
knative-prow Bot requested review from dsimansk and jrangelramos May 15, 2026 17:15
@knative-prow knative-prow Bot added the size/M 🤖 PR changes 30-99 lines, ignoring generated files. label May 15, 2026
@knative-prow

knative-prow Bot commented May 15, 2026

Copy link
Copy Markdown

Hi @Itx-Psycho0. 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.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

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 added the needs-ok-to-test 🤖 Needs an org member to approve testing label May 15, 2026
@matejvasek

matejvasek commented May 15, 2026 •

Copy link
Copy Markdown
Contributor

This deserves a comprehensive integration testing.

@matejvasek

Copy link
Copy Markdown
Contributor

One of the adepts for testing could be our "private git repo" tests. Right now we are compiling special build image with our own CA. That should not be necessary now. We could use ordinary image with the new option.

@matejvasek

Copy link
Copy Markdown
Contributor

But that's not the only test. You should add multitude tests to verify various components respect the CA.

@matejvasek

Copy link
Copy Markdown
Contributor

@matejvasek

Copy link
Copy Markdown
Contributor

What happens if CA is out of three?

@matejvasek

Copy link
Copy Markdown
Contributor

What happens if path is relative vs. absolute

@knative-prow knative-prow Bot added size/L 🤖 PR changes 100-499 lines, ignoring generated files. and removed size/M 🤖 PR changes 30-99 lines, ignoring generated files. labels May 15, 2026
@codecov

codecov Bot commented May 15, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 12.00000% with 66 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.90%. Comparing base (c0d60c2) to head (dfc8b06).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
pkg/buildpacks/builder.go 8.69% 40 Missing and 2 partials ⚠️
pkg/s2i/builder.go 0.00% 23 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3751      +/-   ##
==========================================
- Coverage   57.06%   56.90%   -0.16%     
==========================================
  Files         181      181              
  Lines       21144    21211      +67     
==========================================
+ Hits        12065    12070       +5     
- Misses       7855     7915      +60     
- Partials     1224     1226       +2     
Flag Coverage Δ
e2e 35.82% <12.00%> (-0.10%) ⬇️
e2e go 31.39% <14.03%> (-0.08%) ⬇️
e2e node 27.19% <14.03%> (-0.07%) ⬇️
e2e python 31.76% <14.03%> (-0.08%) ⬇️
e2e quarkus 27.31% <14.03%> (-0.07%) ⬇️
e2e rust 26.71% <14.03%> (-0.06%) ⬇️
e2e springboot 25.23% <14.03%> (-0.06%) ⬇️
e2e typescript 27.29% <14.03%> (-0.07%) ⬇️
e2e-config-ci 28.24% <14.03%> (-0.07%) ⬇️
integration 17.29% <0.00%> (-0.06%) ⬇️
unit macos-14 44.94% <14.03%> (-0.12%) ⬇️
unit macos-latest 44.94% <14.03%> (-0.12%) ⬇️
unit ubuntu-24.04-arm 45.19% <12.00%> (-0.13%) ⬇️
unit ubuntu-latest 45.89% <14.03%> (-0.12%) ⬇️
unit windows-latest 44.98% <14.03%> (-0.12%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lkingland

Copy link
Copy Markdown
Member

/ok-to-test

@knative-prow knative-prow Bot added ok-to-test 🤖 Non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test 🤖 Needs an org member to approve testing labels May 18, 2026
@matejvasek

Copy link
Copy Markdown
Contributor

This needs more integration tests.

@matejvasek

Copy link
Copy Markdown
Contributor

This is build-time CA. The docs already says that but maybe it would be better to call it --build-cafile so it absolutely obvious.

@matejvasek matejvasek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Needs more integration tests.

@knative-prow

knative-prow Bot commented Jun 1, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Itx-Psycho0
Once this PR has been reviewed and has the lgtm label, please ask for approval from matejvasek. 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

@github-actions

Copy link
Copy Markdown
Contributor

This Pull Request is stale because it has been open for 90 days with
no activity. It will automatically close after 30 more days of
inactivity. Reopen with /reopen. Mark as fresh by adding the
comment /remove-lifecycle stale.

@github-actions github-actions Bot added the lifecycle/stale 🤖 No recent activity. label Aug 31, 2026
@knative-prow knative-prow Bot added size/XL 🤖 PR changes 500-999 lines, ignoring generated files. and removed size/L 🤖 PR changes 100-499 lines, ignoring generated files. labels Sep 9, 2026
@Itx-Psycho0

Copy link
Copy Markdown
Contributor Author

Hi @matejvasek

I've added comprehensive integration tests as you requested. The new tests verify that CA certificate bundles work correctly during builds for both pack and s2i builders.

Tests Added

  1. TestInt_BuildCACertFile
    Main integration test that verifies:
    Pack builder uses Paketo ca-certificates binding mechanism
    S2I builder uses environment variables for CA bundle
    Both builders can successfully build with custom CA certificates

TestInt_BuildCACertFile_RelativePath
Tests relative path resolution

TestInt_BuildCACertFile_MissingFile
Tests error handling for missing files

Ready for review! Let me know if you'd like any adjustments.

@Itx-Psycho0

Copy link
Copy Markdown
Contributor Author

/retest

@Itx-Psycho0

Copy link
Copy Markdown
Contributor Author

/remove-lifecycle stale

@github-actions github-actions Bot removed the lifecycle/stale 🤖 No recent activity. label Sep 10, 2026
@lkingland

Copy link
Copy Markdown
Member

Thanks for the effort on this, @Itx-Psycho0. I'm going to close it for now: @matejvasek's review concerns are still open, and @morrone reported that the change didn't fix their case. In particular, the integration tests only show that a build succeeds with a CA file mounted, not that the CA is actually trusted. A test where TLS is intercepted by a custom CA (for example, reusing the private git repo tests, as Matej suggested) would demonstrate it. CI also has failing checks.

If you'd like to pick this back up, you're very welcome to resubmit with those concerns addressed and verified against a custom-CA setup.

@lkingland lkingland closed this Oct 29, 2026
@Itx-Psycho0

Copy link
Copy Markdown
Contributor Author

/reopen

@knative-prow knative-prow Bot reopened this Nov 7, 2026
@knative-prow

knative-prow Bot commented Nov 7, 2026

Copy link
Copy Markdown

@Itx-Psycho0: Reopened this PR.

Details

In response to this:

/reopen

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.

@Itx-Psycho0
Itx-Psycho0 force-pushed the feat/ca-bundle-support branch from 4af7cd1 to c823936 Compare November 7, 2026 11:34
@Itx-Psycho0

Copy link
Copy Markdown
Contributor Author

Hi @lkingland @matejvasek,

You were right to close this. I went back through everything, including @morrone's report, and the earlier versions never actually got the CA trusted. Here's what was wrong:

The first version only set env vars like SSL_CERT_FILE. Paketo buildpacks ignore those. The only way to add a CA at build time is a ca-certificates service binding, which is why morrone saw no change.
The later binding version copied the whole bundle into a single file, but Paketo wants one certificate per file. A corporate bundle with many certs wouldn't work.
The env var was never bound because bindEnv still said ca-bundle.
The integration tests only showed that a build succeeds with a file mounted, not that the CA is trusted. CI was red as well.
I've redone it from scratch on current main. The flag is now --build-cafile, as Matej suggested. It also works as FUNC_BUILD_CAFILE and as build.caFile in func.yaml. The file is split into a proper ca-certificates binding with one cert per file, mounted read-only, and deleted after the build.

About Matej's questions:

A relative path is resolved against the function directory and an absolute path is used as is. A file outside the project tree is fine because it gets copied into the binding.
A file with no valid certificates fails early with a clear error.
For now it's pack only. With s2i or host builds, or with --remote, you get a clear error instead of the flag being silently ignored. I can follow up on s2i and on-cluster builds separately if you want them.

About the test: I tried to reuse the private git repo test with the stock builder image as Matej suggested, but it can't work there. The Paketo ca-certificates buildpack adds the CA through SSL_CERT_DIR, and git in the jammy image uses gnutls, which ignores that. So I left that test as it is, with a comment explaining why. Instead I added TestInt_PackBuildTrustsCAFile. It starts a Go module proxy over TLS with a cert signed by a custom CA made in the test, and builds a Go function that depends on a module from it, using the stock ghcr.io/knative/builder-jammy-tiny:v2 image. This is the same kind of download that failed for morrone (a buildpack fetching over intercepted TLS). It has three cases:

with --build-cafile: the build passes and the proxy really served the module
without it: same image, the build fails with a TLS handshake error on the proxy
a bundle with an unrelated CA first and the right one second: it still passes
Unit tests cover the binding layout, a custom SERVICE_BINDING_ROOT, relative and absolute paths, a missing file, a file without certs, and cleanup. make check, check-schema and verify-codegen pass, and docs and schema are regenerated.

I don't have a cluster on my machine, so the integration test has only been compiled here. It runs in the Integration Tests job on this PR. I'll keep an eye on it and fix it if it fails.

@morrone, if you can try this branch with func build --builder pack --build-cafile , that would be great.

Thanks for the patience on this one!

@Itx-Psycho0

Copy link
Copy Markdown
Contributor Author

update :- I ran TestInt_PackBuildTrustsCAFile locally against Docker 29.9.3 and all three cases pass. Without the CA, the build fails with x509: certificate signed by unknown authority. With it, the Paketo buildpack logs Added 1 additional CA certificate(s) to system truststore.

@knative-prow-robot knative-prow-robot added the needs-rebase Cannot be merged due to conflicts with HEAD. label Nov 13, 2026
@Itx-Psycho0
Itx-Psycho0 force-pushed the feat/ca-bundle-support branch from c823936 to 9eb143a Compare November 13, 2026 07:45
@knative-prow-robot knative-prow-robot removed the needs-rebase Cannot be merged due to conflicts with HEAD. label Nov 13, 2026
@Itx-Psycho0

Copy link
Copy Markdown
Contributor Author

Rebased on current main and regenerated the docs. The failing checks were the Prepare Images registry issue fixed in #4138, plus Maven download errors in the springboot/quarkus template tests. I ran TestInt_PackBuildTrustsCAFile again on the rebased branch against Docker and all three cases still pass.

@lkingland

Copy link
Copy Markdown
Member

Thanks @Itx-Psycho0

Confirmed TestInt_PackBuildTrustsCAFile fails without the CA and passes with, including a two-CA bundle, so the binding works. The flag name, the Paketo binding and relative/absolute paths from @matejvasek's review are covered. Four things came up during my review that admittedly turn this into a bit of a larger effort"

  1. Let's consider storing the path in the function's "local settings" (.func/local.yaml, next to remote) instead of func.yaml. This is the right place for environment-specific settings and is not source controlled. This seems to make sense as this setting is specifically for describing a the machine behind a proxy, not the function itself.

If left in func.yaml, this setting gets committed, and every other copy would use this path even if not necessary, and later func deploy --remote would fails with "--build-cafile is not supported for remote (on-cluster) builds yet" (including the operator's rebuilds).

A remote deploy should ignore the remembered value and only reject the flag when it is given on that command, which is what you get with settings defined in .func/local.yaml.

  1. Please confirm, but I think we need to mount the binding with the SELinux relabel (:ro,z). Without this, Podman on Fedora/RHEL can't read the directory.

  2. @matejvasek asked for tests, and I agree, ensuring all our various components respect the CA. Today one integration test covers a Go module fetch. That's a good start. We should probably add add a Python case, since that is what Insert CA cert bundle during build to deal with transparent proxy #3721 reported, and ideally one per runtime (Node, Quarkus/Spring Boot, Rust), each fetching a dependency through the TLS proxy.

  3. git doesn't honor the CA (gnutls ignores SSL_CERT_DIR), which is why the private-git test couldn't use the stock image. That limit is only in a test comment today. Perhaps we could just note this in the flag help and docs? Could GIT_SSL_CAINFO cover git too?

@matejvasek, if you're available, does the Go module proxy test work for you in place of the private-git one, given the gnutls limit?

@morrone, would you be able to try this branch against your proxy? We confirmed the CA is trusted for a Go function, but couldn't fully verify a Python one end to end.

One step closer

Add --build-cafile ($FUNC_BUILD_CAFILE, func.yaml build.caFile) to build,
deploy and run. The pack builder passes the CA to the build as a Paketo
ca-certificates service binding, with one PEM certificate per file, mounted
read-only under SERVICE_BINDING_ROOT (default /platform/bindings) next to
any user bindings. The temporary binding directory is removed after the
build. A relative path is resolved against the function root; files outside
the function directory work too.

The option is pack only: s2i and host builds and remote (on-cluster)
deploys return an error.

New integration test TestInt_PackBuildTrustsCAFile serves a Go module proxy
over TLS with a custom CA and builds a function depending on it with the
stock ghcr.io/knative/builder-jammy-tiny:v2 image: it succeeds with the CA
file (also as a bundle with an unrelated CA first) and fails without it.
TestInt_PrivateGitRepository keeps the patched image, as git in jammy uses
gnutls and ignores SSL_CERT_DIR.

Checks run on this commit:
- go build -tags exclude_graphdriver_btrfs ./...: ok
- go test ./cmd/... ./pkg/buildpacks/... ./pkg/functions/... -count=1: ok
  (pkg/functions with umask 022; TestTemplates_ModeCustom fails with
  umask 0002 on upstream main too)
- go vet -tags integration ./pkg/builders/... and compile-only run: ok
- make check, make check-schema, hack/verify-codegen.sh: ok

Fixes knative#3721

Signed-off-by: Itx-Psycho0 <anuragh3re@gmail.com>
…imes

Follow-up to review on knative#3751.

Keep the CA file in the function's local settings (.func/local.yaml,
next to remote) instead of func.yaml. It describes the machine behind
a proxy, not the function, so it must not be committed and applied to
every other copy. A value remembered there is ignored by remote
(on-cluster) builds and by builders other than pack; --build-cafile or
FUNC_BUILD_CAFILE given on such a command is still an error.

Mount the CA binding with "ro,z" so that Podman (or Docker with SELinux)
on Fedora/RHEL relabels it and the build can read it. Without SELinux
"z" is a no-op. The directory is our own temporary one.

Add TestInt_PackBuildCAFileRuntimes: each runtime's build fetches its
real dependencies through a TLS-intercepting proxy which re-signs them
with a test CA. Node, TypeScript, Spring Boot and Quarkus pass with the
CA file alone, and Python fails without it. Python also needs
REQUESTS_CA_BUNDLE, as Poetry uses its own CA bundle. Rust is skipped:
the builder's Rust buildpack group has no CA Certificates buildpack.

Add TestInt_PackBuildCAFileGit: git, linked against GnuTLS, ignores the
CA ("server certificate verification failed. CAfile: none") and works
once GIT_SSL_CAINFO points at the mounted certificate.

Document all of this in docs/building-functions/custom-ca.md and point
to it from the flag help.

Signed-off-by: Itx-Psycho0 <anuragh3re@gmail.com>
@Itx-Psycho0
Itx-Psycho0 force-pushed the feat/ca-bundle-support branch from 9eb143a to 160216a Compare November 26, 2026 11:26
@knative-prow knative-prow Bot added size/XXL 🤖 PR changes 1000+ lines, ignoring generated files. and removed size/XL 🤖 PR changes 500-999 lines, ignoring generated files. labels Nov 26, 2026
@Itx-Psycho0

Copy link
Copy Markdown
Contributor Author

hey @lkingland thanks for going through it, pushed a new commit for all 4 (also rebased on main)

1. local settings
moved it to .func/local.yaml as buildCAFile, func.yaml and the schema don't have it anymore. a remembered value is ignored by deploy --remote and by non-pack builders, and only --build-cafile / FUNC_BUILD_CAFILE given on that command errors. tests cover both, including remembered + --remote going through and the value still being there after

2. selinux
mount is ro,z now. confirmed docker's mount parser (which pack uses) accepts it and the real build still passes, but i don't have a fedora/podman box so i couldn't check the selinux side myself. if someone can run it there that would be great

3. tests per runtime
added a test that puts a tls-intercepting proxy in front of the build (re-signs everything with a test ca, like #3721), so each runtime pulls its real deps through it:

  • go, node, typescript, springboot, quarkus: pass with just the ca file
  • python without the ca: fails, as expected
  • python with the ca: fails too. pip is fine (it installs poetry through the proxy) but poetry sync uses its own ca bundle (certifi) and ignores SSL_CERT_DIR where paketo adds the ca. i think that's the actual reason @morrone's case didn't work. with REQUESTS_CA_BUNDLE pointing at the mounted cert it passes (26 packages through the proxy)
  • rust: fails before cargo runs. the rust group in our builder has no paketo ca-certificates buildpack at all, so the binding is never applied. skipped in the test with that reason

4. git
yes GIT_SSL_CAINFO works. tested a go module fetched with git through the proxy: with only the ca file git fails with server certificate verification failed. CAfile: none, with GIT_SSL_CAINFO pointing at the mounted cert it passes. documented in the flag help and a new docs/building-functions/custom-ca.md

two things i'd like your take on:

  • right now GIT_SSL_CAINFO and REQUESTS_CA_BUNDLE have to go in build.buildEnvs, which brings back the "committed to func.yaml" problem from point 1. should func just set both itself when the ca file is in use? the catch is they replace the whole bundle so git/poetry would trust only those certs, fine behind an intercepting proxy but not if the ca is only for one private server
  • rust probably needs ca-certificates added to the builder's rust group (or func adding it as a pre-buildpack when the ca file is set). happy to look at that in a follow-up so this pr doesn't grow more

@morrone if you get a chance to try it, for python you'd need the REQUESTS_CA_BUNDLE env from the doc for now

@Itx-Psycho0

Copy link
Copy Markdown
Contributor Author

/test unit-tests

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

Labels

ok-to-test 🤖 Non-member PR verified by an org member that is safe to test. size/XXL 🤖 PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Insert CA cert bundle during build to deal with transparent proxy

4 participants