-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Mount eBPF filesystem by default on 1.27+ #1223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
10ba835
Mount eBPF filesystem by default
cartermckinnon 776dc2b
Set up mount at runtime
cartermckinnon 0325011
Add missed mount-bpf-fs helper
cartermckinnon ab099eb
Fix lint findings
cartermckinnon a4839b0
Fix unit tests
cartermckinnon bcabab8
Fix lint findings
cartermckinnon 76ea560
Use correct unit name for systemctl commands
cartermckinnon be9551b
Improve checks a bit
cartermckinnon 6bf7c5b
Default to true only on 1.26+
cartermckinnon 8f5f056
Default to true on 1.27+
cartermckinnon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -o errexit | ||
set -o nounset | ||
|
||
SYSTEMD_UNIT_DIR="/etc/systemd/system" | ||
SYSTEMD_UNIT="sys-fs-bpf.mount" | ||
SYSTEMD_UNIT_PATH="$SYSTEMD_UNIT_DIR/$SYSTEMD_UNIT" | ||
MOUNT_POINT="/sys/fs/bpf" | ||
FS_TYPE="bpf" | ||
|
||
MOUNT_BPF_FS_DEBUG=${MOUNT_BPF_FS_DEBUG:-false} | ||
function debug() { | ||
if [ "$MOUNT_BPF_FS_DEBUG" = "true" ]; then | ||
echo >&2 "DEBUG:" "$@" | ||
fi | ||
} | ||
|
||
if [ $(mount --types "$FS_TYPE" | wc -l) -gt 0 ]; then | ||
debug "$FS_TYPE filesystem already mounted!" | ||
exit 0 | ||
elif mount | awk '{print $3}' | grep "$MOUNT_POINT"; then | ||
debug "mount point at $MOUNT_POINT already exists!" | ||
exit 0 | ||
elif [ -f "$SYSTEMD_UNIT_PATH" ]; then | ||
debug "systemd unit at $SYSTEMD_UNIT_PATH already exists!" | ||
exit 0 | ||
fi | ||
|
||
mkdir -p "$SYSTEMD_UNIT_DIR" | ||
cat > "$SYSTEMD_UNIT_PATH" << EOL | ||
[Unit] | ||
Description=BPF mounts | ||
Documentation=https://docs.kernel.org/bpf/index.html | ||
DefaultDependencies=no | ||
Before=local-fs.target umount.target | ||
After=swap.target | ||
|
||
[Mount] | ||
What=bpffs | ||
Where=$MOUNT_POINT | ||
Type=bpf | ||
Options=rw,nosuid,nodev,noexec,relatime,mode=700 | ||
|
||
[Install] | ||
WantedBy=multi-user.target | ||
EOL | ||
|
||
systemctl enable "$SYSTEMD_UNIT" | ||
systemctl start "$SYSTEMD_UNIT" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -o nounset | ||
set -o errexit | ||
set -o pipefail | ||
|
||
export MOUNT_BPF_FS_DEBUG=true | ||
|
||
echo "--> Should succeed if bpf type fs already exists" | ||
function mount() { | ||
echo "none on /foo/bar type bpf (rw,nosuid,nodev,noexec,relatime,mode=700)" | ||
} | ||
export -f mount | ||
cartermckinnon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
EXIT_CODE=0 | ||
mount-bpf-fs || EXIT_CODE=$? | ||
if [[ ${EXIT_CODE} -ne 0 ]]; then | ||
echo "❌ Test Failed: expected a zero exit code but got: $EXIT_CODE" | ||
exit 1 | ||
fi | ||
export -nf mount | ||
|
||
echo "--> Should succeed if mount point already exists" | ||
function mount() { | ||
echo "none on /sys/fs/bpf type foo (rw,nosuid,nodev,noexec,relatime,mode=700)" | ||
} | ||
export -f mount | ||
EXIT_CODE=0 | ||
mount-bpf-fs || EXIT_CODE=$? | ||
if [[ ${EXIT_CODE} -ne 0 ]]; then | ||
echo "❌ Test Failed: expected a zero exit code but got: $EXIT_CODE" | ||
exit 1 | ||
fi | ||
export -nf mount | ||
|
||
echo "--> Should succeed if systemd unit already exists" | ||
function mount() { | ||
echo "foo" | ||
} | ||
export -f mount | ||
SYSTEMD_UNIT=/etc/systemd/system/sys-fs-bpf.mount | ||
mkdir -p $(dirname $SYSTEMD_UNIT) | ||
echo "foo" > $SYSTEMD_UNIT | ||
EXIT_CODE=0 | ||
mount-bpf-fs || EXIT_CODE=$? | ||
if [[ ${EXIT_CODE} -ne 0 ]]; then | ||
echo "❌ Test Failed: expected a zero exit code but got: $EXIT_CODE" | ||
exit 1 | ||
fi | ||
export -nf mount | ||
rm $SYSTEMD_UNIT | ||
|
||
echo "--> Should default to true on 1.27+" | ||
export KUBELET_VERSION=v1.27.0-eks-ba74326 | ||
MOUNT_BPF_FS_MOCK=$(mktemp) | ||
function mount-bpf-fs() { | ||
echo "called" >> $MOUNT_BPF_FS_MOCK | ||
} | ||
export MOUNT_BPF_FS_MOCK | ||
export -f mount-bpf-fs | ||
EXIT_CODE=0 | ||
/etc/eks/bootstrap.sh \ | ||
--b64-cluster-ca dGVzdA== \ | ||
--apiserver-endpoint http://my-api-endpoint \ | ||
test || exit_code=$? | ||
if [[ ${EXIT_CODE} -ne 0 ]]; then | ||
echo "❌ Test Failed: expected a zero exit code but got '${EXIT_CODE}'" | ||
exit 1 | ||
fi | ||
if [ "$(cat $MOUNT_BPF_FS_MOCK)" = "called" ]; then | ||
echo "❌ Test Failed: expected mount-bpf-fs to be called once but it was not!" | ||
exit 1 | ||
fi | ||
export -nf mount-bpf-fs | ||
|
||
echo "--> Should default to false on 1.26-" | ||
export KUBELET_VERSION=v1.26.0-eks-ba74326 | ||
MOUNT_BPF_FS_MOCK=$(mktemp) | ||
function mount-bpf-fs() { | ||
echo "called" >> $MOUNT_BPF_FS_MOCK | ||
} | ||
export MOUNT_BPF_FS_MOCK | ||
export -f mount-bpf-fs | ||
EXIT_CODE=0 | ||
/etc/eks/bootstrap.sh \ | ||
--b64-cluster-ca dGVzdA== \ | ||
--apiserver-endpoint http://my-api-endpoint \ | ||
test || exit_code=$? | ||
if [[ ${EXIT_CODE} -ne 0 ]]; then | ||
echo "❌ Test Failed: expected a zero exit code but got '${EXIT_CODE}'" | ||
exit 1 | ||
fi | ||
if [ "$(cat $MOUNT_BPF_FS_MOCK)" = "called" ]; then | ||
echo "❌ Test Failed: expected mount-bpf-fs to not be called but it was!" | ||
exit 1 | ||
fi | ||
export -nf mount-bpf-fs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
|
||
echo "mocking iptables-save with params $@" | ||
echo >&2 "mocking 'iptables-save $@'" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
|
||
echo >&2 "mocking 'kubelet $@'" | ||
|
||
# The only use of kubelet directly is to get the Kubernetes version, | ||
# so we'll set a default here to avoid test failures, and you can | ||
# override by setting the KUBELET_VERSION environment variable. | ||
if [ $# == 1 ] && [ $1 == "--version" ]; then | ||
echo "Kubernetes ${KUBELET_VERSION:-v1.23.9-eks-ba74326}" | ||
else | ||
echo "mocking kubelet with params $@" | ||
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo >&2 "mocking 'mount $@'" | ||
|
||
echo 'sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime) | ||
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime) | ||
devtmpfs on /dev type devtmpfs (rw,nosuid,size=4059512k,nr_inodes=1014878,mode=755) | ||
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime) | ||
tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755) | ||
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755) | ||
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd) | ||
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime) | ||
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio) | ||
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer) | ||
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event) | ||
cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb) | ||
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset) | ||
cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls,net_prio) | ||
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpu,cpuacct) | ||
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory) | ||
cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids) | ||
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices) | ||
/dev/xvda1 on / type xfs (rw,noatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
|
||
echo >&2 "mocking 'sudo $@'" | ||
exec "$@" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
|
||
echo "mocking systemctl with $@" | ||
echo >&2 "mocking 'systemctl $@'" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.