Software security is not security software. Here we're concerned with topics like authentication, access control, confidentiality, cryptography, and privilege management.
from Crypto.PublicKey import RSA
key = RSA.generate(2048)
f = open('mykey.pem','w')
f.write(key.exportKey(format='PEM'))
f.close()
require 'openssl'
key = OpenSSL::PKey::RSA.new 2048
File.open('mykey.pem', 'w') do |file|
file.write(key.to_pem)
end
--profiling
flag is not present in the command to start the component or the flag is set to true
.iptables
based on the networking options in Pod configurations. Setting makeIPTablesUtilChains
to enabled:false
in a Kubelet configuration prevents the Kubelet from managing network traffic between containers and the rest of the world. This prevents the Kubelet from enforcing the necessary network security requirements and setting up the connectivity requested by containers.iptables
because of the setting makeIPTablesUtilChains: false
.
apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
makeIPTablesUtilChains: false
--profiling
flag is not present in the command to start the component or the flag is set to true
.readOnlyRootFilesystem: false
setting disables this restriction, which allows an attacker to tamper with the local file system or write malicious executable to disk.readOnlyRootFilesystem
field to false
, which permits applications inside a container to write data to the local disk.
...
kind: Pod
...
spec:
containers:
- name: ...
...
securityContext:
readOnlyRootFilesystem: false
...
AlwaysPullImages
admission controller can prevent this bypass.AlwaysPullImages
admission controller in the --enable-admission-plugins
flag.
...
kind: Pod
...
spec:
containers:
- command:
- kube-apiserver
...
- --enable-admission-plugins=PodNodeSelector,LimitRanger
...
AlwaysAdmit
admission controller is enabled.AlwaysAdmit
admission controller.
...
kind: Pod
...
spec:
containers:
- command:
- kube-apiserver
...
- --enable-admission-plugins=AlwaysAdmit,PodSecurityPolicy
...
--client-cert-auth
flag is set to false
.--client-cert-auth
flag to false
.
...
spec:
containers:
- command:
...
- etcd
...
--client-cert-auth=false
...
--audit-log-maxage
flag defines the maximum number of days to retain old audit log files. Either the flag is not present in the command to start a Kubernetes API server or the retention period is set to less than 30 days.--audit-log-maxage
flag to 2
(2 days), which is too short.
...
kind: Pod
...
spec:
containers:
- command:
- kube-apiserver
...
- --audit-log-maxage=2
...
--audit-log-maxbackup
flag defines the maximum number of log files to retain. Either this flag is not present in the command to start a Kubernetes API server or the maximum number of log files to retain is less than 10.--audit-log-maxbackup
flag to 2
, which insufficiently retains only two log files.
...
kind: Pod
...
spec:
containers:
- command:
- kube-apiserver
...
- --audit-log-maxbackup=2
...
--audit-log-maxsize
flag sets the maximum size in megabytes (MB) of the audit log file before it's automatically rotated. Either this flag is not present in the command to start a Kubernetes API server or the maximum size of the audit log file is set to less than 100 MB.--audit-log-maxsize
flag to 2
(megabytes), which is insufficient.
...
kind: Pod
...
spec:
containers:
- command:
- kube-apiserver
...
- ----audit-log-maxsize=2
...
ProtectKernelDefaults
setting is left unset or is set to false, a Kubelet can modify kernel parameters at runtime. Kernel parameters should be optimized and hardened before the Kubernetes deployment. Granting a Kubelet the ability to alter kernel parameters expands the attack surface of the host operating system.ProtectKernelDefaults: false
setting.
apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
ProtectKernelDefaults: false
streamingConnectionIdleTimeout
field of a Kubelet configuration specifies the maximum amount of time a streaming connection is idle before the connection is automatically closed. Setting idle timeouts protects against denial-of-service attacks and running out of connections. Setting the field value to 0
disables the idle timeout.streamingConnectionIdleTimeout
field to 0
.
apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
streamingConnectionIdleTimeout: 0
AlwaysAllow
mode because it allows all requests.AlwaysAllow
as one of the authorization modes.
...
kind: Pod
...
spec:
containers:
- command:
- kube-apiserver
...
- --authorization-mode=...,AlwaysAllow,...
...
--root-ca-file
flag, which specifies a root Certification Authority (CA) file. As a result, the Kubernetes controller manager does not publish a corresponding root CA certificate to Pods. Without the root CA certificate, the Pods cannot verify the API server's serving certificate before establishing connections. Such connections are susceptible to a man-in-the-middle attack.--root-ca-file
flag.
...
kind: Pod
...
spec:
containers:
- command:
- kube-controller-manager
image: k8s.gcr.io/kube-controller-manager:v1.9.7
imagePullPolicy: IfNotPresent
...
...
kind: Pod
...
spec:
containers:
- command:
- kube-controller-manager
image: example.domain/kube-controller-manager:v1.9.7
imagePullPolicy: IfNotPresent
...
AlwaysAllow
mode or the Webhook
mode. An unspecified authorization mode defaults to AlwaysAllow
. The Kubelet does not perform any authorization check in AlwaysAllow
mode because it allows all requests. Because Kubelets are the Kubernetes principal agents to manage a worker machine workload, attackers can use uncontrolled requests to gain access to insufficiently protected and security sensitive service APIs.AlwaysAllow
.
apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
authorization:
mode: AlwaysAllow
clientCAFile
field that specifies the CA bundle used to verify client certificates.
apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
--kubelet-client-certificate
flag and the --kubelet-client-key
flag respectively to enable certificate-based authentication to Kubelets.
...
spec:
containers:
- command:
- kube-apiserver
- --audit-log-maxage=50
- --audit-log-maxbackup=20
- --audit-log-maxsize=200
image: gcr.io/google_containers/kube-apiserver-amd64:v1.6.0
...