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
34 changes: 34 additions & 0 deletions .github/actions/build-chroot-images/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Build cached chroot images
description: Load checkout-built integration images using daily GitHub Actions layer caches
inputs:
browser:
description: Include the API proxy image used by browser tests
default: 'false'
runner-variant:
description: Distinguish the browser runner matrix caches
default: ubuntu-latest
runs:
using: composite
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
with:
driver: docker

- name: Expose GitHub Actions cache runtime for Buildx CLI
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
for (const name of ['ACTIONS_RUNTIME_TOKEN', 'ACTIONS_RESULTS_URL']) {
const value = process.env[name];
if (!value) throw new Error(`Missing ${name} for Buildx cache`);
if (name === 'ACTIONS_RUNTIME_TOKEN') core.setSecret(value);
core.exportVariable(name, value);
}

- name: Build and verify local integration images
shell: bash
env:
CHROOT_BROWSER: ${{ inputs.browser }}
CHROOT_CACHE_VARIANT: ${{ github.job }}-${{ inputs.runner-variant }}-${{ runner.arch }}
run: bash scripts/ci/build-chroot-images.sh
47 changes: 45 additions & 2 deletions .github/workflows/supply-chain-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,28 @@ jobs:
df -h /

- name: Configure Docker Hub cache
env:
AWF_DOCKER_CONTAINERD_SNAPSHOTTER: ${{ matrix.scan == 'pr-images' && 'true' || 'false' }}
run: bash scripts/ci/configure-docker-mirror.sh

- name: Set up Docker Buildx for cached PR builds
if: matrix.scan == 'pr-images'
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
with:
driver: docker

- name: Expose GitHub Actions cache runtime for Buildx CLI
if: matrix.scan == 'pr-images'
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
for (const name of ['ACTIONS_RUNTIME_TOKEN', 'ACTIONS_RESULTS_URL']) {
const value = process.env[name];
if (!value) throw new Error(`Missing ${name} for Buildx cache`);
if (name === 'ACTIONS_RUNTIME_TOKEN') core.setSecret(value);
core.exportVariable(name, value);
}

- name: Prepare pinned Grype scanner
if: matrix.scan != 'licenses'
run: docker pull ghcr.io/anchore/grype@sha256:fd4ab4d1042b522c896e73bdf09ab8bf384fa417df99d6dd0d6e1008c7e7c821
Expand Down Expand Up @@ -202,6 +222,10 @@ jobs:
-e GRYPE_DB_CACHE_DIR=/cache \
ghcr.io/anchore/grype@sha256:fd4ab4d1042b522c896e73bdf09ab8bf384fa417df99d6dd0d6e1008c7e7c821 \
db update
# Docker creates root-owned DB directories; actions/cache runs as the
# runner user and must be able to traverse and archive every file.
sudo chown -R "$(id -u):$(id -g)" "$GRYPE_DB"
chmod -R u+rwX "$GRYPE_DB"

- name: Save Grype vulnerability DB cache
if: matrix.scan != 'licenses'
Expand Down Expand Up @@ -263,9 +287,12 @@ jobs:
GRYPE_DB: ${{ runner.temp }}/grype-db
run: |
python3 - <<'PYEOF'
import hashlib, os, subprocess, sys
import datetime, hashlib, os, subprocess, sys
cwd = os.getcwd()
db_cache = os.environ['GRYPE_DB']
# Never import yesterday's package layers: refresh apt/apk security
# upgrades at least daily, while reusing all stages within the UTC day.
cache_day = datetime.datetime.now(datetime.timezone.utc).strftime('%Y-%m-%d')
# The router build requires the SHA-256 of its OpenAPI contract.
with open('containers/router/openapi.yaml', 'rb') as f:
router_openapi_sha256 = hashlib.sha256(f.read()).hexdigest()
Expand Down Expand Up @@ -306,12 +333,28 @@ jobs:
tag = f'awf-pr-scan-{name}:pr'
tar = f'/tmp/awf-pr-scan-{name}.tar'
print(f'::group::docker build {name}', flush=True)
b = subprocess.run(['docker', 'build', *build_args, '-t', tag, context])
cache_scope = f'supply-chain-v1-{name}-{cache_day}'
# The Docker driver shares the daemon's image store. Do not
# --pull enclave-agent's exact locally built build-tools base.
pull_args = [] if name == 'enclave-agent' else ['--pull']
b = subprocess.run([
'docker', 'buildx', 'build', '--load', '--progress=plain',
*pull_args,
'--cache-from', f'type=gha,version=2,scope={cache_scope}',
'--cache-to', f'type=gha,version=2,mode=max,scope={cache_scope}',
*build_args, '-t', tag, context,
])
print('::endgroup::', flush=True)
prune_build_cache()
if b.returncode != 0:
print(f'::error::docker build failed for {name}', flush=True)
rc = b.returncode
# Cache export can fail after --load has created the tag.
subprocess.run(
['docker', 'image', 'rm', '--force', tag],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
continue
if name == 'build-tools':
build_tools_ready = True
Expand Down
38 changes: 18 additions & 20 deletions .github/workflows/test-chroot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jobs:
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v4

- name: Configure Docker Hub cache
env:
AWF_DOCKER_CONTAINERD_SNAPSHOTTER: 'true'
run: bash scripts/ci/configure-docker-mirror.sh

- name: Setup Node.js
Expand All @@ -41,10 +43,10 @@ jobs:
run: /opt/google/chrome/chrome --version

- name: Build local containers
run: |
docker build -t ghcr.io/github/gh-aw-firewall/squid:latest containers/squid/
docker build -t ghcr.io/github/gh-aw-firewall/agent:latest containers/agent/
docker build -t ghcr.io/github/gh-aw-firewall/api-proxy:latest containers/api-proxy/
uses: ./.github/actions/build-chroot-images
with:
browser: 'true'
runner-variant: ${{ matrix.os }}

- name: Run real chroot browser launch
run: npm run test:integration -- --testPathPatterns=chroot-browser --verbose
Expand All @@ -63,6 +65,8 @@ jobs:
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v4

- name: Configure Docker Hub cache
env:
AWF_DOCKER_CONTAINERD_SNAPSHOTTER: 'true'
run: bash scripts/ci/configure-docker-mirror.sh

- name: Setup Node.js
Expand Down Expand Up @@ -136,10 +140,7 @@ jobs:
run: npm run build

- name: Build local containers
run: |
echo "=== Building local containers ==="
docker build -t ghcr.io/github/gh-aw-firewall/squid:latest containers/squid/
docker build -t ghcr.io/github/gh-aw-firewall/agent:latest containers/agent/
uses: ./.github/actions/build-chroot-images

- name: Pre-test cleanup
run: |
Expand Down Expand Up @@ -181,6 +182,8 @@ jobs:
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v4

- name: Configure Docker Hub cache
env:
AWF_DOCKER_CONTAINERD_SNAPSHOTTER: 'true'
run: bash scripts/ci/configure-docker-mirror.sh

- name: Setup Node.js
Expand Down Expand Up @@ -283,10 +286,7 @@ jobs:
run: npm run build

- name: Build local containers
run: |
echo "=== Building local containers ==="
docker build -t ghcr.io/github/gh-aw-firewall/squid:latest containers/squid/
docker build -t ghcr.io/github/gh-aw-firewall/agent:latest containers/agent/
uses: ./.github/actions/build-chroot-images

- name: Pre-test cleanup
run: |
Expand Down Expand Up @@ -327,6 +327,8 @@ jobs:
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v4

- name: Configure Docker Hub cache
env:
AWF_DOCKER_CONTAINERD_SNAPSHOTTER: 'true'
run: bash scripts/ci/configure-docker-mirror.sh

- name: Setup Node.js
Expand Down Expand Up @@ -360,10 +362,7 @@ jobs:
run: npm run build

- name: Build local containers
run: |
echo "=== Building local containers ==="
docker build -t ghcr.io/github/gh-aw-firewall/squid:latest containers/squid/
docker build -t ghcr.io/github/gh-aw-firewall/agent:latest containers/agent/
uses: ./.github/actions/build-chroot-images

- name: Pre-test cleanup
run: |
Expand Down Expand Up @@ -404,6 +403,8 @@ jobs:
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v4

- name: Configure Docker Hub cache
env:
AWF_DOCKER_CONTAINERD_SNAPSHOTTER: 'true'
run: bash scripts/ci/configure-docker-mirror.sh

- name: Setup Node.js
Expand All @@ -419,10 +420,7 @@ jobs:
run: npm run build

- name: Build local containers
run: |
echo "=== Building local containers ==="
docker build -t ghcr.io/github/gh-aw-firewall/squid:latest containers/squid/
docker build -t ghcr.io/github/gh-aw-firewall/agent:latest containers/agent/
uses: ./.github/actions/build-chroot-images

- name: Pre-test cleanup
run: |
Expand Down
105 changes: 12 additions & 93 deletions containers/agent/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ FROM ubuntu:22.04@sha256:0a9887931b0e38af2e3487ed39e29436b0535c4f3f52e57745baaf7

RUN set -eux; \
BROWSER_PKGS="libasound2 libatk-bridge2.0-0 libatk1.0-0 libatspi2.0-0 libcairo2 libcups2 libdbus-1-3 libdrm2 libexpat1 libgbm1 libglib2.0-0 libnspr4 libnss3 libpango-1.0-0 libpangocairo-1.0-0 libudev1 libx11-6 libxcb1 libxcomposite1 libxdamage1 libxext6 libxfixes3 libxkbcommon0 libxrandr2 libxrender1 libxshmfence1 fonts-liberation"; \
apt-get -o Acquire::Retries=3 update && \
apt-get -o Acquire::Retries=3 -o APT::Update::Error-Mode=any update && \
apt-get -o Acquire::Retries=3 install -y --no-install-recommends $BROWSER_PKGS && \
apt-get -o Acquire::Retries=3 upgrade -y --no-install-recommends && \
# Include dependencies already in the base image (e.g. libpcre3), not just
Expand All @@ -65,42 +65,12 @@ RUN set -eux; \
FROM ${BASE_IMAGE} AS one-shot-token-build

COPY one-shot-token/one-shot-token.c /tmp/one-shot-token.c
# Use the base image's standard archive/security mirrors, not DNS-only Azure selection.
RUN set -eux; \
force_archive_mirror() { \
echo "Falling back to archive.ubuntu.com mirror..." >&2; \
if [ -f /etc/apt/sources.list ]; then \
sed -i 's|http://azure.archive.ubuntu.com|http://archive.ubuntu.com|g' /etc/apt/sources.list; \
sed -i 's|http://security.ubuntu.com|http://archive.ubuntu.com|g' /etc/apt/sources.list 2>/dev/null || true; \
fi; \
if [ -d /etc/apt/sources.list.d ]; then \
find /etc/apt/sources.list.d -name '*.sources' -exec \
sed -i -e 's|http://azure.archive.ubuntu.com|http://archive.ubuntu.com|g' \
-e 's|http://security.ubuntu.com|http://archive.ubuntu.com|g' {} + 2>/dev/null || true; \
fi; \
rm -rf /var/lib/apt/lists/* && \
apt-get -o Acquire::Retries=3 -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 update; \
}; \
apt_install_retry() { \
apt-get -o Acquire::Retries=3 -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 \
install -y --no-install-recommends "$@" && return 0; \
echo "apt-get install failed (likely mirror fetch timeout), forcing archive.ubuntu.com and retrying..." >&2; \
force_archive_mirror; \
apt-get -o Acquire::Retries=3 -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 \
install -y --no-install-recommends "$@"; \
}; \
if getent hosts azure.archive.ubuntu.com >/dev/null 2>&1; then \
if [ -f /etc/apt/sources.list ]; then \
sed -i 's|http://archive.ubuntu.com|http://azure.archive.ubuntu.com|g' /etc/apt/sources.list; \
sed -i 's|http://security.ubuntu.com|http://azure.archive.ubuntu.com|g' /etc/apt/sources.list; \
fi; \
if [ -d /etc/apt/sources.list.d ]; then \
find /etc/apt/sources.list.d -name '*.sources' -exec \
sed -i -e 's|http://archive.ubuntu.com|http://azure.archive.ubuntu.com|g' \
-e 's|http://security.ubuntu.com|http://azure.archive.ubuntu.com|g' {} +; \
fi; \
fi && \
apt-get -o Acquire::Retries=3 -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 update && \
apt_install_retry gcc libc6-dev binutils && \
apt-get -o Acquire::Retries=3 -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 \
-o APT::Update::Error-Mode=any update && \
apt-get -o Acquire::Retries=3 -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 \
install -y --no-install-recommends gcc libc6-dev binutils && \
gcc -shared -fPIC -fvisibility=hidden -O2 -Wall -s \
-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 \
-o /tmp/one-shot-token.so /tmp/one-shot-token.c -ldl -lpthread && \
Expand All @@ -110,85 +80,34 @@ FROM ${BASE_IMAGE}

COPY --from=browser-libs /usr/local/share/awf/ /usr/local/share/awf/

# Optionally switch to Azure apt mirror for faster package fetches in CI
# Only rewrite if azure.archive.ubuntu.com is resolvable (BuildKit DNS can fail)
# Falls back to default archive.ubuntu.com which is universally reachable
RUN if getent hosts azure.archive.ubuntu.com >/dev/null 2>&1; then \
echo "Using Azure apt mirror (DNS resolved successfully)"; \
if [ -f /etc/apt/sources.list ]; then \
sed -i 's|http://archive.ubuntu.com|http://azure.archive.ubuntu.com|g' /etc/apt/sources.list; \
sed -i 's|http://security.ubuntu.com|http://azure.archive.ubuntu.com|g' /etc/apt/sources.list; \
fi; \
if [ -d /etc/apt/sources.list.d ]; then \
find /etc/apt/sources.list.d -name '*.sources' -exec \
sed -i 's|http://archive.ubuntu.com|http://azure.archive.ubuntu.com|g' {} + 2>/dev/null || true; \
find /etc/apt/sources.list.d -name '*.sources' -exec \
sed -i 's|http://security.ubuntu.com|http://azure.archive.ubuntu.com|g' {} + 2>/dev/null || true; \
fi; \
else \
echo "Azure apt mirror not reachable, using default archive.ubuntu.com"; \
fi

# Install required and runner-parity packages, apply security upgrades, then install
# Node.js 22.23.2 and npm 12.2.1. Keeping apt work in one layer avoids repeatedly
# downloading package indexes during cold CI builds.
# Note: Some packages may already exist in runner-like base images, apt handles this gracefully
# apt_update_retry: retries up to 3 times with backoff; if all fail, reverts to archive.ubuntu.com
# Retain the base image's mirrors; apt retries fetch failures and rejects partial indexes.
RUN set -eux; \
force_archive_mirror() { \
echo "Falling back to archive.ubuntu.com mirror..." >&2; \
if [ -f /etc/apt/sources.list ]; then \
sed -i 's|http://azure.archive.ubuntu.com|http://archive.ubuntu.com|g' /etc/apt/sources.list; \
sed -i 's|http://security.ubuntu.com|http://archive.ubuntu.com|g' /etc/apt/sources.list 2>/dev/null || true; \
fi; \
if [ -d /etc/apt/sources.list.d ]; then \
find /etc/apt/sources.list.d -name '*.sources' -exec \
sed -i -e 's|http://azure.archive.ubuntu.com|http://archive.ubuntu.com|g' \
-e 's|http://security.ubuntu.com|http://archive.ubuntu.com|g' {} + 2>/dev/null || true; \
fi; \
rm -rf /var/lib/apt/lists/* && \
apt-get -o Acquire::Retries=3 -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 update; \
}; \
apt_update_retry() { \
local i; for i in 1 2 3; do \
rm -rf /var/lib/apt/lists/*; \
if apt-get -o Acquire::Retries=3 -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 \
update > /tmp/apt-update.log 2>&1; then \
cat /tmp/apt-update.log; \
if ! grep -q "Failed to fetch" /tmp/apt-update.log; then return 0; fi; \
else \
cat /tmp/apt-update.log; \
fi; \
echo "apt-get update attempt $i/3 failed or had fetch failures, retrying in $((i*10))s..." >&2; sleep $((i*10)); \
done; \
echo "All apt-get update retries failed, falling back to archive.ubuntu.com..." >&2; \
force_archive_mirror; \
apt-get -o Acquire::Retries=3 -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 \
-o APT::Update::Error-Mode=any update; \
}; \
apt_install_retry() { \
apt-get -o Acquire::Retries=3 -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 \
install -y --no-install-recommends "$@" && return 0; \
echo "apt-get install failed (likely mirror fetch timeout), forcing archive.ubuntu.com and retrying..." >&2; \
force_archive_mirror; \
apt-get -o Acquire::Retries=3 -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 \
install -y --no-install-recommends "$@"; \
}; \
apt_upgrade_retry() { \
apt-get -o Acquire::Retries=3 -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 \
upgrade -y && return 0; \
echo "apt-get upgrade failed (likely mirror fetch timeout), forcing archive.ubuntu.com and retrying..." >&2; \
force_archive_mirror && \
apt-get -o Acquire::Retries=3 -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 upgrade -y; \
upgrade -y; \
}; \
PKGS="iptables curl ca-certificates git gnupg dnsutils net-tools netcat-openbsd libcap2-bin libgdiplus libev-dev libssl-dev php-intl php-gd python3"; \
apt_update_retry && \
apt_install_retry $PKGS && \
# Native packages serve non-chroot execution. Chroot execution uses the
# independent Ubuntu 22.04 payload above, never these newer image libraries.
BROWSER_PKGS="$(cat /usr/local/share/awf/browser-packages.txt)"; \
BROWSER_PKGS="$(cat /usr/local/share/awf/browser-packages.txt)" && \
# Ubuntu 24.04 renamed several of these to time_t-64 variants (e.g. libasound2t64),
# and the old names became ambiguous virtual packages. Prefer the t64 package when
# the base image provides one, otherwise keep the 22.04 name.
BROWSER_ACTUAL_PKGS=""; \
BROWSER_ACTUAL_PKGS="" && \
for pkg in $BROWSER_PKGS; do \
if apt-cache show "${pkg}t64" >/dev/null 2>&1; then \
BROWSER_ACTUAL_PKGS="$BROWSER_ACTUAL_PKGS ${pkg}t64"; \
Expand Down
Loading
Loading