Repository navigation
feat: Add CA certificate bundle support for builds - #3751
Itx-Psycho0 wants to merge 2 commits into
Conversation
|
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 Tip We noticed you've done this a few times! Consider joining the org to skip this step and gain Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions 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. |
|
This deserves a comprehensive integration testing. |
|
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. |
|
But that's not the only test. You should add multitude tests to verify various components respect the CA. |
|
Also check out https://github.com/paketo-buildpacks/ca-certificates |
|
What happens if CA is out of three? |
|
What happens if path is relative vs. absolute |
Codecov Report❌ Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
/ok-to-test |
|
This needs more integration tests. |
|
This is build-time CA. The docs already says that but maybe it would be better to call it |
matejvasek
left a comment
There was a problem hiding this comment.
Needs more integration tests.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Itx-Psycho0 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
This Pull Request is stale because it has been open for 90 days with |
|
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
Ready for review! Let me know if you'd like any adjustments. |
|
/retest |
|
/remove-lifecycle stale |
|
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. |
|
/reopen |
|
@Itx-Psycho0: Reopened this PR. DetailsIn response to this:
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. |
4af7cd1 to
c823936
Compare
|
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. 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. 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 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! |
|
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. |
c823936 to
9eb143a
Compare
|
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. |
|
Thanks @Itx-Psycho0 Confirmed
If left in func.yaml, this setting gets committed, and every other copy would use this path even if not necessary, and later 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.
@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>
9eb143a to
160216a
Compare
|
hey @lkingland thanks for going through it, pushed a new commit for all 4 (also rebased on main) 1. local settings 2. selinux 3. tests per runtime
4. git two things i'd like your take on:
@morrone if you get a chance to try it, for python you'd need the REQUESTS_CA_BUNDLE env from the doc for now |
|
/test unit-tests |
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.