-
Notifications
You must be signed in to change notification settings - Fork 805
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add --with-ssl-cert-file option to build command #6046
base: main
Are you sure you want to change the base?
Conversation
ded206e
to
e5f136d
Compare
"/etc/pki/tls/cacert.pem", // OpenELEC | ||
"/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem", // CentOS/RHEL 7 | ||
"/etc/ssl/cert.pem", // Alpine Linux | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is x509_unix.go an appropriate name? With the first line, I thought maybe x509_windows.go? Similar comment next file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so? I was copying the style used for other files in this repo such as 30c2e31
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: aeijdenberg, TomSweeneyRedHat The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Generally looks good to me, a couple of nits and it looks like your branch needs updating. |
Ephemeral COPR build failed. @containers/packit-build please check. |
8e4b52a
to
fd18d72
Compare
Accepted changes, rebased, squashed and fixed the issue in the Fedora tests, by using the same pattern as for similar files (such as /etc/hostname). Thanks for the review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a strong opinion on this one but this seems like a slippery slope.
I can certainly see why this argument might be handy but allowing this might open the door for a lot of other similar things. Personally I think this is better done by callers to set up the env and mount in any way they like. Hard coding /host-ssl-cert-file
just feels super awkward, and no it is not about the specific path name but just in general.
I would like to know what @nalind thinks about this as I am not really a buildah maintainer.
run_common.go
Outdated
hostCertBytes, err := os.ReadFile(resolvedSSLCertPath) | ||
if err != nil { | ||
return "", fmt.Errorf("error reading cert file on host: %w", err) | ||
} | ||
|
||
cfile := filepath.Join(rdir, filepath.Base(containerPath)) | ||
if err = ioutils.AtomicWriteFile(cfile, hostCertBytes, 0o644); err != nil { | ||
return "", fmt.Errorf("writing %s into the container: %w", containerPath, err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know how big the certs files can be but generally it seems best to copy it without reading the full thing into memory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to use io.Copy()
util/x509.go
Outdated
} | ||
return potFile, nil | ||
} | ||
return "", errors.New("please set SSL_CERT_FILE to use --ssl-cert-file option") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing in this function relates to the cli option. Buildah might be used via the API as well so the cli options should generally not be used in the backend as these errors would make no sense to callers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks that makes sense. Have reworded the message.
If it wasn't set to a hard-coded path, and rather something like ie this patch also sets env variable |
(I was making some other changes to address other feedback, and made a change like the above at the same time and pushed that onto this branch for discussion) |
This makes the root CAs from the host available to containers during a build. Co-authored-by: Tom Sweeney <tsweeney@redhat.com> Signed-off-by: Adam Eijdenberg <adam@continusec.com>
28070e3
to
b81b823
Compare
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?