Skip to content
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

fix cacert() to work with openssl's defaults #71

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions distroless/private/cacerts.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def _cacerts_impl(ctx):
mtree.add_dir("/etc", mode = "0755", time = ctx.attr.time)
mtree.add_parents("/etc/ssl/certs", mode = "0755", time = ctx.attr.time, skip = [1])
mtree.add_file("/etc/ssl/certs/ca-certificates.crt", cacerts, time = ctx.attr.time, mode = ctx.attr.mode)
mtree.add_link("/usr/lib/ssl/cert.pem", "/etc/ssl/certs/ca-certificates.crt", time = ctx.attr.time, mode = ctx.attr.mode)
mtree.add_parents("/usr/share/doc/ca-certificates", time = ctx.attr.time)
mtree.add_file("/usr/share/doc/ca-certificates/copyright", copyright, time = ctx.attr.time, mode = ctx.attr.mode)
mtree.build(output = output, mnemonic = "CaCertsTarGz", inputs = [cacerts, copyright])
Expand Down
6 changes: 5 additions & 1 deletion distroless/private/tar.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ DEFAULT_ARGS = [
"--options=gzip:!timestamp",
]

def _mtree_line(dest, type, content = None, uid = DEFAULT_UID, gid = DEFAULT_GID, time = DEFAULT_TIME, mode = DEFAULT_MODE):
def _mtree_line(dest, type, content = None, link = None, uid = DEFAULT_UID, gid = DEFAULT_GID, time = DEFAULT_TIME, mode = DEFAULT_MODE):
# mtree expects paths to start with ./ so normalize paths that starts with
# `/` or relative path (without / and ./)
if not dest.startswith("."):
Expand All @@ -33,6 +33,9 @@ def _mtree_line(dest, type, content = None, uid = DEFAULT_UID, gid = DEFAULT_GID
]
if content:
spec.append("content=" + content)
if link:
spec.append("link=" + link)

return " ".join(spec)

def _add_parents(path, uid = DEFAULT_UID, gid = DEFAULT_GID, time = DEFAULT_TIME, mode = DEFAULT_MODE, skip = []):
Expand Down Expand Up @@ -94,6 +97,7 @@ def _create_mtree(ctx = None):
return struct(
entry = lambda path, type, **kwargs: content.add(_mtree_line(path, type, **kwargs)),
add_file = lambda path, file, **kwargs: content.add(_mtree_line(path, "file", content = file.path, **kwargs)),
add_link = lambda path, src, **kwargs: content.add(_mtree_line(path, "link", link = src, **kwargs)),
add_dir = lambda path, **kwargs: content.add(_mtree_line(path, "dir", **kwargs)),
add_parents = lambda path, **kwargs: content.add_all(_add_parents(path, **kwargs), uniquify = True),
build = lambda **kwargs: _build_tar(ctx, _build_mtree(ctx, content), **kwargs),
Expand Down
1 change: 1 addition & 0 deletions examples/cacerts/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ assert_tar_listing(
./etc/ssl/certs time=0.0 mode=755 gid=0 uid=0 type=dir
./etc/ssl/certs/ca-certificates.crt time=0.0 mode=555 gid=0 uid=0 type=file size=200313
./usr time=0.0 mode=755 gid=0 uid=0 type=dir
./usr/lib/ssl/cert.pem time=0.0 mode=555 gid=0 uid=0 type=link link=/etc/ssl/certs/ca-certificates.crt
./usr/share time=0.0 mode=755 gid=0 uid=0 type=dir
./usr/share/doc time=0.0 mode=755 gid=0 uid=0 type=dir
./usr/share/doc/ca-certificates time=0.0 mode=755 gid=0 uid=0 type=dir
Expand Down
1 change: 1 addition & 0 deletions examples/debian_snapshot/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ PACKAGES = [
"@bullseye//dpkg",
"@bullseye//apt",
"@bullseye//perl",
"@bullseye//openssl",
]

# Creates /var/lib/dpkg/status with installed package information.
Expand Down
4 changes: 4 additions & 0 deletions examples/debian_snapshot/test_linux_amd64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ commandTests:
command: "head"
args: ["-1", "/etc/ssl/certs/ca-certificates.crt"]
expectedOutput: [-----BEGIN CERTIFICATE-----]
- name: "in depth ca-certs check"
command: "/usr/bin/openssl"
args: ["s_client", "-connect", "www.google.com:443"]
expectedOutput: ["Verify return code: 0 .ok."]
4 changes: 4 additions & 0 deletions examples/debian_snapshot/test_linux_arm64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ commandTests:
command: "head"
args: ["-1", "/etc/ssl/certs/ca-certificates.crt"]
expectedOutput: [-----BEGIN CERTIFICATE-----]
- name: "in depth ca-certs check"
command: "/usr/bin/openssl"
args: ["s_client", "-connect", "www.google.com:443"]
expectedOutput: ["Verify return code: 0 .ok."]
Loading