Skip to content
Open
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
1 change: 1 addition & 0 deletions .ado/images/build-sandbox-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ extends:
--toolchain-feed "$TOOLCHAIN_FEED" \
--crates-feed "$CRATES_FEED" \
--platform linux/${{ target.arch }} \
--engine docker \
--registry-name "$ACR_SERVER" --tag "$BUILD_BUILDID"
displayName: Build offline-verified agent and proxy
env:
Expand Down
22 changes: 13 additions & 9 deletions .ado/images/sandbox-agent/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@ ARG BUILD_ID
ARG QDK_SOURCE_SHA
ARG QDK_BUILD_ARGS='["--qdk","--cli"]'
LABEL qdk.copilot-sandbox.build-id=${BUILD_ID} \
qdk.copilot-sandbox.interface=2 \
org.opencontainers.image.revision=${QDK_SOURCE_SHA}
SHELL ["/bin/bash", "-euo", "pipefail", "-c"]
RUN tdnf -y upgrade && tdnf -y install \
gcc binutils make glibc-devel kernel-headers pkgconf git tar xz unzip jq curl ca-certificates \
python3 python3-devel python3-pip nodejs nodejs-npm gh \
less procps-ng file time gdb which diffutils patch findutils shadow-utils sed grep gawk \
less procps-ng file time gdb which diffutils patch findutils shadow-utils sed grep gawk socat \
&& tdnf clean all
COPY scripts/ /opt/sandbox/scripts/
COPY runtime/ /opt/sandbox/runtime/
COPY copilot/ /opt/sandbox/copilot/
RUN useradd --create-home --uid 1000 --user-group --shell /bin/bash agent \
&& install -d -o agent -g agent /work /home/agent/.copilot /home/agent/.cargo /home/agent/.npm \
&& install -d -m 0755 /run/qdk-relay \
&& passwd -l root \
&& ! command -v sudo
ENV MSRUSTUP_HOME=/opt/msrustup \
Expand All @@ -37,14 +39,14 @@ ENV MSRUSTUP_HOME=/opt/msrustup \
PYRIGHT_PYTHON_CACHE_DIR=/opt/pyright \
QDK_BUILD_ARGS=${QDK_BUILD_ARGS} \
PATH=/opt/qdk-venv/bin:/opt/msrustup/multiplexers/bin:/opt/msrustup/bin:/opt/rustup/bin:/usr/local/bin:/usr/bin:/bin
RUN --mount=type=bind,from=qdk,source=.ado/images/install-msrustup.sh,target=/opt/sandbox/install-msrustup.sh,readonly \
RUN --mount=type=bind,from=qdk,source=qdk/.ado/images/install-msrustup.sh,target=/opt/sandbox/install-msrustup.sh,readonly \
--mount=type=secret,id=msrustup_access_token \
--mount=type=tmpfs,target=/tmp \
bash /opt/sandbox/scripts/install_rust.sh

# Set up feeds, install the Copilot CLI, and build the QDK (by default, not the whole repo)
FROM tools AS prepared
RUN --mount=type=bind,from=qdk,target=/qdk,readonly \
RUN --mount=type=bind,from=qdk,source=qdk,target=/qdk,readonly \
--mount=type=secret,id=npmrc \
--mount=type=secret,id=pip_index_url \
--mount=type=secret,id=cargo_token \
Expand All @@ -57,11 +59,12 @@ RUN git clone https://github.com/microsoft/qdk-chemistry.git /opt/qdk-chemistry

# Lock things down (proxy, copilot hooks, etc)
FROM prepared AS runtime-base
COPY --chmod=0444 runtime/policy/copilot-sandbox.json /etc/github-copilot/policy.d/copilot-sandbox.json
COPY runtime/policy/copilot-sandbox.json /etc/github-copilot/policy.d/copilot-sandbox.json
RUN chown 0:0 /etc/github-copilot/policy.d/copilot-sandbox.json \
&& chmod 0444 /etc/github-copilot/policy.d/copilot-sandbox.json \
&& chmod 0755 /etc/github-copilot /etc/github-copilot/policy.d \
&& chmod 0555 /opt/sandbox/runtime/entrypoint.sh /opt/sandbox/runtime/sandbox-push \
/opt/sandbox/runtime/receive-token \
/opt/sandbox/runtime/hooks/* /opt/sandbox/runtime/policy/tool_policy.py \
&& ln -s /opt/sandbox/copilot/node_modules/.bin/copilot /usr/local/bin/copilot \
&& ln -s /opt/sandbox/runtime/sandbox-push /usr/local/bin/sandbox-push \
Expand All @@ -78,22 +81,23 @@ ENV HOME=/home/agent \
PYRIGHT_PYTHON_GLOBAL_NODE=1 \
PYRIGHT_PYTHON_NODEJS_WHEEL=0 \
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 \
HTTPS_PROXY=http://proxy:3128 \
HTTP_PROXY=http://proxy:3128 \
HTTPS_PROXY=http://127.0.0.1:3128 \
HTTP_PROXY=http://127.0.0.1:3128 \
NO_PROXY=localhost,127.0.0.1
USER 1000:1000
WORKDIR /work

# Make sure the QDK still builds locked down
FROM runtime-base AS verify
RUN --network=none --mount=type=bind,from=qdk,target=/qdk,readonly \
RUN --network=none --mount=type=bind,from=qdk,source=qdk,target=/qdk,readonly \
bash -c 'source /opt/sandbox/runtime/entrypoint.sh; verify_policy' \
&& /opt/qdk-venv/bin/qir-runner --version \
&& bash /opt/sandbox/scripts/build_qdk.sh \
&& printf '%s\n' "$QDK_BUILD_ARGS" > /tmp/offline-verified
&& printf '%s\n' "$QDK_BUILD_ARGS" > /tmp/offline-verified \
&& chmod 0444 /tmp/offline-verified

# Actual image for running copilot
FROM runtime-base AS runtime
COPY --from=verify --chmod=0444 /tmp/offline-verified /opt/sandbox/offline-verified
COPY --from=verify /tmp/offline-verified /opt/sandbox/offline-verified
ENTRYPOINT ["/opt/sandbox/runtime/entrypoint.sh"]
CMD ["copilot", "--allow-all"]
4 changes: 2 additions & 2 deletions .ado/images/sandbox-agent/runtime/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ setup_chemistry_repo() {
}

load_token() {
local path=${1:-/run/secrets/gh_token}
[[ -s $path ]] || { info 'The gh_token Compose secret is required.'; return 1; }
local path=${1:-/tmp/qdk-sandbox/gh_token}
[[ -s $path ]] || { info 'The launcher must deliver the PAT before the workload starts.'; return 1; }
COPILOT_GITHUB_TOKEN=$(<"$path")
GH_TOKEN=$COPILOT_GITHUB_TOKEN
export COPILOT_GITHUB_TOKEN GH_TOKEN
Expand Down
11 changes: 11 additions & 0 deletions .ado/images/sandbox-agent/runtime/receive-token
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
# The launcher pipes the PAT to stdin after boundary verification. /tmp is tmpfs, so it never touches disk.
set -euo pipefail
umask 0077
directory=/tmp/qdk-sandbox
# mkdir and noclobber fail if anything already exists, so a planted file or link is never reused.
mkdir "$directory"
set -o noclobber
cat > "$directory/gh_token"
chmod 0400 "$directory/gh_token"
[[ -s $directory/gh_token ]]
10 changes: 7 additions & 3 deletions .ado/images/sandbox-proxy/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@ FROM ${BASE_IMAGE}
ARG BUILD_ID
ARG QDK_SOURCE_SHA
LABEL qdk.copilot-sandbox.build-id=${BUILD_ID} \
qdk.copilot-sandbox.interface=2 \
org.opencontainers.image.revision=${QDK_SOURCE_SHA}
RUN tdnf -y upgrade && tdnf -y install squid ca-certificates shadow-utils openssl && tdnf clean all && \
RUN tdnf -y upgrade && tdnf -y install squid socat ca-certificates shadow-utils openssl && tdnf clean all && \
find / -xdev -type f -perm /6000 -exec chmod a-s {} + && \
usermod -L root
COPY squid.conf allowlist.txt allowlist.local.txt /etc/squid/
COPY entrypoint.sh /usr/local/bin/proxy-entrypoint
# Named volumes copy this ownership on first mount, so only squid can create the relay socket.
RUN chmod 0555 /usr/local/bin/proxy-entrypoint && \
install -d -o squid -g squid -m 0755 /run/qdk-relay
# Squid needs a certificate to peek at SNI; nothing trusts it and splice never decrypts.
RUN openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes -days 36500 \
-subj /CN=copilot-sandbox-proxy-unused \
-keyout /etc/squid/peek.pem -out /etc/squid/peek.pem && \
chown squid:squid /etc/squid/peek.pem && chmod 0400 /etc/squid/peek.pem && \
squid -k parse -f /etc/squid/squid.conf
USER squid
EXPOSE 3128
ENTRYPOINT ["/usr/sbin/squid", "-N", "-f", "/etc/squid/squid.conf"]
ENTRYPOINT ["/usr/local/bin/proxy-entrypoint"]
2 changes: 2 additions & 0 deletions .ado/images/sandbox-proxy/allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ api.github.com
.business.githubcopilot.com
.enterprise.githubcopilot.com
copilot-proxy.githubusercontent.com
# Probe names only: the launcher maps them to loopback and the host, which Squid must refuse.
.qdk-boundary.test
22 changes: 22 additions & 0 deletions .ado/images/sandbox-proxy/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
# Squid listens only on loopback; the agent reaches it through a Unix socket on the shared relay volume.
set -euo pipefail

stop() {
trap '' TERM INT
kill -TERM "${children[@]}" 2>/dev/null || true
}

/usr/sbin/squid -N -f /etc/squid/squid.conf &
children=($!)
/usr/bin/socat UNIX-LISTEN:/run/qdk-relay/proxy.sock,fork,unlink-early,mode=0666,max-children=256 \
TCP:127.0.0.1:3128 &
children+=($!)
trap stop TERM INT

# Exit when either process dies, so the agent loses connectivity rather than seeing a half-working proxy.
status=0
wait -n || status=$?
stop
wait || true
exit "$status"
3 changes: 2 additions & 1 deletion .ado/images/sandbox-proxy/squid.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Without a usable tls-cert Squid silently disables peeking, so SNI would go unchecked.
http_port 3128 ssl-bump tls-cert=/etc/squid/peek.pem generate-host-certificates=off
# Loopback only: the agent has no network and reaches this port through the relay socket.
http_port 127.0.0.1:3128 ssl-bump tls-cert=/etc/squid/peek.pem generate-host-certificates=off

# The goal here is to only allow connections by domain name to domains in the allowlist(s).
# If you specify a raw IP, the -n will prevent the reverse lookup that might have let it work
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ __pycache__/
/source/wasm/
/samples/
/target/
/tools/copilot-sandbox/seccomp.json
.config/1espt/PipelineAutobaseliningConfig.yml
Loading