Repository navigation
101 lines (89 loc) · 3.1 KB
/
Copy pathverify.yml
File metadata and controls
101 lines (89 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
name: verify
on:
pull_request:
push:
branches: [main]
permissions:
contents: read
jobs:
verify:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: 20
cache: npm
- name: Install locked dependencies without lifecycle scripts
run: npm ci --ignore-scripts
- name: Assert verification inputs match checked-out HEAD
shell: bash
run: |
set -Eeuo pipefail
verification_paths=(
.github/workflows/verify.yml
package.json
package-lock.json
tsconfig.json
tsconfig.scripts.json
src
scripts
eval
test
)
git diff --exit-code HEAD -- "${verification_paths[@]}"
untracked="$(git ls-files --others --exclude-standard -- "${verification_paths[@]}")"
if [[ -n "$untracked" ]]; then
echo "::error::Dependency installation created untracked verification inputs."
echo "$untracked"
exit 1
fi
- name: Verify with outbound network disabled
shell: bash
run: |
set -Eeuo pipefail
command -v sudo unshare setpriv ip timeout >/dev/null
host_netns="$(readlink /proc/self/ns/net)"
runner_uid="$(id -u)"
runner_gid="$(id -g)"
sudo env \
"CI=${CI:-true}" \
"HOME=$HOME" \
"PATH=$PATH" \
"HOST_NETNS=$host_netns" \
"RUNNER_UID=$runner_uid" \
"RUNNER_GID=$runner_gid" \
unshare --net -- bash -Eeuo pipefail <<'NETWORK_NAMESPACE'
ip link set lo up
isolated_netns="$(readlink /proc/self/ns/net)"
if [[ "$isolated_netns" == "$HOST_NETNS" ]]; then
echo "::error::Network namespace isolation is not active."
exit 1
fi
interfaces=(/sys/class/net/*)
if (( ${#interfaces[@]} != 1 )) || [[ "${interfaces[0]##*/}" != "lo" ]]; then
echo "::error::Isolated namespace has a non-loopback interface."
exit 1
fi
ipv4_default="$(ip route show default)"
ipv6_default="$(ip -6 route show default)"
if [[ -n "$ipv4_default" || -n "$ipv6_default" ]]; then
echo "::error::Isolated namespace has a default route."
exit 1
fi
if timeout 3 bash -c "exec 3<>/dev/tcp/1.1.1.1/443" 2>/dev/null; then
echo "::error::Outbound TCP unexpectedly succeeded."
exit 1
fi
echo "Network isolation active: $isolated_netns; outbound TCP blocked."
exec setpriv \
--reuid="$RUNNER_UID" \
--regid="$RUNNER_GID" \
--clear-groups \
--inh-caps=-all \
--ambient-caps=-all \
--bounding-set=-all \
--no-new-privs \
npm run verify
NETWORK_NAMESPACE