Skip to content

Commit 26a483c

Browse files
authored
Add remediation information to all checks (#14)
* For each check, print information about how it can be remediated. * Add a unit test to enforce that this is added for all built-in checks.
1 parent 372bdaf commit 26a483c

29 files changed

+127
-61
lines changed

docs/generated/checks.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
The following table enumerates built-in checks:
22

3-
| Name | Enabled by default | Description | Template | Parameters |
4-
| ---- | ------------------ | ----------- | -------- | ---------- |
5-
| dangling-service | Yes | Alert on services that don't have any matching deployments | dangling-service | `{}` |
6-
| default-service-account | No | Alert on pods that use the default service account | service-account | `{"serviceAccount":"^(|default)$"}` |
7-
| deprecated-service-account-field | Yes | Alert on deployments that use the deprecated serviceAccount field | deprecated-service-account-field | `{}` |
8-
| env-var-secret | Yes | Alert on objects using a secret in an environment variable | env-var | `{"name":".*secret.*"}` |
9-
| no-extensions-v1beta | Yes | Alert on objects using deprecated API versions under extensions v1beta | disallowed-api-obj | `{"group":"extensions","version":"v1beta.+"}` |
10-
| no-liveness-probe | No | Alert on containers which don't specify a liveness probe | liveness-probe | `{}` |
11-
| no-read-only-root-fs | Yes | Alert on containers not running with a read-only root filesystem | read-only-root-fs | `{}` |
12-
| no-readiness-probe | No | Alert on containers which don't specify a readiness probe | readiness-probe | `{}` |
13-
| non-existent-service-account | Yes | Alert on pods referencing a service account that isn't found | non-existent-service-account | `{}` |
14-
| privileged-container | Yes | Alert on deployments with containers running in privileged mode | privileged | `{}` |
15-
| required-annotation-email | No | Alert on objects without an 'email' annotation with a valid email | required-annotation | `{"key":"email","value":"[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+"}` |
16-
| required-label-owner | No | Alert on objects without the 'owner' label | required-label | `{"key":"owner"}` |
17-
| run-as-non-root | Yes | Alert on containers not set to runAsNonRoot | run-as-non-root | `{}` |
18-
| unset-cpu-requirements | Yes | Alert on containers without CPU requests and limits set | cpu-requirements | `{"lowerBoundMillis":0,"requirementsType":"any","upperBoundMillis":0}` |
19-
| unset-memory-requirements | Yes | Alert on containers without memory requests and limits set | memory-requirements | `{"lowerBoundMB":0,"requirementsType":"any","upperBoundMB":0}` |
20-
| writable-host-mount | No | Alert on containers that mount a host path as writable | writable-host-mount | `{}` |
3+
| Name | Enabled by default | Description | Remediation | Template | Parameters |
4+
| ---- | ------------------ | ----------- | ----------- | -------- | ---------- |
5+
| dangling-service | Yes | Alert on services that don't have any matching deployments | Make sure your service's selector correctly matches the labels on one of your deployments. | dangling-service | `{}` |
6+
| default-service-account | No | Alert on pods that use the default service account | Create a dedicated service account for your pod. See https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/ for more details. | service-account | `{"serviceAccount":"^(|default)$"}` |
7+
| deprecated-service-account-field | Yes | Alert on deployments that use the deprecated serviceAccount field | Use the serviceAccoutName field instead of the serviceAccount field. | deprecated-service-account-field | `{}` |
8+
| env-var-secret | Yes | Alert on objects using a secret in an environment variable | Don't use raw secrets in an environment variable. Instead, either mount the secret as a file or use a secretKeyRef. See https://kubernetes.io/docs/concepts/configuration/secret/#using-secrets for more details. | env-var | `{"name":"(?i).*secret.*"}` |
9+
| no-extensions-v1beta | Yes | Alert on objects using deprecated API versions under extensions v1beta | Migrate to using the apps/v1 API versions for these objects. See https://kubernetes.io/blog/2019/07/18/api-deprecations-in-1-16/ for more details. | disallowed-api-obj | `{"group":"extensions","version":"v1beta.+"}` |
10+
| no-liveness-probe | No | Alert on containers which don't specify a liveness probe | Specify a liveness probe in your container. See https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/ for more details. | liveness-probe | `{}` |
11+
| no-read-only-root-fs | Yes | Alert on containers not running with a read-only root filesystem | Set readOnlyRootFilesystem to true in your container's securityContext. | read-only-root-fs | `{}` |
12+
| no-readiness-probe | No | Alert on containers which don't specify a readiness probe | Specify a readiness probe in your container. See https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/ for more details. | readiness-probe | `{}` |
13+
| non-existent-service-account | Yes | Alert on pods referencing a service account that isn't found | Make sure to create the service account, or to refer to an existing service account. | non-existent-service-account | `{}` |
14+
| privileged-container | Yes | Alert on deployments with containers running in privileged mode | Don't run your container as privileged unless required. | privileged | `{}` |
15+
| required-annotation-email | No | Alert on objects without an 'email' annotation with a valid email | Add an email annotation to your object with the contact information of the object's owner. | required-annotation | `{"key":"email","value":"[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+"}` |
16+
| required-label-owner | No | Alert on objects without the 'owner' label | Add an email annotation to your object with information about the object's owner. | required-label | `{"key":"owner"}` |
17+
| run-as-non-root | Yes | Alert on containers not set to runAsNonRoot | Set runAsUser to a non-zero number, and runAsNonRoot to true, in your pod or container securityContext. See https://kubernetes.io/docs/tasks/configure-pod-container/security-context/ for more details. | run-as-non-root | `{}` |
18+
| unset-cpu-requirements | Yes | Alert on containers without CPU requests and limits set | Set your container's CPU requests and limits depending on its requirements. See https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#requests-and-limits for more details. | cpu-requirements | `{"lowerBoundMillis":0,"requirementsType":"any","upperBoundMillis":0}` |
19+
| unset-memory-requirements | Yes | Alert on containers without memory requests and limits set | Set your container's memory requests and limits depending on its requirements. See https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#requests-and-limits for more details. | memory-requirements | `{"lowerBoundMB":0,"requirementsType":"any","upperBoundMB":0}` |
20+
| writable-host-mount | No | Alert on containers that mount a host path as writable | If you need to access files on the host, mount them as readOnly. | writable-host-mount | `{}` |

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.14
44

55
require (
66
github.com/Masterminds/sprig/v3 v3.1.0
7+
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d
78
github.com/fatih/color v1.9.0
89
github.com/ghodss/yaml v1.0.0
910
github.com/gobuffalo/packr v1.30.1

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWX
6363
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
6464
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
6565
github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g=
66+
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpHMqeKTCYkitsPqHNxTmd4SNR5r94FGM8=
67+
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d/go.mod h1:asat636LX7Bqt5lYEZ27JNDcqxfjdBQuJ/MM4CN/Lzo=
6668
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
6769
github.com/agnivade/levenshtein v1.0.1/go.mod h1:CURSv5d9Uaml+FovSIICkLbAUZ9S4RqaHDIsdSBg7lM=
6870
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package builtinchecks
2+
3+
import (
4+
"strings"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
"github.com/stretchr/testify/require"
9+
)
10+
11+
func TestBuiltInChecksWellFormed(t *testing.T) {
12+
checks, err := List()
13+
require.NoError(t, err)
14+
for _, check := range checks {
15+
t.Run(check.Name, func(t *testing.T) {
16+
assert.NotEmpty(t, check.Remediation, "Please add remediation")
17+
assert.True(t, strings.HasSuffix(check.Remediation, "."), "Please end your remediation texts with a period (got %q)", check.Remediation)
18+
})
19+
}
20+
}

internal/builtinchecks/yamls/dangling-service.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
name: "dangling-service"
22
description: "Alert on services that don't have any matching deployments"
3+
remediation: "Make sure your service's selector correctly matches the labels on one of your deployments."
34
scope:
45
objectKinds:
56
- Service
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
name: "deprecated-service-account-field"
2-
description: "Alert on deployments that use the deprecated serviceAccount field"
1+
name: "default-service-account"
2+
description: "Alert on pods that use the default service account"
3+
remediation: >-
4+
Create a dedicated service account for your pod.
5+
See https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/ for more details.
36
scope:
47
objectKinds:
58
- DeploymentLike
6-
template: "deprecated-service-account-field"
9+
template: "service-account"
10+
params:
11+
serviceAccount: "^(|default)$"
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
name: "default-service-account"
2-
description: "Alert on pods that use the default service account"
1+
name: "deprecated-service-account-field"
2+
description: "Alert on deployments that use the deprecated serviceAccount field"
3+
remediation: "Use the serviceAccoutName field instead of the serviceAccount field."
34
scope:
45
objectKinds:
56
- DeploymentLike
6-
template: "service-account"
7-
params:
8-
serviceAccount: "^(|default)$"
7+
template: "deprecated-service-account-field"
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
name: "env-var-secret"
22
description: "Alert on objects using a secret in an environment variable"
3+
remediation: >-
4+
Don't use raw secrets in an environment variable. Instead, either mount the secret as a file or use a secretKeyRef.
5+
See https://kubernetes.io/docs/concepts/configuration/secret/#using-secrets for more details.
36
scope:
47
objectKinds:
58
- DeploymentLike
69
template: "env-var"
710
params:
8-
name: ".*secret.*"
11+
name: "(?i).*secret.*"

internal/builtinchecks/yamls/liveness-probe.yaml

Lines changed: 0 additions & 6 deletions
This file was deleted.

internal/builtinchecks/yamls/no-extensions-v1beta.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
name: "no-extensions-v1beta"
22
description: "Alert on objects using deprecated API versions under extensions v1beta"
3+
remediation: >-
4+
Migrate to using the apps/v1 API versions for these objects.
5+
See https://kubernetes.io/blog/2019/07/18/api-deprecations-in-1-16/ for more details.
36
scope:
47
objectKinds:
58
- Any

0 commit comments

Comments
 (0)