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

Fix control C-0211 #501

Merged
merged 2 commits into from
Sep 4, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"set-procmount-default",
"set-fsgroup-value",
"set-fsgroupchangepolicy-value",
"set-systctls-params",
"set-sysctls-params",
"set-supplementalgroups-values"
],
"baseScore": 8,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ package armo_builtins

### POD ###

# Fails if securityContext.systctls is not set
# Fails if securityContext.sysctls is not set
deny[msga] {
# verify the object kind
pod := input[_]
pod.kind = "Pod"

# check securityContext has systctls set
not pod.spec.securityContext.systctls
# check securityContext has sysctls set
not pod.spec.securityContext.sysctls

path := "spec.securityContext.systctls"
path := "spec.securityContext.sysctls"
msga := {
"alertMessage": sprintf("Pod: %v does not set 'securityContext.systctls'", [pod.metadata.name]),
"alertMessage": sprintf("Pod: %v does not set 'securityContext.sysctls'", [pod.metadata.name]),
"packagename": "armo_builtins",
"alertScore": 7,
"failedPaths": [],
Expand All @@ -26,19 +26,19 @@ deny[msga] {

### WORKLOAD ###

# Fails if securityContext.systctls is not set
# Fails if securityContext.sysctls is not set
deny[msga] {
# verify the object kind
wl := input[_]
manifest_kind := {"Deployment","ReplicaSet","DaemonSet","StatefulSet","Job"}
manifest_kind[wl.kind]

# check securityContext has systctls set
not wl.spec.template.spec.securityContext.systctls
# check securityContext has sysctls set
not wl.spec.template.spec.securityContext.sysctls

path := "spec.template.spec.securityContext.systctls"
path := "spec.template.spec.securityContext.sysctls"
msga := {
"alertMessage": sprintf("Workload: %v does not set 'securityContext.systctls'", [wl.metadata.name]),
"alertMessage": sprintf("Workload: %v does not set 'securityContext.sysctls'", [wl.metadata.name]),
"packagename": "armo_builtins",
"alertScore": 7,
"failedPaths": [],
Expand All @@ -51,18 +51,18 @@ deny[msga] {

### CRONJOB ###

# Fails if securityContext.systctls is not set
# Fails if securityContext.sysctls is not set
deny[msga] {
# verify the object kind
cj := input[_]
cj.kind == "CronJob"

# check securityContext has systctls set
not cj.spec.jobTemplate.spec.template.spec.securityContext.systctls
# check securityContext has sysctls set
not cj.spec.jobTemplate.spec.template.spec.securityContext.sysctls

path := "spec.jobTemplate.spec.template.spec.securityContext.systctls"
path := "spec.jobTemplate.spec.template.spec.securityContext.sysctls"
msga := {
"alertMessage": sprintf("CronJob: %v does not set 'securityContext.systctls'", [cj.metadata.name]),
"alertMessage": sprintf("CronJob: %v does not set 'securityContext.sysctls'", [cj.metadata.name]),
"packagename": "armo_builtins",
"alertScore": 7,
"failedPaths": [],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "set-systctls-params",
"name": "set-sysctls-params",
"attributes": {
"armoBuiltin": true
},
Expand Down Expand Up @@ -45,7 +45,7 @@
],
"ruleDependencies": [
],
"description": "Fails if securityContext.systctls is not set.",
"remediation": "Set securityContext.systctls params",
"description": "Fails if securityContext.sysctls is not set.",
"remediation": "Set securityContext.sysctls params",
"ruleQuery": "armo_builtins"
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[
{
"alertMessage": "CronJob: hello does not set 'securityContext.systctls'",
"alertMessage": "CronJob: hello does not set 'securityContext.sysctls'",
"packagename": "armo_builtins",
"alertScore": 7,
"failedPaths": [],
"fixPaths": [{"path": "spec.jobTemplate.spec.template.spec.securityContext.systctls", "name": "net.ipv4.tcp_syncookie", "value": "1"}],
"fixPaths": [{"path": "spec.jobTemplate.spec.template.spec.securityContext.sysctls", "name": "net.ipv4.tcp_syncookie", "value": "1"}],
"ruleStatus": "",
"alertObject": {
"k8sApiObjects": [
Expand Down
1 change: 1 addition & 0 deletions rules/set-sysctls-params/test/pod-pass/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
15 changes: 15 additions & 0 deletions rules/set-sysctls-params/test/pod-pass/input/pod1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
Dismissed Show dismissed Hide dismissed
kind: Pod
metadata:
name: sysctl-example
Dismissed Show dismissed Hide dismissed
spec:
securityContext:
Dismissed Show dismissed Hide dismissed
sysctls:
Dismissed Show dismissed Hide dismissed
- name: net.core.somaxconn
value: "1024"
- name: kernel.shm_rmid_forced
value: "0"
containers:
- name: sysctl-test-container
Dismissed Show dismissed Hide dismissed
Dismissed Show dismissed Hide dismissed
Dismissed Show dismissed Hide dismissed
Dismissed Show dismissed Hide dismissed
Dismissed Show dismissed Hide dismissed
Dismissed Show dismissed Hide dismissed
image: busybox
command: [ "sleep", "1000000" ]
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[
{
"alertMessage": "Pod: nginx does not set 'securityContext.systctls'",
"alertMessage": "Pod: nginx does not set 'securityContext.sysctls'",
"packagename": "armo_builtins",
"alertScore": 7,
"failedPaths": [],
"fixPaths": [{"path": "spec.securityContext.systctls", "name": "net.ipv4.tcp_syncookie", "value": "1"}],
"fixPaths": [{"path": "spec.securityContext.sysctls", "name": "net.ipv4.tcp_syncookie", "value": "1"}],
"ruleStatus": "",
"alertObject": {
"k8sApiObjects": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[
{
"alertMessage": "Workload: my-deployment does not set 'securityContext.systctls'",
"alertMessage": "Workload: my-deployment does not set 'securityContext.sysctls'",
"packagename": "armo_builtins",
"alertScore": 7,
"failedPaths": [],
"fixPaths": [{"path": "spec.template.spec.securityContext.systctls", "name": "net.ipv4.tcp_syncookie", "value": "1"}],
"fixPaths": [{"path": "spec.template.spec.securityContext.sysctls", "name": "net.ipv4.tcp_syncookie", "value": "1"}],
"ruleStatus": "",
"alertObject": {
"k8sApiObjects": [
Expand Down
Loading