Skip to content

Commit

Permalink
ci: add cis-1.23 hardening in sles rke2 terraform script
Browse files Browse the repository at this point in the history
Signed-off-by: Yang Chiu <yang.chiu@suse.com>
  • Loading branch information
yangchiu authored and David Ko committed Jul 18, 2023
1 parent d359421 commit 19a768b
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 3 deletions.
2 changes: 2 additions & 0 deletions test_framework/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def RANCHER_CHART_GIT_REPO = params.RANCHER_CHART_GIT_REPO ? params.RANCHER_CHAR
def RANCHER_CHART_GIT_BRANCH = params.RANCHER_CHART_GIT_BRANCH ? params.RANCHER_CHART_GIT_BRANCH : ""
def RANCHER_CHART_INSTALL_VERSION = params.RANCHER_CHART_INSTALL_VERSION ? params.RANCHER_CHART_INSTALL_VERSION : ""
def LONGHORN_TRANSIENT_VERSION = params.LONGHORN_TRANSIENT_VERSION ? params.LONGHORN_TRANSIENT_VERSION : ""
def CIS_HARDENING = params.CIS_HARDENING ? params.CIS_HARDENING : false
def REGISTRY_URL
def REGISTRY_USERNAME
def REGISTRY_PASSWORD
Expand Down Expand Up @@ -134,6 +135,7 @@ node {
--env TF_VAR_azure_crt_password=${AZURE_CRT_PASSWORD} \
--env TF_VAR_azure_tenant_id=${AZURE_TENANT_ID} \
--env TF_VAR_azure_subscription_id=${AZURE_SUBSCRIPTION_ID} \
--env TF_VAR_cis_hardening=${CIS_HARDENING} \
${imageName}
"""

Expand Down
8 changes: 8 additions & 0 deletions test_framework/scripts/longhorn-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,14 @@ install_longhorn_stable(){

create_longhorn_namespace(){
kubectl create ns ${LONGHORN_NAMESPACE}
if [[ "${TF_VAR_cis_hardening}" == true ]]; then
kubectl label ns default ${LONGHORN_NAMESPACE} pod-security.kubernetes.io/enforce=privileged
kubectl label ns default ${LONGHORN_NAMESPACE} pod-security.kubernetes.io/enforce-version=latest
kubectl label ns default ${LONGHORN_NAMESPACE} pod-security.kubernetes.io/audit=privileged
kubectl label ns default ${LONGHORN_NAMESPACE} pod-security.kubernetes.io/audit-version=latest
kubectl label ns default ${LONGHORN_NAMESPACE} pod-security.kubernetes.io/warn=privileged
kubectl label ns default ${LONGHORN_NAMESPACE} pod-security.kubernetes.io/warn-version=latest
fi
}


Expand Down
2 changes: 2 additions & 0 deletions test_framework/terraform/aws/sles/data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ data "template_file" "provision_rke2_server" {
rke2_cluster_secret = random_password.cluster_secret.result
rke2_server_public_ip = aws_eip.lh_aws_eip_controlplane[0].public_ip
rke2_version = var.k8s_distro_version
cis_hardening = var.cis_hardening
}
}

Expand All @@ -47,5 +48,6 @@ data "template_file" "provision_rke2_agent" {
rke2_server_url = "https://${aws_eip.lh_aws_eip_controlplane[0].public_ip}:9345"
rke2_cluster_secret = random_password.cluster_secret.result
rke2_version = var.k8s_distro_version
cis_hardening = var.cis_hardening
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,20 @@ token: ${rke2_cluster_secret}
EOF

systemctl enable rke2-agent.service

if [ "${cis_hardening}" == true ]; then
cat << EOF > /etc/sysctl.d/60-rke2-cis.conf
vm.panic_on_oom=0
vm.overcommit_memory=1
kernel.panic=10
kernel.panic_on_oops=1
EOF
systemctl restart systemd-sysctl
useradd -r -c "etcd user" -s /sbin/nologin -M etcd -U
cat << EOF >> /etc/rancher/rke2/config.yaml
profile: "cis-1.23"
EOF
fi

systemctl start rke2-agent.service
exit $?
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@ node-taint:
EOF

systemctl enable rke2-server.service

if [ "${cis_hardening}" == true ]; then
cat << EOF > /etc/sysctl.d/60-rke2-cis.conf
vm.panic_on_oom=0
vm.overcommit_memory=1
kernel.panic=10
kernel.panic_on_oops=1
EOF
systemctl restart systemd-sysctl
useradd -r -c "etcd user" -s /sbin/nologin -M etcd -U
cat << EOF >> /etc/rancher/rke2/config.yaml
profile: "cis-1.23"
EOF
fi

systemctl start rke2-server.service

until (KUBECONFIG=/etc/rancher/rke2/rke2.yaml /var/lib/rancher/rke2/bin/kubectl get pods -A | grep 'Running'); do
Expand Down
11 changes: 8 additions & 3 deletions test_framework/terraform/aws/sles/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ variable "k8s_distro_name" {

variable "k8s_distro_version" {
type = string
default = "v1.25.3+k3s1"
default = "v1.27.1+k3s1"
description = <<-EOT
kubernetes version that will be deployed
rke: (default: v1.22.5-rancher1-1)
k3s: (default: v1.25.3+k3s1)
rke2: (default: v1.25.3+rke2r1)
k3s: (default: v1.27.1+k3s1)
rke2: (default: v1.27.2+rke2r1)
EOT
}

Expand All @@ -117,3 +117,8 @@ variable "create_load_balancer" {
type = bool
default = false
}

variable "cis_hardening" {
type = bool
default = false
}

0 comments on commit 19a768b

Please sign in to comment.