README
¶
HAOS
HAOS is a Linux distribution designed to harden and secure an OS that
in turn operates a Kubernetes cluster with as little maintenance as possible.
Additionally the OS is designed to be managed by kubectl
once a cluster is bootstrapped.
Nodes only need to join a cluster and then all aspects of the OS can be managed
from Kubernetes. Both HAOS and k3s upgrades are handled by the HAOS operator.
Quick Start
Download the ISO from the latest release and run it
in VMware, VirtualBox, KVM, or bhyve. The server will automatically start a single node Kubernetes cluster.
Log in with the user rancher
and run kubectl
. This is a "live install" running from the ISO media
and changes will not persist after reboot.
To copy HAOS to local disk, after logging in as rancher
run sudo HAOS install
. Then remove the ISO
from the virtual machine and reboot.
Live install (boot from ISO) requires at least 2GB of RAM. Local install requires 1GB RAM.
Design
Core design goals of HAOS are
- Hardened and secure OS
- Minimal OS for running Kubernetes by way of k3s
- Ability to upgrade and configure using
kubectl
- Versatile installation to allow easy creation of OS images.
File System Structure
Critical to the design of HAOS is how that file system is structured. A booted system will look as follows
/etc - ephemeral
/usr - read-only (except /usr/local is writable and persistent)
/HAOS - system files
/home - persistent
/var - persistent
/opt - persistent
/usr/local - persistent
/etc
All configuration in the system is intended to be ephemeral. If you change anything in /etc
it
will revert on next reboot. If you wish to persist changes to the configuration they must be done
in the HAOS config.yaml
which will be applied on each boot.
/usr
The entire user space is stored in /usr
and as read-only. The only way to change /usr
is to
change versions of HAOS. The directory /usr/local
is a symlink to /var/local
and therefore
writable.
/HAOS
The HAOS directory contains the core operating system files references on boot to construct the file system. It contains squashfs images and binaries for HAOS, k3s, and the Linux kernel. On boot the appropriate version for all three will be chosen and configured.
/var, /usr/local, /home, /opt
Persistent changes should be kept in /var
, /usr/local
, /home
, or /opt
.
Upstream Distros
Most of the user-space binaries comes from Alpine and are repackaged for HAOS. Currently the kernel source is coming from Ubuntu 20.04 LTS. Some code and a lot of inspiration came from LinuxKit
Installation
Interactive Installation
Interactive installation is done from booting from the ISO. The installation is done by running
HAOS install
. The HAOS install
sub-command is only available on systems booted live.
An installation to disk will not have HAOS install
. Follow the prompts to install HAOS to disk.
The installation will format an entire disk. If you have a single hard disk attached to the system it will not ask which disk but just pick the first and only one.
Automated Installation
Installation can be automated by using kernel cmdline parameters. There are a lot of creative solutions to booting a machine with cmdline args. You can remaster the HAOS ISO, PXE boot, use qemu/kvm, or automate input with packer. The kernel and initrd are available in the HAOS release artifacts, along with the ISO.
The cmdline value haos.mode=install
or haos.fallback_mode=install
is required to enable automated installations.
Below is a reference of all cmdline args used to automate installation
cmdline | Default | Example | Description |
---|---|---|---|
haos.mode | install | Boot HAOS to the installer, not an interactive session | |
haos.fallback_mode | install | If a valid HAOS_STATE partition is not found to boot from, run the installation | |
haos.install.silent | false | true | Ensure no questions will be asked |
haos.install.force_efi | false | true | Force EFI installation even when EFI is not detected |
haos.install.device | /dev/vda | Device to partition and format (/dev/sda, /dev/vda) | |
haos.install.config_url | https://gist.github.com/.../dweomer.yaml | The URL of the config to be installed at /HAOS/system/config.yaml |
|
haos.install.iso_url | https://github.com/1898andCo/HAOS../haos-amd64.iso | ISO to download and install from if booting from kernel/vmlinuz and not ISO. | |
haos.install.no_format | true | Do not partition and format, assume layout exists already | |
haos.install.tty | auto | ttyS0 | The tty device used for console |
haos.install.debug | false | true | Run installation with more logging and configure debug for installed system |
haos.install.power_off | false | true | Shutdown the machine after install instead of rebooting |
Custom partition layout
By default HAOS expects one partition to exist labeled HAOS_STATE
. HAOS_STATE
is expected to be an ext4 formatted filesystem with at least 2GB of disk space. The installer will create this
partitions and file system automatically, or you can create them manually if you have a need for an advanced file system layout.
Bootstrapped Installation
You can install HAOS to a block device from any modern Linux distribution. Just download and run install.sh. This script will run the same installation as the ISO but is a bit more raw and will not prompt for configuration.
Usage: ./install.sh [--force-efi] [--debug] [--tty TTY] [--poweroff] [--takeover] [--no-format] [--config https://.../config.yaml] DEVICE ISO_URL
Example: ./install.sh /dev/vda https://github.com/1898andCo/HAOS/releases/download/v0.10.0/haos.iso
DEVICE must be the disk that will be partitioned (/dev/vda). If you are using --no-format it should be the device of the HAOS_STATE partition (/dev/vda2)
The parameters names refer to the same names used in the cmdline, refer to README.md for
more info.
Remastering ISO
To remaster the ISO all you need to do is copy /HAOS
and /boot
from the ISO to a new folder. Then modify /boot/grub/grub.cfg
to add whatever kernel cmdline args for auto-installation.
To build a new ISO just use the utility grub-mkrescue
as follows:
# Ubuntu: apt install grub-efi grub-pc-bin mtools xorriso
# CentOS: dnf install grub2-efi grub2-pc mtools xorriso
# Alpine: apk add grub-bios grub-efi mtools xorriso
mount -o loop haos.iso /mnt
mkdir -p iso/boot/grub
cp -rf /mnt/HAOS iso/
cp /mnt/boot/grub/grub.cfg iso/boot/grub/
# Edit iso/boot/grub/grub.cfg
grub-mkrescue -o haos-new.iso iso/ -- -volid HAOS
GRUB2 CAVEAT: Some non-Alpine installations of grub2 will create ${ISO}/boot/grub2
instead of ${ISO}/boot/grub
which will generally lead to broken installation media. Be mindful of this and modify the above commands
(that work with this path) accordingly. Systems that exhibit this behavior typically have grub2-mkrescue
on the path instead of grub-mkrescue
.
Takeover Installation
A special mode of installation is designed to install to a current running Linux system. This only works on ARM64 and x86_64. Download install.sh
and run with the --takeover
flag. This will install HAOS to the current root and override the grub.cfg. After you reboot the system HAOS will then delete all files on the root partition that are not HAOS and then shutdown. This mode is particularly handy when creating cloud images. This way you can use an existing base image like Ubuntu and install HAOS over the top, snapshot, and create a new image.
In order for this to work a couple of assumptions are made. First the root (/) is assumed to be an ext4 partition. Also it is assumed that grub2 is installed and looking for the configuration at /boot/grub/grub.cfg
. When running --takeover
ensure that you also set --no-format
and DEVICE must be set to the partition of /
. Refer to the AWS packer template to see this mode in action. Below is any example of how to run a takeover installation.
./install.sh --takeover --debug --tty ttyS0 --config /tmp/config.yaml --no-format /dev/vda1 https://github.com/1898andCo/HAOS/releases/download/v0.10.0/haos.iso
ARM Overlay Installation
If you have a custom ARMv7 or ARM64 device you can easily use an existing bootable ARM image to create a HAOS setup.
All you must do is boot the ARM system and then extract haos-rootfs-arm.tar.gz
to the root (stripping one path,
look at the example below) and then place your cloud-config at /HAOS/system/config.yaml
. For example:
curl -sfL https://github.com/1898andCo/HAOS/releases/download/v0.10.0/haos-rootfs-arm.tar.gz | tar zxvf - --strip-components=1 -C /
cp myconfig.yaml /haos/system/config.yaml
sync
reboot -f
This method places HAOS on disk and also overwrites /sbin/init
.
On next reboot your ARM bootloader and kernel should be loaded,
but then when user space is to be initialized HAOS should take over.
One important consideration at the moment is that HAOS assumes the root device is not read only.
This typically means you need to remove ro
from the kernel cmdline.
This should be fixed in a future release.
Configuration
All configuration is done through a single cloud-init style config file that is either packaged in the image, downloaded though cloud-init or managed by Kubernetes. The configuration file is found at
/HAOS/system/config.yaml
/var/lib/rancher/HAOS/config.yaml
/var/lib/rancher/HAOS/config.d/*
The /HAOS/system/config.yaml
file is reserved for the system installation and should not be
modified on a running system. This file is usually populated by during the image build or
installation process and contains important bootstrap information (such as networking or cloud-init
data sources).
The /var/lib/rancher/HAOS/config.yaml
or config.d/*
files are intended to be used at runtime.
These files can be manipulated manually, through scripting, or managed with the Kubernetes operator.
Sample config.yaml
A full example of the HAOS configuration file is as below.
ssh_authorized_keys:
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQAB...
- github:ibuildthecloud
write_files:
- encoding: ""
content: |-
#!/bin/bash
echo hello, local service start
owner: root
path: /etc/local.d/example.start
permissions: '0755'
boot_manifests:
- url: "https://manifest.at.blob.or.git.provider.example/manifest.yaml"
sha256: "edeaaff3f1774ad2888673770c6d64097e391bc362d7d6fb34982ddf0efd18cb"
hostname: myhost
init_cmd:
- "echo hello, init command"
boot_cmd:
- "echo hello, boot command"
run_cmd:
- "echo hello, run command"
haos:
data_sources:
- aws
- cdrom
modules:
- kvm
- nvme
sysctl:
kernel.printk: "4 4 1 7"
kernel.kptr_restrict: "1"
dns_nameservers:
- 8.8.8.8
- 1.1.1.1
ntp_servers:
- 0.us.pool.ntp.org
- 1.us.pool.ntp.org
wifi:
- name: home
passphrase: mypassword
- name: nothome
passphrase: somethingelse
password: rancher
server_url: https://someserver:6443
token: TOKEN_VALUE
labels:
region: us-west-1
somekey: somevalue
k3s_args:
- server
- "--disable-agent"
environment:
http_proxy: http://myserver
https_proxy: http://myserver
taints:
- key1=value1:NoSchedule
- key1=value1:NoExecute
Refer to the configuration reference for full details of each configuration key.
Kubernetes
Since HAOS is built on k3s all Kubernetes configuration is done by configuring
k3s. This is primarily done through environment
and k3s_args
keys in config.yaml
.
The write_files
or boot_manifests
keys can be used to populate the /var/lib/rancher/k3s/server/manifests
folder with apps you'd like to deploy on boot.
Refer to k3s docs for more information on how to configure Kubernetes.
Kernel cmdline
All configuration can be passed as kernel cmdline parameters too. The keys are dot
separated. For example haos.token=TOKEN
. If the key is a slice, multiple values are set by
repeating the key, for example haos.dns_nameserver=1.1.1.1 haos.dns_nameserver=8.8.8.8
. You
can use the plural or singular form of the name, just ensure you consistently use the same form. For
map values the form key[key]=value
form is used, for example haos.sysctl[kernel.printk]="4 4 1 7"
.
If the value has spaces in it ensure that the value is quoted. Boolean keys expect a value of
true
or false
or no value at all means true
. For example haos.install.efi
is the same
as haos.install.efi=true
.
Phases
Configuration is applied in three distinct phases: initrd
, boot
, runtime
. initrd
is run during the initrd phase before the root disk has been mounted. boot
is run after
the root disk is mounted and the file system is setup, but before any services have started.
There is no networking available yet at this point. The final stage runtime
is executed after
networking has come online. If you are using a configuration from a cloud provider (like AWS
userdata) it will only be run in the runtime
phase. Below is a table of which config keys
are supported in each phase.
Key | initrd | boot | runtime |
---|---|---|---|
ssh_authorized_keys | x | x | |
write_files | x | x | x |
boot_manifests | x | ||
hostname | x | x | x |
run_cmd | x | ||
boot_cmd | x | ||
init_cmd | x | ||
haos.data_sources | x | ||
haos.modules | x | x | x |
haos.sysctls | x | x | x |
haos.ntp_services | x | x | |
haos.dns_nameservers | x | x | |
haos.wifi | x | x | |
haos.password | x | x | x |
haos.server_url | x | x | |
haos.token | x | x | |
haos.labels | x | x | |
haos.k3s_args | x | x | |
haos.environment | x | x | x |
haos.taints | x | x |
Networking
Networking is powered by connman
. To configure networking a couple of helper keys are
available: haos.dns_nameserver
, haos.ntp_servers
, haos.wifi
. Refer to the
reference for a full explanation of those keys. If you wish
to configure a HTTP proxy set the http_proxy
, and https_proxy
fields in haos.environment
.
All other networking configuration should be done by configuring connman directly by using the
write_files
key to create connman service
files.
Upgrade and Maintenance
Upgrading and reconfiguring HAOS is all handled through the Kubernetes operator. The operator is still in development. More details to follow. The basic design is that one can set the desired k3s and HAOS versions, plus their configuration and the operator will roll that out to the cluster.
Automatic Upgrades
Integration with rancher/system-upgrade-controller has been implemented as of v0.9.0.
To enable a HAOS node to automatically upgrade from the latest GitHub release you will need to make sure it has the label
haos.io/upgrade
with value enabled
(for HAOS versions prior to v0.11.x please use label plan.upgrade.cattle.io/HAOS-latest
). The upgrade controller will then spawn an upgrade job
that will drain most pods, upgrade the HAOS content under /haos/system
, and then reboot. The system should come back up running the latest
kernel and k3s version bundled with HAOS and ready to schedule pods.
Pre v0.9.0
If your HAOS installation is running a version prior to the v0.9.0 release or one of its release candidates you can setup the system upgrade controller to upgrade your HAOS by following these steps:
# apply the system-upgrade-controller manifest (once per cluster)
kubectl apply -f https://raw.githubusercontent.com/rancher/haos/v0.10.0/overlay/share/rancher/k3s/server/manifests/system-upgrade-controller.yaml
# after the system-upgrade-controller pod is Ready, apply the plan manifest (once per cluster)
kubectl apply -f https://raw.githubusercontent.com/rancher/haos/v0.10.0/overlay/share/rancher/k3s/server/manifests/system-upgrade-plans/HAOS-latest.yaml
# apply the `plan.upgrade.cattle.io/HAOS-latest` label as described above (for every HAOS node), e.g.
kubectl label nodes -l haos.io/mode plan.upgrade.cattle.io/HAOS-latest=enabled # this should work on any cluster with HAOS installations at v0.7.0 or greater
Manual Upgrades
For single-node or development use cases, where the operator is not being used, you can upgrade the rootfs and kernel with the following commands. If you do not specify HAOS_VERSION, it will default to the latest release.
When using an overlay install such as on Raspberry Pi (see ARM Overlay Installation) the original distro kernel (such as Raspbian) will continue to be used. On these systems the haos-upgrade-kernel script will exit with a warning and perform no action.
export HAOS_VERSION=v0.10.0
/usr/share/rancher/k3os/scripts/k3os-upgrade-rootfs
/usr/share/rancher/k3os/scripts/k3os-upgrade-kernel
You should always remember to backup your data first, and reboot after upgrading.
Manual Upgrade Scripts Have Been DEPRECATED
These scripts have been deprecated as of v0.9.0 are still on the system at /usr/share/rancher/k3os/scripts
.
Building
To build HAOS you just need Docker and then run make
. All artifacts will be put in ./dist/artifacts
.
If you are running on Linux you can run ./scripts/run
to run a VM of HAOS in the terminal. To exit
the instance type CTRL+a c
to get the qemu console and then q
for quit.
The source for the kernel is in https://github.com/rancher/k3os-kernel
and similarly you
just need to have Docker and run make
to compile the kernel.
Configuration Reference
Below is a reference of all keys available in the config.yaml
ssh_authorized_keys
A list of SSH authorized keys that should be added to the rancher
user. HAOS primarily
has one user, rancher
. The root
account is always disabled, has no password, and is never
assigned a ssh key. SSH keys can be obtained from GitHub user accounts by using the format
github:${USERNAME}
. This is done by downloading the keys from https://github.com/${USERNAME}.keys
.
Example
ssh_authorized_keys:
- "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC2TBZGjE+J8ag11dzkFT58J3XPONrDVmalCNrKxsfADfyy0eqdZrG8hcAxAR/5zuj90Gin2uBR4Sw6Cn4VHsPZcFpXyQCjK1QDADj+WcuhpXOIOY3AB0LZBly9NI0ll+8lo3QtEaoyRLtrMBhQ6Mooy2M3MTG4JNwU9o3yInuqZWf9PvtW6KxMl+ygg1xZkljhemGZ9k0wSrjqif+8usNbzVlCOVQmZwZA+BZxbdcLNwkg7zWJSXzDIXyqM6iWPGXQDEbWLq3+HR1qKucTCSxjbqoe0FD5xcW7NHIME5XKX84yH92n6yn+rxSsyUfhJWYqJd+i0fKf5UbN6qLrtd/D"
- "github:ibuildthecloud"
write_files
A list of files to write to disk on boot. These files can be either plain text, gziped, base64 encoded, or base64+gzip encoded.
Example
write_files:
- encoding: b64
content: CiMgVGhpcyBmaWxlIGNvbnRyb2xzIHRoZSBzdGF0ZSBvZiBTRUxpbnV4...
owner: root:root
path: /etc/connman/main.conf
permissions: '0644'
- content: |
# My new /etc/sysconfig/samba file
SMDBOPTIONS="-D"
path: /etc/sysconfig/samba
- content: !!binary |
f0VMRgIBAQAAAAAAAAAAAAIAPgABAAAAwARAAAAAAABAAAAAAAAAAJAVAAAAAA
AEAAHgAdAAYAAAAFAAAAQAAAAAAAAABAAEAAAAAAAEAAQAAAAAAAwAEAAAAAAA
AAAAAAAAAwAAAAQAAAAAAgAAAAAAAAACQAAAAAAAAAJAAAAAAAAcAAAAAAAAAB
...
path: /bin/arch
permissions: '0555'
- content: |
15 * * * * root ship_logs
path: /etc/crontab
hostname
Set the system hostname. This value will be overwritten by DHCP if DHCP supplies a hostname for the system.
Example
hostname: myhostname
boot_manifests
A list of URLs (and optionally SHA256 sums) of manifests to download and apply at boot. This is similar
to using write_files
to write to /var/rancher/k3s/server/manifests
, but enables the "bootstrap"
yaml files to live outside of the config file.
These files will be re-downloaded and saved on every boot. If a SHA256 is provided and it does not match the file download, the file will not be saved to disk. Two files may not have the same name - don't download two "demo.yaml" files at different URLs and expect them both to persist to disk.
Example
boot_manifests:
- url: "https://manifests.my.s3.example/bootstrap.yaml"
- url: "https://manifests.with.sha.example/demo.yaml"
sha256: "cba52c6d5a71c04d7e517ced1328ec310f76e07d3727810da2a2d97c7196ede3"
init_cmd
, boot_cmd
, run_cmd
All three keys are used to run arbitrary commands on startup in the respective phases of initrd
,
boot
and runtime
. Commands are ran after write_files
so it is possible to write a script to
disk and run it from these commands. That often makes it easier to do longer form setup.
haos.data_sources
These are the data sources used for download config from cloud provider. The valid options are:
aws
cdrom
digitalocean
gcp
hetzner
openstack
packet
scaleway
vultr
More than one can be supported at a time, for example:
haos:
data_sources:
- openstack
- cdrom
When multiple data sources are specified they are probed in order and the first to provide /run/config/userdata
will halt further processing.
haos.modules
A list of kernel modules to be loaded on start.
Example
haos:
modules:
- kvm
- nvme
haos.sysctls
Kernel sysctl to setup on start. These are the same configuration you'd typically find in /etc/sysctl.conf
.
Must be specified as string values.
haos:
sysctl:
kernel.printk: 4 4 1 7 # the YAML parser will read as a string
kernel.kptr_restrict: "1" # force the YAML parser to read as a string
haos.ntp_servers
Fallback ntp servers to use if NTP is not configured elsewhere in connman.
Example
haos:
ntp_servers:
- 0.us.pool.ntp.org
- 1.us.pool.ntp.org
haos.dns_nameservers
Fallback DNS name servers to use if DNS is not configured by DHCP or in a connman service config.
Example
haos:
dns_nameservers:
- 8.8.8.8
- 1.1.1.1
haos.wifi
Simple wifi configuration. All that is accepted is name
and passphrase
. If you require more
complex configuration then you should use write_files
to write a connman service config.
Example:
haos:
wifi:
- name: home
passphrase: mypassword
- name: nothome
passphrase: somethingelse
haos.password
The password for the rancher
user. By default there is no password for the rancher
user.
If you set a password at runtime it will be reset on next boot because /etc
is ephemeral. The
value of the password can be clear text or an encrypted form. The easiest way to get this encrypted
form is to just change your password on a Linux system and copy the value of the second field from
/etc/shadow
. You can also encrypt a password using openssl passwd -1
.
Example
haos:
password: "$1$tYtghCfK$QHa51MS6MVAcfUKuOzNKt0"
Or clear text
haos:
password: supersecure
haos.server_url
The URL of the k3s server to join as an agent.
Example
haos:
server_url: https://myserver:6443
haos.token
The cluster secret or node token. If the value matches the format of a node token it will automatically be assumed to be a node token. Otherwise it is treated as a cluster secret.
Example
haos:
token: myclustersecret
Or a node token
haos:
token: "K1074ec55daebdf54ef48294b0ddf0ce1c3cb64ee7e3d0b9ec79fbc7baf1f7ddac6::node:77689533d0140c7019416603a05275d4"
haos.labels
Labels to be assigned to this node in Kubernetes on registration. After the node is first registered in Kubernetes the value of this setting will be ignored.
Example
haos:
labels:
region: us-west-1
somekey: somevalue
haos.k3s_args
Arguments to be passed to the k3s process. The arguments should start with server
or agent
to be valid.
k3s_args
is an exec-style (aka uninterpreted) argument array which means that when specifying a flag with a value one
must either join the flag to the value with an =
in the same array entry or specify the flag in an entry by itself
immediately followed the value in another entry, e.g.:
# K3s flags with values joined with `=` in single entry
haos:
k3s_args:
- server
- "--cluster-cidr=10.107.0.0/23"
- "--service-cidr=10.107.1.0/23"
# Effectively invokes k3s as:
# exec "k3s" "server" "--cluster-cidr=10.107.0.0/23" "--service-cidr=10.107.1.0/23"
# K3s flags with values in following entry
haos:
k3s_args:
- server
- "--cluster-cidr"
- "10.107.0.0/23"
- "--service-cidr"
- "10.107.1.0/23"
# Effectively invokes k3s as:
# exec "k3s" "server" "--cluster-cidr" "10.107.0.0/23" "--service-cidr" "10.107.1.0/23"
haos.environment
Environment variables to be set on k3s and other processes like the boot process. Primary use of this field is to set the http proxy.
Example
haos:
environment:
http_proxy: http://myserver
https_proxy: http://myserver
haos.taints
Taints to set on the current node when it is first registered. After the node is first registered the value of this field is ignored.
haos:
taints:
- "key1=value1:NoSchedule"
- "key1=value1:NoExecute"
Development
Please install the git hooks by running ./install-hooks
. This will ensure that
the code is formatted correctly and that the commit message is formatted correctly.
License
Copyright (c) 2014-2020 Rancher Labs, Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Documentation
¶
There is no documentation for this package.
Directories
¶
Path | Synopsis |
---|---|
pkg
|
|
cc
Package cc is responsible for applying the cloud config to the system
|
Package cc is responsible for applying the cloud config to the system |
cli
Package cli
|
Package cli |
questions
Package questions allows the cli to ask questions to the user.
|
Package questions allows the cli to ask questions to the user. |
ssh
Package ssh is responsible for setting up the ssh keys for the system
|
Package ssh is responsible for setting up the ssh keys for the system |
system
Package system abstracts the filesystem layout of the system and exposes functions to copy and move files
|
Package system abstracts the filesystem layout of the system and exposes functions to copy and move files |