Skip to content

Instantly share code, notes, and snippets.

@andsens
andsens / util-linux-nsenter--keep-caps-bug.md
Last active October 31, 2026 16:27
`nsenter --keep-caps` bug

nsenter --keep-caps with --user alone: an analysis

Written by an AI coding assistant (Claude); line numbers are from util-linux master at becdb8b, and the same code is in v2.42.3.

What happens

main() enters namespaces in two passes, the user namespace last unless the first pass fails without it (nsenter.c:915-926):

@andsens
andsens / Dockerfile
Created August 4, 2026 18:55
Test harness for testing DNS rebind attacks (not complete! illustration of an internal test)
FROM node:20.19.5-alpine3.22
ARG NPM_TOKEN
USER root
RUN apk add --no-cache su-exec bind
COPY src/__tests__/assets/named.conf src/__tests__/assets/overrides.rpz /etc/bind/
RUN mkdir /var/log/bind
WORKDIR /library
COPY tools/_.npmrc .npmrc
@andsens
andsens / cluster.json
Last active May 29, 2025 12:39
Phoenix cluster config schemas
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"$schema": {
"type": "string"
},
"domain": {
"description": "The domain of the cluster",
"type": "string",
#!/usr/bin/env bash
set -Eeo pipefail; shopt -s inherit_errexit
main() {
DOC="step-kms-renew - Renew a KMS backed certificate
Usage:
step-kms-renew [options] (<crt-file>|<kms-crt-uri>) <kms-key>
Options:
--context=CTX The context name to apply for the given command.
@andsens
andsens / notebook.sh
Last active October 26, 2022 11:38
Bash notebook for nifty things
#!/usr/bin/env bash
# wait for backgrounded jobs and propagate $?>0.
local pid
while read -r pid; do wait "$pid"; done < <(jobs -p)
# wait for backgrounded jobs, propagate $?>0, and exit early on failure.
while (($(jobs -p | wc -l) > 0)); do
if wait -n; then
:
@andsens
andsens / patch-bluetooth-driver.sh
Created February 2, 2021 07:34
Patches the linux bluetooth driver to handle dongles that report they are CSR, but really aren't
#!/usr/bin/env bash
# https://askubuntu.com/questions/1168123/how-do-i-get-my-bluetooth-device-working/1192200#1192200
set -e
SCRIPTDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
main() {
local kernver
kernver=$(uname -r)
sudo apt update
#!/usr/bin/env bash
# Inspired by https://blog.nimamoh.net/yubi-key-gpg-wsl2/
# Guide:
# Install GPG on windows & Unix
# Add "enable-putty-support" to gpg-agent.conf
# Download wsl-ssh-pageant and npiperelay and place the executables in "C:\Users\[USER]\AppData\Roaming\" under wsl-ssh-pageant & npiperelay
# https://github.com/benpye/wsl-ssh-pageant/releases/tag/20190513.14
# https://github.com/NZSmartie/npiperelay/releases/tag/v0.1
# Adjust relay() below if you alter those paths
@andsens
andsens / Component.tsx
Created April 18, 2020 07:46
FragmentReference reproduce for relay-tools/relay-compiler-language-typescript
import { ComponentPaginationQuery } from "./artifacts/ComponentPaginationQuery.graphql";
import { Component_items$key } from "./artifacts/Component_items.graphql";
export function Component(props: { itemsFragment: Component_items$key }) {
const {
data: { items },
} = usePaginationFragment<ComponentPaginationQuery, Component_items$key>(
graphql`
fragment Component_items on Viewer
@argumentDefinitions(
@andsens
andsens / naval_fate.sh
Created July 29, 2019 22:26
Demonstration of docopt.sh
#!/usr/bin/env bash
DOC="Naval Fate.
Usage:
naval_fate.sh ship <name> move <x> <y> [--speed=<kn>]
naval_fate.sh ship shoot <x> <y>
Options:
--speed=<kn> Speed in knots [default: 10].
@andsens
andsens / Dockerfile
Last active June 6, 2019 14:14
Kibana docker container with pre-optimized bundles
ARG KIBANA_VERSION
FROM docker.elastic.co/kibana/kibana:${KIBANA_VERSION}
ARG KIBANA_VERSION
ARG LOGTRAIL_VERSION
USER root
RUN NODE_OPTIONS="--max_old_space_size=4096" kibana-plugin install https://github.com/sivasamyk/logtrail/releases/download/v${LOGTRAIL_VERSION}/logtrail-${KIBANA_VERSION}-${LOGTRAIL_VERSION}.zip
COPY kibana.yaml /usr/share/kibana/config/kibana.yml
COPY elasticsearch.repo /etc/yum.repos.d/elasticsearch.repo