Skip to content

fix: relax perf_event_paranoid/kptr_restrict for EKS Auto Mode (Bottlerocket)#454

Merged
salvatoredipietro merged 3 commits into
aws:mainfrom
jcwolfaws:fix/eks-auto-perf-event-paranoid
May 27, 2026
Merged

fix: relax perf_event_paranoid/kptr_restrict for EKS Auto Mode (Bottlerocket)#454
salvatoredipietro merged 3 commits into
aws:mainfrom
jcwolfaws:fix/eks-auto-perf-event-paranoid

Conversation

@jcwolfaws

Copy link
Copy Markdown
Contributor

Issue #, if available: N/A

Description of changes:
Tested on a fresh EKS Auto Mode 1.31 cluster (Bottlerocket workload node). PSS / privileged / hostPID / hostPath all work on default namespaces. One gap on Auto specifically: Bottlerocket ships with perf_event_paranoid=2 and a non-zero kptr_restrict, and the plugin doesn't relax them inside the pod — so aperf record fails with a "Run sudo sysctl -w …" error.

This PR has the plugin write -1 to /proc/sys/kernel/perf_event_paranoid and 0 to /proc/sys/kernel/kptr_restrict before invoking aperf record. The pod is already privileged with hostPID, so it can write the host's /proc/sys. The writes are best-effort (|| echo "Warning: …") so distros that don't need them, or restrict them further, don't break the recording flow.

On EKS Auto Mode (Bottlerocket), the host kernel ships with
perf_event_paranoid=2 and a non-zero kptr_restrict, which causes
'aperf record' to fail with a "Run sudo sysctl -w ..." error from
inside the privileged pod. Since the pod is already privileged with
hostPID, write the relaxed values directly to the host's /proc/sys
before invoking aperf record.
@jcwolfaws jcwolfaws requested a review from a team as a code owner May 22, 2026 22:01
Comment thread kubectl-aperf
Per review feedback on PR aws#454: capture the host's original
/proc/sys/kernel/perf_event_paranoid and /proc/sys/kernel/kptr_restrict
values before relaxing them, and restore them on EXIT/INT/TERM via a
trap so the host is left as we found it even if aperf record fails or
the pod is signaled.
@jcwolfaws

Copy link
Copy Markdown
Contributor Author

Updated in b047bbd to address @salvatoredipietro's feedback: capture the original perf_event_paranoid and kptr_restrict values up front, then restore them via a trap on EXIT/INT/TERM so the host sysctls are reset whether aperf record succeeds, fails, or the pod is signaled. I exercised the trap locally on a tempdir to confirm the restore also fires on the failure path.

Live test on EKS Auto Mode (Bottlerocket) showed that the EXIT trap
alone is unreliable: the script blocks on 'sleep 7200' after record,
and the SIGKILL that follows 'kubectl delete pod' (after grace period)
prevents the trap from running, leaving the host with relaxed
perf_event_paranoid/kptr_restrict.

Restore the original values explicitly as soon as 'aperf record'
returns, then clear the trap. The trap remains as a fallback for the
case where 'aperf record' itself crashes before we reach this point.

Verified end-to-end on a Bottlerocket EKS Auto node: host sysctls go
2->-1 during record and back to 2 after the script restores them, even
after the pod is deleted.
@jcwolfaws

Copy link
Copy Markdown
Contributor Author

Tested live on a Bottlerocket EKS Auto Mode 1.31 node. First run of the trap-only approach surfaced a real issue: the script blocks on sleep 7200 after aperf record, and the SIGKILL that follows kubectl delete pod (after the grace period) prevents the EXIT trap from running. Verified by inspecting /proc/sys/kernel/* from a separate privileged hostPID pod after the aperf pod was deleted — sysctls were still relaxed.

Pushed 8261189 which restores the originals explicitly as soon as aperf record returns and clears the trap. The trap stays as a fallback for the case where aperf record itself crashes before we reach the restore line.

Re-verified end-to-end: orig captured as paranoid=2, kptr=1, restored to paranoid=2, kptr=1 post-pod-deletion.

@salvatoredipietro

Copy link
Copy Markdown
Contributor

Tested live on a Bottlerocket EKS Auto Mode 1.31 node. First run of the trap-only approach surfaced a real issue: the script blocks on sleep 7200 after aperf record, and the SIGKILL that follows kubectl delete pod (after the grace period) prevents the EXIT trap from running. Verified by inspecting /proc/sys/kernel/* from a separate privileged hostPID pod after the aperf pod was deleted — sysctls were still relaxed.

Pushed 8261189 which restores the originals explicitly as soon as aperf record returns and clears the trap. The trap stays as a fallback for the case where aperf record itself crashes before we reach the restore line.

Re-verified end-to-end: orig captured as paranoid=2, kptr=1, restored to paranoid=2, kptr=1 post-pod-deletion.

Great, Thanks!

@salvatoredipietro salvatoredipietro merged commit 494ce29 into aws:main May 27, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants