Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration updates (EKS 1.24+) #9

Open
wants to merge 4 commits into
base: updated-disk-settings-12
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions amazon-eks-al2.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ build {
provisioner "shell" {
execute_command = "echo 'packer' | {{ .Vars }} sudo -S -E bash -eux '{{ .Path }}'"

env = {
MOTD_CONTENT = var.motd_content
}

scripts = [
"scripts/cis-benchmark.sh",
"scripts/cis-docker.sh",
Expand Down
43 changes: 9 additions & 34 deletions scripts/cis-benchmark.sh
Original file line number Diff line number Diff line change
Expand Up @@ -200,43 +200,16 @@ sed -i 's/SELINUX=disabled/SELINUX=enforcing/g' /etc/selinux/config

echo "1.7.1.1 - ensure message of the day is configured properly"
rm -f /etc/cron.d/update-motd
cat > /etc/update-motd.d/30-banner <<"OUTEREOF"
cat > /etc/update-motd.d/30-banner <<EOF
#!/bin/sh
cat <<"EOF"
You are accessing a U.S. Government (USG) Information System (IS) that is provided for USG-authorized use only.

By using this IS (which includes any device attached to this IS), you consent to the following conditions:
-The USG routinely intercepts and monitors communications on this IS for purposes including, but not limited to, penetration testing, COMSEC monitoring, network operations and defense, personnel misconduct (PM), law enforcement (LE), and counterintelligence (CI) investigations.
-At any time, the USG may inspect and seize data stored on this IS.
-Communications using, or data stored on, this IS are not private, are subject to routine monitoring, interception, and search, and may be disclosed or used for any USG-authorized purpose.
-This IS includes security measures (e.g., authentication and access controls) to protect USG interests--not for your personal benefit or privacy.
-Notwithstanding the above, using this IS does not constitute consent to PM, LE or CI investigative searching or monitoring of the content of privileged communications, or work product, related to personal representation or services by attorneys, psychotherapists, or clergy, and their assistants. Such communications and work product are private and confidential. See User Agreement for details.
cat "$MOTD_CONTENT"
EOF
OUTEREOF

echo "1.7.1.2 - ensure local login warning banner is configured properly"
cat > /etc/issue <<EOF
You are accessing a U.S. Government (USG) Information System (IS) that is provided for USG-authorized use only.

By using this IS (which includes any device attached to this IS), you consent to the following conditions:
-The USG routinely intercepts and monitors communications on this IS for purposes including, but not limited to, penetration testing, COMSEC monitoring, network operations and defense, personnel misconduct (PM), law enforcement (LE), and counterintelligence (CI) investigations.
-At any time, the USG may inspect and seize data stored on this IS.
-Communications using, or data stored on, this IS are not private, are subject to routine monitoring, interception, and search, and may be disclosed or used for any USG-authorized purpose.
-This IS includes security measures (e.g., authentication and access controls) to protect USG interests--not for your personal benefit or privacy.
-Notwithstanding the above, using this IS does not constitute consent to PM, LE or CI investigative searching or monitoring of the content of privileged communications, or work product, related to personal representation or services by attorneys, psychotherapists, or clergy, and their assistants. Such communications and work product are private and confidential. See User Agreement for details.
EOF
cat > /etc/issue <<< "$MOTD_CONTENT"

echo "1.7.1.3 - ensure remote login warning banner is configured properly"
cat > /etc/issue.net <<EOF
You are accessing a U.S. Government (USG) Information System (IS) that is provided for USG-authorized use only.

By using this IS (which includes any device attached to this IS), you consent to the following conditions:
-The USG routinely intercepts and monitors communications on this IS for purposes including, but not limited to, penetration testing, COMSEC monitoring, network operations and defense, personnel misconduct (PM), law enforcement (LE), and counterintelligence (CI) investigations.
-At any time, the USG may inspect and seize data stored on this IS.
-Communications using, or data stored on, this IS are not private, are subject to routine monitoring, interception, and search, and may be disclosed or used for any USG-authorized purpose.
-This IS includes security measures (e.g., authentication and access controls) to protect USG interests--not for your personal benefit or privacy.
-Notwithstanding the above, using this IS does not constitute consent to PM, LE or CI investigative searching or monitoring of the content of privileged communications, or work product, related to personal representation or services by attorneys, psychotherapists, or clergy, and their assistants. Such communications and work product are private and confidential. See User Agreement for details.
EOF
cat > /etc/issue.net <<< "$MOTD_CONTENT"

echo "1.7.1.4 - ensure permissions on /etc/motd are configured"
chown root:root /etc/motd
Expand Down Expand Up @@ -327,8 +300,10 @@ echo "2.2.4 - ensure LDAP client is not installed"
yum_remove openldap-clients

echo "3.1.1 - ensure IP forwarding is disabled"
sysctl_entry "net.ipv4.ip_forward = 0"
sysctl_entry "net.ipv6.conf.all.forwarding = 0"
# Required for working container networking
# sysctl_entry "net.ipv4.ip_forward = 0"
# sysctl_entry "net.ipv4.conf.all.forwarding = 0"
# sysctl_entry "net.ipv6.conf.all.forwarding = 0"

echo "3.1.2 - ensure packet redirect sending is disabled"
sysctl_entry "net.ipv4.conf.all.send_redirects = 0"
Expand Down Expand Up @@ -593,7 +568,7 @@ AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS
Subsystem sftp /usr/libexec/openssh/sftp-server
Subsystem sftp /usr/libexec/openssh/sftp-server
AuthorizedKeysCommand /opt/aws/bin/eic_run_authorized_keys %u %f
AuthorizedKeysCommandUser ec2-instance-connect

Expand Down
20 changes: 15 additions & 5 deletions scripts/cis-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ echo "2.1 - 2.17 - ensure the docker configuration is secure"
cat > /etc/docker/daemon.json <<EOF
{
"bridge": "none",
"log-level": "info",
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "5"
"max-file": "10"
},
"icc": false,
"iptables": true,
Expand All @@ -71,10 +70,21 @@ cat > /etc/docker/daemon.json <<EOF
}
},
"live-restore": true,
"userland-proxy": false,
"max-concurrent-downloads": 10,
"experimental": false,
"insecure-registries": [],
"default-ulimits": {
"memlock": {
"Name": "memlock",
"Soft": -1,
"Hard": -1
},
"nproc": {
"Name": "nproc",
"Hard": 32768,
"Soft": 16384
}
},
"icc": false,
"userland-proxy": false,
"no-new-privileges": true
}
EOF
Expand Down
31 changes: 26 additions & 5 deletions scripts/cis-eks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,31 @@ cat > /etc/kubernetes/kubelet/kubelet-config.json <<EOF
"protectKernelDefaults": true,
"serializeImagePulls": false,
"serverTLSBootstrap": true,
"streamingConnectionIdleTimeout": "4h0m0s",
"makeIPTablesUtilChains": true,
"eventRecordQPS": 5,
"RotateCertificate": true,
"tlsCipherSuites": ["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_AES_256_GCM_SHA384", "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305", "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", "TLS_RSA_WITH_AES_256_GCM_SHA384", "TLS_RSA_WITH_AES_128_GCM_SHA256"]
"rotateCertificates": false,
"tlsCipherSuites": [
"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_AES_256_GCM_SHA384",
"TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305",
"TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384",
"TLS_RSA_WITH_AES_256_GCM_SHA384",
"TLS_RSA_WITH_AES_128_GCM_SHA256"
],
"clusterDNS": [
"172.20.0.10"
]
}
EOF

# /usr/bin/kubelet --version
# Kubernetes v1.20.15-eks-ba74326
# -> 1.20
KUBERNETES_VERSION=$(/usr/bin/kubelet --version | sed -E -e 's!^Kubernetes v([0-9]\.[0-9]+).[0-9]+-.*$!\1!')

# Inject CSIServiceAccountToken feature gate to kubelet config if kubernetes version starts with 1.20.
# This is only injected for 1.20 since CSIServiceAccountToken will be moved to beta starting 1.21.
if [[ $KUBERNETES_VERSION == "1.20" ]]; then
KUBELET_CONFIG_WITH_CSI_SERVICE_ACCOUNT_TOKEN_ENABLED=$(cat "/etc/kubernetes/kubelet/kubelet-config.json" | jq '.featureGates += {CSIServiceAccountToken: true}')
echo $KUBELET_CONFIG_WITH_CSI_SERVICE_ACCOUNT_TOKEN_ENABLED > "/etc/kubernetes/kubelet/kubelet-config.json"
fi
15 changes: 15 additions & 0 deletions variables.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,18 @@ variable "snapshot_users" {
type = list(string)
default = []
}

variable "motd_content" {
description = "Message Of The Day (MOTD) banner content."
type = string
default = <<EOF
You are accessing a U.S. Government (USG) Information System (IS) that is provided for USG-authorized use only.

By using this IS (which includes any device attached to this IS), you consent to the following conditions:
-The USG routinely intercepts and monitors communications on this IS for purposes including, but not limited to, penetration testing, COMSEC monitoring, network operations and defense, personnel misconduct (PM), law enforcement (LE), and counterintelligence (CI) investigations.
-At any time, the USG may inspect and seize data stored on this IS.
-Communications using, or data stored on, this IS are not private, are subject to routine monitoring, interception, and search, and may be disclosed or used for any USG-authorized purpose.
-This IS includes security measures (e.g., authentication and access controls) to protect USG interests--not for your personal benefit or privacy.
-Notwithstanding the above, using this IS does not constitute consent to PM, LE or CI investigative searching or monitoring of the content of privileged communications, or work product, related to personal representation or services by attorneys, psychotherapists, or clergy, and their assistants. Such communications and work product are private and confidential. See User Agreement for details.
EOF
}