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
25 changes: 25 additions & 0 deletions code-interpreter/app/services/executor_kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,32 @@ def _create_pod_manifest(
],
)

# Use iptables in an init container to drop all outbound traffic
# before the main executor container starts. Since all containers
# in a pod share a network namespace, rules set here apply to the
# executor container as well. This eliminates the race condition
# where the pod can send network requests before the Kubernetes
# NetworkPolicy is enforced by the CNI.
iptables_script = "set -e && iptables -A OUTPUT -j DROP && ip6tables -A OUTPUT -j DROP"
network_lockdown_container = V1Container(
name="network-lockdown",
image=self.image,
command=["sh", "-c", iptables_script],
security_context={
"runAsUser": 0,
"runAsNonRoot": False,
"allowPrivilegeEscalation": False,
"readOnlyRootFilesystem": True,
"capabilities": {"drop": ["ALL"], "add": ["NET_ADMIN"]},
},
resources={
"limits": {"cpu": "100m", "memory": "32Mi"},
"requests": {"cpu": "10m", "memory": "16Mi"},
},
)

spec = V1PodSpec(
init_containers=[network_lockdown_container],
containers=[container],
restart_policy="Never",
service_account_name=self.service_account if self.service_account else None,
Expand Down
1 change: 1 addition & 0 deletions executor/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ RUN apt-get update \
build-essential \
curl \
gfortran \
iptables \
libfreetype6-dev \
liblapack-dev \
libopenblas-dev \
Expand Down
Loading