feat: add --with-ssl-cert-file option to build command #6046
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This makes the root CAs from the host available to containers during a build.
What type of PR is this?
/kind feature
What this PR does / why we need it:
This makes it easier to use
buildah
to build an image in environments that require custom certificate authorities to make outbound internet connections (for example when using a TLS intercepting HTTPS proxy).Currently
buildah
will automatically passhttps_proxy
(and related) environment variables as ephemeral environment variables to the container forRUN
commands.This change adds an option
--with-ssl-cert-file
(defaults tofalse
) that when set will:SSL_CERT_FILE
if set, else falls back to searching common paths).RUN
command at a different location (/host-ssl-cert-file
).SSL_CERT_FILE=/host-ssl-cert-file
ephemeral environment variable forRUN
commands.A similar outcome can be achieved today by editing
buildah
command to bind mount the current CA store and then edit eachRUN
instruction in theContainerfile
to use, however it felt like it would be nice to make a short-cut for this which seems to augment well the existinghttps_proxy
variable propagation.Current workaround:
How to verify it
Behaviour without flag:
Output:
Behaviour with flag:
Output:
Tested with a local HTTPS proxy server with a self-signed CA and verified that basic
apk add --update --no-cache python3
and similar commands worked without error.(Tested similar on
ubuntu
image, althoughapt
I think runs over HTTP so test wasn't as meaningful)Includes unit and integration tests to verify behaviour.
Which issue(s) this PR fixes:
None
Special notes for your reviewer:
Some issues to consider:
Search path for host CAs
To get the search path of commonly used host CA files I used the list found here:
https://cs.opensource.google/go/go/+/refs/tags/go1.24.1:src/crypto/x509/root_linux.go;l=9-17
Unfortunately that variable is private, and I'm not able to find anything within the standard x509 module that exports it or otherwise makes it available, which is why I put that list in a separate file and copy/pasted the Go LICENSE within there.
It feels less than ideal and open to other ideas.
Path to bind to within the container
This PR currently binds it to
/host-ssl-cert-file
so that it doesn't clash with commonly used paths within a container. This seemed to work fine in my limited testing when usingSSL_CERT_FILE
to point to it, however it's not clear whetherSSL_CERT_FILE
will work for all applications and whether it may be best to instead bind this on top of well-known locations for where this file normally is.Happy to take feedback on alternate suggestions.
Does this PR introduce a user-facing change?