Skip to content

eBPF-based security platform

Documentation: add a scalability page to Operate

Daniel Borkmanneb12b90e1ffd
diff --git a/Documentation/operate/index.rst b/Documentation/operate/index.rst
index 80a9b41f..971065ac 100644
--- a/Documentation/operate/index.rst
+++ b/Documentation/operate/index.rst
@@ -22,6 +22,7 @@ verdict is an incident: follow :doc:`/operate/incident-tampered`.
system-requirements
overhead
+ scalability
deployment-checklist
boot-integration
initialize
diff --git a/Documentation/operate/overhead.rst b/Documentation/operate/overhead.rst
index 9f97f4ca..3d18cea4 100644
--- a/Documentation/operate/overhead.rst
+++ b/Documentation/operate/overhead.rst
@@ -527,6 +527,7 @@ Related
-------
- :doc:`/operate/system-requirements`
+- :doc:`/operate/scalability`
- :doc:`/reference/systemd-units`
- :doc:`/reference/files`
- :doc:`/reference/formats/eventlog`
diff --git a/Documentation/operate/scalability.rst b/Documentation/operate/scalability.rst
new file mode 100644
index 00000000..18b2e24d
--- /dev/null
+++ b/Documentation/operate/scalability.rst
@@ -0,0 +1,258 @@
+..
+ SPDX-License-Identifier: BSD-2-Clause
+ Copyright (c) 2026 Authors of shirudo
+
+:page-type: Reference
+:audience: Operators
+
+Scalability
+===========
+
+How the pull from OCI registries grows with the number of targets, and
+where shirudo and the kernel limit what one target and one upatch can
+hold. shirudo's limits come from its code. Kernel limits come from the
+kernel source and can differ between kernel versions and architectures;
+each one names its constant so that you can look it up in your kernel.
+:doc:`/operate/overhead` describes what one target uses.
+
+Fleet
+-----
+
+shirudo keeps no fleet state and has no push channel. Every target runs
+its own timers and pulls from the registries its config image names, so
+the load on a registry grows with the number of targets that follow it.
+
+Registry requests
+~~~~~~~~~~~~~~~~~
+
+.. list-table::
+ :header-rows: 1
+ :widths: 24 76
+
+ * - Command
+ - Requests per target
+ * - ``bpm repo update``
+ - Every minute, for every repository: the index manifest, the index
+ and its signature, each downloaded in full. There is no
+ conditional request, and the cached index is not consulted.
+ * - ``bpm tree sync``
+ - Every minute with a tree configured: the tree's manifest, payload
+ and signature, in full. An upatch the tree adds is fetched once,
+ manifest and blob, and cached by its layer digest.
+ * - ``bpm upgrade``
+ - Nothing until the cached index lists a newer version of an
+ installed package. Then the package manifest and the whole
+ package archive.
+
+A registry that challenges for a bearer token gets three requests for
+each of these: the request without credentials, the token request and
+the request again with the token. Tokens are not kept between requests
+or runs. Every request opens a new connection with its own TLS 1.3
+handshake.
+
+N targets that follow R repositories and a tree therefore send a registry
+about N × (3R + 3) requests per minute, three times that with token
+authentication, and download the indexes, the tree payload and their
+signatures N times a minute. An index holds at most 512 entries and has
+to parse within 8 MiB.
+
+Timing and failures
+~~~~~~~~~~~~~~~~~~~
+
+- ``shirudo-bpm-repo-update.timer`` starts the update at boot and 60
+ seconds after each run ends. ``shirudo-bpm-tree-sync.timer`` starts
+ the sync 60 seconds after boot and every 60 seconds after that.
+ Neither timer sets a random delay, so targets spread over the minute
+ only as far as their boot times and run times differ. Targets that
+ boot together, after a power cut for example, poll together.
+- A version pushed to an index reaches every target that follows the
+ repository within about a minute, and every target that has the
+ package installed downloads the whole archive, up to 256 MiB, in that
+ minute. There is no delta and no resumed download.
+- A failed request is not retried. A failed run waits for the next run of
+ its timer, and status 429 and ``Retry-After`` get no special handling.
+ One unreachable repository does not stop the update of the others,
+ and ``bpm upgrade`` still runs from the cached indexes.
+- A connection has 30 seconds to open, and a transfer that moves less
+ than 1 byte per second for 60 seconds is cut. A request has no overall
+ time limit; the service has 30 minutes.
+
+Staged rollouts
+~~~~~~~~~~~~~~~
+
+- A repository is one registry endpoint, ``oci://<host>[:<port>]`` without
+ a path, and its index is always ``shirudo/bpm-index:stable`` on it.
+ There is no mirror or fallback list. To stage a package, publish it to
+ a registry that only canary targets follow before the one the fleet
+ follows. Targets reach different registries, or a pull-through cache,
+ only when their config images name them.
+- The upatch tree is the only source with selectors: kernel release,
+ kernel build ID, architecture, kernel configuration and node labels.
+ Its reference can be a tag other than ``stable``. A target moves past
+ an operation that does not select it for good, so labels changed later
+ do not apply operations it skipped before.
+- A tree publication carries every operation since the first, at most
+ 512 of them. ``bpm tree append`` refuses the 513th, and targets refuse a
+ publication that does not start at the first operation.
+
+:doc:`/operate/deliver-packages` sets up repositories and the tree.
+
+Collectors
+~~~~~~~~~~
+
+With an endpoint configured, every target sends one keepalive and one
+request per map of every loaded upatch every 5 seconds after the previous
+run ends, about 12 a minute each. A collector serves N targets with M
+exported maps each about 12 × N × (M + 1) requests a minute. A request
+waits 10 seconds by default and is retried 3 times. See
+:doc:`/operate/telemetry`.
+
+One target
+----------
+
+shirudo sets no limit on the number of upatches a target loads. The limits
+below decide how far one target goes.
+
+shirudo limits
+~~~~~~~~~~~~~~
+
+.. list-table::
+ :header-rows: 1
+ :widths: 24 38 38
+
+ * - Item
+ - Limit
+ - When it is reached
+ * - Boot restore
+ - The init record of a boot holds at most 64 KiB: about 1.9 KiB, plus
+ 95 bytes and the name for every restored upatch. About 550
+ upatches with 20-character names fit, 400 with 63-character names.
+ - ``init`` extends the register and then fails to append its
+ record, with ``eventlog: append failed after extend -- chain/log
+ desync; operator must reconcile``. ``shirudo status`` then
+ reports a register its replay cannot explain.
+ * - Eventlog
+ - Readers accept at most 8 MiB, across all boots, and the log is never
+ rotated. A load or an unload adds about 330 bytes plus the name,
+ and every boot adds its init record. 100 upatches with 20-character
+ names fill 8 MiB in about 600 boots.
+ - A load is undone as unmeasured (``tpm_error``), ``init`` stops,
+ and status, replay and attestation fail. With
+ ``eventlog.max_bytes`` set, loads, unloads and ``init`` refuse
+ ``eventlog_full`` first. See U6 in the
+ :doc:`/security/threat-model`.
+ * - ``upatch list --json``
+ - 64 KiB, 162 bytes plus the name per upatch: about 360 upatches with
+ 20-character names.
+ - ``upatch list: json encode failed``, exit status 1. The text
+ listing has no limit.
+ * - ``shirudo status --json``
+ - 8 MiB
+ - ``status: json encode failed``
+ * - Installed packages
+ - 256, and at most 128 upatches per package
+ - ``bpm install`` refuses a 257th package. A package with more
+ upatches fails to install or upgrade.
+ * - Trusted certificates
+ - 16
+ - ``keys add`` refuses the certificate.
+ * - Node labels
+ - 64, with keys and values shorter than 256 bytes
+ - ``bpm tree sync`` stops at the first operation that selects on
+ labels.
+
+Kernel limits
+~~~~~~~~~~~~~
+
+The kernel sets no limit on the number of BPF programs, maps or links
+and charges their memory to the memory cgroup of the loading process,
+unless it boots with ``cgroup.memory=nobpf``.
+The JIT memory limit, ``net.core.bpf_jit_limit``, refuses only callers
+without ``CAP_BPF``. What bounds a target is the attach point.
+
+.. list-table::
+ :header-rows: 1
+ :widths: 22 50 28
+
+ * - Attach kind
+ - Limit
+ - Constant
+ * - ``fentry``, ``fexit``, ``fmod_ret``, ``lsm``
+ - 36 programs per kernel function on x86-64, 37 on arm64 and 38 on
+ riscv64, counted together for all four kinds. An ``lsm`` program
+ counts on the hook's ``bpf_lsm_<hook>`` function, which shirudo's
+ own programs share.
+ - ``BPF_MAX_TRAMP_LINKS`` in ``include/linux/bpf.h``
+ * - ``tp_btf``
+ - No limit per tracepoint
+ -
+ * - ``kprobe``, ``kretprobe``
+ - No limit per symbol; every attachment is a perf event of its own
+ -
+ * - ``uprobe.multi``
+ - 1,048,576 offsets per link, which shirudo also enforces
+ - ``MAX_UPROBE_MULTI_CNT`` in ``kernel/trace/bpf_trace.c``
+ * - ``cgroup_skb``
+ - 64 programs per direction on ``/sys/fs/cgroup``, shared with any
+ other software that attaches there
+ - ``BPF_CGROUP_MAX_PROGS`` in ``kernel/bpf/cgroup.c``
+ * - ``netfilter``
+ - One program. shirudo attaches every ``netfilter`` program at
+ ``NF_IP6_PRI_RAW_BEFORE_DEFRAG`` on IPv6 pre-routing, and the kernel
+ refuses a second BPF hook at the same priority with ``EBUSY``.
+ - ``nf_hook_entries_grow()`` in ``net/netfilter/core.c``
+
+shirudo's 48 guards are BPF LSM programs on 39 hooks. Nine hooks carry
+two of them: ``bprm_check_security``, ``file_open``, ``inode_link``,
+``inode_mkdir``, ``inode_removexattr``, ``inode_rename``,
+``inode_setxattr``, ``inode_symlink`` and ``inode_unlink``. On x86-64 an
+``lsm`` upatch therefore has 34 places left on those hooks, 35 on the other
+30 hooks shirudo uses and 36 on every other hook. shirudo does not count
+them: a load that finds the attach point full fails at ``link_create``
+with the kernel's ``E2BIG``, or ``EBUSY`` for ``netfilter``, in category
+``unknown``.
+
+One upatch
+----------
+
+.. list-table::
+ :header-rows: 1
+ :widths: 30 70
+
+ * - Item
+ - Limit
+ * - ``.upatch`` file
+ - 16 MiB. :doc:`/reference/formats/upatch-format` lists the limit of
+ every field.
+ * - Signature
+ - 64 KiB in the kernel, ``BPF_PROG_MAX_SIGNATURE_SIZE``.
+ ``shirudo build`` writes at most 16 KiB.
+ * - Signed loader
+ - Its instructions and the value of its metadata map together less
+ than 16 MiB, the size of the buffer the kernel verifies
+ (``DYNPTR_MAX_SIZE``). At most 1,000,000 instructions
+ (``BPF_COMPLEXITY_LIMIT_INSNS``).
+ * - Each program
+ - The verifier processes at most 1,000,000 instructions and allows
+ 64 maps (``MAX_USED_MAPS``), 256 subprograms (``BPF_MAX_SUBPROGS``)
+ and one arena.
+ * - Arena
+ - 4 GiB (``kernel/bpf/arena.c``)
+ * - Name
+ - 255 characters from ``A-Z``, ``a-z``, ``0-9``, ``.``, ``_`` and
+ ``-``, not starting with ``.``. A decoder names its upatch in 64
+ bytes, so only upatches with names of at most 63 characters can
+ have one.
+ * - Map export
+ - :doc:`/upatches/maps-arenas-serializers` and
+ :doc:`/upatches/decoders` give the serializer and decoder limits.
+ * - Package
+ - 128 upatches, 4096 archive entries and 256 MiB
+
+Related
+-------
+
+- :doc:`/operate/overhead`
+- :doc:`/operate/deliver-packages`
+- :doc:`/upatches/attach-kinds`
+- :doc:`/security/threat-model`