Skip to content
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
21 changes: 16 additions & 5 deletions api/src/e2eTest/java/aussie/e2e/support/E2EHarness.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@
public final class E2EHarness {

private static final Logger LOG = LoggerFactory.getLogger(E2EHarness.class);
private static final String CASSANDRA_IMAGE =
"cassandra:4.1.4@sha256:ff549dfa84dddd83e426d6e13d2d18a3aa00dd3c7fcff5c2529e6d6fda6b7207";
private static final String REDIS_IMAGE =
"redis:7.2.5-alpine@sha256:6aaf3f5e6bc8a592fbfe2cccf19eb36d27c39d12dab4f4b01556b7449e7b1f44";
private static final String NODE_IMAGE =
"node:24-alpine@sha256:116b800c3754b440ee0aa3ed2f20f5bf3d99a554bfd9adeea09ea8017f6e85f5";
private static final String PROMETHEUS_IMAGE =
"prom/prometheus:v2.48.0@sha256:b440bc0e8aa5bab44a782952c09516b6a50f9d7b2325c1ffafac7bc833298e2e";
private static final String ALERTMANAGER_IMAGE =
"prom/alertmanager:v0.26.0@sha256:361db356b33041437517f1cd298462055580585f26555c317df1a3caf2868552";
private static final String BOOTSTRAP_KEY = "aussie_v1_" + generateRandomSecret(32);
private static final String JWS_SIGNING_KEY = generateSigningKey();
// Per-run shared secret expected by the demo's /__test__/* endpoints in the
Expand Down Expand Up @@ -97,7 +107,8 @@ private E2EHarness() {

this.network = Network.newNetwork();

this.cassandra = new CassandraContainer(DockerImageName.parse("cassandra:4.1"))
this.cassandra = new CassandraContainer(
DockerImageName.parse(CASSANDRA_IMAGE).asCompatibleSubstituteFor("cassandra"))
.withNetwork(network)
.withNetworkAliases("cassandra")
.withEnv("CASSANDRA_DC", "datacenter1")
Expand All @@ -107,15 +118,15 @@ private E2EHarness() {
.withStartupTimeout(Duration.ofMinutes(3))
.withLogConsumer(new Slf4jLogConsumer(LoggerFactory.getLogger("e2e.cassandra")));

this.redis = new GenericContainer<>(DockerImageName.parse("redis:7-alpine"))
this.redis = new GenericContainer<>(DockerImageName.parse(REDIS_IMAGE))
.withNetwork(network)
.withNetworkAliases("redis")
.withExposedPorts(6379)
.withCommand("redis-server", "--appendonly", "yes")
.waitingFor(Wait.forLogMessage(".*Ready to accept connections.*", 1))
.withLogConsumer(new Slf4jLogConsumer(LoggerFactory.getLogger("e2e.redis")));

this.demo = new GenericContainer<>(DockerImageName.parse("node:24-alpine"))
this.demo = new GenericContainer<>(DockerImageName.parse(NODE_IMAGE))
.withNetwork(network)
.withNetworkAliases("demo")
.withExposedPorts(3000)
Expand All @@ -137,7 +148,7 @@ private E2EHarness() {
this.replica = apiContainer(apiImage, translationConfig, "api-replica", "e2e.api.replica");
this.alertmanagerConfig = null;
this.alertmanager = null;
this.prometheus = new GenericContainer<>(DockerImageName.parse("prom/prometheus:v2.48.0"))
this.prometheus = new GenericContainer<>(DockerImageName.parse(PROMETHEUS_IMAGE))
.withNetwork(network)
.withNetworkAliases("prometheus")
.withExposedPorts(9090)
Expand Down Expand Up @@ -295,7 +306,7 @@ public synchronized void startObservabilityStack(int webhookPort) {
return;
}
this.alertmanagerConfig = createE2eAlertmanagerConfig(resolveApiProjectDir(), webhookPort);
this.alertmanager = new GenericContainer<>(DockerImageName.parse("prom/alertmanager:v0.26.0"))
this.alertmanager = new GenericContainer<>(DockerImageName.parse(ALERTMANAGER_IMAGE))
.withNetwork(network)
.withNetworkAliases("alertmanager")
.withExposedPorts(9093)
Expand Down
6 changes: 3 additions & 3 deletions docs/platform/ci.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ security, rollout, secret, probe, disruption, and dependency-egress contract;
run the same check locally with `make deployment-contract`.
All third-party GitHub Actions are pinned to full commit SHAs; the workflow
contract check rejects mutable tags. Run it locally with `make workflow-contract`.
The release JVM builder/runtime bases, packaged-E2E runtime, and CI service
images are pinned to digests too; run `make container-contract` to reject
mutable release inputs. CLI release archives use the source commit timestamp
The release JVM builder/runtime bases, packaged-E2E runtime and dependency
images, and CI service images are pinned to digests too; run
`make container-contract` to reject mutable release inputs. CLI release archives use the source commit timestamp
and normalized ownership/ordering so repeated builds of the same tag have
stable archive contents.
Pull requests run dependency review, while the scheduled `Security` workflow
Expand Down
32 changes: 28 additions & 4 deletions tools/container_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,47 @@
RELEASE_INPUTS = (
ROOT / "api/src/main/docker/Dockerfile.jvm",
ROOT / "api/src/main/docker/Dockerfile.e2e",
ROOT / "api/src/e2eTest/java/aussie/e2e/support/E2EHarness.java",
ROOT / ".github/workflows/ci.yml",
ROOT / ".github/workflows/security.yml",
)
SYNTAX = re.compile(r"^\s*#\s*syntax\s*=\s*(?P<image>[^\s]+)", re.IGNORECASE)
FROM = re.compile(r"^\s*FROM\s+(?P<image>[^\s]+)", re.IGNORECASE)
SERVICE_IMAGE = re.compile(r"^\s+image:\s+(?P<image>[^\s#]+)")
SCANNER_IMAGE = re.compile(r"^\s+TRIVY_IMAGE:\s+(?P<image>[^\s#]+)")
JAVA_CONTAINER_CONSTANT = re.compile(
r"private\s+static\s+final\s+String\s+(?P<name>[A-Z][A-Z0-9_]*_IMAGE)"
r"\s*=\s*\"(?P<image>[^\"]+)\""
)
JAVA_CONTAINER_IMAGE = re.compile(r'DockerImageName\.parse\(\s*"(?P<image>[^"]+)"\)')
DIGEST = re.compile(r"@sha256:[0-9a-f]{64}$")


def mutable_image_refs(paths: tuple[Path, ...] = RELEASE_INPUTS) -> list[str]:
violations = []
for path in paths:
patterns = (SYNTAX, FROM) if path.name.startswith("Dockerfile") else (SERVICE_IMAGE, SCANNER_IMAGE)
for line_number, line in enumerate(path.read_text().splitlines(), 1):
match = next((pattern.match(line) for pattern in patterns if pattern.match(line)), None)
if match is not None and not DIGEST.search(match.group("image")):
if path.name.startswith("Dockerfile"):
patterns = (SYNTAX, FROM)
elif path.suffix == ".java":
patterns = (JAVA_CONTAINER_IMAGE,)
else:
patterns = (SERVICE_IMAGE, SCANNER_IMAGE)
source = path.read_text()
matches = []
if path.suffix == ".java":
matches.extend(
(source.count("\n", 0, match.start()) + 1, match)
for match in JAVA_CONTAINER_CONSTANT.finditer(source)
)
for line_number, line in enumerate(source.splitlines(), 1):
matches.extend(
(line_number, match)
for pattern in patterns
for match in (pattern.search(line),)
if match is not None
)
for line_number, match in matches:
if not DIGEST.search(match.group("image")):
relative = path.relative_to(ROOT) if path.is_relative_to(ROOT) else path
violations.append(f"{relative}:{line_number}: {match.group('image')}")
return violations
Expand Down
13 changes: 13 additions & 0 deletions tools/container_contract_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,16 @@ def test_mutable_scanner_image_is_rejected(self):
container_contract.mutable_image_refs((workflow,)),
[f"{workflow}:2: ghcr.io/aquasecurity/trivy:latest"],
)

def test_mutable_java_container_image_is_rejected(self):
with TemporaryDirectory() as directory:
source = Path(directory) / "E2EHarness.java"
source.write_text(
'private static final String REDIS_IMAGE =\n'
' "redis:7-alpine";\n'
'this.redis = new GenericContainer<>(DockerImageName.parse(REDIS_IMAGE));\n'
)
self.assertEqual(
container_contract.mutable_image_refs((source,)),
[f"{source}:1: redis:7-alpine"],
)
Loading