2022-02-10 17:27:00 +00:00
|
|
|
def defaultOSConfigure(vm)
|
2022-06-13 20:36:26 +00:00
|
|
|
box = vm.box.to_s
|
2024-08-12 16:26:19 +00:00
|
|
|
if box.include?("ubuntu")
|
2022-06-14 15:40:29 +00:00
|
|
|
vm.provision "Set DNS", type: "shell", inline: "netplan set ethernets.eth0.nameservers.addresses=[8.8.8.8,1.1.1.1]; netplan apply", run: 'once'
|
2022-06-13 20:36:26 +00:00
|
|
|
elsif box.include?("Leap") || box.include?("Tumbleweed")
|
2022-08-26 18:42:04 +00:00
|
|
|
vm.provision "Install apparmor-parser", type: "shell", inline: "zypper install -y apparmor-parser"
|
2024-08-12 16:26:19 +00:00
|
|
|
elsif box.include?("rocky") || box.include?("centos")
|
2022-08-26 16:36:13 +00:00
|
|
|
vm.provision "Disable firewall", type: "shell", inline: "systemctl stop firewalld"
|
2022-06-13 20:36:26 +00:00
|
|
|
elsif box.include?("alpine")
|
2024-03-18 21:06:24 +00:00
|
|
|
vm.provision "Install tools", type: "shell", inline: "apk add coreutils"
|
2022-06-13 20:36:26 +00:00
|
|
|
elsif box.include?("microos")
|
2024-03-18 21:06:24 +00:00
|
|
|
# Add stuff here, but we always need to reload at the end
|
2022-06-13 20:36:26 +00:00
|
|
|
vm.provision 'reload', run: 'once'
|
|
|
|
end
|
2022-06-14 15:40:29 +00:00
|
|
|
end
|
|
|
|
|
2024-10-23 16:36:06 +00:00
|
|
|
# getInstallType is used to control which version of k3s to install
|
|
|
|
# To install a specific version, set release_version to the version number
|
|
|
|
# To install a specific commit, set release_version to the commit SHA
|
|
|
|
# To install the latest commit from a branch, leave release_version empty
|
|
|
|
# and set release_channel to "commit" and set branch to the branch name
|
2024-05-06 18:18:25 +00:00
|
|
|
def getInstallType(vm, release_version, branch, release_channel='')
|
2022-06-14 15:40:29 +00:00
|
|
|
if release_version == "skip"
|
|
|
|
install_type = "INSTALL_K3S_SKIP_DOWNLOAD=true"
|
2024-10-23 16:36:06 +00:00
|
|
|
elsif !release_version.empty? && release_version.start_with?("v1")
|
2022-06-14 15:40:29 +00:00
|
|
|
return "INSTALL_K3S_VERSION=#{release_version}"
|
2024-10-23 16:36:06 +00:00
|
|
|
elsif !release_version.empty?
|
|
|
|
return "INSTALL_K3S_COMMIT=#{release_version}"
|
2024-08-26 15:22:42 +00:00
|
|
|
elsif !release_channel.empty? && release_channel != "commit"
|
2024-05-06 18:18:25 +00:00
|
|
|
return "INSTALL_K3S_CHANNEL=#{release_channel}"
|
2022-06-14 15:40:29 +00:00
|
|
|
else
|
2024-03-18 21:06:24 +00:00
|
|
|
jqInstall(vm)
|
2024-05-10 11:09:52 +00:00
|
|
|
scripts_location = Dir.exist?("./scripts") ? "./scripts" : "../scripts"
|
2022-06-14 15:40:29 +00:00
|
|
|
# Grabs the last 5 commit SHA's from the given branch, then purges any commits that do not have a passing CI build
|
|
|
|
# MicroOS requires it not be in a /tmp/ or other root system folder
|
2024-10-23 16:36:06 +00:00
|
|
|
vm.provision "Get latest commit", type: "shell", path: scripts_location +"/latest_commit.sh", env: {GH_TOKEN:ENV['GH_TOKEN']}, args: [branch, "/tmp/k3s_commits"]
|
2022-06-14 15:40:29 +00:00
|
|
|
return "INSTALL_K3S_COMMIT=$(head\ -n\ 1\ /tmp/k3s_commits)"
|
|
|
|
end
|
2022-07-29 21:56:02 +00:00
|
|
|
end
|
|
|
|
|
2023-08-01 16:32:34 +00:00
|
|
|
def addCoverageDir(vm, role, gocover)
|
|
|
|
if gocover.empty?
|
|
|
|
return
|
|
|
|
end
|
2023-06-05 21:15:17 +00:00
|
|
|
service = role.include?("agent") ? "k3s-agent" : "k3s"
|
|
|
|
script = <<~SHELL
|
|
|
|
mkdir -p /tmp/k3scov
|
|
|
|
echo -e 'GOCOVERDIR=/tmp/k3scov' >> /etc/default/#{service}
|
|
|
|
systemctl daemon-reload
|
|
|
|
SHELL
|
|
|
|
vm.provision "go coverage", type: "shell", inline: script
|
|
|
|
end
|
|
|
|
|
2023-01-27 02:17:33 +00:00
|
|
|
def getHardenedArg(vm, hardened, scripts_location)
|
|
|
|
if hardened.empty?
|
|
|
|
return ""
|
|
|
|
end
|
|
|
|
hardened_arg = <<~HARD
|
|
|
|
protect-kernel-defaults: true
|
|
|
|
secrets-encryption: true
|
|
|
|
kube-controller-manager-arg:
|
|
|
|
- 'terminated-pod-gc-threshold=10'
|
|
|
|
kubelet-arg:
|
|
|
|
- 'streaming-connection-idle-timeout=5m'
|
|
|
|
- 'make-iptables-util-chains=true'
|
|
|
|
- 'event-qps=0'
|
2024-07-25 16:37:03 +00:00
|
|
|
- "tls-cipher-suites=TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305,TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305"
|
2023-01-27 02:17:33 +00:00
|
|
|
kube-apiserver-arg:
|
|
|
|
- 'audit-log-path=/var/lib/rancher/k3s/server/logs/audit.log'
|
|
|
|
- 'audit-policy-file=/var/lib/rancher/k3s/server/audit.yaml'
|
|
|
|
- 'audit-log-maxage=30'
|
|
|
|
- 'audit-log-maxbackup=10'
|
|
|
|
- 'audit-log-maxsize=100'
|
|
|
|
HARD
|
2024-07-25 16:37:03 +00:00
|
|
|
|
|
|
|
if hardened == "psa" || hardened == "true"
|
2023-01-27 02:17:33 +00:00
|
|
|
vm.provision "Set kernel parameters", type: "shell", path: scripts_location + "/harden.sh", args: [ "psa" ]
|
|
|
|
hardened_arg += " - 'admission-control-config-file=/var/lib/rancher/k3s/server/psa.yaml'"
|
2024-07-25 16:37:03 +00:00
|
|
|
elsif hardened == "psp"
|
|
|
|
vm.provision "Set kernel parameters", type: "shell", path: scripts_location + "/harden.sh"
|
|
|
|
hardened_arg += " - 'enable-admission-plugins=NodeRestriction,NamespaceLifecycle,ServiceAccount,PodSecurityPolicy'"
|
2023-01-27 02:17:33 +00:00
|
|
|
else
|
|
|
|
puts "Invalid E2E_HARDENED option"
|
|
|
|
exit 1
|
|
|
|
end
|
2024-08-12 16:26:19 +00:00
|
|
|
if vm.box.to_s.include?("ubuntu")
|
2024-07-25 16:37:03 +00:00
|
|
|
vm.provision "Install kube-bench", type: "shell", inline: <<-SHELL
|
|
|
|
export KBV=0.8.0
|
|
|
|
curl -L "https://github.com/aquasecurity/kube-bench/releases/download/v${KBV}/kube-bench_${KBV}_linux_amd64.deb" -o "kube-bench_${KBV}_linux_amd64.deb"
|
|
|
|
dpkg -i "./kube-bench_${KBV}_linux_amd64.deb"
|
|
|
|
SHELL
|
|
|
|
end
|
2023-01-27 02:17:33 +00:00
|
|
|
return hardened_arg
|
|
|
|
end
|
|
|
|
|
2024-03-18 21:06:24 +00:00
|
|
|
def jqInstall(vm)
|
|
|
|
box = vm.box.to_s
|
2024-08-12 16:26:19 +00:00
|
|
|
if box.include?("ubuntu")
|
2024-03-18 21:06:24 +00:00
|
|
|
vm.provision "Install jq", type: "shell", inline: "apt install -y jq"
|
|
|
|
elsif box.include?("Leap") || box.include?("Tumbleweed")
|
|
|
|
vm.provision "Install jq", type: "shell", inline: "zypper install -y jq"
|
2024-08-12 16:26:19 +00:00
|
|
|
elsif box.include?("rocky")
|
2024-03-18 21:06:24 +00:00
|
|
|
vm.provision "Install jq", type: "shell", inline: "dnf install -y jq"
|
2024-08-12 16:26:19 +00:00
|
|
|
elsif box.include?("centos")
|
2024-03-18 21:06:24 +00:00
|
|
|
vm.provision "Install jq", type: "shell", inline: "yum install -y jq"
|
|
|
|
elsif box.include?("alpine")
|
|
|
|
vm.provision "Install jq", type: "shell", inline: "apk add coreutils"
|
|
|
|
elsif box.include?("microos")
|
|
|
|
vm.provision "Install jq", type: "shell", inline: "transactional-update pkg install -y jq"
|
|
|
|
vm.provision 'reload', run: 'once'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-29 21:56:02 +00:00
|
|
|
def dockerInstall(vm)
|
|
|
|
vm.provider "libvirt" do |v|
|
|
|
|
v.memory = NODE_MEMORY + 1024
|
|
|
|
end
|
|
|
|
vm.provider "virtualbox" do |v|
|
|
|
|
v.memory = NODE_MEMORY + 1024
|
|
|
|
end
|
2023-01-18 17:34:52 +00:00
|
|
|
box = vm.box.to_s
|
|
|
|
if box.include?("ubuntu")
|
2022-08-31 22:40:17 +00:00
|
|
|
vm.provision "shell", inline: "apt update; apt install -y docker.io"
|
2023-01-18 17:34:52 +00:00
|
|
|
elsif box.include?("Leap")
|
2022-07-29 21:56:02 +00:00
|
|
|
vm.provision "shell", inline: "zypper install -y docker apparmor-parser"
|
2023-01-18 17:34:52 +00:00
|
|
|
elsif box.include?("microos")
|
2022-07-29 21:56:02 +00:00
|
|
|
vm.provision "shell", inline: "transactional-update pkg install -y docker apparmor-parser"
|
|
|
|
vm.provision 'docker-reload', type: 'reload', run: 'once'
|
|
|
|
vm.provision "shell", inline: "systemctl enable --now docker"
|
2024-08-12 16:26:19 +00:00
|
|
|
elsif box.include?("rocky")
|
2023-01-18 17:34:52 +00:00
|
|
|
vm.provision "shell", inline: "dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo"
|
|
|
|
vm.provision "shell", inline: "dnf install -y docker-ce"
|
2022-07-29 21:56:02 +00:00
|
|
|
end
|
|
|
|
end
|