Skip to content

Commit

Permalink
Changes rock base to bare
Browse files Browse the repository at this point in the history
Switching to a bare-based image will reduce the overall image size
and reduces attack surface area.

The original Dockerfile uses gcr.io/distroless/static:nonroot, which has
only a few packages. We can add those packages and switch to a
bare-based image. Additionally, the original image is a non-root image,
thus, we should also switch our rock to be non-root.

We can no longer use ensure_image_contains_paths to check if files exist
in the rock images, since they are now bare-based. Instead, we can use
ensure_image_contains_paths_bare, which checks the image layers instead.
Because of this, we need sufficient permissions to check the
/var/lib/docker folder.
  • Loading branch information
claudiubelu committed Oct 28, 2024
1 parent c5526f5 commit 9da5dc9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tests/sanity/test_pinniped.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ def test_pinniped(version: str):
assert EXPECTED_HELPSTR in docker_run.stdout

# check rock filesystem
docker_util.ensure_image_contains_paths(rock.image, EXPECTED_FILES)
docker_util.ensure_image_contains_paths_bare(rock.image, EXPECTED_FILES)
6 changes: 4 additions & 2 deletions tests/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ commands =
black {tox_root}/integration --check --diff

[testenv:sanity]
description = Run integration tests
description = Run sanity tests
deps =
-r {tox_root}/requirements-test.txt
allowlist_externals =
sudo
commands =
pytest -v \
sudo -E {envpython} -m pytest -v \
--maxfail 1 \
--tb native \
--log-cli-level DEBUG \
Expand Down
19 changes: 18 additions & 1 deletion v0.30.0/rockcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ description: >
version: v0.30.0
license: Apache-2.0

base: [email protected]
base: bare
build-base: [email protected]
run-user: _daemon_
platforms:
amd64:

Expand All @@ -19,6 +20,22 @@ services:
startup: enabled

parts:
add-base-packages:
plugin: nil
stage-packages:
# Original Dockerfile uses gcr.io/distroless/static:nonroot as a base.
# This image contains the following:
# https://github.com/GoogleContainerTools/distroless/blob/1533e54a73805ec13fe0cc68218fc7a215a0a6f7/base/README.md
- ca-certificates
- tzdata
- base-passwd

# Can't have stage packages and stage slices together, apparently.
add-base-slices:
plugin: nil
stage-packages:
- base-files_tmp

build-deps:
plugin: nil
build-snaps:
Expand Down

0 comments on commit 9da5dc9

Please sign in to comment.