Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(platform): refresh Debian packages in image builds daily so security fixes ship (#15464)

Nicholas Tindlec52ce5d6cff7
diff --git a/.github/scripts/test_e2e_seed_cache_contract.py b/.github/scripts/test_e2e_seed_cache_contract.py
index 35eb0f1dd0..62b3787536 100644
--- a/.github/scripts/test_e2e_seed_cache_contract.py
+++ b/.github/scripts/test_e2e_seed_cache_contract.py
@@ -126,6 +126,19 @@ class E2ESeedCacheContractTests(unittest.TestCase):
)
+class E2EImageBuildContractTests(unittest.TestCase):
+ def test_backend_images_reinstall_os_packages_daily(self):
+ workflow = (
+ Path(__file__).resolve().parents[1] / "workflows/platform-fullstack-ci.yml"
+ ).read_text(encoding="utf-8")
+ build = workflow.split(
+ "- name: Set up Platform - Build backend Docker images\n", 1
+ )[1].split("\n - name:", 1)[0]
+ # APT_REFRESH in backend/Dockerfile: the date re-runs the package
+ # installs once a day, so E2E tests the OS packages that ship.
+ self.assertIn('--set "*.args.APT_REFRESH=$(date -u +%F)"', build)
+
+
class E2ECoverageContractTests(unittest.TestCase):
def test_test_floor_includes_shared_file_security_suite(self):
workflow = (
diff --git a/.github/workflows/copilot-setup-steps.yml b/.github/workflows/copilot-setup-steps.yml
index 2c069611a5..c0c0590e17 100644
--- a/.github/workflows/copilot-setup-steps.yml
+++ b/.github/workflows/copilot-setup-steps.yml
@@ -196,10 +196,12 @@ jobs:
- name: Build migrate Docker image with cache
working-directory: autogpt_platform
run: |
- # Build the migrate image with buildx for GHA caching
+ # Build the migrate image with buildx for GHA caching. The UTC date
+ # re-runs its package installs once a day (APT_REFRESH).
docker buildx build \
--cache-from type=gha \
--cache-to type=gha,mode=max \
+ --build-arg APT_REFRESH="$(date -u +%F)" \
--target migrate \
--tag autogpt_platform-migrate:latest \
--load \
diff --git a/.github/workflows/platform-fullstack-ci.yml b/.github/workflows/platform-fullstack-ci.yml
index 9d597890d2..47da76b385 100644
--- a/.github/workflows/platform-fullstack-ci.yml
+++ b/.github/workflows/platform-fullstack-ci.yml
@@ -370,7 +370,10 @@ jobs:
run: |
targets=$(python -c "import yaml; s = yaml.safe_load(open('docker-compose.resolved.yml'))['services']; print(' '.join(n for n, c in s.items() if 'build' in c and n != 'frontend'))")
echo "Baking: $targets"
- docker buildx bake --allow=fs.read=.. -f docker-compose.resolved.yml --load $targets
+ # The UTC date re-runs the backend's package installs once a day
+ # (APT_REFRESH), so E2E tests the OS packages that ship.
+ docker buildx bake --allow=fs.read=.. -f docker-compose.resolved.yml --load \
+ --set "*.args.APT_REFRESH=$(date -u +%F)" $targets
- name: Set up Platform - Build frontend Docker image
id: platform-build-frontend
diff --git a/.github/workflows/platform-single-container-docker.yml b/.github/workflows/platform-single-container-docker.yml
index b00374468a..b26c572bfe 100644
--- a/.github/workflows/platform-single-container-docker.yml
+++ b/.github/workflows/platform-single-container-docker.yml
@@ -116,6 +116,13 @@ jobs:
BUILD_CACHE_ARCH: ${{ matrix.suffix }}
run: python3 .github/scripts/single_container_cache.py
+ # A new APT_REFRESH re-runs the images' package installs instead of
+ # reusing cached ones, so Debian security fixes ship within a day.
+ - name: Set the daily OS package refresh
+ id: apt-refresh
+ shell: bash
+ run: echo "date=$(date -u +%F)" >> "$GITHUB_OUTPUT"
+
- name: Test appliance runtime helpers
shell: bash
env:
@@ -148,6 +155,7 @@ jobs:
targets: single-container
set: |
*.platform=${{ matrix.platform }}
+ *.args.APT_REFRESH=${{ steps.apt-refresh.outputs.date }}
single-container.args.IMAGE_VERSION=sha-${{ github.sha }}
single-container.args.VCS_REF=${{ github.sha }}
single-container.output=type=docker
@@ -324,6 +332,11 @@ jobs:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}
+ - name: Set the daily OS package refresh
+ id: apt-refresh
+ shell: bash
+ run: echo "date=$(date -u +%F)" >> "$GITHUB_OUTPUT"
+
- name: Build and push platform digest
id: build
uses: docker/bake-action@d3418bd7d0e9324001bca92fa8ba175ea7e6dc9b # v7.3.0
@@ -333,6 +346,7 @@ jobs:
targets: single-container
set: |
*.platform=${{ matrix.platform }}
+ *.args.APT_REFRESH=${{ steps.apt-refresh.outputs.date }}
single-container.args.IMAGE_VERSION=sha-${{ github.sha }}
single-container.args.VCS_REF=${{ github.sha }}
single-container.tags=${{ env.DEPLOY_IMAGE }}
diff --git a/.github/workflows/scripts/check_actions_status.py b/.github/workflows/scripts/check_actions_status.py
index 17383913fa..aeb14d0e84 100644
--- a/.github/workflows/scripts/check_actions_status.py
+++ b/.github/workflows/scripts/check_actions_status.py
@@ -50,9 +50,7 @@ def get_environment_variables() -> Tuple[str, str, str, str, str]:
sys.exit(1)
-def make_api_request(
- url: str, headers: Dict[str, str]
-) -> Tuple[Dict, Optional[str]]:
+def make_api_request(url: str, headers: Dict[str, str]) -> Tuple[Dict, Optional[str]]:
"""Make an API request and return its JSON and next-page URL."""
try:
print("Making API request to:", url)
@@ -65,9 +63,7 @@ def make_api_request(
sys.exit(1)
-def get_paginated_items(
- url: str, headers: Dict[str, str], item_key: str
-) -> List[Dict]:
+def get_paginated_items(url: str, headers: Dict[str, str], item_key: str) -> List[Dict]:
"""Retrieve all pages from a GitHub list endpoint."""
items = []
@@ -101,9 +97,7 @@ def action_run_order(run: Dict) -> Tuple[int, int, int]:
)
-def is_superseded_cancellation(
- check_run: Dict, workflow_runs: List[Dict]
-) -> bool:
+def is_superseded_cancellation(check_run: Dict, workflow_runs: List[Dict]) -> bool:
"""Return whether a canceled check belongs to a superseded workflow run."""
action_run_id = get_action_run_id(check_run)
if action_run_id is None:
@@ -202,9 +196,7 @@ def main():
print(f"Current run ID: {current_run_id}")
while True:
- check_runs = get_paginated_items(
- check_runs_endpoint, headers, "check_runs"
- )
+ check_runs = get_paginated_items(check_runs_endpoint, headers, "check_runs")
print(f"Processing {len(check_runs)} check runs...")
runs_in_progress = any(
@@ -218,9 +210,7 @@ def main():
workflow_runs = get_paginated_items(
workflow_runs_endpoint, headers, "workflow_runs"
)
- _, all_others_passed = process_check_runs(
- check_runs, workflow_runs
- )
+ _, all_others_passed = process_check_runs(check_runs, workflow_runs)
break
print(
diff --git a/.github/workflows/scripts/test_check_actions_status.py b/.github/workflows/scripts/test_check_actions_status.py
index 4c2b284fdc..5354a0b2c5 100644
--- a/.github/workflows/scripts/test_check_actions_status.py
+++ b/.github/workflows/scripts/test_check_actions_status.py
@@ -45,9 +45,7 @@ class ProcessCheckRunsTests(unittest.TestCase):
self.assertEqual(process_check_runs([skipped_check]), (False, True))
def test_accepts_cancellation_superseded_by_passing_workflow_run(self):
- result = process_check_runs(
- [CANCELED_CHECK], [CANCELED_RUN, PASSING_RUN]
- )
+ result = process_check_runs([CANCELED_CHECK], [CANCELED_RUN, PASSING_RUN])
self.assertEqual(result, (False, True))
@@ -92,18 +90,14 @@ class ProcessCheckRunsTests(unittest.TestCase):
def test_rejects_cancellation_replaced_by_failed_workflow_run(self):
failed_run = {**PASSING_RUN, "conclusion": "failure"}
- result = process_check_runs(
- [CANCELED_CHECK], [CANCELED_RUN, failed_run]
- )
+ result = process_check_runs([CANCELED_CHECK], [CANCELED_RUN, failed_run])
self.assertEqual(result, (False, False))
def test_rejects_cancellation_replaced_by_different_workflow(self):
unrelated_run = {**PASSING_RUN, "workflow_id": 8}
- result = process_check_runs(
- [CANCELED_CHECK], [CANCELED_RUN, unrelated_run]
- )
+ result = process_check_runs([CANCELED_CHECK], [CANCELED_RUN, unrelated_run])
self.assertEqual(result, (False, False))
@@ -113,9 +107,7 @@ class ProcessCheckRunsTests(unittest.TestCase):
"details_url": "https://checks.example.com/result/1001",
}
- result = process_check_runs(
- [external_check], [CANCELED_RUN, PASSING_RUN]
- )
+ result = process_check_runs([external_check], [CANCELED_RUN, PASSING_RUN])
self.assertEqual(result, (False, False))
@@ -147,7 +139,12 @@ class ProcessCheckRunsTests(unittest.TestCase):
"status": "completed",
"conclusion": "failure",
}
- failed = {"id": 8, "name": "test", "status": "completed", "conclusion": "failure"}
+ failed = {
+ "id": 8,
+ "name": "test",
+ "status": "completed",
+ "conclusion": "failure",
+ }
self.assertEqual(process_check_runs([copilot, failed]), (False, False))
def test_a_failing_journeys_leg_is_advisory_but_smoke_still_blocks(self):
diff --git a/autogpt_platform/backend/Dockerfile b/autogpt_platform/backend/Dockerfile
index e315e0bd28..35b7a30cf2 100644
--- a/autogpt_platform/backend/Dockerfile
+++ b/autogpt_platform/backend/Dockerfile
@@ -11,6 +11,13 @@ WORKDIR /app
RUN echo 'Acquire::http::Pipeline-Depth 0;\nAcquire::http::No-Cache true;\nAcquire::BrokenProxy true;\n' > /etc/apt/apt.conf.d/99fixbadproxy
+# APT_REFRESH is part of the cache key of every RUN after it, so a new value
+# re-runs the package installs below and security fixes reach the images
+# instead of staying behind a cached layer. CI passes the UTC date, which
+# refreshes them once a day. Every stage that installs packages declares it
+# before its first install.
+ARG APT_REFRESH
+
# Install Node.js repository key and setup
RUN apt-get update --allow-releaseinfo-change --fix-missing \
&& apt-get install -y curl ca-certificates gnupg \
@@ -67,6 +74,9 @@ WORKDIR /app/autogpt_platform/backend
ENV DEBIAN_FRONTEND=noninteractive
+# APT_REFRESH re-runs the package install below; see the builder stage.
+ARG APT_REFRESH
+
# Install only what's needed for prisma migrate: Node.js and minimal Python for prisma-python
# libatomic1: debian:13-slim no longer ships it, but the Prisma CLI's bundled
# Node (copied from the builder, which had it via build-essential) dynamically
@@ -113,6 +123,10 @@ WORKDIR /app
ENV DEBIAN_FRONTEND=noninteractive
+# APT_REFRESH re-runs the package installs below, Chromium included; see the
+# builder stage.
+ARG APT_REFRESH
+
# Install Python, FFmpeg, ImageMagick, and CLI tools for agent use.
# bubblewrap provides OS-level sandbox (whitelist-only FS + no network)
# for the bash_exec MCP tool (fallback when E2B is not configured).
diff --git a/autogpt_platform/single-container/Dockerfile b/autogpt_platform/single-container/Dockerfile
index 9adbcfb194..145760f87a 100644
--- a/autogpt_platform/single-container/Dockerfile
+++ b/autogpt_platform/single-container/Dockerfile
@@ -83,6 +83,12 @@ RUN install -d -m 0755 /opt/prisma-python \
ENV DEBIAN_FRONTEND=noninteractive
+# APT_REFRESH is part of the cache key of every RUN after it, so a new value
+# re-runs the package install below and security fixes reach the image instead
+# of staying behind a cached layer. CI passes the UTC date, which refreshes it
+# once a day.
+ARG APT_REFRESH
+
# Block service auto-start during package installation; Supervisor owns every
# daemon at runtime. PostgreSQL comes from PGDG to retain PG15 parity on Debian
# 13, while Valkey comes from Debian's security-maintained BSD build.
@@ -256,8 +262,8 @@ ENV PATH="/opt/rabbitmq/sbin:/opt/erlang/bin:/opt/openssl/bin:/usr/lib/postgresq
FORCE_FLAG_GRAPHITI_MEMORY=true \
AUTOGPT_PUBLIC_URL=http://localhost:3000
-# Build arguments change on every build, so they are declared only after the
-# last layer-producing step to keep them out of the layer cache keys.
+# These build arguments change on every build, so they are declared only after
+# the last layer-producing step to keep them out of the layer cache keys.
ARG IMAGE_VERSION=dev
ARG VCS_REF=unknown
diff --git a/autogpt_platform/single-container/tests/test_dockerfile_layers.py b/autogpt_platform/single-container/tests/test_dockerfile_layers.py
index 56792f8427..5af295c441 100644
--- a/autogpt_platform/single-container/tests/test_dockerfile_layers.py
+++ b/autogpt_platform/single-container/tests/test_dockerfile_layers.py
@@ -8,11 +8,16 @@ ASSET_DIR = Path(__file__).resolve().parents[1]
APPLIANCE_DOCKERFILE = ASSET_DIR / "Dockerfile"
BACKEND_DOCKERFILE = ASSET_DIR.parent / "backend" / "Dockerfile"
BAKE_PATH = ASSET_DIR / "docker-bake.hcl"
+WORKFLOW_PATH = (
+ ASSET_DIR.parents[1] / ".github/workflows/platform-single-container-docker.yml"
+)
SERVER_BASE = "FROM debian:13-slim AS server-base"
SERVER = "FROM server-base AS server"
APPLIANCE = "FROM autogpt-backend-base AS single-container"
LAYER_STEPS = {"ADD", "COPY", "RUN"}
+PACKAGE_REFRESH = "APT_REFRESH"
+PACKAGE_INSTALL = re.compile(r"\bapt(?:-get)? (?:update|install|upgrade)\b")
def instructions(path: Path) -> list[str]:
@@ -41,6 +46,18 @@ def stage(lines: list[str], header: str) -> list[str]:
return lines[start:end]
+def stages(lines: list[str]) -> dict[str, list[str]]:
+ """Map each stage's FROM instruction to the instructions in that stage."""
+ result: dict[str, list[str]] = {}
+ current: list[str] | None = None
+ for line in lines:
+ if line.startswith("FROM "):
+ current = result.setdefault(line, [])
+ elif current is not None:
+ current.append(line)
+ return result
+
+
def run_commands(lines: list[str]) -> set[str]:
return {
command.strip()
@@ -50,6 +67,20 @@ def run_commands(lines: list[str]) -> set[str]:
}
+def declares(line: str, argument: str) -> bool:
+ return line.startswith("ARG ") and line.split()[1].split("=")[0] == argument
+
+
+def installs_packages(line: str) -> bool:
+ return line.startswith("RUN ") and bool(PACKAGE_INSTALL.search(line))
+
+
+def workflow_jobs(workflow: str) -> dict[str, str]:
+ """Map each job id in a workflow to its indented body."""
+ jobs = workflow.split("\njobs:\n", 1)[1]
+ return dict(re.findall(r"^ ([\w-]+):\n((?:(?: .*)?\n)*)", jobs, re.M))
+
+
class ApplianceLayerOrderTest(unittest.TestCase):
"""The appliance stacks its dependencies under AutoGPT's code.
@@ -100,7 +131,9 @@ class ApplianceLayerOrderTest(unittest.TestCase):
def test_build_arguments_follow_every_layer(self) -> None:
arguments = [
- i for i, line in enumerate(self.appliance) if line.startswith("ARG ")
+ i
+ for i, line in enumerate(self.appliance)
+ if line.startswith("ARG ") and not declares(line, PACKAGE_REFRESH)
]
self.assertTrue(arguments, "the appliance declares its build arguments")
self.assertEqual(
@@ -123,5 +156,75 @@ class ApplianceLayerOrderTest(unittest.TestCase):
)
+class PackageRefreshTest(unittest.TestCase):
+ """OS package installs run again once a day instead of staying cached.
+
+ A build argument is part of the cache key of every RUN after its ARG. Each
+ stage that installs packages declares APT_REFRESH before its first install
+ and CI passes the UTC date, so Debian's security fixes reach the images
+ within a day rather than waiting behind a cached layer.
+ """
+
+ def test_every_package_install_follows_the_refresh_argument(self) -> None:
+ for dockerfile in (BACKEND_DOCKERFILE, APPLIANCE_DOCKERFILE):
+ installing = {
+ header: body
+ for header, body in stages(instructions(dockerfile)).items()
+ if any(installs_packages(line) for line in body)
+ }
+ self.assertTrue(installing, f"no package installs found in {dockerfile}")
+ for header, body in installing.items():
+ first_install = next(
+ i for i, line in enumerate(body) if installs_packages(line)
+ )
+ with self.subTest(dockerfile=dockerfile.parent.name, stage=header):
+ self.assertTrue(
+ any(
+ declares(line, PACKAGE_REFRESH)
+ for line in body[:first_install]
+ ),
+ f"{PACKAGE_REFRESH} must be declared before the first install",
+ )
+
+ def test_chromium_install_follows_the_refresh_argument(self) -> None:
+ installs = [
+ body[:i]
+ for body in stages(instructions(BACKEND_DOCKERFILE)).values()
+ for i, line in enumerate(body)
+ if installs_packages(line) and re.search(r"\bchromium\b", line)
+ ]
+ self.assertEqual(len(installs), 1, "the backend installs Chromium once")
+ self.assertTrue(
+ any(declares(line, PACKAGE_REFRESH) for line in installs[0]),
+ "a cached Chromium layer would keep shipping a vulnerable browser",
+ )
+
+ def test_every_image_build_passes_the_utc_date(self) -> None:
+ workflow = WORKFLOW_PATH.read_text(encoding="utf-8")
+ builds = 0
+ for job, body in workflow_jobs(workflow).items():
+ steps = re.split(r"\n - ", body)
+ for index, step in enumerate(steps):
+ if "uses: docker/bake-action@" not in step:
+ continue
+ builds += 1
+ with self.subTest(job=job):
+ self.assertIn(
+ f"*.args.{PACKAGE_REFRESH}="
+ "${{ steps.apt-refresh.outputs.date }}",
+ step,
+ )
+ dates = [
+ earlier
+ for earlier in steps[:index]
+ if re.search(r"^\s+id: apt-refresh$", earlier, re.M)
+ ]
+ self.assertEqual(len(dates), 1, "an earlier step sets the date")
+ self.assertIn(
+ 'echo "date=$(date -u +%F)" >> "$GITHUB_OUTPUT"', dates[0]
+ )
+ self.assertEqual(builds, workflow.count("uses: docker/bake-action@"))
+
+
if __name__ == "__main__":
unittest.main()
diff --git a/autogpt_platform/single-container/tests/test_frontend_environment.py b/autogpt_platform/single-container/tests/test_frontend_environment.py
index 6fa1ce112c..47d090cb6b 100644
--- a/autogpt_platform/single-container/tests/test_frontend_environment.py
+++ b/autogpt_platform/single-container/tests/test_frontend_environment.py
@@ -178,7 +178,7 @@ class FrontendEnvironmentTest(unittest.TestCase):
):
self.assertEqual(policy.count(table), 1)
self.assertIn(
- 'GRANT SELECT (id, email),\n'
+ "GRANT SELECT (id, email),\n"
' INSERT (id, email, name, "updatedAt"),\n'
' UPDATE (email, "updatedAt")',
policy,