<?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" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by hdhoang on Medium]]></title>
        <description><![CDATA[Stories by hdhoang on Medium]]></description>
        <link>https://medium.com/@hdhoang?source=rss-2f187e89fee2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*_RMPNfoICs7FRgYA.jpg</url>
            <title>Stories by hdhoang on Medium</title>
            <link>https://medium.com/@hdhoang?source=rss-2f187e89fee2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 07:28:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hdhoang/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Mythical 0-link, readable file and other wonkeries]]></title>
            <link>https://medium.com/coccoc-engineering-blog/mythical-0-link-readable-file-and-other-wonkeries-a3dbe0c82b38?source=rss-2f187e89fee2------2</link>
            <guid isPermaLink="false">https://medium.com/p/a3dbe0c82b38</guid>
            <category><![CDATA[sre]]></category>
            <category><![CDATA[troubleshooting]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[containerd]]></category>
            <category><![CDATA[k8s]]></category>
            <dc:creator><![CDATA[hdhoang]]></dc:creator>
            <pubDate>Wed, 13 Sep 2023 05:07:29 GMT</pubDate>
            <atom:updated>2023-09-13T05:07:29.109Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<p>Here are some unassorted strangeness we encountered recently, while<br>using k8s/containers on linux.</p><h3>Unbalanced directory index</h3><p>one day, a k8s node logged these messages every few hours, in bundles of 4:</p><pre>EXT4-fs warning (device md1): ext4_dx_add_entry:2380: Directory (ino: 211566352) index full, reach max htree level :2<br>EXT4-fs warning (device md1): ext4_dx_add_entry:2384: Large directory feature is not enabled on this filesystem<br>EXT4-fs warning (device md1): ext4_dx_add_entry:2380: Directory (ino: 211566352) index full, reach max htree level :2<br>EXT4-fs warning (device md1): ext4_dx_add_entry:2384: Large directory feature is not enabled on this filesystem<br>EXT4-fs warning (device md1): ext4_dx_add_entry:2380: Directory (ino: 211566352) index full, reach max htree level :2<br>EXT4-fs warning (device md1): ext4_dx_add_entry:2384: Large directory feature is not enabled on this filesystem<br>EXT4-fs warning (device md1): ext4_dx_add_entry:2380: Directory (ino: 211566352) index full, reach max htree level :2<br>EXT4-fs warning (device md1): ext4_dx_add_entry:2384: Large directory feature is not enabled on this filesystem</pre><p>the mentioned directory was always inode 211566352, so the situation impacted just 1 workload. redhat has a <a href="https://access.redhat.com/solutions/29894">nice article</a> explaining the mechanism at work, and a note explaining why it happened occasionally:</p><blockquote>Files can still be successfully created if the hash of their filename does not fall into an already full hash bucket.</blockquote><p>It includes an auditd log searching example at syscall level (egcreat, openat, …). however, at CocCoc, we’re more familiar with<a href="https://github.com/iovisor/bpftrace/blob/master/docs/reference_guide.md#1-kprobekretprobe-dynamic-tracing-kernel-level">ebpftooling</a>,<br>and the message contained a function-ish hint ext4_dx_add_entry. let’s hunt for the failing process:</p><pre>## is there some related probe/tracepoint?<br>$ sudo bpftrace -l &#39;*ext4_dx*&#39;<br>hardware:*ext4_dx*:<br>kprobe:ext4_dx_add_entry<br>kprobe:ext4_dx_csum<br>kprobe:ext4_dx_csum_set<br>kprobe:ext4_dx_find_entry<br>software:*ext4_dx*:<br><br><br>## yes, neat, let&#39;s grab any failling call &amp; print out the process<br>$ sudo bpftrace -e &#39;kretprobe:ext4_dx_add_entry /retval !=0/ {printf(&quot;%d %s: %d\n&quot;, pid, comm, retval);}&#39; |head -n 30<br>Attaching 1 probe...<br>2916472 php-fpm: -28<br>2916472 php-fpm: -28<br>2916472 php-fpm: -28<br>2916472 php-fpm: -28<br><br><br>## what is that<br>$ sudo systemctl status 2916472<br>...<br>kubepods-burstable.slice/kubepods-burstable-pod834b7b00_d731_4186_803c_8c4a35a84627.slice/cri-containerd-41b8343f32f8623c7d20942813b4a48c72cc0d34ae74<br>...<br>$ sudo crictl ps | grep 41b8343f3<br>...php...41b8343f3...some-app</pre><p>From there, we could do kubectl debug into the container &amp; look around for any huge directory. this app creates temporary files in a flat directory:</p><pre>$ stat /app/tmp<br>  File: /app/tmp<br>  Size: 586358784       Blocks: 1145712    IO Block: 4096   directory<br>Device: 901h/2305d      Inode: 211566352   Links: 2<br><br><br>## that&#39;s our reported inode! what&#39;s in there? links=2 shows that there&#39;s no subdirectory<br>$ find /app/tmp -type f | wc -l<br>4781597<br>$ du -h /app/tmp<br>242G    /app/tmp</pre><p>At this point, we made the mistake of rollout-restarting the deployment. new pods started working fine right away, but the old pods were still around in Terminating state. linux was busy removing the files in their overlayfs mount, including the above giant directories &amp; their files. that caused ~3hours of high write-iops to commit filesystem metadata on the nodes, which slowed down other unrelated workloads. we had to cordon them during that time, and moved more important pods out of there.</p><p>The strangest effect was that pods on other nodes also failed readiness check randomly. it turned out some of their mysqlrouters were on the heavy-load nodes. the db clusters were totally fine, they run on different HW.</p><pre>routing ERROR [7fc427ed7700] connecting to backend failed: Connection timed out (generic:110)<br>routing ERROR [7fc4286d8700] connecting to backend failed: not set (destinations:1)<br>routing ERROR [7fc425690700] connecting to backend failed: not set (destinations:1)<br>router Application got fatal signal: 11<br>router stack_bottom = 0 thread_stack 0x0<br>router /usr/lib64/mysqlrouter/private/libmysqlharness.so.1(my_print_stacktrace(unsigned char const*, unsigned long)+0x41) [0x7fc430782d71]<br>router /usr/lib64/mysqlrouter/private/libmysqlharness.so.1(+0xdc3b1) [0x7fc43076d3b1]<br>router /lib64/libpthread.so.0(+0x12d00) [0x7fc4303b4d00]<br>router /usr/lib64/mysqlrouter/private/libmysqlrouter_routing.so.1(MySQLRoutingAPI::get_destinations() const+0x22) [0x7fc42d04e4d2]<br>router /usr/lib64/mysqlrouter/private/libmysqlrouter_routing.so.1(+0x8e1bb) [0x7fc42d04f1bb]</pre><p>I still don’t understand how a network-heavy app can be disturbed so much by disk io. perhaps it checkpoints or logs something in critical path? but that’s now <a href="https://youtu.be/4G-YQA_bsOU">water under the bridge</a>.</p><h3>Filesystem IO-load and containerd</h3><p>Segue from the previous issue, for a long time we have been facing this situation:</p><ul><li>Growing amount of linux process/thread (tasks) on some k8s nodes</li><li>All of the extra ones are containerd-shim processes, with no related running containers</li></ul><p>Each shim is small, but the overall built-up causes system-wide degradation:</p><ul><li>atop, our favorite recording tool, starts failing with Malloc failed for compression buffer</li><li>Anything that scales per-process or per-cgroup has more useless work to do</li></ul><p>Here is an example which started running &amp; finished its work during the above deletion:</p><pre>## filtering out `collecting metrics` errors<br>$ sudo grep 513f9b55e96a /var/log/containerd.log.1|grep -v collecting|grep -o T.*<br>T14:14:36.809200001+07:00&quot; level=info msg=&quot;CreateContainer within sandbox \&quot;3ced0a60e406e5a4fff274f794947ff96129d15ccb8cabca3f3cc867511265da\&quot; for &amp;ContainerMetadata{Name:worker-5,Attempt:436,} returns container id \&quot;513f9b55e96a531360dc266d6c13124c5b7a2e027552245912203ab96b60e98f\&quot;&quot;<br>T14:14:36.810770998+07:00&quot; level=info msg=&quot;StartContainer for \&quot;513f9b55e96a531360dc266d6c13124c5b7a2e027552245912203ab96b60e98f\&quot;&quot;<br>T14:14:37.979214517+07:00&quot; level=info msg=&quot;StartContainer for \&quot;513f9b55e96a531360dc266d6c13124c5b7a2e027552245912203ab96b60e98f\&quot; returns successfully&quot;<br>T14:44:43.486606295+07:00&quot; level=error msg=&quot;Failed to pipe stdout of container \&quot;513f9b55e96a531360dc266d6c13124c5b7a2e027552245912203ab96b60e98f\&quot;&quot; error=&quot;read /proc/self/fd/62: file already closed&quot;<br>T14:44:52.439833260+07:00&quot; level=error msg=&quot;failed to handle container TaskExit event &amp;TaskExit{ContainerID:513f9b55e96a531360dc266d6c13124c5b7a2e027552245912203ab96b60e98f,ID:513f9b55e96a531360dc266d6c13124c5b7a2e027552245912203ab96b60e98f,Pid:211974,ExitStatus:0,ExitedAt:2023-09-06 07:44:42.439304235 +0000 UTC,XXX_unrecognized:[],}&quot; error=&quot;failed to stop container: context deadline exceeded: unknown&quot;<br>T14:47:02.214579151+07:00&quot; level=info msg=&quot;TaskExit event &amp;TaskExit{ContainerID:513f9b55e96a531360dc266d6c13124c5b7a2e027552245912203ab96b60e98f,ID:513f9b55e96a531360dc266d6c13124c5b7a2e027552245912203ab96b60e98f,Pid:211974,ExitStatus:0,ExitedAt:2023-09-06 07:44:42.439304235 +0000 UTC,XXX_unrecognized:[],}&quot;<br>T14:52:34.752879642+07:00&quot; level=info msg=&quot;RemoveContainer for \&quot;513f9b55e96a531360dc266d6c13124c5b7a2e027552245912203ab96b60e98f\&quot;&quot;<br>T14:52:55.277595056+07:00&quot; level=info msg=&quot;RemoveContainer for \&quot;513f9b55e96a531360dc266d6c13124c5b7a2e027552245912203ab96b60e98f\&quot;&quot;<br>T14:52:55.277675179+07:00&quot; level=error msg=&quot;RemoveContainer for \&quot;513f9b55e96a531360dc266d6c13124c5b7a2e027552245912203ab96b60e98f\&quot; failed&quot; error=&quot;failed to set removing state for container \&quot;513f9b55e96a531360dc266d6c13124c5b7a2e027552245912203ab96b60e98f\&quot;: container is already in removing state&quot;<br>T14:53:00.815222826+07:00&quot; level=info msg=&quot;RemoveContainer for \&quot;513f9b55e96a531360dc266d6c13124c5b7a2e027552245912203ab96b60e98f\&quot; returns successfully&quot;<br><br>## it&#39;s still here a day later, and will be forever more<br>$ ps aux|grep 513f9b55e96a<br>root      211874  0.0  0.0 708400  7324 ?        Sl   Sep06   0:02 containerd-shim -namespace k8s.io -workdir /var/lib/containerd/io.containerd.runtime.v1.linux/k8s.io/513f9b55e96a531360dc266d6c13124c5b7a2e027552245912203ab96b60e98f -address /run/containerd/containerd.sock -containerd-binary /usr/bin/containerd -systemd-cgroup</pre><p>After 10s, from ExitedAt :44:42 to deadline exceeded :44:52, containerd gave up on removing the task, and the orphan shim stays around from then.</p><p>Again with ebpf in one hand and the flow around this area in another, we think that discarding/unmounting each container’s overlay filesystem is io-intensive as well as io-sensitive.</p><pre>## with https://github.com/tanelpoder/0xtools<br>$ sudo psn -G kstack<br> samples | avg_threads | comm                        | state                  | kstack<br>------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------<br>       3 |        1.00 | (md*_resync)                | Disk (Uninterruptible) | kthread()-&gt;md_thread()-&gt;md_do_sync.cold.90()-&gt;msleep()<br>       2 |        0.67 | (containerd)                | Disk (Uninterruptible) | syscall_exit_to_user_mode()-&gt;exit_to_user_mode_prepare()-&gt;task_work_run()-&gt;cleanup_mnt()-&gt;deactivate_locked_super()-&gt;kill_anon_super()-&gt;generic_shutdown_super()-&gt;sync_filesystem()-&gt;ovl_sync_fs()-&gt;sync_filesystem()-&gt;__writeback_inodes_sb_nr()-&gt;wb_wait_for_completion()<br>       2 |        0.67 | (exe)                       | Disk (Uninterruptible) | __x64_sys_mount()-&gt;do_mount()-&gt;path_mount()-&gt;rwsem_down_write_slowpath()</pre><pre>## stack going back from sync_fs through to containerd process<br># sorry, i forgot the command used to get this, perhaps something in bcc-tools for stack snooping<br>  ffffffffc067aea1 b&#39;ext4_sync_fs&#39;<br>  ffffffff818f55b1 b&#39;sync_filesystem&#39;<br>  ffffffffc07811e9 b&#39;ovl_sync_fs&#39;<br>  ffffffff818f55b1 b&#39;sync_filesystem&#39;<br>  ffffffff818bc9c2 b&#39;generic_shutdown_super&#39;<br>  ffffffff818bcab4 b&#39;kill_anon_super&#39;<br>  ffffffff818bc37f b&#39;deactivate_locked_super&#39;<br>  ffffffff818df498 b&#39;cleanup_mnt&#39;<br>  ffffffff816aa276 b&#39;task_work_run&#39;<br>  ffffffff8170fdf9 b&#39;exit_to_user_mode_prepare&#39;<br>  ffffffff81e882c8 b&#39;syscall_exit_to_user_mode&#39;<br>  ffffffff8200008c b&#39;entry_SYSCALL_64_after_hwframe&#39;<br>  55eb400e0750     b&#39;syscall.Syscall&#39;<br>  55eb40209055     b&#39;github.com/containerd/containerd/mount.unmount&#39;<br>  55eb4020930d     b&#39;github.com/containerd/containerd/mount.UnmountAll&#39;<br>  55eb4020d404     b&#39;github.com/containerd/containerd/mount.WithTempMount.func2&#39;<br>  55eb4020c7a3     b&#39;github.com/containerd/containerd/mount.WithTempMount&#39;<br>  55eb407b6860     b&#39;github.com/containerd/containerd/oci.WithAdditionalGIDs.func1&#39;<br>  55eb40e199d2     b&#39;github.com/containerd/containerd/vendor/github.com/containerd/cri/pkg/containerd/opts.WithAdditionalGIDs.func1&#39;<br>  55eb407af412     b&#39;github.com/containerd/containerd/oci.ApplyOpts&#39;<br>  55eb4080196a     b&#39;github.com/containerd/containerd.WithSpec.func1&#39;<br>  55eb407e37f9     b&#39;github.com/containerd/containerd.(*Client).NewContainer&#39;<br>  55eb40f06bb1     b&#39;github.com/containerd/containerd/vendor/github.com/containerd/cri/pkg/server.(*criService).CreateContainer&#39;<br>  55eb40f25abd     b&#39;github.com/containerd/containerd/vendor/github.com/containerd/cri/pkg/server.(*instrumentedService).CreateContainer&#39;<br>  55eb40da0278     b&#39;github.com/containerd/containerd/vendor/k8s.io/cri-api/pkg/apis/runtime/v1alpha2._RuntimeService_CreateContainer_Handler.func1&#39;<br>  55eb4106167f     b&#39;github.com/containerd/containerd/vendor/github.com/grpc-ecosystem/go-grpc-prometheus.(*ServerMetrics).UnaryServerInterceptor.func1$<br>  55eb40d0bedd     b&#39;github.com/containerd/containerd/vendor/k8s.io/cri-api/pkg/apis/runtime/v1alpha2._RuntimeService_CreateContainer_Handler&#39;<br>  55eb40646676     b&#39;github.com/containerd/containerd/vendor/google.golang.org/grpc.(*Server).processUnaryRPC&#39;<br>  55eb4064a399     b&#39;github.com/containerd/containerd/vendor/google.golang.org/grpc.(*Server).handleStream&#39;<br>  55eb40657a1d     b&#39;github.com/containerd/containerd/vendor/google.golang.org/grpc.(*Server).serveStreams.func1.1&#39;<br>  55eb400c33e1     b&#39;runtime.goexit&#39;<br>    b&#39;containerd&#39; [1310]</pre><p>Cloudfoundry discussed <a href="https://www.cloudfoundry.org/blog/an-overlayfs-journey-with-the-garden-team/">this general problem</a>. CocCoc is following with great interest for newer containerd 1.6 LTS releases with fixes around handling overlay deletion. Some recent ones improved short-term, temporary mounts by marking them readonly. Containerd maintainers also made a <a href="https://github.com/containerd/containerd/pull/9004/files#diff-1d0d1c3863f35bb86ef37975c4e1a2062e6ca71e6f6a94dc385f8a3556284ddcR117">great reproduction</a> with strace fault-injection feature:</p><pre># step 2: strace to inject failpoint for the pod&#39;s shim<br>sudo strace -p $(pidof target-shim) --trace=umount2 -f --detach-on=execve -e inject=umount2:delay_enter=12s</pre><p>A more fundamental fix, using overlayfs volatile mode to alleviate whole-system load, is <a href="https://github.com/containerd/containerd/pull/4785">in design phase for now</a>.</p><p>We can’t do much else to mitigate this problem, due to the nature of php/nodejs/python applications with many loose files for each container, and the way we <a href="https://medium.com/coccoc-engineering-blog/our-journey-to-kubernetes-container-design-principles-is-your-back-bag-9166fc4736d2#957e">pass php files to nginx containers</a> in a shared emptyDir volume.</p><h3>Ghost hostPath files</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*brgd2BTC9Q5Wk7ikPDCe7A.png" /><figcaption>Source: <a href="https://www.snexplores.org/wp-content/uploads/2019/11/860_ghoststairs.png">https://www.snexplores.org/wp-content/uploads/2019/11/860_ghoststairs.png</a></figcaption></figure><p>Onward to the main title. as part of migrating on-host applications to k8s, we mount some files as hostPath volume into containers, and let host cronjobs write new data into them. for a time, this worked correctly:</p><pre>## manifest fragments<br><br>volumes:<br>- name: host-data<br>  hostPath:<br>    path: /tmp/data.txt<br>    type: File<br>containers:<br>- name: app<br>  volumeMounts:<br>  - name: host-data<br>    mountPath: /data.txt<br>    readOnly: true</pre><pre>## updating from host is reflected in container<br>host$ echo version1 &gt; /tmp/data.txt<br>app$ cat /data.txt<br>version1<br><br>host$ echo version2 &gt; /tmp/data.txt<br>app $ cat /data.txt</pre><p>But update to the cronjob code introduced a new phenomenon. On host, we can see the new data in the file, but k8s pods read only old data.</p><pre>host$ echo version3 &gt; /tmp/new.txt<br>host$ mv -f /tmp/new.txt /tmp/data.txt<br>host$ cat /tmp/data.txt<br>version3<br><br>app $ cat /data.txt<br>version2</pre><p>Oops! here is the reason:</p><pre>host$ stat /tmp/data.txt<br>  File: /tmp/data.txt<br>  Size: 9               Blocks: 8          IO Block: 4096   regular file<br>Device: 901h/2305d      Inode: 68812819    Links: 1<br><br>app $ stat /data.txt<br>  File: /data.txt<br>  Size: 9               Blocks: 8          IO Block: 4096   regular file<br>Device: 901h/2305d      Inode: 68812816    Links: 0<br>app $ mount|grep data<br>/dev/md1 on /data.txt type ext4 (ro,relatime,errors=remount-ro)</pre><p>hostPath is implemented as a bind-mount, so it’s “translated” to specific inode once at the pod setup phase. after mv rewrote the path to different inode, 68812816 is kept alive only by the mount namespace. It’s similar to a running process holding open a deleted file, giving DEL state in lsof listings. but this 0-link file is still reachable from host, via the container’s root/ under /proc:</p><pre>host$ sudo cat /proc/4185645/root/data.txt<br>version2</pre><p>Our mitigation for this one was changing hostPath up a level, to share the more-stable directory as volume instead. It would still break the same way if someone rename the directory, but it’s less likely. And further, we’ll work with people to share the data updates in a more robust way.</p><p>We hope you can have fun with the substrate under containers as we’re having here.</p><p><em>Originally published at </em><a href="https://nest.pijul.com/hdhoang/homes:main/WF6HOUZUSQPAW.DUAQA"><em>https://nest.pijul.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a3dbe0c82b38" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coccoc-engineering-blog/mythical-0-link-readable-file-and-other-wonkeries-a3dbe0c82b38">Mythical 0-link, readable file and other wonkeries</a> was originally published in <a href="https://medium.com/coccoc-engineering-blog">Coccoc Engineering Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Have you seen DNS TYPE0 CLASS256?]]></title>
            <link>https://medium.com/coccoc-engineering-blog/have-you-seen-dns-type0-class256-896b10af92fc?source=rss-2f187e89fee2------2</link>
            <guid isPermaLink="false">https://medium.com/p/896b10af92fc</guid>
            <category><![CDATA[internet]]></category>
            <category><![CDATA[dns]]></category>
            <category><![CDATA[rust]]></category>
            <dc:creator><![CDATA[hdhoang]]></dc:creator>
            <pubDate>Thu, 19 Jan 2023 06:43:06 GMT</pubDate>
            <atom:updated>2023-02-10T04:44:56.849Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<p>we run a recursive resolver for historical reason. these recent months, we started seeing messages like this in unbound.log, with different names:</p><pre>info: resolving cctv-api.cdn20.com.cd23f.com. TYPE0 CLASS256<br>info: resolving cctv-api.cdn20.com.chnc.cloudcsp.com. TYPE0 CLASS256<br>info: resolving cctv-api.wswebpic.com.chnc.cloudcsp.com. TYPE0 CLASS256<br>info: resolving overseatest.livehttp.speedcdns.com. TYPE0 CLASS256<br>info: resolving wangsu-1.ttyuyin.com.cdn20.com. TYPE0 CLASS256<br>info: resolving wangsu-3.ttyuyin.com.cdn20.com. TYPE0 CLASS256</pre><p>afaik we have no relationship with such infrastructure (CCTV in some Chinese cloud?). we blocked the most queried labels, and move on to other things. however i have a nagging question: what is that?</p><p>i still have no details about the chinese parties, but after some searching &amp; reproduction, i think there is a defect-attractor in DNS-packet construction. in order to avoid search-suffix behaviour, people write .-ending names in config, and some software will construct an invalid DNS query:</p><ul><li>haproxy, before 2020 <a href="https://github.com/haproxy/haproxy/issues/435">https://github.com/haproxy/haproxy/issues/435</a></li><li>gnupg dirmngr, in 2017 <a href="https://dev.gnupg.org/T3517#106524">https://dev.gnupg.org/T3517#106524</a></li><li>nongnu LWIP, in 2020 <a href="https://savannah.nongnu.org/bugs/?58473#comment3">https://savannah.nongnu.org/bugs/?58473#comment3</a></li></ul><p>the sequence is potentially like this:</p><ol><li>split name by .</li><li>for each item, construct ${length}${label} segments. the final empty label gets converted to its own 0x0 byte</li><li>concat the segments together, then append the empty label 0x0, regardless of previous step</li><li>append the DNS type &amp; class (always IN/0x1 for Internet)</li></ol><p>Thus, now we have a name that ends with \0\0 (or 00 00 in hexdump view). The question now appends usual Type A (00 01), Class IN (00 01), but those become misaligned:</p><pre>Okay:<br>03 ?? ?? ?? 00|  00 01|    00 01<br>ll  c  o  m . | TYPE A|CLASS  IN<br><br>Wrong:<br>03 ?? ?? ?? 00|  00 00|    01 00 01<br>ll  c  o  m . | TYPE 0|CLASS 256 FORMAT ERROR, i hope the server answer</pre><p>for more background, check out <a href="https://jvns.ca/blog/2022/09/12/why-do-domain-names-end-with-a-dot-/#in-a-dns-request-response-domain-names-don-t-have-a-trailing">jvns’ blog</a> or view responses in various formats with <a href="https://dnsinstitute.com/webdnsquery/">DNS institute tool</a>.</p><p>i also found a <a href="https://groups.google.com/g/comp.protocols.dns.bind/c/pIVLil7p8wA/m/Y0bxMyn5bI0J">different case from 2001</a>, where a (windows-based?) client sent TYPE &amp; CLASS as little-endian, not big-endian, resulting in TYPE256 CLASS256 query.</p><h3>Reproduction</h3><p>a single ping, comrade. just one, for range. — Marko Ramius (in The Hunt for Red October)</p><p>we can catch the non-Internet class queries with tcpdump/pcap filter udp port 53 and dns.query.class &gt; 1 , or wireshark/tshark dns.qry.class &gt; 1 . but i want to generate those wrong Questions on-demand, to observe and quote the various DNS servers’ log lines about them, as well as to put <a href="https://www.netmeister.org/blog/dns-rrs.html">all kind of TYPEs</a> in the Q and see what they look like.</p><pre>declare -a TYPES=(type1 type2 cname type6 mx txt aaaa srv dname type65 type255 caa)</pre><p>The core code is over here <a href="https://nest.pijul.com/hdhoang/homes:main/CHTEJVPDN5R2S.CUAAA">https://nest.pijul.com/hdhoang/homes:main/CHTEJVPDN5R2S.CUAAA</a>, with core function:</p><pre>fn naughty_question(qtype: Rtype) -&gt; Question&lt;Dname&lt;Vec&lt;u8&gt;&gt;&gt; {<br>    let name = Dname::vec_from_str(&quot;example.&quot;).unwrap();<br>    let mut bytes = name.into_octets();<br>    bytes.push(0);<br>    Question::new_in(<br>        // Safety: I want to do it wrong<br>        unsafe { Dname::from_octets_unchecked(bytes) },<br>        qtype,<br>    )<br>}<br>#[test]<br>fn it_is_different() {<br>    assert!(<br>        !Question::from((Dname::vec_from_str(&quot;example.&quot;).unwrap(), Rtype::Any))<br>            .eq(&amp;naughty_question(Rtype::Any))<br>    );<br>}</pre><p>i chose NLnet Labs’ <a href="https://lib.rs/crates/domain">domain crate</a>, because it is self-contained, and comes with a resolver. fortunately it exposes the above hand-off function to give users&#39; direct access to parsed domain bytes. i haven&#39;t wrapped my head around how to properly print out all kinds of answer data yet, so i resigned to asserting that the queried server ignores/refuses the bad questions. i can construct a bad Dname, pinky-promise to domain that it is good, and let it help me with the rest of DNS+UDP wrapping &amp; handling! an alternative would be trust-dns&#39;s proto &amp; client crates.</p><p>I queried some usual resource types against an unbound server:</p><pre>declare -a TYPES=(type1 type2 cname type6 mx txt aaaa srv dname type65 type255 caa)<br><br>for type in ${TYPES[*]}; do cargo r -q -- @unbound.address $type; done</pre><pre>A: b&quot;\0\0\x81\x85\0\x01\0\0\0\0\0\0\x07example\0\0\0\x01\0&quot;<br>NS: server ignored us, perhaps: Custom { kind: TimedOut, error: &quot;all timed out&quot; }<br>CNAME: b&quot;\0\0\x81\x85\0\x01\0\0\0\0\0\0\x07example\0\0\0\x05\0&quot;<br>SOA: b&quot;\0\0\x81\x85\0\x01\0\0\0\0\0\0\x07example\0\0\0\x06\0&quot;<br>MX: b&quot;\0\0\x81\x85\0\x01\0\0\0\0\0\0\x07example\0\0\0\x0f\0&quot;<br>TXT: b&quot;\0\0\x81\x85\0\x01\0\0\0\0\0\0\x07example\0\0\0\x10\0&quot;<br>AAAA: b&quot;\0\0\x81\x85\0\x01\0\0\0\0\0\0\x07example\0\0\0\x1c\0&quot;<br>SRV: b&quot;\0\0\x81\x85\0\x01\0\0\0\0\0\0\x07example\0\0\0!\0&quot;<br>DNAME: server ignored us, perhaps: Custom { kind: TimedOut, error: &quot;all timed out&quot; }<br>HTTPS: server ignored us, perhaps: Custom { kind: TimedOut, error: &quot;all timed out&quot; }<br>ANY: b&quot;\0\0\x81\x85\0\x01\0\0\0\0\0\0\x07example\0\0\0\xff\0&quot;<br>CAA: server ignored us, perhaps: Custom { kind: TimedOut, error: &quot;all timed out&quot; }</pre><p>“perhaps” is because, as we see below, the program sometimes doesn’t receive response data. unbound logs clear messages:</p><pre>unbound[1626:0] info: resolving example. TYPE0 CLASS256<br>unbound[1626:4] info: resolving example. TYPE0 CLASS512<br>unbound[1626:2] info: resolving example. TYPE0 CLASS1280<br>unbound[1626:3] info: resolving example. TYPE0 CLASS1536<br>unbound[1626:1] info: resolving example. TYPE0 CLASS3840<br>unbound[1626:5] info: resolving example. TYPE0 CLASS4096<br>unbound[1626:2] info: resolving example. TYPE0 CLASS7168<br>unbound[1626:4] info: resolving example. TYPE0 CLASS8448<br>unbound[1626:3] info: resolving example. TYPE0 CLASS9984<br>unbound[1626:3] info: resolving example. TYPE0 CLASS65280</pre><p>Here is tcpdump’s translation of the traffic:</p><pre>0+ [1au] Type0 (Class 256)? example. (37)<br>0 FormErr 0/0/1 (36)<br>0+ Type0 (Class 256)? example. (26)<br>0 Refused 0/0/0 (25)<br>0+ [1au] Type0 (Class 512)? example. (37)<br>0 FormErr 0/0/1 (36)<br>0+ Type0 (Class 512)? example. (26)<br>0 Refused 0/0/0 (25)<br>0+ [1au] Type0 (Class 1280)? example. (37)<br>0 FormErr 0/0/1 (36)<br>0+ Type0 (Class 1280)? example. (26)<br>0 Refused 0/0/0 (25)<br>0+ [1au] Type0 (Class 1536)? example. (37)<br>0 FormErr 0/0/1 (36)<br>0+ Type0 (Class 1536)? example. (26)<br>0 Refused 0/0/0 (25)<br>0+ [1au] Type0 (Class 3840)? example. (37)<br>0 FormErr 0/0/1 (36)<br>0+ Type0 (Class 3840)? example. (26)<br>0 Refused 0/0/0 (25)<br>0+ [1au] Type0 (Class 4096)? example. (37)<br>0 FormErr 0/0/1 (36)<br>0+ Type0 (Class 4096)? example. (26)<br>0 Refused 0/0/0 (25)<br>0+ [1au] Type0 (Class 7168)? example. (37)<br>0 FormErr 0/0/1 (36)<br>0+ Type0 (Class 7168)? example. (26)<br>0 Refused 0/0/0 (25)<br>0+ [1au] Type0 (Class 8448)? example. (37)<br>0 FormErr 0/0/1 (36)<br>0+ Type0 (Class 8448)? example. (26)<br>0 Refused 0/0/0 (25)<br>0+ [1au] Type0 (Class 9984)? example. (37)<br>0 FormErr 0/0/1 (36)<br>0+ Type0 (Class 9984)? example. (26)<br>0 Refused 0/0/0 (25)<br>0+ [1au] Type0 (Class 16640)? example. (37)<br>0 FormErr 0/0/1 (36)<br>0+ Type0 (Class 16640)? example. (26)<br>0 Refused 0/0/0 (25)<br>0+ [1au] Type0 (Class 65280)? example. (37)<br>0 FormErr 0/0/1 (36)<br>0+ Type0 (Class 65280)? example. (26)<br>0 Refused 0/0/0 (25)<br>0+ [1au] A (Class 256)? example. (37)<br>0 FormErr 0/0/1 (36)</pre><p>(you see why i said perhaps). this last one A (Class 256)? is from a CAA rtype. its high byte gets reinterpreted as type A again! but the Class 256 is never fixable, and the whole packet is malformed beyond repair anyhow.</p><p>i hope someone out there come across this &amp; figure out whatever is happening with the clients sending these queries.</p><p>i tested against ISC bind, but it says only:</p><pre>client: warning: client 4.5.6.7#33870: message parsing failed: unexpected end of input</pre><p>CoreDNS, NLnet NSD, systemd-resolved doesn’t log anything about these at all in my testing. of the cloudflare addresses, .1 and .3 replies quickly &amp; i can print the response, but i miss .2 traffic consistently:</p><pre>for s in 1 2 3; do cargo r -q -- @1.1.1.$s aaaa; done<br>AAAA: b&quot;\0\0\x81\x84\0\x01\0\0\0\0\0\0\x07example\0\0\0\x1c\0&quot;<br>AAAA: server ignored us, perhaps: Custom { kind: TimedOut, error: &quot;all timed out&quot; }<br>AAAA: b&quot;\0\0\x81\x84\0\x01\0\0\0\0\0\0\x07example\0\0\0\x1c\0&quot;</pre><p>nothing comes back from .2:</p><pre>0+ [1au] Type0 (Class 7168)? example. (37)<br>0 NotImp 0/0/0 (25)<br>0+ [1au] Type0 (Class 7168)? example. (37)<br>0+ [1au] Type0 (Class 7168)? example. (37)<br>0 NotImp 0/0/0 (25)</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=896b10af92fc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coccoc-engineering-blog/have-you-seen-dns-type0-class256-896b10af92fc">Have you seen DNS TYPE0 CLASS256?</a> was originally published in <a href="https://medium.com/coccoc-engineering-blog">Coccoc Engineering Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[concrete reproduction checks my thinking]]></title>
            <link>https://medium.com/coccoc-engineering-blog/concrete-reproduction-checks-my-thinking-1399c1144718?source=rss-2f187e89fee2------2</link>
            <guid isPermaLink="false">https://medium.com/p/1399c1144718</guid>
            <dc:creator><![CDATA[hdhoang]]></dc:creator>
            <pubDate>Sun, 21 Aug 2022 15:11:48 GMT</pubDate>
            <atom:updated>2023-02-10T04:45:25.057Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<p>I almost reported an issue, right up to the point where bisecting doesn’t reproduce it reliably.</p><p>I run both kafka-minion <a href="https://github.com/redpanda-data/kminion/blob/v1.0.2/options/options.go#L63">v1, known under cloudhut org</a> and kminion <a href="https://github.com/redpanda-data/kminion/blob/v2.2.0/docs/reference-config.yaml#L13">v2, now under redpanda-data org</a> in parallel, in order to gauge how their metrics compare. (Truth be told, i wrote some suboptimal configs for kafka-minion, and the dashboards are too tied up with such config.) They use the same configuration via a systemd EnvironmentFile. That&#39;s the only method supported by kafka-minion whose Options are deserialized by struct definion:</p><pre>string `envconfig:&quot;KAFKA_TLS_CA_FILE_PATH&quot;`</pre><p>kminion can load config from some koanf providers: env and/or yaml. There&#39;s a transformation step to collapse yaml maps into a flat environment variable name:</p><pre>kafka.tls.caFilepath =&gt; `KAFKA_TLS_CAFILEPATH`</pre><p>Due to some recent issue, I wanted to build kminion from git repo. However, moving beyond <a href="https://github.com/redpanda-data/kminion/pull/147">commit a066</a> gave a weird error:</p><pre>&quot;caller&quot;: &quot;kminion/main.go:43&quot;,<br> &quot;msg&quot;: &quot;failed to parse config&quot;,<br> &quot;error&quot;: &quot;1 error(s) decoding:\n\n* &#39;kafka.tls.ca[0]&#39; expected type &#39;uint8&#39;, got unconvertible type &#39;map[string]interface {}&#39;, value: &#39;map[file:map[path:kafka_chain.pem]]&#39;&quot;,<br> &quot;stacktrace&quot;: &quot;main.main\n\t/home/me/github/kminion/main.go:43\nruntime.main\n\t/usr/lib/golang/src/runtime/proc.go:250&quot;</pre><p>map[file:map[path:kafka_chain.pem]] okay, I see my CA file here (actually the content is ISRG root CA). But what&#39;s this &#39;kafka.tls.ca[0]&#39; expected type &#39;uint8&#39;? Why is something plugging a map into an integer? At least I have a clean commit to write a bisect demo.</p><p>So I copied over the EnvironmentFile, removed anything about SASL authentication, exporter, set 0:9092 as bootstrap.servers for a quick recognizable failure once the app passes config parsing. And let git bisect run rip!</p><p>It pointed somewhere around the merge commit, as i expected. But then i had doubt, and set kafka-minion’s envvar in a shell:</p><pre>&gt; env KAFKA_TLS_CAFILEPATH=kafka_chain.pem kafka-minion<br>...snip...Connection refused</pre><p>eh, it got right up to trying connection? what happened to my bug?</p><p>As it happened, the envvar intended for kafka-minion ( KAFKA_TLS_CA_FILE_PATH) matches koanf auto-hydration(?), and it tried to construct this structure:</p><pre>kafka:<br> tls:<br>  ca:<br>   file:<br>    path: &quot;kafka_chain.pem&quot;</pre><p>because the new feature now accepts this structure:</p><pre>kafka:<br> tls:<br>  ca: MIIF....base64 DER data....</pre><p>Thus, the expected first element should have been a byte from the certificate.</p><p>With the new-issue tab firmly closed, I added to kminion’s systemd unit file:</p><pre>[Service]<br>UnsetEnvironment=KAFKA_TLS_CA_FILE_PATH</pre><p>As usual, I succeeded by nearly failing.</p><p><em>Originally published at </em><a href="https://hdhoang.substack.com/p/concrete-reproduction-checks-my-thinking"><em>https://hdhoang.substack.com</em></a><em> on August 21, 2022.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1399c1144718" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coccoc-engineering-blog/concrete-reproduction-checks-my-thinking-1399c1144718">concrete reproduction checks my thinking</a> was originally published in <a href="https://medium.com/coccoc-engineering-blog">Coccoc Engineering Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[podman encountered selinux (it’s somewhat effective!)]]></title>
            <link>https://medium.com/coccoc-engineering-blog/podman-encountered-selinux-its-somewhat-effective-446a17fa7242?source=rss-2f187e89fee2------2</link>
            <guid isPermaLink="false">https://medium.com/p/446a17fa7242</guid>
            <category><![CDATA[audit]]></category>
            <category><![CDATA[selinux]]></category>
            <category><![CDATA[fedora]]></category>
            <category><![CDATA[podman]]></category>
            <dc:creator><![CDATA[hdhoang]]></dc:creator>
            <pubDate>Fri, 28 Jan 2022 06:08:45 GMT</pubDate>
            <atom:updated>2022-04-19T08:01:44.546Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<p>I’ve been running <a href="https://spins.fedoraproject.org/">fedora 35</a> for a few months, ever since a mishap with VM image borked a previous OS. The whole time, SELinux is in Enforcing mode without trouble. It&#39;s quite a testament to Fedora, flatpak, &amp; many people for making the policies sensible out of the box. The below is my first denial trouble, and how I went about it.</p><p>I was running a <a href="https://github.com/edenhill/kcat">kcat</a> (née kafkacat) container with <a href="https://podman.io/">podman</a>. That works fine with network=host to reach brokers, using no authentication:</p><pre>$; podman run --rm -it --network=host edenhill/kcat:1.7.0 -b kafka:9092 -L -t test<br>Metadata for points-events (from broker 20: kafka:9092/2):<br>3 brokers:<br> broker 20 at kafka2:9092<br> broker 30 at kafka3:9092<br> broker 10 at kafka1:9092 (controller)<br>1 topics:<br> topic &quot;test&quot; with 12 partitions:<br>...</pre><p>Now I want to read data, which requires SASL authentication. In my config dir, I make a key=value file kcat.conf:</p><pre>bootstrap.seers=kafka:9093<br>security.protocol=SASL_PLAINTEXT <br>sasl.username=hdhoang <br>sasl.password=notreal <br>sasl.mechanism=SCRAM-SHA-512</pre><p>Then we can bind-mount the file into the container and let kcat use it:</p><pre>$; podman run --mount type=bind,src=./kcat.conf,dst=/kcat.conf,ro --rm -it --network=host edenhill/kcat:1.7.0 -F /kcat.conf -L -t test <br>% ERROR: Failed to open /kcat.conf: Permission denied</pre><p>Permission? Hum, I’m sure my editor can read/write it fine. Plus the image’s USER is 0, it can read (its own) /etc/shadow:</p><pre>?$; podman run --rm -it edenhill/kcat:1.7.0 -F /etc/shadow <br>% Reading configuration from file /etc/shadow <br>% ERROR: /etc/shadow:1: expected property=value</pre><p>Anything weird about the podman mount syntax, perhaps we submount a directory or so?</p><pre>?$; podman run --mount type=bind,src=./kcat.conf,dst=/kcat.conf,ro --rm -it --network=host edenhill/kcat:1.7.0 -F /kcat.conf/ -L -t test <br>% ERROR: Failed to open /kcat.conf/: Not a directory</pre><p>Nope, /kcat.conf inside is a file alright.</p><p>Next, we go to the 1-stop shop for system log: journald</p><pre>‽$; journalctl -S -2min<br>...<br>systemd[1223]: Started libcrun container.<br>podman[32416]: 2022- m=+0.228695948 container init 3761ccc06aed60bc55fa05c7e21e16766612d5b729f8410dfd5ee89ac40f7ca2 (image=docker.io/edenhill/kcat:1.7.0, name=tender_proskuriakova)<br>audit[32457]: AVC avc:  denied  { read } for  pid=32457 comm=&quot;kcat&quot; name=&quot;kcat.conf&quot; dev=&quot;dm-0&quot; ino=2265717 scontext=system_u:system_r:container_t:s0:c734,c838 tcontext=unconfined_u:object_r:user_home_t:s0 tclass=file permissive=0<br>conmon[32454]: % ERROR: Failed to open /kcat.conf: Permission denied<br>podman[32416]: 2022- m=+0.239698372 container start 3761ccc06aed60bc55fa05c7e21e16766612d5b729f8410dfd5ee89ac40f7ca2 (image=docker.io/edenhill/kcat:1.7.0, name=tender_proskuriakova)<br>podman[32416]: 2022- m=+0.239904686 container attach 3761ccc06aed60bc55fa05c7e21e16766612d5b729f8410dfd5ee89ac40f7ca2 (image=docker.io/edenhill/kcat:1.7.0, name=tender_proskuriakova)<br>podman[32416]: 2022- m=+0.249848927 container died 3761ccc06aed60bc55fa05c7e21e16766612d5b729f8410dfd5ee89ac40f7ca2 (image=docker.io/edenhill/kcat:1.7.0, name=tender_proskuriakova)<br>podman[32416]: 2022- m=+0.340016809 container remove 3761ccc06aed60bc55fa05c7e21e16766612d5b729f8410dfd5ee89ac40f7ca2 (image=docker.io/edenhill/kcat:1.7.0, name=tender_proskuriakova)<br>setroubleshoot[32377]: AnalyzeThread.run(): Cancel pending alarm<br>setroubleshoot[32377]: SELinux is preventing kcat from read access on the file kcat.conf. For complete SELinux messages run: sealert -l 0ce26f33-daec-4ae8-a7b0-5526da0d0a16<br>setroubleshoot[32377]: SELinux is preventing kcat from read access on the file kcat.conf.<br><br>    *****  Plugin catchall (100. confidence) suggests   **************************<br><br>    If you believe that kcat should be allowed read access on the kcat.conf file by default.<br>    Then you should report this as a bug.<br>    You can generate a local policy module to allow this access.<br>    Do<br>    allow this access for now by executing:<br>  # ausearch -c &#39;kcat&#39; --raw | audit2allow -M my-kcat<br>  # semodule -X 300 -i my-kcat.pp<br>...</pre><p>It captured kcat’s output too (as <a href="https://github.com/containers/conmon/">conmon</a> helper), and before that, audit system logged an denial (AVC is “ <a href="https://wikiless.org/wiki/Security-Enhanced_Linux?lang=en#Features">access vector cache</a>” if you’re curious). At this point, we can do sudo setenforce 0 then reboot and get on with life, but sometimes avoiding a reboot is fun!!</p><p>The audit entry contains relevant info, but let’s first follow <a href="https://fedoramagazine.org/troubleshooting-selinux/">setroubleshoot</a>’s helpful advice to use sealert -l to analyze the denial by its UUID:</p><pre>$; sealert -l 0ce26f33-daec-4ae8-a7b0-5526da0d0a16<br>SELinux is preventing kcat from read access on the file kcat.conf.<br><br>*****  Plugin catchall (100. confidence) suggests   **************************<br><br>If you believe that kcat should be allowed read access on the kcat.conf file by default.<br>Then you should report this as a bug.<br>You can generate a local policy module to allow this access.<br>Do<br>allow this access for now by executing:<br># ausearch -c &#39;kcat&#39; --raw | audit2allow -M my-kcat<br># semodule -X 300 -i my-kcat.pp<br><br>Additional Information:<br>Source Context                system_u:system_r:container_t:s0:c734,c838<br>Target Context                unconfined_u:object_r:user_home_t:s0<br>Target Objects                kcat.conf [ file ]<br>Source                        kcat<br>Source Path                   kcat<br>Port                          &lt;Unknown&gt;<br>Host                          HOSTNAME<br>Source RPM Packages<br>Target RPM Packages<br>SELinux Policy RPM            selinux-policy-targeted-35.11-1.fc35.noarch<br>Local Policy RPM              selinux-policy-targeted-35.11-1.fc35.noarch<br>Selinux Enabled               True<br>Policy Type                   targeted<br>Enforcing Mode                Enforcing<br>Host Name                     HOSTNAME<br>Platform                      Linux HOSTNAME 5.15.16-200.fc35.x86_64 #1 SMP Thu Jan<br>                              20 15:38:18 UTC 2022 x86_64 x86_64<br>Alert Count                   1<br>First Seen                    2022-01-28 10:41:44 +07<br>Last Seen                     2022-01-28 10:41:44 +07<br>Local ID                      0ce26f33-daec-4ae8-a7b0-5526da0d0a16<br><br>Raw Audit Messages<br>type=AVC msg=audit(1643341304.588:387): avc:  denied  { read } for  pid=32457 comm=&quot;kcat&quot; name=&quot;kcat.conf&quot; dev=&quot;dm-0&quot; ino=2265717 scontext=system_u:system_r:container_t:s0:c734,c838 tcontext=unconfined_u:object_r:user_home_t:s0 tclass=file permissive=0<br><br><br>Hash: kcat,container_t,user_home_t,file,read</pre><p>It begins with the same suggestion for ausearch | audit2allow ; semodule as root (ie prompt prefix #). The most salient point is the source &amp; target contexts</p><pre>Source Context system_u:system_r:container_t:s0:c734,c838<br>Target Context unconfined_u:object_r:user_home_t:s0</pre><p>This is a different layer of access-control on top of UN*X owner/perm system. I don’t want to dissect it now, just to connect to my kafka cluster. Target context comes from the file’s SElinux attribute:</p><pre>‽$; ls -Z kcat.conf<br>unconfined_u:object_r:user_home_t:s0 kcat.conf</pre><p>Then setroubleshoot shows a bunch of details about my environment, and the audit message we saw in journal earlier. That’s straight forward enough, we can apply the suggestion, no? Now I took pause and wanted to see what audit2allow will do:</p><pre>$; sudo ausearch -c &#39;kcat&#39; --raw | audit2allow<br>#============= container_t ==============<br>allow container_t user_home_t:file read;</pre><p>Many fewer words, and it allows a container_t to read user_home_t. Ah, that will allow all containers to read (when I pass more bind-mount on commandline), not just this config file, but all of my videos as well! I don&#39;t want to do that! How about we <a href="https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9-beta/html/using_selinux/troubleshooting-problems-related-to-selinux_using-selinux#fixing-an-analyzed-selinux-denial_troubleshooting-problems-related-to-selinux">relabel the kcat config as container-relevant</a> instead?</p><pre>‽$; sudo semanage fcontext -a -t container_t kcat.conf<br>ValueError: Type container_t is invalid, must be a file or device type</pre><p>Huh, container_t is not a type for files, I guess it&#39;s for processes instead (eg our in-container kcat). Where do I discover types of files that containers can access? Ahha, the images&#39; content or overlay directories should be a good place:</p><pre>$; podman images| rg kcat<br>docker.io/edenhill/kcat                   1.7.0                    19bf67fb247a  5 months ago   40.1 MB<br><br>$; ls -dZ .local/share/containers/storage/overlay-images/19bf67fb247a06236ec706184f071a70e87438af550f58fd2cc53a4a238fe548/<br>unconfined_u:object_r:container_ro_file_t:s0 .local/share/containers/storage/overlay-images/19bf67fb247a06236ec706184f071a70e87438af550f58fd2cc53a4a238fe548/</pre><p>container_ro_file_t fits well with our purpose: containers can read it, but not modify. It would be an additional Read-Only enforcement on top of bind,ro flag, to ensure the containers don&#39;t edit our config under us.</p><p>To apply to kcat.conf, we add a policy to the context store system-wide:</p><pre>‽$; sudo semanage fcontext -a -t container_ro_file_t kcat.conf</pre><p>And reapply the policy for our file, to “restore context” on it:</p><pre>$; restorecon kcat.conf</pre><p>Now kcat can read it, and huh I made a typo!</p><pre>$; podman run --mount type=bind,src=kcat.conf,dst=/kcat.conf,ro --rm -it --network=host edenhill/kcat:1.7.0 -F /kcat.conf<br>% Reading configuration from file /kcat.conf<br>% ERROR: /kcat.conf:1: No such configuration property: &quot;boostrap.seers&quot;</pre><p>Where does the user_home_t label comes from anyway? It was applied at file creation time, based on the path (or path glob) of the file. For example, I can create a random file under ~/.ssh/, and that file gains a different labels:</p><pre>$; touch ~/.ssh/test<br>$; ls -Z ~/.ssh/test<br>unconfined_u:object_r:ssh_home_t:s0 /home/hdhoang/.ssh/test</pre><p>But moving the kcat.conf file there keeps its current label</p><pre>$; mv kcat.conf ~/.ssh/test<br>$; ls -Z ~/.ssh/test<br>unconfined_u:object_r:container_ro_file_t:s0 /home/hdhoang/.ssh/test</pre><p>Until an explicit restorecon rereads current policies &amp; relabels it. Your videos &amp; your ssh config/keys have different labels by default!</p><p>I hope this post introduced some initial vocab around SElinux denial, and some considerations on how to address it on a case-by-case basis. It looks helpful as a systemwide access enforcement mechanism, not just for file but also <a href="https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9-beta/html/using_selinux/getting-started-with-selinux_using-selinux#benefits-of-selinux_getting-started-with-selinux">TCP/UDP ports/sockets</a>. However, I don’t know how well the debugging can scale to production use-cases.</p><p>After you leave, please try discovering some past denials on your workstation: sudo sealert.You may find something strange, eg gdb trying to read graphic device /dev/card0. Have fun sleuthing the reason!</p><p><em>Originally published at </em><a href="https://hdhoang.substack.com/p/podman-encountered-selinux"><em>https://hdhoang.substack.com</em></a><em> on January 28, 2022.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=446a17fa7242" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coccoc-engineering-blog/podman-encountered-selinux-its-somewhat-effective-446a17fa7242">podman encountered selinux (it’s somewhat effective!)</a> was originally published in <a href="https://medium.com/coccoc-engineering-blog">Coccoc Engineering Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Quick words on Vector]]></title>
            <link>https://medium.com/coccoc-engineering-blog/quick-words-on-vector-c18eb3ed4633?source=rss-2f187e89fee2------2</link>
            <guid isPermaLink="false">https://medium.com/p/c18eb3ed4633</guid>
            <category><![CDATA[observability]]></category>
            <category><![CDATA[vector]]></category>
            <dc:creator><![CDATA[hdhoang]]></dc:creator>
            <pubDate>Wed, 29 Dec 2021 08:02:02 GMT</pubDate>
            <atom:updated>2022-04-29T09:19:09.571Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<p>Today’s a quick introduction to Timber Vector. It’s a multi-purpose metrics&amp;log routing tool, <a href="https://vector.dev/docs/setup/deployment/">positioned as sending source agent and/or aggregation node</a>. We first trialed it in several log-to-metric pipelines, aggregating error rate &amp; latency histograms out of app log. But the most impactful application it delivered is a logging sidecar.</p><p>Originally, our php-fpm apps write messages directly to kafka. However, the CGI-style request-response model proved problematic with:</p><ul><li>conn set up, including TCP roundtrip, then SASL login roundtrip</li><li>each connection delivered 1 message</li><li>conn tear down, using up pod-&gt;broker TCP tuples</li></ul><p>This raised users’ request latencies, held up php-fpm process pool, and used kafka less efficiently without message batching.</p><p>Fortunately, the info we wanted to deliver is available from pod’s nginx log formatting. We set up a sidecar Vector listening on loopback syslog, with some minimal data editing, then producing to kafka a batch at a time.</p><pre># nginx config<br>log_format demo escape=json &#39;{&#39;<br>      &#39;&quot;user_agent&quot;:&quot;$http_user_agent&quot;,&#39;<br>      &#39;&quot;cookies&quot;:&quot;$http_cookie&quot;,&#39;<br>      &#39;&quot;event_time_float&quot;:&quot;$msec&quot;,&#39;<br>      &#39;&quot;datetime&quot;:&quot;$time_iso8601&quot;,&#39;<br>      &#39;&quot;ip&quot;:&quot;$remote_addr&quot;,&#39;<br>      &#39;&quot;uri&quot;:&quot;$request_uri&quot;,&#39;<br>      &#39;&quot;http_response_code&quot;:&quot;$status&quot;&#39;<br>      &#39;}&#39;;</pre><pre>map &quot;$request_uri&quot; $loggable {<br>      ~^/interesting/ 1;<br>      default 0;<br>}</pre><pre>access_log syslog:server=127.0.0.1:1514 demo if=$loggable;</pre><pre># vector config in TOML format</pre><pre># prometheus-format metrics at pod&#39;s ip:8998/metrics<br>[sources.internal_metrics]<br>type = &quot;internal_metrics&quot;<br>[sinks.vector_metrics]<br>type = &quot;prometheus&quot;<br>    inputs = [&quot;internal_metrics&quot;]<br>    address = &quot;0.0.0.0:8998&quot;</pre><pre># extract, transform, and store pipeline<br>[sources.syslog]<br>type = &quot;syslog&quot;<br>    mode = &quot;udp&quot;<br>    address = &quot;127.0.0.1:1514&quot;<br><br>[transforms.parse_json]<br>type = &quot;remap&quot;<br>    inputs = [&quot;syslog&quot;]<br><br>source = &quot;&quot;&quot;<br>log_data, err = parse_json(.message)</pre><pre># nginx log time_iso8601 sample &quot;datetime&quot;:&quot;2019-08-12T16:23:38+07:00&quot;<br># to parse event date/time from it:<br>datetime, err = split(log_data.datetime, pattern: &quot;+&quot;)[0]<br>log_data.event_time = replace(datetime, &quot;T&quot;, &quot; &quot;)<br>log_data.event_date, err = split(log_data.event_time, &quot; &quot;)[0]<br>del(log_data.datetime)<br><br>. = log_data<br>&quot;&quot;&quot;<br><br># For initial debugging<br># [sinks.stdout]<br># type = &quot;console&quot;<br>#    inputs = [&quot;parse_json&quot;]<br>#    encoding.codec = &quot;json&quot;<br><br>[sinks.logstore]<br>type = &quot;kafka&quot;<br>    inputs = [&quot;parse_json&quot;]<br>    encoding.codec = &quot;json&quot;<br><br>    batch = { max_events = 250 }<br>    compression = &quot;none&quot;<br>    librdkafka_options.&quot;compression.codec&quot; = &quot;zstd&quot;<br><br>    healthcheck = true<br>    librdkafka_options.&quot;client.id&quot; = &quot;${HOSTNAME}&quot;<br><br>    sasl.enabled = true<br>    bootstrap_servers = &quot;${KAFKA_BROKER_LIST}&quot;<br>    sasl.mechanism = &quot;SCRAM-SHA-256&quot;<br>    sasl.password = &quot;${KAFKA_SASL_PASSWORD}&quot;<br>    sasl.username = &quot;${KAFKA_SASL_ACCOUNT}&quot;<br>    topic = &quot;${KAFKA_TOPIC}&quot;</pre><p>Because the messages are batched, we can apply in-protocol compression on them, reducing transfer &amp; storage cost on kafka brokers. This pattern became well-used throughout our k8s deployments.</p><p>The parse_json transform above demonstrates vector’s home-grown <a href="https://vector.dev/docs/reference/vrl/">Remap Language (VRL)</a>. It has similar utility to Logstash grok or JRuby, but with an explicit compiling step at config parsing, to validate and avoid runtime errors. The go-esque error handling (<a href="https://vector.dev/docs/reference/vrl/errors/#305">if err != nil</a>), coupled with forceful quick override (fallible_op!() to abort processing on error), affords good iteration for early development, while still mark fallible calls explicitly for future review. Rust-inspired <a href="https://vector.dev/docs/reference/vrl/examples/#unhandled-fallible-assignment">compile error messages</a> with actionable suggestion save us from runtime surprises in the face of realworld complications. When surpises happen anyway, we can route such erroneous data to a <a href="https://vector.dev/highlights/2021-11-18-failed-event-routing/">secondary pipeline</a> for manual inspection &amp; replay. VRL also provides functions to <a href="https://vector.dev/docs/reference/vrl/functions/#redact">redact sensitive data</a>, or <a href="https://vector.dev/highlights/2021-11-18-csv-enrichment/">enrich raw data</a> with more descriptive values. To capture &amp; detect regression in processing, vector specifies a <a href="https://vector.dev/docs/reference/configuration/unit-tests/">unit-testing scheme</a> for transforms. Config writer can inject data at several steps to excerise the transforms, then assert that output events appear as expected. There was such out-there experiment as WASM-binary transformation, but it <a href="https://vector.dev/highlights/2021-08-23-removing-wasm/">was removed</a> in favor of Lua and VRL.</p><p>Compared to the Elastic beats+logstash combo, or Treasure Data fluent-bit/fluentd ecosystem, there are pros (single tool, transform stages testing, flexible routing with numerous sources &amp; sinks), and several cons:</p><ul><li>evolving configuration scheme, with no 1.0 on <a href="https://roadmap.vector.dev/">roadmap</a> yet</li><li>lacks of examples/tutorials, as well as old versions’ docs on the webpage</li><li>being 3rd-party to every potential sink &amp; source</li></ul><p>In early 2021, the acquisition into DataDog, a big player in ObsOps space, is a big boon. DD places vector at the center of <a href="https://www.datadoghq.com/blog/dash-2021-new-feature-roundup/#observability-pipelines">their upcoming pipeline platform</a>. The release cadence picked up pace, with clear upgrade guidance between versions.</p><p>Early 2022, ClickHouse community added a guide on using Vector for shipping log straight into CH: <a href="https://clickhouse.com/docs/en/integrations/vector-to-clickhouse/">https://clickhouse.com/docs/en/integrations/vector-to-clickhouse/</a>.</p><p>We have another kafka-to-compressed-file pipeline. Due to the clear ratio and decompression speed advantage, we agreed to do hourly rotation with Zstandard. We ended up using td-agent (a distribution of fluentd+plugins) calling zstd cmdline, mostly due to vector <a href="https://github.com/vectordotdev/vector/issues/2302">not supporting zstd with file sink yet</a>.</p><p>Regarding perf, the website <a href="https://web.archive.org/web/20210417234631/https://vector.dev/#performance">used to have a benchmark table</a> sourced from their <a href="https://github.com/vectordotdev/vector-test-harness#results">test-harness repo</a>, but skipped it in a recent redesign. There are some evaluations around, but this <a href="https://medium.com/ibm-cloud/log-collectors-performance-benchmarking-8c5218a08fea">article from 2021–09</a> doesn’t specify version of tested software. In our experience with the log-to-metrics extraction, a couple of vector pods could keep up with the k8s log volume which previously overwhelmed 8 logstash instances, at a fraction of memory &amp; CPU usage. While I’m writing this, vector <a href="https://vector.dev/releases/0.19.0/">released 0.19</a> which fixed some perf regressions, as well as adding opportunistic parallelism to some transformation types.</p><p>I hope to have piqued your interest in the tool. Let’s try browsing through <a href="https://vector.dev/docs/reference/vrl/examples/">their VRL samples &amp; find inspirations</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c18eb3ed4633" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coccoc-engineering-blog/quick-words-on-vector-c18eb3ed4633">Quick words on Vector</a> was originally published in <a href="https://medium.com/coccoc-engineering-blog">Coccoc Engineering Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[psmisc 23.2 killall doesn’t match long process names]]></title>
            <link>https://medium.com/coccoc-engineering-blog/psmisc-23-2-killall-doesnt-match-long-process-names-f8d777928938?source=rss-2f187e89fee2------2</link>
            <guid isPermaLink="false">https://medium.com/p/f8d777928938</guid>
            <category><![CDATA[debian-buster]]></category>
            <category><![CDATA[debian-bullseye]]></category>
            <category><![CDATA[killall]]></category>
            <category><![CDATA[debian-10]]></category>
            <category><![CDATA[debian-11]]></category>
            <dc:creator><![CDATA[hdhoang]]></dc:creator>
            <pubDate>Wed, 04 Aug 2021 10:10:15 GMT</pubDate>
            <atom:updated>2021-08-18T03:18:03.481Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<h3>psmisc 23.x killall doesn’t match long process names</h3><p>This is an <a href="https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=912748">old</a>, <a href="https://gitlab.com/psmisc/psmisc/-/commit/1188315cd037d73bf946a0003b70c6423cc330d2">fixed issue</a> (<a href="https://gitlab.com/psmisc/psmisc/-/merge_requests/28">with more fixes to come</a>), but I would like to highlight it for anyone having trouble with killall. It affects Debian10 buster (stable release <a href="https://wiki.debian.org/DebianBuster">from 2019 until 2021</a>) and Debian11 bullseye, plus derivative Ubuntu versions. Reproduction based on Debian bug #912748:</p><pre>❯ podman run -it registry.hub.docker.com/amd64/debian:buster-slim bash -c &#39;apt update -qq &amp;&amp; apt install -qqy psmisc procps; bash -i&#39;</pre><pre># ln -sf /bin/sleep 0123456789abcd &amp;&amp; ./0123456789abcd 1h &amp;<br># ln -sf /bin/sleep 0123456789abcde &amp;&amp; ./0123456789abcde 1h &amp;<br># ln -sf /bin/sleep 0123456789abcdef &amp;&amp; ./0123456789abcdef 1h &amp;</pre><p>With debian9, psmisc 22.21:</p><pre>psmisc-22.21# pgrep -fla abcd<br>261 ./0123456789abcd 1h<br>264 ./0123456789abcde 1h<br>267 ./0123456789abcdef 1h</pre><pre>psmisc-22.21# killall -v -0 0123456789abcd<br>Killed 0123456789abcd(261) with signal 0<br>psmisc-22.21# killall -v -0 0123456789abcde<br>Killed 0123456789abcde(264) with signal 0<br>psmisc-22.21# killall -v -0 0123456789abcdef<br>Killed 0123456789abcdef(267) with signal 0</pre><p>With debian10, psmisc 23.2:</p><pre>psmisc-23.2# pgrep -fla abcd<br>322 ./0123456789abcd 1h<br>325 ./0123456789abcde 1h<br>328 ./0123456789abcdef 1h</pre><pre>psmisc-23.2# killall -v -0 0123456789abcd<br>Killed 0123456789abcd(322) with signal 0<br>psmisc-23.2# killall -v -0 0123456789abcde<br>Killed 0123456789abcde(325) with signal 0<br>Killed 0123456789abcde(328) with signal 0<br>psmisc-23.2# killall -v -0 0123456789abcdef<br>0123456789abcdef: no process found</pre><p>With debian11, psmisc 23.4:</p><pre>psmisc-23.4# killall -v -0 0123456789abcd<br>Killed 0123456789abcd(329) with signal 0<br>psmisc-23.4# killall -v -0 0123456789abcde<br>Killed 0123456789abcde(332) with signal 0<br>Killed 0123456789abcde(335) with signal 0<br>psmisc-23.4# killall -v -0 0123456789abcdef<br>Killed 0123456789abcde(332) with signal 0<br>Killed 0123456789abcde(335) with signal 0</pre><p>You can imagine our surprise when a logrotate postrotate action didn&#39;t poke any process, and the services keep sending log to a deleted file descriptor. Fortunately, we don&#39;t use killall for other purposes, so the 15-character-prefix multikill didn&#39;t bite us.</p><p>Our developers noticed missing log before we rolled this to production. They also took the initiative to convert convoluted init.d scripts to declarative systemd units. This avoids both name-based guessing like killall/ pkill, and old-style PID-file based process management.</p><p>In the future, killall is looking into safer, non-pid-racing methods such as <a href="https://gitlab.com/psmisc/psmisc/-/issues/37">openat+pidfd</a>. Let&#39;s keep an eye out for such improvements, for situations where we can&#39;t apply cgroups or other namespacing methods.</p><p><em>Originally published at </em><a href="https://hdhoang.substack.com/p/psmisc-232-killall-doesnt-match-long"><em>https://hdhoang.substack.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f8d777928938" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coccoc-engineering-blog/psmisc-23-2-killall-doesnt-match-long-process-names-f8d777928938">psmisc 23.2 killall doesn’t match long process names</a> was originally published in <a href="https://medium.com/coccoc-engineering-blog">Coccoc Engineering Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kludging AAAA for a tailnet]]></title>
            <link>https://hdhoang.medium.com/kludging-aaaa-for-a-tailnet-d785262647bf?source=rss-2f187e89fee2------2</link>
            <guid isPermaLink="false">https://medium.com/p/d785262647bf</guid>
            <category><![CDATA[tailscale]]></category>
            <category><![CDATA[zero-trust]]></category>
            <category><![CDATA[dns]]></category>
            <category><![CDATA[jq]]></category>
            <dc:creator><![CDATA[hdhoang]]></dc:creator>
            <pubDate>Mon, 26 Jul 2021 13:59:26 GMT</pubDate>
            <atom:updated>2021-09-23T02:59:52.432Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<p>Tailscale is great. <a href="https://medium.com/u/fe5021f7cc83">Avery Pennarun</a> asked for <a href="https://nitter.1d4.us/apenwarr/status/1418220505950298112#m">questions</a>. Here’s my question: can we get more details on IPv6 for peers in the KB, please?</p><p>With MagicDNS enabled, we can resolve node.domain.example.beta.tailscale.net. to the tailnet 100.64/10 addresses:</p><pre>❯ nslookup peer.domain.example.beta.tailscale.net.<br>Server:  UnKnown<br>Address:  100.100.100.100</pre><pre>Name:    peer.domain.example.beta.tailscale.net<br>Address:  100.99.46.53</pre><p>Apps resolves &amp; caches such IPv4 addresses. However, when the peer disconnects from tailnet, or changes its address, our apps’ packets to old addresses would go out via non-encrypted IPv4 default routes:</p><pre># ip ro get 100.101.102.103<br>100.101.102.103 dev tailscale0  src 100.117.192.41<br># # that&#39;s correct &amp; fine<br># ip ro get 100.99.46.53<br>100.99.46.53 via 10.1.1.1 dev br-lan  src 10.9.9.9<br># # oh whoops, I hope we have additional encryption/authentication for these packets!!!</pre><p>The tailnet also allocate IPv6 address from <a href="https://tailscale.com/kb/1105/other-vpns/?q=fd7a">ULA subnet</a> fd7a:115c:a1e0::/48 with <a href="https://github.com/tailscale/tailscale/issues/1152#issuecomment-808837885">straight-forward embedding</a> of the <a href="https://github.com/tailscale/tailscale/blob/d37451bac6f38cc09b853b08b1dc8359ba767fa1/net/tsaddr/tsaddr.go#L104">3-octet tail</a> (heh):</p><pre>$ tailscale status -json | \<br>     jq -r &#39;.Peer[] | .DNSName + &quot;\t&quot; + .TailAddr&#39; | \<br>     perl -npe &#39;s/100\.(\d+)\.(\d+)\.(\d+)/sprintf(&quot;fd7a:115c:a1e0:ab12:4843:cd96:62%02x:%02x%02x&quot;,int($1),int($2),int($3))/e&#39;</pre><p>(Please keep in mind, the status -json data format is subject to change)</p><p>The <a href="https://nitter.1d4.us/bradfitz/status/1420239927233499147#m">core embedding</a> is 100.99.46.102 as fd7a:115c:a1e0:ab12:4843:cd96:98.99.46.102 (I don’t get why they <a href="https://github.com/tailscale/tailscale/blob/main/net/tsaddr/tsaddr.go#L63-L71">change 100 to 98</a> though, maybe to satisfy /104 mask somewhere). The ULA is inserted into route table as a /48 subnet, instead of exact-/32-one-host-only as with IPv4:</p><pre>❯ route -6 print fd7a*</pre><pre>IPv6 Route Table<br>==================<br>Active Routes:<br> If Metric Network Destination      Gateway<br>  4      5 fd7a:115c:a1e0::/48      On-link<br>  4    261 fd7a:115c:a1e0:ab12:4843:cd96:62ba:be22/128<br>                                    On-link</pre><p>As I understand, it’s more leak-proof than IPv4 addresses (and the convenient MagicDNS names). Sadly, the world is full of potholes, and tailscale <a href="https://github.com/tailscale/tailscale/blob/81cdd2f26c74859d7059c843c903d7b89291c0de/ipn/ipnlocal/local.go#L1745-L1756">explicitly discards IPv6 addresses</a> from MagicDNS answers for peers, even though <a href="https://tailscale.com/kb/1054/dns/?q=fd7a#how-can-i-test-my-dns-configuration">KB 1054 shows such an answer</a> in the Windows output.</p><p>Either way, we can generate a hosts file with custom -6 names for our current peers:</p><pre>tailscale status -json | jq &#39;<br>(.Self | [.TailscaleIPs[1], .HostName + &quot;-v6 &quot;, .HostName + &quot;.$animal-$dance.ts.net&quot;]) ,<br>(.Peer | map([.TailscaleIPs[1], .HostName +&quot;-v6 &quot;, .HostName + &quot;.$animal-$dance.ts.net&quot;]) |.[])<br>|@tsv&#39; --raw-output</pre><pre>fd7a:115c:a1e0:ab12:4843:cd96:62ba:be22 here-v6 here.yak-bebop.ts.net<br>fd7a:115c:a1e0:ab12:4843:cd96:6265:6667 hello-v6 hello.yak-bebop.ts.net<br>fd7a:115c:a1e0:ab12:4843:cd96:62ab:cd12 peer-v6 peer.yak-bebop.ts.net</pre><p>It’s not Magic. It’s downright manual like the primordial Inter-network, but it wfm. And it will cover <a href="https://tailscale.com/kb/1153/enabling-https/">HTTPS-enabled tailnet aliases</a> as well.</p><p>With “static” hosts file, we can also make services bind to the ULA tailnet address<a href="https://fly.io/blog/incoming-6pn-private-networks/"> the way Fly suggests for their 6PN network</a>:</p><pre>syncthing -gui-address=<a href="http://map-v6:8384/">http://$(uname -n)-v6:8384/</a></pre><p>Voila, only trusted, up-to-date remote management only.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d785262647bf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PSA: these DNS servers return bogus A for non-existent names]]></title>
            <link>https://hdhoang.medium.com/psa-these-dns-servers-return-bogus-a-for-non-existent-names-d1de21172e8c?source=rss-2f187e89fee2------2</link>
            <guid isPermaLink="false">https://medium.com/p/d1de21172e8c</guid>
            <dc:creator><![CDATA[hdhoang]]></dc:creator>
            <pubDate>Wed, 30 Jun 2021 11:35:50 GMT</pubDate>
            <atom:updated>2021-06-30T11:52:42.638Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<p>A honest resolver would say NXDOMAIN for nx.example.net:</p><pre>❯ dog -t A nx.example.net <a href="http://twitter.com/1">@1</a>.1.1.1<br>Status: NXDomain<br>SOA example.net. 1h00m00s A &quot;ns.icann.org.&quot; &quot;noc.dns.icann.org.&quot; 2021022375 2h00m00s 1h00m00s 14d0h00m00s 1h00m00s</pre><p>(good job, medium, on autolinking @ )</p><p>Not these guys, though. They want to direct your traffic to a blackhole (as of 2021–06):</p><pre>❯ dog -t ANY nx.example.net <a href="http://twitter.com/203">@203</a>.113.131.2<br>A nx.example.net. 10s   125.235.4.59</pre><pre>❯ dog -t A nx.example.net <a href="http://twitter.com/203">@203</a>.113.131.3<br>A nx.example.net. 10s   125.235.4.59</pre><p>This has been happening for a few years:</p><ul><li>2018 <a href="https://pastebin.com/8VF8hjRy">https://pastebin.com/8VF8hjRy</a><br>Though I don’t understand why someone in MSK timezone would use these DNS servers, maybe it’s a shared vendor software?</li><li>2018–06, very detailed <a href="https://www.qurium.org/alerts/dns-tampering-in-vietnam/">https://www.qurium.org/alerts/dns-tampering-in-vietnam/</a></li><li>2018 pcap <a href="https://packettotal.com/app/analysis?id=cf2318ae795e1beaf067a048565b5ede&amp;name=dns">https://packettotal.com/app/analysis?id=cf2318ae795e1beaf067a048565b5ede&amp;name=dns</a></li><li>2019–02&amp;04 <a href="https://hocvps.com/cai-dat-lets-encrypt/comment-page-14/#comment-36284">https://hocvps.com/cai-dat-lets-encrypt/comment-page-14/#comment-36284</a></li><li>2019–07 <a href="https://dockerquestions.com/2019/07/10/i-got-problem-while-using-nginx-to-direct-requests-to-services-defined-in-docker-compose-yml/">https://dockerquestions.com/2019/07/10/i-got-problem-while-using-nginx-to-direct-requests-to-services-defined-in-docker-compose-yml/</a><br>This one is SCARY, something was allocated the address, and could have mitm’d everyone else</li><li>2021–03 <a href="https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=985809">https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=985809</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d1de21172e8c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kafka under page fault pressure]]></title>
            <link>https://medium.com/coccoc-engineering-blog/kafka-under-page-fault-pressure-f157d61b82e7?source=rss-2f187e89fee2------2</link>
            <guid isPermaLink="false">https://medium.com/p/f157d61b82e7</guid>
            <category><![CDATA[jvm]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[mmap]]></category>
            <category><![CDATA[kafka]]></category>
            <dc:creator><![CDATA[hdhoang]]></dc:creator>
            <pubDate>Wed, 30 Jun 2021 11:28:19 GMT</pubDate>
            <atom:updated>2021-08-03T05:38:45.416Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<p>There are times to talk <a href="https://jvns.ca/blog/2021/05/24/blog-about-what-you-ve-struggled-with/">about failures</a>. You can take away some reference links from our investigation so far:</p><ul><li>JVM GC pause from background IO during <a href="https://engineering.linkedin.com/blog/2016/02/eliminating-large-jvm-gc-pauses-caused-by-background-io-traffic">GC log file write</a> (Other time in <a href="https://stackoverflow.com/q/65111590">GC log</a>), fixable by writing to tmpfs</li><li>JVM pause because of <a href="https://www.evanjones.ca/jvm-mmap-pause-finding.html">hsperfdata file</a> write, at GC and safepoint, fixable by -XX:+PerfDisableSharedMem</li><li>System pagefault/page scan impact <a href="https://www.evanjones.ca/jvm-mmap-pause.html">on mmap/JVM FileChannel</a>. Applications don’t explicitly issue I/O, so they <a href="https://events.static.linuxfound.org/sites/events/files/lcjp13_moriya.pdf">don’t expect access delay</a>.</li><li>Update (2021–07): Qumulo used perf to investigate their mmap/munmap latency <a href="https://qumulo.com/blog/page-faults-and-high-performance-storage/">https://qumulo.com/blog/page-faults-and-high-performance-storage/</a> and DoorDash too <a href="https://doordash.engineering/2021/04/01/examining-problematic-memory-with-bpf-perf-and-memcheck/">https://doordash.engineering/2021/04/01/examining-problematic-memory-with-bpf-perf-and-memcheck/</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/1*mRmpMw4Nyly2jfKgwrRCKw.png" /></figure><p>For tracking a segment file’s metadata, Kafka opens 2 index/timeindex mmaps, around 10MB each:</p><pre>❯ lsof -p $(pgrep -f Kafka) | grep test-2<br>java    8555 cp-kafka  mem       REG                9,1   10485756   63703507 /var/lib/kafka/test-2/00000000000000000000.timeindex<br>java    8555 cp-kafka  mem       REG                9,1   10485760   63703506 /var/lib/kafka/test-2/00000000000000000000.index<br>java    8555 cp-kafka  139u      REG                9,1          0   63703505 /var/lib/kafka/test-2/00000000000000000000.log</pre><p>We observe increased producer latencies when the servers are reclaiming memory. The graphs below are:</p><ul><li>system free memory, from <a href="https://www.collectd.org/wiki/index.php/Plugin:Memory">collectd Memory plugin</a> (zoomed to the last 2GB, flipped so that higher is worse). These servers have no swap configured</li><li>p99 of kafka.network:type=RequestMetrics,name=TotalTimeMs,request={Produce} , exported using <a href="https://github.com/banzaicloud/kafka-operator/blob/3af3431afbe0377986de43a67eec543b34666793/pkg/sdk/v1beta1/kafkacluster_types.go#L836-L842">banzaicloud jmx_exporter configuration</a> (higher is worse)</li><li>kafka_Coordinator_Group_GroupMetadataManager_NumGroupsPreparingRebalance corresponds to unstable consumer groups managed by the __consumer_offsets partition-leader (roughly, because there are apps which periodically unsubscribe by design too)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_AZvvY0r2zHPeyaa-MpwOQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZeoWjl38WUi1cJJjedDxUQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RoMS0VAVRfUawcGL9j75tw.png" /></figure><p>Starting after 17:00, the colocated Clickhouse database on the same servers execute periodic disk+memory heavy queries. When linux wants to reclaim some RAM for new allocations, the file-backed mmap indices are prime candidates. The files get flushed to disk, and need to be read back for the next update. This blocks the network threads serving producers. As we understand, this is a large-scale version of the hsperfdata situation.</p><p>The consumer group members <a href="https://chrzaszcz.dev/2019/06/kafka-heartbeat-thread/">periodically checks in</a> with GroupCoordinator (by default the deadline is heartbeat.interval.ms=3000 ). When they are unlucky, the check-in happens when Kafka is blocked on IO, causing spurious heartbeat expiration:</p><pre>[2021-06-28 17:09:54,675] INFO [GroupCoordinator 8]: Preparing to rebalance group A in state PreparingRebalance with old generation 960 (__consumer_offsets-47) (reason: removing member kafka-python-2.0.1-6724cef1-22fe-40e1-af10-a09a5fd44cc3 on heartbeat expiration) (kafka.coordinator.group.GroupCoordinator)<br>[2021-06-28 17:09:54,676] INFO [GroupCoordinator 8]: Preparing to rebalance group B in state PreparingRebalance with old generation 587 (__consumer_offsets-31) (reason: removing member kafka-python-2.0.1-3ffcf8e4-2ceb-4a77-8fc6-d63c105b4467 on heartbeat expiration) (kafka.coordinator.group.GroupCoordinator)<br>[2021-06-28 17:09:54,694] INFO [GroupCoordinator 8]: Preparing to rebalance group C in state PreparingRebalance with old generation 5899 (__consumer_offsets-39) (reason: removing member app.modules.log-ebc11b25-f1c8-4c1d-a90f-6ada3b345aca on heartbeat expiration) (kafka.coordinator.group.GroupCoordinator)</pre><p>Management topic __consumer_offsets as well as data topics have ISR shrinking &amp; expanding back:</p><pre>[2021-06-28 17:07:40,364] INFO [Partition __consumer_offsets-7 broker=8] Shrinking ISR from 8,6,5 to 8 (kafka.cluster.Partition)<br>[2021-06-28 17:07:40,406] INFO [Partition __consumer_offsets-39 broker=8] Shrinking ISR from 8,3,2 to 8 (kafka.cluster.Partition)<br>[2021-06-28 17:07:40,825] INFO [Partition __consumer_offsets-7 broker=8] Expanding ISR from 8 to 8,5 (kafka.cluster.Partition)<br>[2021-06-28 17:07:40,929] INFO [Partition __consumer_offsets-7 broker=8] Expanding ISR from 8,5 to 8,5,6 (kafka.cluster.Partition)<br>[2021-06-28 17:07:41,010] INFO [Partition __consumer_offsets-31 broker=8] Expanding ISR from 8 to 8,2 (kafka.cluster.Partition)<br>[2021-06-28 17:07:41,017] INFO [Partition __consumer_offsets-47 broker=8] Expanding ISR from 8 to 8,4 (kafka.cluster.Partition)</pre><p>For more untimely, or longer pauses, the broker can even lose its <a href="https://medium.com/coccoc-engineering-blog/distributed-computing-consensus-protocol-part-1-d461a151368b?source=rss-b5c0e13a5ff------2">ZK session</a>, expiring its ephemeral znode. When that happens it loses all topic leadership rights, and the Kafka cluster enters much wasteful rebalancing.</p><p>We have applied <a href="https://docs.confluent.io/platform/current/kafka/deployment.html">recommended</a> GC and system tunings, and also raised zookeeper.session.timeout.ms from 6s to 30s. Now we don’t have a better solution than <a href="https://kafka.apache.org/documentation.html#basic_ops_cluster_expansion">migrating the brokers</a> out of these servers. Thank to our system for <a href="https://medium.com/coccoc-engineering-blog/secret-management-architecture-9d3a575d7fb?source=rss-b5c0e13a5ff------2">secret management</a> and <a href="https://medium.com/coccoc-engineering-blog/adding-authorization-to-a-running-kafka-cluster-e13e39c5b70e?source=rss-b5c0e13a5ff------2">access control</a>, we could survey and identify clients on each cluster, and switch them to a CNAME-based bootstrap server list, moving clear of the problematic brokers.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f157d61b82e7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coccoc-engineering-blog/kafka-under-page-fault-pressure-f157d61b82e7">Kafka under page fault pressure</a> was originally published in <a href="https://medium.com/coccoc-engineering-blog">Coccoc Engineering Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An nginx mis-ssl story]]></title>
            <link>https://medium.com/coccoc-engineering-blog/an-nginx-mis-ssl-story-6ce246c6cfae?source=rss-2f187e89fee2------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ce246c6cfae</guid>
            <category><![CDATA[vagrantfile]]></category>
            <category><![CDATA[legacy]]></category>
            <category><![CDATA[debian]]></category>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[trap]]></category>
            <dc:creator><![CDATA[hdhoang]]></dc:creator>
            <pubDate>Wed, 31 Mar 2021 11:05:08 GMT</pubDate>
            <atom:updated>2021-03-31T11:05:08.492Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<p>In this post we would like to present an issue we met with nginx, due to using old and deprecated config method.</p><p>We have prepared <a href="https://gist.github.com/hdhoang/c9e9f062c82e8556aa66091468140fc4">a gist with Vagrantfile</a> that you can play along, based on current stable Debian 10 (buster), with nginx 1.14. It prepares nginx, hostsentries, a CA+certificate bundle, and finally copies our config files to /vagrant/for later use. After cloning the gist, you can start the environment with vagrant up, enter it as root with vagrant ssh -c &#39;sudo bash&#39;, and tear it down with vagrant destroy.</p><p>Our adventure starts with simple HTTP site:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/434a53067bbe72bbb295eddfe9ef1638/href">https://medium.com/media/434a53067bbe72bbb295eddfe9ef1638/href</a></iframe><p>With our custom hostsfile, we can check that it works:</p><pre>; curl <a href="http://simple.site.example/">http://simple.site.example</a><br>simple.site.example</pre><p>And at every step, nginx has no complaint about our conf files:</p><pre>; nginx -t<br>nginx: the configuration file /etc/nginx/nginx.conf syntax is ok<br>nginx: configuration file /etc/nginx/nginx.conf test is successful<br>; nginx -s reload</pre><p>To keep up with the modern web, we enable https on the simple site, as a new server block:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de14b2ff047e093fac065107f672b9c5/href">https://medium.com/media/de14b2ff047e093fac065107f672b9c5/href</a></iframe><p>This is the state of demo after we do vagrant up. HTTPS now works, as long as we trust our custom CA in the demo environment:</p><pre>; curl --cacert /etc/nginx/conf.d/CA.pem <a href="https://simple.site.example/">https://simple.site.example</a><br>simple.site.example</pre><p>Next we make another site, but bundling the HTTP+HTTPS settings in the same block to avoid repeating the content:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/03c11f1f6b115d6796a81b91f62a77ee/href">https://medium.com/media/03c11f1f6b115d6796a81b91f62a77ee/href</a></iframe><p>The sites both work:</p><pre>; cp -v /vagrant/worse-is-better.conf /etc/nginx/conf.d/<br>‘/vagrant/worse-is-better.conf’ -&gt; ‘/etc/nginx/conf.d/worse-is-better.conf’<br>; nginx -t<br>nginx: the configuration file /etc/nginx/nginx.conf syntax is ok<br>nginx: configuration file /etc/nginx/nginx.conf test is successful<br>; nginx -s reload</pre><pre>; curl <a href="http://simple.site.example/">http://simple.site.example</a><br>simple.site.example<br>; curl --cacert /etc/nginx/conf.d/CA.pem <a href="https://simple.site.example/">https://simple.site.example</a><br>simple.site.example</pre><pre>; curl <a href="http://worse-is-better.site.example/">http://worse-is-better.site.example</a><br>it is better here<br>; curl --cacert /etc/nginx/conf.d/CA.pem <a href="https://worse-is-better.site.example/">https://worse-is-better.site.example</a><br>it is better here</pre><p>Words come from branding to shorten the name to better.site only, so we copy the config over to a new file:</p><pre>; sed &#39;s/worse-is-//g&#39; &#39;/etc/nginx/conf.d/worse-is-better.conf&#39; &gt;&gt; &#39;/etc/nginx/conf.d/better.conf&#39;<br>; diff &#39;/etc/nginx/conf.d/worse-is-better.conf&#39; &#39;/etc/nginx/conf.d/better.conf&#39;<br>4c4<br>&lt; server_name worse-is-better.site.example;<br>---<br>&gt; server_name better.site.example;</pre><pre>; nginx -t<br>nginx: the configuration file /etc/nginx/nginx.conf syntax is ok<br>nginx: configuration file /etc/nginx/nginx.conf test is successful<br>; nginx -s reload</pre><p>And with that, we have broken HTTP support on all sites:</p><pre>; curl simple.site.example<br>&lt;html&gt;<br>&lt;head&gt;&lt;title&gt;400 The plain HTTP request was sent to HTTPS port&lt;/title&gt;&lt;/head&gt;<br>&lt;body bgcolor=”white”&gt;<br>&lt;center&gt;&lt;h1&gt;400 Bad Request&lt;/h1&gt;&lt;/center&gt;<br>&lt;center&gt;The plain HTTP request was sent to HTTPS port&lt;/center&gt;<br>&lt;hr&gt;&lt;center&gt;nginx/1.14.2&lt;/center&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;<br>; curl -I worse-is-better.site.example<br>HTTP/1.1 400 Bad Request<br>Server: nginx/1.14.2</pre><p>After disabling better.conf, let’s review what happened. Our config files, in aggregate, have these listen and ssl_on directives in different server blocks:</p><pre>; cd /etc/nginx/conf.d/ &amp;&amp; grep -E &#39;listen|ssl &#39; *conf*<br>better.conf.disabled: listen 80;<br>better.conf.disabled: listen 443;<br>better.conf.disabled: ssl on;</pre><pre>simple-https.conf: listen 443;<br>simple-https.conf: ssl on;</pre><pre>simple.conf: listen 80;</pre><pre>worse-is-better.conf: listen 80;<br>worse-is-better.conf: listen 443;<br>worse-is-better.conf: ssl on;</pre><p>By alphabetical application of the files, we inadvertently made nginx expect TLS protocol on TCP port 80 (thus it said “sent to HTTPS port”), while previously simple.conf opened port 80 as plain HTTP protocol (and <a href="https://en.wikipedia.org/wiki/Worse_is_better">worse-is-better</a> had no impact). This <a href="https://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl">obsolete directive</a> gives a warning with nginx&gt;=1.15, with a fix suggestion:</p><pre>nginx: [warn] the &quot;ssl&quot; directive is deprecated, use the &quot;listen … ssl&quot; directive instead in /etc/nginx/conf.d/better.conf:8</pre><p>Thus, we have to review our config files to disarm this trap for the future:</p><pre>-listen 443;<br>-ssl on;<br>+listen 443 ssl;</pre><p>There is another piece of the puzzle we have in the baseline Vagrant setup:</p><pre>    # disable Debian nginx welcome site<br># In most cases, administrators will remove this file from sites-enabled/ and<br># leave it as reference inside of sites-available where it will continue to be<br># updated by the nginx packaging team.<br>    ln -vsf /dev/null /etc/nginx/sites-enabled/default</pre><p>Welcome-to-nginx config in /etc/nginx/sites-available/default specifies a default_server for port 80. If we had such a catch-all server block, it would take priority and keep our port 80 as plain-HTTP, pre-empting our incident above. Such a block with server_name _ is a good place to log unexpected requests arriving at our nginx, potentially helps detecting and debugging other misconfigurations.</p><p>Further reading:</p><ul><li><a href="https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/">Common nginx pitfalls</a> on nginx wiki</li><li><a href="https://www.digitalocean.com/community/tutorials/understanding-nginx-server-and-location-block-selection-algorithms">Higher level </a><a href="https://www.digitalocean.com/community/tutorials/understanding-nginx-server-and-location-block-selection-algorithms">server_name and </a><a href="https://www.digitalocean.com/community/tutorials/understanding-nginx-server-and-location-block-selection-algorithms">location matching</a>, by DigitalOcean</li></ul><p>Hope this helps!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ce246c6cfae" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coccoc-engineering-blog/an-nginx-mis-ssl-story-6ce246c6cfae">An nginx mis-ssl story</a> was originally published in <a href="https://medium.com/coccoc-engineering-blog">Coccoc Engineering Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>