Linux misc:
# Where is the file
find / -name "docker.sock" 2>/dev/null
# Remove user ubuntu from group floppy
gpasswd -d ubuntu floppy
Checking connectivity:
nc -v <ip-address> <port>
# timeout 1 sec
nc -v -w1 <ip-address> <port>
# nc -v -w1 1.2.3.4 80
# nc: connect to 1.2.3.4 port 80 (tcp) timed out: Operation now in progress
# curl with max timeout 1 sec
curl -m 1 http://my-svc.my-ns.svc.cluster.local
# If needing to specify what to resolve
curl --resolve "hello-world.example:80:$( minikube ip )" -i http://hello-world.example
# Checksums
echo '9016f6048ff9827ef58934e98f28a8026634c10b4e6fcc1df49451038a23a9aa kube-apiserver' |
sha256sum --check
sha512sum binaries/* > checksums.txt
crictl ps
crictl ps -a
watch -n2 crictl ps -a
# find container based on e.g. falco container_id
crictl ps -id f86cd629e71c
# find pod info based on pod id found in container info
crictl pods -id cab6dafd045d5
# Asked for formatting displaying 'time in nanoseconds'
falco --list |grep nano
# Unbuffered
falco -U
# Unbuffered, events of particular kind
falco -U | grep "Package management process"
man Dockerfile
man docker-run
# Run in PID kernel namespace of other container
docker run -d --name=c2 --pid=container:c1 nginx:alpine sleep infinity
# Run in process host namespace (e.g. run htop in container, showing entire host)
docker run --pid=host some-image-with-htop htop
cd /etc/kubernetes/pki
# show certificate
openssl x509 -text -noout -in ca.crt
# Check if certificate is signed by certificate authority
openssl verify -verbose -CAfile ca.crt apiserver.crt
# Sign certificate with Kubernetes CA (creates valid cert to set up user in kubeconfig)
openssl x509 -req -in /root/60099.csr -CA /etc/kubernetes/pki/ca.crt -CAkey /etc/kubernetes/pki/ca.key -CAcreateserial -out /root/60099.crt -days 500
apparmor_status
apparmor_parser <profile-file>
trivy image httpd:2.4.39-alpine |grep -E 'CVE-2016-9841|CVE-this|CVE-that'
# -n: Create 16-char length base64 pw without newline being appended to value
echo -n "this-is-very-sec" |base64
# re-encrypt all secrets
k get secret -A -o yaml | k replace -f -
# read secret from etcd
# Lookup connection params from docs
ETCDCTL_API=3 etcdctl --cacert=/etc/kubernetes/pki/etcd/ca.crt --cert=/etc/kubernetes/pki/apiserver-etcd-client.crt --key=/etc/kubernetes/pki/apiserver-etcd-client.key --endpoints=127.0.0.1:2379 get /registry/secrets/one/s2
# from name to pod, to container, to command, to PID
crictl pods --name collector1
crictl ps --pod a61e29997e607
crictl inspect e18e766d288ac | grep args -A1
ps aux |grep <command-executed-in-pod>
# trace ls command
strace ls
# strace with summary of calls and number of calls
strace -cw ls
# attach to pid 1945, following forks
# break after while (ctrl+c), then view summary
strace -cw -p 1945 -f
ls -al /proc/1945
cd /proc/1945
# root filesystem of container
ls -al /proc/1945/root/
# File descriptors
ls -al /proc/1945/fd/
# The executable
ls -al /proc/1945/exe
# Apparmor settings
cat /proc/1/attr/current
# Examine contents of file descriptors (e.g. name of k create secret generic <name-of-secret>)
cat ./fd/10 | grep <name-of-secret>
# Binary file (standard input) matches
cat ./fd/10 | strings | grep <name-of-secret>
cat ./fd/10 | strings | grep <name-of-secret> -B5 -A15
# Exploring capabilities
cat /proc/1234/status | grep Cap
# decode CapBnd set:
capsh --decode=0000003fffffffff
# env
cat environ
# Examine process tree including pids
pstree -p
# Find process listening on port 1234
#
# Using netstat, to install
apt install net-tools
#
# -u adds UDP
# -a all sockets (default: connected)
netstat -tulpan | grep 1234
netstat -plnt | grep 1234
# using lsof
lsof -i :1234
# Update repositories
apt update
apt-get update
# Search package to install
apt-cache search kubetail
apt install kubetail
# List & examine
apt list
apt show kube-bench
# Uninstall
apt remove kube-bench
k kustomize overlays/accept | kube-linter lint -
k kustomize overlays/accept | kubesec scan -
kubectl get --raw "/api/v1/nodes/cks8930-node1/proxy/configz" | jq