This is an experiment to learn Alpine, ARM, Containers, Security, and Enterprise Infrastruicture
Use any of this at your own risk!!
Tools used, but may be swapped out with preffered container technology
- 4x 8GB Raspberry Pi 4
- 4x 500GB SSDs
- Alpine – Minimal based Linux Distribution
- NerdCtl – Command line utility to administer containerd
- Container Network Interface
- [SmallStep-CA]
- [Authelia]
- [Vaultwarden]
- [Dashy]
- [Uptime Kuma]
- [Netbox]
- [Minio]
- [Keepalived]
- [DRBD]
- Raspberry Pi CM4 emmc configuration
- Alpine Installation
- Disk Partitioning
- File System Formating
- fstab file format
For Cm4
- Install RPIBoot in Windows
- Jumper J2
- Create usercfg.txt
- Add
otg_mode=1
for the USB ports to work - remove jumper
- Unplug NVME Drive before install to install on emmc
- If you own a dns name us it or home.arpa RFC Reference
- do a sys install on the mmcblk0
- poweroff
- plug in NVME
- boot
- fdisk /dev/nvme0n1
- Create new partition
- mkfs.ext4 /dev/nvme0n1p1
- Note UUID
- apk add nano
- edit fstab
- UUID=14886657-84eb-4cec-85a7-de78cdfd1724 / ext4 defaults 0 2
- mount -a
- date
- chronyc -a sources
- chronyc -a tracking
- chronyc -a 'burst 4/4'
- chronyc -a makestep
- Alpine Packages
- Containerd Installation
- Container Network Interface (CNI) Installation
- NerdCTL Installation
- nano /etc/apk/repositories
- uncomment community in addition to main
- apk update
- apk add containerd iptables ip6tables
- rc-service containerd start
- rc-update add containerd
- cd /home/thor/
- wget https://github.com/containernetworking/plugins/releases/download/v1.1.1/cni-plugins-linux-arm64-v1.1.1.tgz
- wget https://github.com/containerd/nerdctl/releases/download/v1.0.0/nerdctl-1.0.0-linux-arm64.tar.gz
- cp nerdctl-1.0.0-linux-arm64.tar.gz /usr/local/bin/
- cd /usr/local/bin/
- tar -xzf nerdctl-1.0.0-linux-arm64.tar.gz
- rm nerdctl-1.0.0-linux-arm64.tar.gz
- cd /home/thor/
- mkdir -p /opt/cni/bin
- cp cni-plugins-linux-arm64-v1.1.1.tgz /opt/cni/bin/
- tar -xzf cni-plugins-linux-arm64-v1.1.1.tgz
- rm cni-plugins-linux-arm64-v1.1.1.tgz
- Basic Dcoker Compose File Layout
- DNS
- DHCP
- DNS/DHCP Security Best Practices
- Docker User Group
- Docker Environment file
Use the Instructions from Pi-Hole Quickstart
- Place the docker-compose.yml file in the /srv folder to keep all container files on the NVME or external storage
- Create the below folder structure under srv
- config – Used to store configutaion files for all containers
- data – Used to store data files for all containers
- In future labs, we will be able to backup all of our configurations or data quickly by just grabbing one folder
cd /srv/config/pihole
mkdir vol
mkdir env
- For every container, we will create the same three folders: vol for persistent volumes, env for environment variables, and secrets to store passwords
- cd /srv/config/pihole/vol/
mkdir etc-pihole
mkdir etc-dnsmasq.d
- Update docker-compose to use the recently created folders
- Try processing the docker compose file. First change directory to /srv. My most often used commands:
nerdctl compose up --detach
nerdctl compose ps
nerdctl compose down
nerdctl compose logs
nerdctl compose logs --follow
nerdctl compose config
nerdctl compose pull
- Use the logs option to find the auto generated admin password
- Move variables to use an environment file
- Do not need secrets because random password is stored encrypted in pihole volume
- Sometimes environment variables are used just to set the initial password when spinning up a container. Once the password is stored in an encrypted format within the data or configuration file, remove all references to password environment variables and store passwords in a password database
nerdctl exec -it pihole pihole -a -p
- Run
ps aux
Notice the user the pi processes are running. We want to create users for the pi container to runas - Enter the container with
nerdctl exec -it pihole /bin/bash
and then docat /etc/passwd
Note the pihole userid and www-data userid
exit
to leave container back to the host 19.Create a pihole user and piwww useradduser pihole --disabled-password
adduser pihole_www-data --disabled-password
cat /etc/passwd
- Note the userid of each, example 1001 and 1002
- Edit environment variables - PIHOLE_UID: 1001 - PIHOLE_GID: 1001 - WEB_UID: 1002 - WEB_GID: 1002
- Down and up the compose file or just up it again
- Rootless Containers
nerdctl rootless Upgrade Alpine to New Release
- Required rootlesskit and slirp4netns can only be found in the edge repositories
- edit /etc/apk/repositories
- Comment out current version and uncomment edge main and community
apk update
apk add --upgrade apk-tools
apk upgrade --available
apk install rootlesskit
needed by containerd-rootless.shapk install slirp4netns
needed by containerd-rootless.shapk add iproute2-minimal
needed by containerd-rootless.shmodprobe tun
Need to add instructions to include on startupmkdir /run/user
chmod 1777 /run/user
Sticky bit is important- create file /etc/profile.d/xdg_runtime_dir.sh
if test -z "${XDG_RUNTIME_DIR}"; then
export XDG_RUNTIME_DIR=/run/user/$(id -u)
if ! test -d "${XDG_RUNTIME_DIR}"; then
mkdir "${XDG_RUNTIME_DIR}"
chmod 0700 "${XDG_RUNTIME_DIR}"
fi
fi
- Set password to the pihole user to login and out, then disable
- passwd pihole temppass
- login pihole
- exit
- passwd -l pihole
- Switch to the pihole user
su - pihole
the dash is important to set the XDG_RUNTIME_VARIABLE - edit /etc/subuid
- pihole:231072:65536
- edit /etc/subgid
- pihole:231072:65536
containerd-rootless.sh
nerdctl rootless Upgrade Alpine to New Release
- Required rootlesskit and slirp4netns can only be found in the edge repositories
- edit /etc/apk/repositories
- Comment out current version and uncomment edge main and community
apk update
apk add --upgrade apk-tools
apk upgrade --available
apk add iproute2-minimal
needed by containerd-rootless.shapk add curl
need to check github for most recent versionmodprobe tun
Need to add instructions to include on startupmodprobe ip_tables
modprobe ip6_tables
- sysctl net.ipv4.ip_unprivileged_port_start=0 #needed to bind to lower ports
- create file /etc/profile.d/xdg_runtime_dir.sh
if test -z "${XDG_RUNTIME_DIR}"; then
export XDG_RUNTIME_DIR=/tmp/$(id -u)
if ! test -d "${XDG_RUNTIME_DIR}"; then
mkdir "${XDG_RUNTIME_DIR}"
chmod 0700 "${XDG_RUNTIME_DIR}"
fi
fi
- Switch to the pihole user
su - pihole
the dash is important to set the XDG_RUNTIME_VARIABLE - edit /etc/subuid
- pihole:100100000:65536
- edit /etc/subgid
- pihole:100100000:65536
- apk add shadow-subids
-
apk add util-linux-misc
-
cd /etc/local.d/
-
touch mount.start
-
echo “mount --make-rshared /” > mount.start
-
chmod +x mount.start
-
rc-update add local
-
Enable cgroups
-
set rc.conf rc_cgroup_mode="unified"
-
rc-service cgroups start
-
rc-update add cgroups
-
containerd-rootless.sh
- apk add libc6-compat
- download full version of containerd
- Enable cgroups
- set rc.conf rc_cgroup_mode="unified"
- rc-service cgroups start
- rc-update add cgroups