Skip to content

Commit

Permalink
Add k3s-cis-1.9 profile
Browse files Browse the repository at this point in the history
    Original PR: rancher#251
 	- Add last minors for auto k3s version matching
 	- Reduce default output of validate-yaml
 	- Rework 5.1.1 audit
 	- Add 5.1.3 and 5.1.6 with k3s whitelist exceptions
 	- Convert 5.1.1 and 5.1.6 to Automated
 	- Convert 5.1.3 to Scored/Automated with a hardcoded whitelist
 	- lint fix
 	- Change cr_whitelist to bash array
 	- Revert "Change cr_whitelist to bash array"
		- This reverts commit 72449a0.
 	- Add exception for 5.1.5
 	- Typo fix
  • Loading branch information
dereknola authored and andypitcher committed Nov 29, 2024
1 parent 3990244 commit 677b3aa
Show file tree
Hide file tree
Showing 8 changed files with 2,121 additions and 2 deletions.
10 changes: 8 additions & 2 deletions hack/validate-yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ function main(){
FAILED_CFGS_YML=()
FAILED_CFGS_KB=()
FAILED_CHECKS_TYPE=()
DEBUG=${DEBUG:-}

if [ -n "$DEBUG" ]; then
set -x
fi
# Loop through all benchmarks
for cfg in ${CFGS}; do
set -x

# yammlint is configured with ../.yamllint.yaml, to catch any liniting errors for a given benchmark. If result isn't empty, FAILED_CFGS_YML is appended with the failing benchmark.
if [ -n "$(yamllint -s package/cfg/$cfg)" ]; then
FAILED_CFGS_YML+=("$cfg")
Expand Down Expand Up @@ -46,8 +50,10 @@ function main(){
else
FAILED_CFGS_KB+=("$cfg")
fi
set +x
done
if [ -n "$DEBUG" ]; then
set +x
fi

# Test if any profiles have errors, either FAILED_CFGS_YML or FAILED_CFGS_KB or FAILED_CHECKS_TYPE is greater than 0, fails.
if [ ${#FAILED_CFGS_YML[@]} -gt 0 ]; then
Expand Down
10 changes: 10 additions & 0 deletions package/cfg/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ version_mapping:
- "gke-1.6.0"
"aks-1.0":
- "aks-1.0"
"v1.24.17+k3s1": "k3s-cis-1.24-hardened"
"v1.25.16+k3s4": "k3s-cis-1.7-hardened"
"v1.26.15+k3s1": "k3s-cis-1.8-hardened"
"v1.27.16+k3s1": "k3s-cis-1.9"

target_mapping:
# EKS
Expand Down Expand Up @@ -448,3 +452,9 @@ target_mapping:
- "controlplane"
- "etcd"
- "policies"
"k3s-cis-1.9":
- "master"
- "node"
- "controlplane"
- "etcd"
- "policies"
54 changes: 54 additions & 0 deletions package/cfg/k3s-cis-1.9/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
## Version-specific settings that override the values in cfg/config.yaml

master:
components:
- apiserver
- kubelet
- scheduler
- controllermanager
- etcd
- policies
apiserver:
bins:
- containerd
kubelet:
bins:
- containerd
defaultkubeconfig: /var/lib/rancher/k3s/agent/kubelet.kubeconfig
defaultcafile: /var/lib/rancher/k3s/agent/client-ca.crt
scheduler:
bins:
- containerd
kubeconfig:
- /var/lib/rancher/k3s/server/cred/scheduler.kubeconfig
controllermanager:
bins:
- containerd
kubeconfig:
- /var/lib/rancher/k3s/server/cred/controller.kubeconfig
etcd:
bins:
- containerd

etcd:
confs: /var/lib/rancher/k3s/server/db/etcd/config

node:
components:
- kubelet
- proxy
kubelet:
bins:
- containerd
confs:
- /var/lib/rancher/k3s/agent/kubelet.kubeconfig
defaultkubeconfig: /var/lib/rancher/k3s/agent/kubelet.kubeconfig
defaultcafile: /var/lib/rancher/k3s/agent/client-ca.crt
proxy:
bins:
- containerd
defaultkubeconfig: /var/lib/rancher/k3s/agent/kubeproxy.kubeconfig
policies:
components:
- policies
62 changes: 62 additions & 0 deletions package/cfg/k3s-cis-1.9/controlplane.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
controls:
version: "cis-1.9"
id: 3
text: "Control Plane Configuration"
type: "controlplane"
groups:
- id: 3.1
text: "Authentication and Authorization"
checks:
- id: 3.1.1
text: "Client certificate authentication should not be used for users (Manual)"
type: "manual"
remediation: |
Alternative mechanisms provided by Kubernetes such as the use of OIDC should be
implemented in place of client certificates.
scored: false

- id: 3.1.2
text: "Service account token authentication should not be used for users (Manual)"
type: "manual"
remediation: |
Alternative mechanisms provided by Kubernetes such as the use of OIDC should be implemented
in place of service account tokens.
scored: false

- id: 3.1.3
text: "Bootstrap token authentication should not be used for users (Manual)"
type: "manual"
remediation: |
Alternative mechanisms provided by Kubernetes such as the use of OIDC should be implemented
in place of bootstrap tokens.
scored: false

- id: 3.2
text: "Logging"
checks:
- id: 3.2.1
text: "Ensure that a minimal audit policy is created (Manual)"
audit: "journalctl -m -u k3s | grep 'Running kube-apiserver' | tail -n1 | grep 'audit-policy-file'"
tests:
test_items:
- flag: "--audit-policy-file"
set: true
remediation: |
Create an audit policy file for your cluster.
scored: false

- id: 3.2.2
text: "Ensure that the audit policy covers key security concerns (Manual)"
type: "manual"
remediation: |
Review the audit policy provided for the cluster and ensure that it covers
at least the following areas,
- Access to Secrets managed by the cluster. Care should be taken to only
log Metadata for requests to Secrets, ConfigMaps, and TokenReviews, in
order to avoid risk of logging sensitive data.
- Modification of Pod and Deployment objects.
- Use of `pods/exec`, `pods/portforward`, `pods/proxy` and `services/proxy`.
For most requests, minimally logging at the Metadata level is recommended
(the most basic level of logging).
scored: false
144 changes: 144 additions & 0 deletions package/cfg/k3s-cis-1.9/etcd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
---
controls:
version: "cis-1.9"
id: 2
text: "Etcd Node Configuration"
type: "etcd"
groups:
- id: 2
text: "Etcd Node Configuration"
checks:
- id: 2.1
text: "Ensure that the --cert-file and --key-file arguments are set as appropriate (Manual)"
audit_config: "cat $etcdconf"
tests:
bin_op: and
test_items:
- path: "{.client-transport-security.cert-file}"
compare:
op: eq
value: "/var/lib/rancher/k3s/server/tls/etcd/server-client.crt"
- path: "{.client-transport-security.key-file}"
compare:
op: eq
value: "/var/lib/rancher/k3s/server/tls/etcd/server-client.key"
remediation: |
If running on with sqlite or a external DB, etcd checks are Not Applicable.
When running with embedded-etcd, K3s generates cert and key files for etcd.
These are located in /var/lib/rancher/k3s/server/tls/etcd/.
If this check fails, ensure that the configuration file $etcdconf
has not been modified to use custom cert and key files.
scored: false

- id: 2.2
text: "Ensure that the --client-cert-auth argument is set to true (Manual)"
audit_config: "cat $etcdconf"
tests:
test_items:
- path: "{.client-transport-security.client-cert-auth}"
compare:
op: eq
value: true
remediation: |
If running on with sqlite or a external DB, etcd checks are Not Applicable.
When running with embedded-etcd, K3s sets the --client-cert-auth parameter to true.
If this check fails, ensure that the configuration file $etcdconf
has not been modified to disable client certificate authentication.
scored: false

- id: 2.3
text: "Ensure that the --auto-tls argument is not set to true (Manual)"
audit_config: "cat $etcdconf"
tests:
bin_op: or
test_items:
- path: "{.client-transport-security.auto-tls}"
compare:
op: eq
value: false
- path: "{.client-transport-security.auto-tls}"
set: false
remediation: |
If running on with sqlite or a external DB, etcd checks are Not Applicable.
When running with embedded-etcd, K3s does not set the --auto-tls parameter.
If this check fails, edit the etcd pod specification file $etcdconf on the master
node and either remove the --auto-tls parameter or set it to false.
client-transport-security:
auto-tls: false
scored: false

- id: 2.4
text: "Ensure that the --peer-cert-file and --peer-key-file arguments are set as appropriate (Manual)"
audit_config: "cat $etcdconf"
tests:
bin_op: and
test_items:
- path: "{.peer-transport-security.cert-file}"
compare:
op: eq
value: "/var/lib/rancher/k3s/server/tls/etcd/peer-server-client.crt"
- path: "{.peer-transport-security.key-file}"
compare:
op: eq
value: "/var/lib/rancher/k3s/server/tls/etcd/peer-server-client.key"
remediation: |
If running on with sqlite or a external DB, etcd checks are Not Applicable.
When running with embedded-etcd, K3s generates peer cert and key files for etcd.
These are located in /var/lib/rancher/k3s/server/tls/etcd/.
If this check fails, ensure that the configuration file $etcdconf
has not been modified to use custom peer cert and key files.
scored: false

- id: 2.5
text: "Ensure that the --peer-client-cert-auth argument is set to true (Manual)"
audit_config: "cat $etcdconf"
tests:
test_items:
- path: "{.peer-transport-security.client-cert-auth}"
compare:
op: eq
value: true
remediation: |
If running on with sqlite or a external DB, etcd checks are Not Applicable.
When running with embedded-etcd, K3s sets the --peer-cert-auth parameter to true.
If this check fails, ensure that the configuration file $etcdconf
has not been modified to disable peer client certificate authentication.
scored: false

- id: 2.6
text: "Ensure that the --peer-auto-tls argument is not set to true (Manual)"
audit_config: "cat $etcdconf"
tests:
bin_op: or
test_items:
- path: "{.peer-transport-security.auto-tls}"
compare:
op: eq
value: false
- path: "{.peer-transport-security.auto-tls}"
set: false
remediation: |
If running on with sqlite or a external DB, etcd checks are Not Applicable.
When running with embedded-etcd, K3s does not set the --peer-auto-tls parameter.
If this check fails, edit the etcd pod specification file $etcdconf on the master
node and either remove the --peer-auto-tls parameter or set it to false.
peer-transport-security:
auto-tls: false
scored: false

- id: 2.7
text: "Ensure that a unique Certificate Authority is used for etcd (Manual)"
audit_config: "cat $etcdconf"
tests:
test_items:
- path: "{.peer-transport-security.trusted-ca-file}"
compare:
op: eq
value: "/var/lib/rancher/k3s/server/tls/etcd/peer-ca.crt"
remediation: |
If running on with sqlite or a external DB, etcd checks are Not Applicable.
When running with embedded-etcd, K3s generates a unique certificate authority for etcd.
This is located at /var/lib/rancher/k3s/server/tls/etcd/peer-ca.crt.
If this check fails, ensure that the configuration file $etcdconf
has not been modified to use a shared certificate authority.
scored: false
Loading

0 comments on commit 677b3aa

Please sign in to comment.