|
15 | 15 | """Images integration tests.""" |
16 | 16 |
|
17 | 17 | import io |
| 18 | +import os |
18 | 19 | import platform |
19 | 20 | import tarfile |
| 21 | +import tempfile |
20 | 22 | import types |
21 | 23 | import unittest |
22 | 24 |
|
23 | 25 | import podman.tests.integration.base as base |
24 | 26 | from podman import PodmanClient |
25 | 27 | from podman.domain.images import Image |
26 | | -from podman.errors import APIError, ImageNotFound, PodmanError |
27 | | - |
| 28 | +from podman.errors import APIError, ContainerError, ImageNotFound, PodmanError |
28 | 29 |
|
29 | 30 | # @unittest.skipIf(os.geteuid() != 0, 'Skipping, not running as root') |
30 | 31 |
|
@@ -197,6 +198,41 @@ def add_file(name: str, content: str): |
197 | 198 | self.assertIsNotNone(image) |
198 | 199 | self.assertIsNotNone(image.id) |
199 | 200 |
|
| 201 | + def test_build_with_secret(self): |
| 202 | + with tempfile.TemporaryDirectory() as context_dir: |
| 203 | + dockerfile_path = os.path.join(context_dir, "Dockerfile") |
| 204 | + with open(dockerfile_path, "w") as f: |
| 205 | + f.write(""" |
| 206 | + FROM quay.io/libpod/alpine_labels:latest |
| 207 | + RUN --mount=type=secret,id=example cat /run/secrets/example > /output.txt |
| 208 | + """) |
| 209 | + |
| 210 | + secret_path = os.path.join(context_dir, "build-secret.txt") |
| 211 | + with open(secret_path, "w") as f: |
| 212 | + f.write("secret123") |
| 213 | + |
| 214 | + image, _ = self.client.images.build( |
| 215 | + path=context_dir, |
| 216 | + secrets=["id=example,src=build-secret.txt"], |
| 217 | + dockerfile="Dockerfile", |
| 218 | + ) |
| 219 | + |
| 220 | + self.assertIsNotNone(image) |
| 221 | + self.assertIsNotNone(image.id) |
| 222 | + |
| 223 | + # Verify secret was passed and stored in file (NOT RECOMMENDED for real use cases) |
| 224 | + container_out = self.client.containers.run( |
| 225 | + image.id, command=["cat", "/output.txt"], remove=True, log_config={"Type": "json-file"} |
| 226 | + ) |
| 227 | + self.assertIn(b"secret123", container_out) |
| 228 | + |
| 229 | + # Verify mounted secret file is not present in image |
| 230 | + with self.assertRaises(ContainerError) as exc: |
| 231 | + self.client.containers.run( |
| 232 | + image.id, command=["cat", "/run/secrets/example"], remove=True |
| 233 | + ) |
| 234 | + self.assertIn("No such file or directory", b"".join(exc.exception.stderr).decode("utf-8")) |
| 235 | + |
200 | 236 | @unittest.skipIf(platform.architecture()[0] == "32bit", "no 32-bit image available") |
201 | 237 | def test_pull_stream(self): |
202 | 238 | generator = self.client.images.pull("ubi8", tag="latest", stream=True) |
|
0 commit comments