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

🐛 SSH Hardening #160

Merged
merged 1 commit into from
Jun 18, 2024
Merged
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
48 changes: 42 additions & 6 deletions templates/cluster-template-calico.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,14 @@ spec:
content: |
# Restrict key exchange, cipher, and MAC algorithms, as per sshaudit.com
# hardening guide.
KexAlgorithms curve25519-sha256,[email protected],diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha256
KexAlgorithms [email protected],curve25519-sha256,[email protected],gss-curve25519-sha256-,diffie-hellman-group16-sha512,gss-group16-sha512-,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha256
Ciphers [email protected],[email protected],[email protected],aes256-ctr,aes192-ctr,aes128-ctr
MACs [email protected],[email protected],[email protected]
HostKeyAlgorithms ssh-ed25519,[email protected],[email protected],[email protected],rsa-sha2-256,rsa-sha2-512,[email protected],[email protected]
HostKeyAlgorithms [email protected],[email protected],[email protected],[email protected],[email protected],ssh-ed25519,rsa-sha2-512,rsa-sha2-256
CASignatureAlgorithms [email protected],ssh-ed25519,rsa-sha2-512,rsa-sha2-256
GSSAPIKexAlgorithms gss-curve25519-sha256-,gss-group16-sha512-
HostbasedAcceptedAlgorithms [email protected],[email protected],[email protected],ssh-ed25519,[email protected],rsa-sha2-512,[email protected],rsa-sha2-256
PubkeyAcceptedAlgorithms [email protected],[email protected],[email protected],ssh-ed25519,[email protected],rsa-sha2-512,[email protected],rsa-sha2-256
- path: /etc/sysctl.d/k8s.conf
content: |
fs.inotify.max_user_watches = 65536
Expand Down Expand Up @@ -245,6 +249,20 @@ spec:
kubectl --kubeconfig /etc/kubernetes/kubelet.conf
patch node $(hostname)
--type strategic -p '{"spec": {"providerID": "ionos://'$${system_uuid}'"}}'
- rm /etc/ssh/ssh_host_*
- ssh-keygen -t rsa -b 4096 -f /etc/ssh/ssh_host_rsa_key -N ""
- ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N ""
- sed -i 's/^\#HostKey \/etc\/ssh\/ssh_host_\(rsa\|ed25519\)_key$/HostKey \/etc\/ssh\/ssh_host_\1_key/g' /etc/ssh/sshd_config
- awk '$5 >= 3071' /etc/ssh/moduli > /etc/ssh/moduli.safe
- mv /etc/ssh/moduli.safe /etc/ssh/moduli
- iptables -I INPUT -p tcp --dport 22 -m state --state NEW -m recent --set
- iptables -I INPUT -p tcp --dport 22 -m state --state NEW -m recent --update --seconds 10 --hitcount 10 -j DROP
- ip6tables -I INPUT -p tcp --dport 22 -m state --state NEW -m recent --set
- ip6tables -I INPUT -p tcp --dport 22 -m state --state NEW -m recent --update --seconds 10 --hitcount 10 -j DROP
- apt-get update
- DEBIAN_FRONTEND=noninteractive apt-get install -q -y netfilter-persistent iptables-persistent
- service netfilter-persistent save
- systemctl restart sshd
initConfiguration:
localAPIEndpoint:
bindPort: ${CONTROL_PLANE_ENDPOINT_PORT:-6443}
Expand Down Expand Up @@ -341,10 +359,14 @@ spec:
content: |
# Restrict key exchange, cipher, and MAC algorithms, as per sshaudit.com
# hardening guide.
KexAlgorithms curve25519-sha256,[email protected],diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha256
KexAlgorithms [email protected],curve25519-sha256,[email protected],gss-curve25519-sha256-,diffie-hellman-group16-sha512,gss-group16-sha512-,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha256
Ciphers [email protected],[email protected],[email protected],aes256-ctr,aes192-ctr,aes128-ctr
MACs [email protected],[email protected],[email protected]
HostKeyAlgorithms ssh-ed25519,[email protected],[email protected],[email protected],rsa-sha2-256,rsa-sha2-512,[email protected],[email protected]
HostKeyAlgorithms [email protected],[email protected],[email protected],[email protected],[email protected],ssh-ed25519,rsa-sha2-512,rsa-sha2-256
CASignatureAlgorithms [email protected],ssh-ed25519,rsa-sha2-512,rsa-sha2-256
GSSAPIKexAlgorithms gss-curve25519-sha256-,gss-group16-sha512-
HostbasedAcceptedAlgorithms [email protected],[email protected],[email protected],ssh-ed25519,[email protected],rsa-sha2-512,[email protected],rsa-sha2-256
PubkeyAcceptedAlgorithms [email protected],[email protected],[email protected],ssh-ed25519,[email protected],rsa-sha2-512,[email protected],rsa-sha2-256
- path: /etc/sysctl.d/k8s.conf
content: |
fs.inotify.max_user_watches = 65536
Expand Down Expand Up @@ -386,6 +408,20 @@ spec:
kubectl --kubeconfig /etc/kubernetes/kubelet.conf
patch node $(hostname)
--type strategic -p '{"spec": {"providerID": "ionos://'$${system_uuid}'"}}'
- rm /etc/ssh/ssh_host_*
- ssh-keygen -t rsa -b 4096 -f /etc/ssh/ssh_host_rsa_key -N ""
- ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N ""
- sed -i 's/^\#HostKey \/etc\/ssh\/ssh_host_\(rsa\|ed25519\)_key$/HostKey \/etc\/ssh\/ssh_host_\1_key/g' /etc/ssh/sshd_config
- awk '$5 >= 3071' /etc/ssh/moduli > /etc/ssh/moduli.safe
- mv /etc/ssh/moduli.safe /etc/ssh/moduli
- iptables -I INPUT -p tcp --dport 22 -m state --state NEW -m recent --set
- iptables -I INPUT -p tcp --dport 22 -m state --state NEW -m recent --update --seconds 10 --hitcount 10 -j DROP
- ip6tables -I INPUT -p tcp --dport 22 -m state --state NEW -m recent --set
- ip6tables -I INPUT -p tcp --dport 22 -m state --state NEW -m recent --update --seconds 10 --hitcount 10 -j DROP
- apt-get update
- DEBIAN_FRONTEND=noninteractive apt-get install -q -y netfilter-persistent iptables-persistent
- service netfilter-persistent save
- systemctl restart sshd
joinConfiguration:
nodeRegistration:
kubeletExtraArgs:
Expand All @@ -405,5 +441,5 @@ spec:
matchLabels:
cluster.x-k8s.io/cluster-name: '${CLUSTER_NAME}'
resources:
- kind: ConfigMap
name: calico
- name: calico
kind: ConfigMap
61 changes: 51 additions & 10 deletions templates/cluster-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ apiVersion: cluster.x-k8s.io/v1beta1
kind: Cluster
metadata:
name: "${CLUSTER_NAME}"
labels:
cluster.x-k8s.io/cluster-name: "${CLUSTER_NAME}"
spec:
clusterNetwork:
pods:
Expand Down Expand Up @@ -52,23 +54,27 @@ spec:
- name: root
sshAuthorizedKeys: [${IONOSCLOUD_MACHINE_SSH_KEYS}]
ntp:
enabled: true
servers:
- 0.de.pool.ntp.org
- 1.de.pool.ntp.org
- 2.de.pool.ntp.org
- 3.de.pool.ntp.org
enabled: true
servers:
- 0.de.pool.ntp.org
- 1.de.pool.ntp.org
- 2.de.pool.ntp.org
- 3.de.pool.ntp.org
files:
- path: /etc/ssh/sshd_config.d/ssh-audit_hardening.conf
owner: root:root
permissions: '0644'
content: |
# Restrict key exchange, cipher, and MAC algorithms, as per sshaudit.com
# hardening guide.
KexAlgorithms curve25519-sha256,[email protected],diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha256
KexAlgorithms [email protected],curve25519-sha256,[email protected],gss-curve25519-sha256-,diffie-hellman-group16-sha512,gss-group16-sha512-,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha256
Ciphers [email protected],[email protected],[email protected],aes256-ctr,aes192-ctr,aes128-ctr
MACs [email protected],[email protected],[email protected]
HostKeyAlgorithms ssh-ed25519,[email protected],[email protected],[email protected],rsa-sha2-256,rsa-sha2-512,[email protected],[email protected]
HostKeyAlgorithms [email protected],[email protected],[email protected],[email protected],[email protected],ssh-ed25519,rsa-sha2-512,rsa-sha2-256
CASignatureAlgorithms [email protected],ssh-ed25519,rsa-sha2-512,rsa-sha2-256
GSSAPIKexAlgorithms gss-curve25519-sha256-,gss-group16-sha512-
HostbasedAcceptedAlgorithms [email protected],[email protected],[email protected],ssh-ed25519,[email protected],rsa-sha2-512,[email protected],rsa-sha2-256
PubkeyAcceptedAlgorithms [email protected],[email protected],[email protected],ssh-ed25519,[email protected],rsa-sha2-512,[email protected],rsa-sha2-256
- path: /etc/sysctl.d/k8s.conf
content: |
fs.inotify.max_user_watches = 65536
Expand Down Expand Up @@ -243,6 +249,20 @@ spec:
kubectl --kubeconfig /etc/kubernetes/kubelet.conf
patch node $(hostname)
--type strategic -p '{"spec": {"providerID": "ionos://'$${system_uuid}'"}}'
- rm /etc/ssh/ssh_host_*
- ssh-keygen -t rsa -b 4096 -f /etc/ssh/ssh_host_rsa_key -N ""
- ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N ""
- sed -i 's/^\#HostKey \/etc\/ssh\/ssh_host_\(rsa\|ed25519\)_key$/HostKey \/etc\/ssh\/ssh_host_\1_key/g' /etc/ssh/sshd_config
- awk '$5 >= 3071' /etc/ssh/moduli > /etc/ssh/moduli.safe
- mv /etc/ssh/moduli.safe /etc/ssh/moduli
- iptables -I INPUT -p tcp --dport 22 -m state --state NEW -m recent --set
- iptables -I INPUT -p tcp --dport 22 -m state --state NEW -m recent --update --seconds 10 --hitcount 10 -j DROP
- ip6tables -I INPUT -p tcp --dport 22 -m state --state NEW -m recent --set
- ip6tables -I INPUT -p tcp --dport 22 -m state --state NEW -m recent --update --seconds 10 --hitcount 10 -j DROP
- apt-get update
- DEBIAN_FRONTEND=noninteractive apt-get install -q -y netfilter-persistent iptables-persistent
- service netfilter-persistent save
- systemctl restart sshd
initConfiguration:
localAPIEndpoint:
bindPort: ${CONTROL_PLANE_ENDPOINT_PORT:-6443}
Expand Down Expand Up @@ -276,6 +296,8 @@ apiVersion: cluster.x-k8s.io/v1beta1
kind: MachineDeployment
metadata:
name: "${CLUSTER_NAME}-workers"
labels:
cluster.x-k8s.io/cluster-name: "${CLUSTER_NAME}"
spec:
clusterName: "${CLUSTER_NAME}"
replicas: ${WORKER_MACHINE_COUNT}
Expand All @@ -284,6 +306,7 @@ spec:
template:
metadata:
labels:
cluster.x-k8s.io/cluster-name: "${CLUSTER_NAME}"
node-role.kubernetes.io/node: ""
spec:
clusterName: "${CLUSTER_NAME}"
Expand Down Expand Up @@ -336,10 +359,14 @@ spec:
content: |
# Restrict key exchange, cipher, and MAC algorithms, as per sshaudit.com
# hardening guide.
KexAlgorithms curve25519-sha256,[email protected],diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha256
KexAlgorithms [email protected],curve25519-sha256,[email protected],gss-curve25519-sha256-,diffie-hellman-group16-sha512,gss-group16-sha512-,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha256
Ciphers [email protected],[email protected],[email protected],aes256-ctr,aes192-ctr,aes128-ctr
MACs [email protected],[email protected],[email protected]
HostKeyAlgorithms ssh-ed25519,[email protected],[email protected],[email protected],rsa-sha2-256,rsa-sha2-512,[email protected],[email protected]
HostKeyAlgorithms [email protected],[email protected],[email protected],[email protected],[email protected],ssh-ed25519,rsa-sha2-512,rsa-sha2-256
CASignatureAlgorithms [email protected],ssh-ed25519,rsa-sha2-512,rsa-sha2-256
GSSAPIKexAlgorithms gss-curve25519-sha256-,gss-group16-sha512-
HostbasedAcceptedAlgorithms [email protected],[email protected],[email protected],ssh-ed25519,[email protected],rsa-sha2-512,[email protected],rsa-sha2-256
PubkeyAcceptedAlgorithms [email protected],[email protected],[email protected],ssh-ed25519,[email protected],rsa-sha2-512,[email protected],rsa-sha2-256
- path: /etc/sysctl.d/k8s.conf
content: |
fs.inotify.max_user_watches = 65536
Expand Down Expand Up @@ -381,6 +408,20 @@ spec:
kubectl --kubeconfig /etc/kubernetes/kubelet.conf
patch node $(hostname)
--type strategic -p '{"spec": {"providerID": "ionos://'$${system_uuid}'"}}'
- rm /etc/ssh/ssh_host_*
- ssh-keygen -t rsa -b 4096 -f /etc/ssh/ssh_host_rsa_key -N ""
- ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N ""
- sed -i 's/^\#HostKey \/etc\/ssh\/ssh_host_\(rsa\|ed25519\)_key$/HostKey \/etc\/ssh\/ssh_host_\1_key/g' /etc/ssh/sshd_config
- awk '$5 >= 3071' /etc/ssh/moduli > /etc/ssh/moduli.safe
- mv /etc/ssh/moduli.safe /etc/ssh/moduli
- iptables -I INPUT -p tcp --dport 22 -m state --state NEW -m recent --set
- iptables -I INPUT -p tcp --dport 22 -m state --state NEW -m recent --update --seconds 10 --hitcount 10 -j DROP
- ip6tables -I INPUT -p tcp --dport 22 -m state --state NEW -m recent --set
- ip6tables -I INPUT -p tcp --dport 22 -m state --state NEW -m recent --update --seconds 10 --hitcount 10 -j DROP
- apt-get update
- DEBIAN_FRONTEND=noninteractive apt-get install -q -y netfilter-persistent iptables-persistent
- service netfilter-persistent save
- systemctl restart sshd
joinConfiguration:
nodeRegistration:
kubeletExtraArgs:
Expand Down
Loading
Loading