Raise gVisor key limit to work around keyring leak

runc creates a session keyring per container, and affected gVisor releases never release them. After roughly 200 containers, new containers fail with EDQUOT from KEYCTL_JOIN_SESSION_KEYRING. Raise gVisor's /proc/sys/kernel/keys/maxkeys at dind startup as a temporary workaround, guarded so a runc DinD does not change the host-wide limit.
This commit is contained in:
agentbox committed 2026-11-09 11:25:55 +00:00
1 parent 37ef3994ed
commit d707520ee8
2 files changed
+62

No files matched your search

@@ -40,6 +40,31 @@ while [[ $# -gt 0 ]]; do
esac
done
# Temporary workaround for gVisor's session keyring leak.
#
# runc creates a new session keyring for every container it starts. gVisor
# (through at least release-20261102.0) never releases those keyrings and caps
# each user namespace's key set at 200. Once the cap is reached, creating any
# new container fails with:
#
# unable to join session keyring: unable to create session key: disk quota exceeded
#
# Raise the cap far enough that a long-running CI dind lasts longer. This does
# not stop the leak; remove it once gVisor releases session keyrings upstream.
# Only write the sysctl inside gVisor: on a runc DinD this is the host-wide key
# limit and changing it would affect the host.
if grep -qi gvisor /proc/version; then
key_maxkeys="${GVISOR_KEY_MAXKEYS:-50000}"
current_key_maxkeys=$(cat /proc/sys/kernel/keys/maxkeys 2>/dev/null || true)
if [[ "${key_maxkeys}" =~ ^[0-9]+$ ]] && (( key_maxkeys > 0 )) && \
[[ "${current_key_maxkeys}" =~ ^[0-9]+$ ]] && \
(( current_key_maxkeys < key_maxkeys )); then
echo "Raising gVisor session keyring limit from ${current_key_maxkeys} to ${key_maxkeys}"
echo "${key_maxkeys}" > /proc/sys/kernel/keys/maxkeys || \
echo "warning: failed to raise gVisor session keyring limit" >&2
fi
fi
# When dockerd uses the overlay storage driver, it will try to mount an overlay
# filesystem under /var/lib/docker. gVisor only supports tmpfs as an upper
# layer, so we mount a tmpfs if it isn't already present.