Skip to content

Commit 2aff977

Browse files
authored
Changes falcosidekick and falcosidekick-ui rock bases to bare (#21)
Switching to a bare-based image will reduce the overall image size and reduces attack surface area. 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. Adds additional check for falcosidekick-ui during the integration test.
1 parent df7641f commit 2aff977

File tree

6 files changed

+43
-36
lines changed

6 files changed

+43
-36
lines changed

falcosidekick-ui/2.2.0/rockcraft.yaml

+7-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ description: |
1010
license: Apache-2.0
1111
version: 2.2.0
1212

13-
13+
base: bare
1414
build-base: [email protected]
1515
run-user: _daemon_
1616

@@ -44,9 +44,12 @@ parts:
4444
# https://github.com/falcosecurity/falcosidekick-ui/blob/v2.2.0/Dockerfile#L8
4545
falcosidekickui-user:
4646
plugin: nil
47-
overlay-script: |
48-
groupadd -R $CRAFT_OVERLAY --system falcosidekickui
49-
useradd -R $CRAFT_OVERLAY --system -g falcosidekickui -u 1234 falcosidekickui
47+
stage-packages:
48+
- base-passwd_data
49+
- base-files_base
50+
override-build: |
51+
groupadd -R $CRAFT_PART_INSTALL --system falcosidekickui
52+
useradd -R $CRAFT_PART_INSTALL --system -g falcosidekickui -u 1234 falcosidekickui
5053
5154
build-falcosidekick-ui:
5255
plugin: nil

falcosidekick/2.29.0/rockcraft.yaml

+7-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ description: |
1010
license: Apache-2.0
1111
version: 2.29.0
1212

13-
13+
base: bare
1414
build-base: [email protected]
1515

1616
platforms:
@@ -36,9 +36,12 @@ parts:
3636
# https://github.com/falcosecurity/falcosidekick/blob/2.29.0/Dockerfile#L8
3737
falcosidekick-user:
3838
plugin: nil
39-
overlay-script: |
40-
groupadd -R $CRAFT_OVERLAY --system falcosidekick
41-
useradd -R $CRAFT_OVERLAY --system -g falcosidekick -u 1234 falcosidekick
39+
stage-packages:
40+
- base-passwd_data
41+
- base-files_base
42+
override-build: |
43+
groupadd -R $CRAFT_PART_INSTALL --system falcosidekick
44+
useradd -R $CRAFT_PART_INSTALL --system -g falcosidekick -u 1234 falcosidekick
4245
4346
build-falcosidekick:
4447
plugin: nil

tests/integration/test_falco.py

+24-25
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,10 @@ def _get_falco_helm_cmd(falco_version: str):
122122
)
123123

124124

125-
def _assert_falco_exporter_up(instance: harness.Instance):
126-
# Assert that falco-exporter is responsive. The falco-exporter image is a bare image,
127-
# so, we're using the falco Pod to curl the falco-exporter endpoint instead.
128-
LOG.info("Checking if falco-exporter is being responsive.")
129-
process = instance.exec(
125+
def _curl_service_via_falco(
126+
instance: harness.Instance, svc_name: str, port: int, endpoint: str
127+
):
128+
return instance.exec(
130129
[
131130
"k8s",
132131
"kubectl",
@@ -137,13 +136,19 @@ def _assert_falco_exporter_up(instance: harness.Instance):
137136
"--",
138137
"curl",
139138
"-s",
140-
"http://falco-exporter:9376/metrics",
139+
f"http://{svc_name}:{port}/{endpoint}",
141140
],
142141
check=True,
143142
capture_output=True,
144143
text=True,
145144
)
146145

146+
147+
def _assert_falco_exporter_up(instance: harness.Instance):
148+
# Assert that falco-exporter is responsive. The falco-exporter image is a bare image,
149+
# so, we're using the falco Pod to curl the falco-exporter endpoint instead.
150+
LOG.info("Checking if falco-exporter is being responsive.")
151+
process = _curl_service_via_falco(instance, "falco-exporter", 9376, "metrics")
147152
assert (
148153
"Total number of scrapes" in process.stdout
149154
), "Expected falco-exporter to return metrics."
@@ -152,30 +157,23 @@ def _assert_falco_exporter_up(instance: harness.Instance):
152157
def _assert_falcosidekick_up(instance: harness.Instance):
153158
# Assert that falcosidekick is responsive. It has a ping method, to which we should get pong.
154159
# The falcosidekick image does not have curl or wget, but the falco image does.
155-
LOG.info("Checking if Falco detected irregularities.")
156-
process = instance.exec(
157-
[
158-
"k8s",
159-
"kubectl",
160-
"--namespace",
161-
"falco",
162-
"exec",
163-
f"{constants.K8S_DAEMONSET}/falco",
164-
"--",
165-
"curl",
166-
"-s",
167-
"http://falcosidekick:2801/ping",
168-
],
169-
check=True,
170-
capture_output=True,
171-
text=True,
172-
)
173-
160+
LOG.info("Checking if falcosidekick is being responsive.")
161+
process = _curl_service_via_falco(instance, "falcosidekick", 2801, "ping")
174162
assert (
175163
"pong" in process.stdout
176164
), "Expected falcosidekick to respond with pong to ping."
177165

178166

167+
def _assert_falcosidekick_ui_up(instance: harness.Instance):
168+
# Assert that falcosidekick-ui is responsive.
169+
# The falcosidekick-ui image does not have curl or wget, but the falco image does.
170+
LOG.info("Checking if falcosidekick-ui is being responsive.")
171+
process = _curl_service_via_falco(
172+
instance, "falcosidekick-ui", 2802, "api/v1/healthz"
173+
)
174+
assert "ok" in process.stdout, "Expected falcosidekick-ui to respond with ok."
175+
176+
179177
def _assert_falco_logs(instance: harness.Instance):
180178
# Falco should have noticed the unexpected behaviour from the event-generator, and it should
181179
# have logged these events to stdout by default.
@@ -264,4 +262,5 @@ def test_integration_falco(function_instance: harness.Instance, image_version):
264262

265263
_assert_falco_logs(function_instance)
266264
_assert_falcosidekick_up(function_instance)
265+
_assert_falcosidekick_ui_up(function_instance)
267266
_assert_falco_exporter_up(function_instance)

tests/sanity/test_falcosidekick.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def test_falcosidekick_rock(image_version):
2121
image = rock.image
2222

2323
# check rock filesystem.
24-
docker_util.ensure_image_contains_paths(image, ROCK_EXPECTED_FILES)
24+
docker_util.ensure_image_contains_paths_bare(image, ROCK_EXPECTED_FILES)
2525

2626
# check binary.
2727
process = docker_util.run_in_docker(

tests/sanity/test_falcosidekick_ui.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_falcosidekick_ui_rock(image_version):
2222
image = rock.image
2323

2424
# check rock filesystem.
25-
docker_util.ensure_image_contains_paths(image, ROCK_EXPECTED_FILES)
25+
docker_util.ensure_image_contains_paths_bare(image, ROCK_EXPECTED_FILES)
2626

2727
# check binary.
2828
process = docker_util.run_in_docker(image, ["/app/falcosidekick-ui", "-v"])

tests/tox.ini

+3-1
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ commands =
3838
description = Run sanity tests
3939
passenv = *
4040
deps = -r {tox_root}/requirements-test.txt
41+
allowlist_externals =
42+
sudo
4143
commands =
42-
pytest -v \
44+
sudo -E {envpython} -m pytest -v \
4345
--maxfail 1 \
4446
--tb native \
4547
--log-cli-level DEBUG \

0 commit comments

Comments
 (0)