源码快照 @ 2026-09-01 (source-only, 剔除非源码素材)
Dependency audit / audit (push) Canceled after 0s
CI / plan (push) Canceled after 0s
Gitoxide helper admission / macos-latest (push) Canceled after 0s
Gitoxide helper admission / ubuntu-latest (push) Canceled after 0s
Gitoxide helper admission / windows-latest (push) Canceled after 0s
Runtime Host peer admission / quality (push) Canceled after 0s
Windows recovery / windows_recovery (push) Canceled after 0s
CI / heavy (push) Canceled after 0s
CI / test (push) Canceled after 0s

This commit is contained in:
agent-radar committed 2026-09-01 19:05:14 +08:00
commit 7be535059e
3358 files changed
+1306357

No files matched your search

@@ -0,0 +1,25 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
FROM python:3.12-slim
RUN python -m pip install --no-cache-dir mitmproxy==12.2.3
COPY egress_filter.py /opt/maka-eval/egress_filter.py
COPY egress-proxy/entrypoint.sh /opt/maka-eval/entrypoint.sh
ENTRYPOINT ["/opt/maka-eval/entrypoint.sh"]
+62
View File
@@ -0,0 +1,62 @@
#!/bin/sh
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
set -eu
STATE_DIR=/opt/maka-egress-state
CERT_DIR=/opt/maka-egress
mkdir -p "$STATE_DIR" "$CERT_DIR"
# Create the audit log if this is the first start. Truncating here would erase
# hits already written if the proxy restarts mid-trial, and the trial would
# look like an honest zero-hit run.
touch "$STATE_DIR/hits.jsonl"
# confdir holds the CA private key and this cell's audit log, so it stays
# container-private and only the certificate reaches the volume the subject
# mounts. Creating the CA here instead of letting mitmdump create it on startup
# publishes the certificate before the proxy port opens, so the health gate
# cannot release `main` against a missing or left-over certificate.
python -c 'import sys
from mitmproxy.certs import CertStore
CertStore.from_store(sys.argv[1], "mitmproxy", 2048)' "$STATE_DIR"
# Publish by rename so a restart cannot expose a truncated certificate to a
# subject that is already running against the previous one.
cp "$STATE_DIR/mitmproxy-ca-cert.pem" "$CERT_DIR/.mitmproxy-ca-cert.pem"
mv "$CERT_DIR/.mitmproxy-ca-cert.pem" "$CERT_DIR/mitmproxy-ca-cert.pem"
# The subject only needs this address so HTTPS_PROXY can keep using the
# service hostname after the namespace policy refuses Docker DNS.
ip="$(getent ahostsv4 "$(hostname)" | awk 'NR == 1 { print $1 }')"
case "$ip" in
"" | 127.*)
echo "could not publish Eval egress proxy IPv4" >&2
exit 1
;;
esac
printf '%s\n' "$ip" > "$CERT_DIR/.proxy-ipv4"
mv "$CERT_DIR/.proxy-ipv4" "$CERT_DIR/proxy-ipv4"
exec mitmdump \
--quiet \
--listen-host 0.0.0.0 \
--listen-port 8080 \
--set block_global=false \
--set rawtcp=false \
--set confdir="$STATE_DIR" \
--scripts /opt/maka-eval/egress_filter.py
+148
View File
@@ -0,0 +1,148 @@
#!/bin/sh
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
set -eu
# gost's allowlist is never written here: the sidecar entrypoint empties it at
# start and this policy only ever forwards through the audited proxy, so gost
# forwards nothing on its own. That also removes the packet-mark exemption gost
# needs when it does forward — the sidecar shares the subject's network
# namespace, so a mark the sidecar can set is one the subject can set too.
GOST_PORT=12345
NFTABLES_RULESET_NAME=gost_egress
PROXY_HOST=maka-eval-mitmproxy
PROXY_PORT=8080
remove_nftables() {
nft delete table inet "$NFTABLES_RULESET_NAME" 2>/dev/null || true
}
PROXY_IPV4_PATH=/opt/maka-egress/proxy-ipv4
resolve_proxy_ip() {
# The proxy publishes this file before it is healthy. Reading it does not
# depend on Docker DNS, so deny-all then allow still has an address.
if [ ! -s "$PROXY_IPV4_PATH" ]; then
return
fi
ip=$(tr -d ' \t\r\n' < "$PROXY_IPV4_PATH")
case "$ip" in
"" | *.*.*.*.* | *[!0-9.]*)
return
;;
esac
# Same four-octet program as relay_agent.IPV4_OCTET_AWK.
if ! printf '%s\n' "$ip" | awk '
BEGIN { FS = "." }
NF != 4 { exit 1 }
{
for (i = 1; i <= 4; i++) {
if ($i !~ /^(0|[1-9][0-9]*)$/ || $i + 0 > 255) exit 1
}
}
'; then
return
fi
printf '%s\n' "$ip"
}
# The only difference between the two modes this policy installs is whether the
# audited proxy is exempt, so they are one ruleset with one optional pair of
# rules rather than two rulesets that have to be kept in step.
apply_ruleset() {
proxy_ip="${1:-}"
nft --file - <<EOF
add table inet $NFTABLES_RULESET_NAME
flush table inet $NFTABLES_RULESET_NAME
table inet $NFTABLES_RULESET_NAME {
chain output {
type nat hook output priority dstnat; policy accept;
fib daddr type local return
${proxy_ip:+ ip daddr $proxy_ip tcp dport $PROXY_PORT return}
meta l4proto tcp redirect to :$GOST_PORT
}
chain egress {
type filter hook output priority filter; policy accept;
# Docker DNATs 127.0.0.11:53 onto another local port before this hook.
# Matching only dport 53 here misses, and the local exemption below
# would then accept the rewritten packet.
ip daddr 127.0.0.11 reject
fib daddr type local accept
${proxy_ip:+ ip daddr $proxy_ip tcp dport $PROXY_PORT accept}
# Rejecting everything else rather than only non-TCP: the nat chain above
# rewrote every TCP destination this policy admits to a local one, so what
# reaches here still carrying a public destination is traffic the nat hook
# never saw — a connection conntrack established before the policy existed.
reject
}
}
EOF
}
setup_proxy_only() {
proxy_ip="$(resolve_proxy_ip)"
if [ -z "$proxy_ip" ]; then
echo "could not resolve Eval egress proxy" >&2
exit 1
fi
apply_ruleset "$proxy_ip"
echo "ok: Eval proxy-only egress applied ($proxy_ip:$PROXY_PORT)"
}
case "${1:-}" in
allow-all)
remove_nftables
echo "ok: allow all egress"
;;
deny-all)
# A phase that asked for no network gets none. Answering it with the
# proxy-only ruleset would hand it a route this override invented, which
# Harbor's own deny-all does not grant either.
apply_ruleset
echo "ok: Eval no-network egress applied"
;;
allow)
shift
if [ "$#" -ne 1 ] || [ "$1" != "$PROXY_HOST" ]; then
echo "Eval egress policy accepts only $PROXY_HOST" >&2
exit 2
fi
setup_proxy_only
;;
show)
if ! rules="$(nft list table inet "$NFTABLES_RULESET_NAME" 2>/dev/null)"; then
echo "mode: allow-all"
elif printf '%s' "$rules" | grep -q "dport $PROXY_PORT"; then
echo "mode: Eval proxy-only"
echo "proxy: $PROXY_HOST:$PROXY_PORT"
else
echo "mode: Eval no-network"
fi
;;
rules)
nft list table inet "$NFTABLES_RULESET_NAME" 2>/dev/null || echo "mode: allow-all"
;;
*)
echo "Usage: network-policy {show|allow-all|deny-all|allow|rules}" >&2
exit 2
;;
esac