<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[My Publication]]></title><description><![CDATA[My Publication]]></description><link>https://kazuru.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Sun, 29 Nov 2026 23:18:40 GMT</lastBuildDate><atom:link href="https://kazuru.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Watching Linux live patch transitions with eBPF]]></title><description><![CDATA[Transitions, the tasks that hold them up, and turning them into alerts with klp-watch]]></description><link>https://kazuru.hashnode.dev/watching-linux-live-patch-transitions-with-ebpf</link><guid isPermaLink="true">https://kazuru.hashnode.dev/watching-linux-live-patch-transitions-with-ebpf</guid><dc:creator><![CDATA[Kazuru]]></dc:creator><pubDate>Sun, 29 Nov 2026 16:12:16 GMT</pubDate><content:encoded><![CDATA[<p>Kernel live patching lets a server take a security fix without a reboot. A live patch is a kernel module that carries new versions of the functions a fix changes, and the kernel redirects calls from the old functions to the new ones. Ubuntu, Red Hat Enterprise Linux, SUSE and other distributions ship their fixes this way.</p>
<p>Loading the module is only the start. Between the moment a patch is enabled and the moment it is fully in place, the kernel runs a <em>transition</em>, and that transition can be fast, slow or stuck. Most monitoring sees none of it. In this post we walk through what a transition is, what holds one up, and how we watch it with klp-watch, an open-source tool we wrote for the job.</p>
<h2>What a transition is</h2>
<p>The kernel cannot swap a function while a task might be in the middle of running it. If a task were halfway through the old version and returned into the new one, it could mix two versions of the same code path. So the kernel moves tasks to the new code one at a time, and only when it is safe for each task.</p>
<p>Every thread carries its own patch state, visible in <code>/proc/&lt;pid&gt;/task/&lt;tid&gt;/patch_state</code>. A thread switches when it is not inside any function the patch changes, which the kernel checks from the thread's stack, or when it returns to user space. Once every thread has switched, the transition is complete and the patch reports <code>transition</code> 0 in <code>/sys/kernel/livepatch/&lt;patch&gt;/</code>.</p>
<p>The kernel functions behind this have plain names. <code>klp_enable_patch</code> starts the work, <code>klp_init_transition</code> and <code>klp_start_transition</code> set it up, <code>klp_try_complete_transition</code> checks whether every task has switched, and <code>klp_complete_transition</code> finishes. If some tasks have not switched yet, the kernel tries again about once a second.</p>
<h2>What holds a transition up</h2>
<p>A task that sleeps inside one of the patched functions cannot switch until it wakes up and leaves that function. A kernel worker thread that waits in a loop is the classic case. While it sleeps there, the transition stays open, the patch reports <code>enabled</code> 1 and <code>transition</code> 1, and only part of the system runs the new code.</p>
<p>Most transitions finish in milliseconds or seconds, so nobody notices. A transition that stays open for minutes is worth knowing about, and so is the name of the thread that holds it.</p>
<h2>Watching it</h2>
<p>klp-watch attaches eBPF kprobes to the kernel functions above and reads sysfs and the per-thread patch state. In its trace mode it prints one JSON line per event. Here is the kernel's own <code>livepatch-sample</code> being enabled on Ubuntu 24.04 (6.8.0-147-generic). We left out the probe lines.</p>
<pre><code class="language-json">{"event":"klp","function":"klp_enable_patch","pid":6339,"comm":"insmod"}
{"event":"klp","function":"klp_init_transition","pid":6339,"comm":"insmod","target":"patched"}
{"event":"sysfs","patch":"livepatch_sample","present":true,"enabled":"0","transition":"1"}
{"event":"klp","function":"klp_start_transition","pid":6339,"comm":"insmod"}
{"event":"klp","function":"klp_try_complete_transition","pid":6339,"comm":"insmod"}
{"event":"klp","function":"klp_complete_transition","pid":6339,"comm":"insmod"}
{"event":"sysfs","patch":"livepatch_sample","present":true,"enabled":"1","transition":"0"}
{"event":"klp","function":"klp_enable_patch","pid":6339,"comm":"insmod","ret":0}
</code></pre>
<p>(Timestamps are trimmed here; every line carries the kernel's monotonic time and the wall time.) Every task switched on the first attempt, so <code>insmod</code> completed the transition itself, 262 ms after it started.</p>
<p>To see a transition held up, we use two modules from the kernel's own live patch selftests. <code>test_klp_callbacks_busy</code> keeps a kernel worker sleeping inside a function, and <code>test_klp_callbacks_demo</code> patches that function. Once the transition has run for two seconds, klp-watch reads every thread's patch state and reports the ones still on the old code, with their kernel stacks:</p>
<pre><code class="language-json">{"event":"blocked","patch":"test_klp_callbacks_demo","target":"patched","transition_ms":2999,
 "tasks":[{"pid":4777,"comm":"kworker/0:0+events","patch_state":0,"wchan":"msleep",
 "stack":["msleep+0x2d/0x50","busymod_work_func+0x35/0x70 [test_klp_callbacks_busy]","process_one_work+0x184/0x3a0", "..."]}]}
</code></pre>
<p>The stack says exactly why the transition is waiting. The worker sleeps in <code>msleep</code>, called from <code>busymod_work_func</code>, which is the function being patched. When the worker is released, klp-watch prints an empty list and the transition completes.</p>
<h2>From events to alerts</h2>
<p>A trace helps while you are looking. On a fleet we want the machine to tell us. klp-watch has two more modes for that.</p>
<p><code>klp-watch status</code> reads sysfs once, prints a report and exits with the codes monitoring systems expect, 0 for OK, 1 for WARNING, 2 for CRITICAL and 3 for UNKNOWN. It needs no root. A transition that runs longer than a limit (ten minutes by default) is critical, and a live patch module that stays loaded after its patch was disabled or replaced is a warning, because its fixes are no longer in effect. Each finding comes with a short hint on what to do:</p>
<pre><code class="language-text">LIVEPATCH CRITICAL - test_klp_callbacks_demo has been patching for 6 s (limit 5 s); some tasks have not switched
  what to do: Run `klp-watch --stacks` to see which tasks hold it up and where they sleep; the kernel keeps retrying.
  Forcing the transition skips the consistency check and is a last resort.
</code></pre>
<p><code>klp-watch agent</code> runs as a service. It traces with eBPF, checks status every few seconds, and raises an alert once when a condition starts or ends. The conditions are a stalled transition, a forced one, a patch that failed to enable, and a module left without its patch. Alerts go to the systemd journal at the right priority, to a JSON log for tools such as Wazuh, to Prometheus metrics, and, if you want, to Slack, Microsoft Teams, a generic webhook or mail. A normal transition is logged but not notified, because every patch goes through one.</p>
<p>Both modes work without eBPF. <code>status</code> never uses it, and the agent falls back to reading sysfs and /proc where eBPF is not allowed. eBPF adds what leaves no trace there, a patch that failed to enable and a forced transition, and the exact time of each step without polling.</p>
<p>The repository has Prometheus alert rules with unit tests, a Grafana dashboard, Wazuh rules and systemd units.</p>
<h2>How we test it</h2>
<p>Every claim above comes from scripts in the repository that load the kernel's sample and selftest live patches in a throwaway virtual machine and fail unless the output is what it should be. For v0.2 we ran them on Linux 5.15 (Ubuntu 22.04), 6.8 (Ubuntu 24.04), 6.12 (Debian 13) and 7.0 (Ubuntu 26.04).</p>
<p>klp-watch only observes. It never changes a patch. It sees every patch that uses the kernel's live patch interface, which covers modules built with kpatch, klp-build and klp-ccp. Oracle Ksplice works differently and is not seen.</p>
<h2>Try it</h2>
<p>The code, the test scripts and the results for each kernel are at <a href="https://github.com/kazuru-chidumbwe/klp-watch">github.com/kazuru-chidumbwe/klp-watch</a>. Version 0.2.0 is the release described here. We would like to hear how it behaves on your kernels and what you would want it to report next.</p>
]]></content:encoded></item><item><title><![CDATA[Keycloak client profiles: one policy condition breaks public clients]]></title><description><![CDATA[A new Keycloak realm is not an OAuth 2.1 server and not a FAPI 2.0 server. It issues authorization codes without PKCE, it accepts authorization requests…]]></description><link>https://kazuru.hashnode.dev/keycloak-client-profiles-one-policy-condition-breaks-public-clients</link><guid isPermaLink="true">https://kazuru.hashnode.dev/keycloak-client-profiles-one-policy-condition-breaks-public-clients</guid><dc:creator><![CDATA[Kazuru]]></dc:creator><pubDate>Fri, 20 Nov 2026 15:22:34 GMT</pubDate><content:encoded><![CDATA[<p>A new Keycloak realm is not an OAuth 2.1 server and not a FAPI 2.0 server. It issues authorization codes without PKCE, it accepts authorization requests that were never pushed, and it gives public clients refresh tokens that work from anywhere, as often as you like. Keycloak ships client profiles that fix all three. We tested how well they do it, and found one choice in the setup that decides whether your public clients keep working.</p>
<p>We ran the same ten checks three times against Keycloak 26.8.2. The first realm used console defaults. The second followed Keycloak's guidance and linked the built-in profiles. The third added every single setting the documentation offers for each check. This post shows what changed between the three and how to repeat it.</p>
<h2>The setup</h2>
<ul>
<li>Keycloak 26.8.2 in production mode (<code>start</code>), image <code>quay.io/keycloak/keycloak@sha256:3879c623248408de29a5303178b5816c77e8dfef3890c361f8c0bbeaa979ba3b</code>, HTTPS with a lab CA.</li>
<li>Realm <code>trackf</code> holds one confidential client and stands for the FAPI 2.0 case.</li>
<li>Realm <code>trackr</code> holds one confidential and one public client and stands for the OAuth 2.1 case.</li>
<li>Every client is created with the fields of the console's create-client wizard. That means standard flow on, direct access grants off and implicit flow off (<code>NewClientForm.tsx</code> at tag 26.8.2, lines 70 to 72).</li>
<li>Each check runs on a new client of its own, and every test that spends tokens gets its own grant, so one test cannot change what the next one sees.</li>
<li>Each check first sends a valid request that must succeed on that client. The negative request then changes one thing only. A refusal from a client that cannot work at all proves nothing, so a negative test without a working control counts as inconclusive, not as a pass.</li>
<li>Every HTTP exchange is written to a log with an id, and each verdict below points to the ids it rests on.</li>
</ul>
<p>The ten checks come from RFC 9700 (OAuth 2.0 Security Best Current Practice), the OAuth 2.1 draft and the FAPI 2.0 Security Profile. The lab repository lists each requirement with its source section and level.</p>
<table>
<thead>
<tr>
<th>#</th>
<th>Check</th>
<th>Level</th>
<th>Default realm</th>
<th>Keycloak guidance</th>
<th>Every setting</th>
</tr>
</thead>
<tbody><tr>
<td>P1</td>
<td>Password grant refused</td>
<td>MUST</td>
<td>pass</td>
<td>pass</td>
<td>pass</td>
</tr>
<tr>
<td>P2</td>
<td>PKCE with S256 required</td>
<td>MUST</td>
<td><strong>fail</strong></td>
<td>pass</td>
<td>pass</td>
</tr>
<tr>
<td>P3</td>
<td>PKCE downgrade refused</td>
<td>MUST</td>
<td>pass</td>
<td>pass</td>
<td>pass</td>
</tr>
<tr>
<td>P4</td>
<td>Pushed authorization request required (FAPI)</td>
<td>MUST</td>
<td><strong>fail</strong></td>
<td>pass</td>
<td>pass</td>
</tr>
<tr>
<td>P5</td>
<td>Exact redirect URI match</td>
<td>MUST</td>
<td>pass</td>
<td>pass</td>
<td>pass</td>
</tr>
<tr>
<td>P6</td>
<td>Code reuse refused</td>
<td>MUST</td>
<td>pass</td>
<td>pass</td>
<td>pass</td>
</tr>
<tr>
<td>P6r</td>
<td>Tokens from a reused code revoked</td>
<td>SHOULD</td>
<td>pass</td>
<td>pass</td>
<td>pass</td>
</tr>
<tr>
<td>P7</td>
<td>Code lifetime 60 seconds or less (FAPI)</td>
<td>MUST</td>
<td>pass</td>
<td>pass</td>
<td>pass</td>
</tr>
<tr>
<td>P8</td>
<td>Client assertion <code>aud</code> is the issuer, as a string (FAPI)</td>
<td>MUST</td>
<td>not used</td>
<td><strong>see below</strong></td>
<td><strong>see below</strong></td>
</tr>
<tr>
<td>P9</td>
<td>Public client refresh token bound or rotated</td>
<td>MUST</td>
<td><strong>fail</strong></td>
<td>pass</td>
<td>pass</td>
</tr>
<tr>
<td>P10</td>
<td><code>iss</code> in the authorization response</td>
<td>MUST</td>
<td>pass</td>
<td>pass</td>
<td>pass</td>
</tr>
</tbody></table>
<p>Seven of the eleven rows pass on a default realm. Direct access grants are off in the wizard, so the password grant is refused. A reused code is refused, and the tokens it first produced stop working. The code lifetime is already 60 seconds, and the issuer is already in the response. The three failures are the ones that matter for browser and mobile apps.</p>
<h2>What a default realm gives you</h2>
<p><strong>No PKCE.</strong> An authorization request with no <code>code_challenge</code> goes through login and comes back with a code. A request with <code>code_challenge_method=plain</code> does the same. This holds for every client in both realms.</p>
<p><strong>No pushed authorization request.</strong> On the FAPI realm, a plain front-channel authorization request, never pushed to the PAR endpoint, still ends in a code.</p>
<p><strong>Public refresh tokens that work anywhere.</strong> We tested refresh tokens from the public client four ways, each on a fresh token so one test could not spoil the next. A normal refresh returned 200. Keycloak handed back a new refresh token, but the old one still worked when we sent it again, with 200. A refresh with a DPoP proof from a different key returned 200, and one with no proof at all also returned 200. So a refresh token taken from a single-page app keeps working, from any machine, until it expires.</p>
<h2>Keycloak's fix: client profiles</h2>
<p>Keycloak has three global client profiles for this: <code>fapi-2-dpop-security-profile</code>, <code>oauth-2-1-for-confidential-client</code> and <code>oauth-2-1-for-public-client</code>. You do not attach a profile to a client directly. You write a client policy, and the policy has two parts. Its conditions decide which clients it applies to, and its profiles decide which executors run on them.</p>
<p>With the profiles linked, the same requests get these answers:</p>
<ul>
<li>No <code>code_challenge</code>: <code>Missing parameter: code_challenge_method</code>.</li>
<li><code>code_challenge_method=plain</code>: <code>Invalid parameter: code challenge method is not matching the configured one</code>.</li>
<li>Unpushed request on the FAPI realm: HTTP 400 and an error page.</li>
<li>Public refresh token with a different DPoP key: 400. With no proof: 400.</li>
</ul>
<p>The public refresh token is now bound to the client's DPoP key, so a stolen copy is useless elsewhere. It is still not rotated in RFC 9700's sense, because Keycloak issues a new refresh token but the old one keeps working from the right key. RFC 9700 accepts either binding or rotation, so this passes. If you also want rotation, turn on <em>Revoke Refresh Token</em> in the realm settings and set <em>Refresh Token Max Reuse</em> to 0. With both set, the old token returned 400 once it had been used.</p>
<p>The FAPI profile also changes your client in ways you should plan for:</p>
<ul>
<li>It switches a confidential client to <code>private_key_jwt</code> authentication (<code>client-jwt</code> in the admin API) but does not register a key. Every token request then fails with <code>Unable to load public key</code> until you add the client's JWKS.</li>
<li>It enforces PAR even though the client's own <em>Pushed authorization request required</em> switch stays off. Read the policy, not the client page, to see what is enforced.</li>
</ul>
<h2>The condition trap</h2>
<p>Keycloak's documentation says to use <code>oauth-2-1-for-confidential-client</code> for confidential clients or <code>oauth-2-1-for-public-client</code> for public clients. It does not say which policy condition to use. The quickest setup is one policy with the condition <code>any-client</code> and both OAuth 2.1 profiles linked. We set that up on a fresh realm on 26.8.2 and created a public client with the wizard fields.</p>
<p>The public client came back with <code>clientAuthenticatorType</code> set to <code>client-jwt</code> and with mTLS-bound access tokens switched on. The confidential profile had been applied to it as well. Its first authorization request, with correct PKCE, was refused before login:</p>
<pre><code class="language-plaintext">error=invalid_client
error_description=invalid client access type: public
</code></pre>
<p>The same client in a realm with one policy per client type kept its authentication type, got PKCE S256 and DPoP binding, and reached the login page. This is the policy set that works:</p>
<pre><code class="language-json">{
  "policies": [
    {
      "name": "oauth21-confidential",
      "enabled": true,
      "conditions": [
        { "condition": "client-access-type", "configuration": { "type": ["confidential"] } }
      ],
      "profiles": ["oauth-2-1-for-confidential-client"]
    },
    {
      "name": "oauth21-public",
      "enabled": true,
      "conditions": [
        { "condition": "client-access-type", "configuration": { "type": ["public"] } }
      ],
      "profiles": ["oauth-2-1-for-public-client"]
    }
  ]
}
</code></pre>
<p>You can send it to <code>PUT /admin/realms/{realm}/client-policies/policies</code>, or build the same two policies in the console under <em>Realm settings</em>, <em>Client policies</em>. On our FAPI realm <code>any-client</code> was fine, because every client in it is a confidential FAPI client. In any realm that mixes client types, use <code>client-access-type</code>.</p>
<h2>One deliberate difference from FAPI 2.0</h2>
<p>FAPI 2.0 asks the server to accept only its own issuer identifier, as a string, in the <code>aud</code> claim of a client assertion. Under the FAPI profile, Keycloak 26.8.2 also accepts a JSON array that holds only the issuer, <code>["https://.../realms/trackf"]</code>. It refuses an array with any second value, an array with only another value, and the token endpoint URL, so no unrelated audience gets through. We reported this as issue <a href="https://github.com/keycloak/keycloak/issues/54743">#54743</a>. The maintainers closed it as not planned, because a single-value array still rules out every other audience and refusing it adds no security. If your conformance suite checks the exact type, expect this one finding.</p>
<h2>Run it yourself</h2>
<p>Everything is in the lab repository, <a href="https://github.com/kazuru-chidumbwe/keycloak-client-profiles-lab">keycloak-client-profiles-lab</a>. On a Linux machine with Docker, one command runs it all:</p>
<pre><code class="language-bash">./run.sh
</code></pre>
<ul>
<li><code>setup-keycloak.sh</code> starts Keycloak at the digest above on <code>127.0.0.1</code>, with a throwaway lab CA.</li>
<li><code>probes.py S0</code>, <code>S1</code> and <code>S2L</code> build both realms for the default, guidance and every-setting cases, run the ten checks and write <code>results.json</code>, with a verdict and evidence ids for every test.</li>
<li><code>trap_anyclient.py</code> builds the two policy sets and records what happens to a public client in each.</li>
<li><code>requirements.yml</code> lists every requirement, its source section and its tests.</li>
</ul>
<p>Codes and tokens are redacted in the log by default. Run the lab against your own Keycloak version before you trust a table written for someone else's, and if a row differs, open an issue with your <code>results.json</code>.</p>
<h2>What we did not test</h2>
<p>The OAuth 2.1 confidential profile binds tokens with mutual TLS, and our lab has no client-certificate PKI yet. So the confidential client in <code>trackr</code> was judged at the default stage only, and under the profiles its results are marked inconclusive. We did not test the mTLS variants of the FAPI profile, and we did not run the OpenID conformance suite, which Keycloak runs itself for its certification.</p>
]]></content:encoded></item></channel></rss>