Skip to content

Commit 8bdfdee

Browse files
k8s:chore - Adding improvements on k8s rules
In this commit I changed to add Safe and Unsafe code in all rules of the k8s. Reference from issue #630 and #1020. Signed-off-by: Wilian Gabriel <[email protected]>
1 parent 5570397 commit 8bdfdee

File tree

2 files changed

+184
-157
lines changed

2 files changed

+184
-157
lines changed

internal/services/engines/kubernetes/rules.go

+63-45
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ import (
2626
func NewAllowPrivilegeEscalation() *text.Rule {
2727
return &text.Rule{
2828
Metadata: engine.Metadata{
29-
ID: "HS-KUBERNETES-1",
30-
Name: "Allow Privilege Escalation",
31-
Description: "Privileged containers share namespaces with the host system, eschew cgroup restrictions, and do not offer any security. They should be used exclusively as a bundling and distribution mechanism for the code in the container, and not for isolation.",
32-
Severity: severities.Medium.ToString(),
33-
Confidence: confidence.High.ToString(),
29+
ID: "HS-KUBERNETES-1",
30+
Name: "Allow Privilege Escalation",
31+
Description: "Privileged containers share namespaces with the host system, eschew cgroup restrictions, and do not offer any security. They should be used exclusively as a bundling and distribution mechanism for the code in the container, and not for isolation.",
32+
Severity: severities.Medium.ToString(),
33+
Confidence: confidence.High.ToString(),
34+
SafeExample: SampleSafeHSKUBERNETES1,
35+
UnsafeExample: SampleVulnerableHSKUBERNETES1,
3436
},
3537
Type: text.AndMatch,
3638
Expressions: []*regexp.Regexp{
@@ -44,11 +46,13 @@ func NewAllowPrivilegeEscalation() *text.Rule {
4446
func NewHostAliases() *text.Rule {
4547
return &text.Rule{
4648
Metadata: engine.Metadata{
47-
ID: "HS-KUBERNETES-2",
48-
Name: "Host Aliases",
49-
Description: "Managing /etc/hosts aliases can prevent the container from modifying the file after a pod's containers have already been started. DNS should be managed by the orchestrator.",
50-
Severity: severities.Low.ToString(),
51-
Confidence: confidence.Medium.ToString(),
49+
ID: "HS-KUBERNETES-2",
50+
Name: "Host Aliases",
51+
Description: "Managing /etc/hosts aliases can prevent the container from modifying the file after a pod's containers have already been started. DNS should be managed by the orchestrator.",
52+
Severity: severities.Low.ToString(),
53+
Confidence: confidence.Medium.ToString(),
54+
SafeExample: SampleSafeHSKUBERNETES2,
55+
UnsafeExample: SampleVulnerableHSKUBERNETES2,
5256
},
5357
Type: text.AndMatch,
5458
Expressions: []*regexp.Regexp{
@@ -62,11 +66,13 @@ func NewHostAliases() *text.Rule {
6266
func NewDockerSock() *text.Rule {
6367
return &text.Rule{
6468
Metadata: engine.Metadata{
65-
ID: "HS-KUBERNETES-3",
66-
Name: "Docker Sock",
67-
Description: "Mounting the docker.socket leaks information about other containers and can allow container breakout.",
68-
Severity: severities.Medium.ToString(),
69-
Confidence: confidence.High.ToString(),
69+
ID: "HS-KUBERNETES-3",
70+
Name: "Docker Sock",
71+
Description: "Mounting the docker.socket leaks information about other containers and can allow container breakout.",
72+
Severity: severities.Medium.ToString(),
73+
Confidence: confidence.High.ToString(),
74+
SafeExample: SampleSafeHSKUBERNETES3,
75+
UnsafeExample: SampleVulnerableHSKUBERNETES3,
7076
},
7177
Type: text.AndMatch,
7278
Expressions: []*regexp.Regexp{
@@ -80,11 +86,13 @@ func NewDockerSock() *text.Rule {
8086
func NewCapabilitySystemAdmin() *text.Rule {
8187
return &text.Rule{
8288
Metadata: engine.Metadata{
83-
ID: "HS-KUBERNETES-4",
84-
Name: "Capability System Admin",
85-
Description: "CAP_SYS_ADMIN is the most privileged capability and should always be avoided.",
86-
Severity: severities.Critical.ToString(),
87-
Confidence: confidence.High.ToString(),
89+
ID: "HS-KUBERNETES-4",
90+
Name: "Capability System Admin",
91+
Description: "CAP_SYS_ADMIN is the most privileged capability and should always be avoided.",
92+
Severity: severities.Critical.ToString(),
93+
Confidence: confidence.High.ToString(),
94+
SafeExample: SampleSafeHSKUBERNETES4,
95+
UnsafeExample: SampleVulnerableHSKUBERNETES4,
8896
},
8997
Type: text.AndMatch,
9098
Expressions: []*regexp.Regexp{
@@ -100,11 +108,13 @@ func NewCapabilitySystemAdmin() *text.Rule {
100108
func NewPrivilegedContainer() *text.Rule {
101109
return &text.Rule{
102110
Metadata: engine.Metadata{
103-
ID: "HS-KUBERNETES-5",
104-
Name: "Privileged Container",
105-
Description: "Privileged containers can allow almost completely unrestricted host access.",
106-
Severity: severities.High.ToString(),
107-
Confidence: confidence.Medium.ToString(),
111+
ID: "HS-KUBERNETES-5",
112+
Name: "Privileged Container",
113+
Description: "Privileged containers can allow almost completely unrestricted host access.",
114+
Severity: severities.High.ToString(),
115+
Confidence: confidence.Medium.ToString(),
116+
SafeExample: SampleSafeHSKUBERNETES5,
117+
UnsafeExample: SampleVulnerableHSKUBERNETES5,
108118
},
109119
Type: text.AndMatch,
110120
Expressions: []*regexp.Regexp{
@@ -118,11 +128,13 @@ func NewPrivilegedContainer() *text.Rule {
118128
func NewSeccompUnconfined() *text.Rule {
119129
return &text.Rule{
120130
Metadata: engine.Metadata{
121-
ID: "HS-KUBERNETES-6",
122-
Name: "Seccomp Unconfined",
123-
Description: "Unconfined Seccomp profiles have full system call access.",
124-
Severity: severities.Low.ToString(),
125-
Confidence: confidence.Low.ToString(),
131+
ID: "HS-KUBERNETES-6",
132+
Name: "Seccomp Unconfined",
133+
Description: "Unconfined Seccomp profiles have full system call access.",
134+
Severity: severities.Low.ToString(),
135+
Confidence: confidence.Low.ToString(),
136+
SafeExample: SampleSafeHSKUBERNETES6,
137+
UnsafeExample: SampleVulnerableHSKUBERNETES6,
126138
},
127139
Type: text.OrMatch,
128140
Expressions: []*regexp.Regexp{
@@ -135,11 +147,13 @@ func NewSeccompUnconfined() *text.Rule {
135147
func NewHostIPC() *text.Rule {
136148
return &text.Rule{
137149
Metadata: engine.Metadata{
138-
ID: "HS-KUBERNETES-7",
139-
Name: "Host IPC",
140-
Description: "Sharing the host's IPC namespace allows container processes to communicate with processes on the host.",
141-
Severity: severities.Medium.ToString(),
142-
Confidence: confidence.Low.ToString(),
150+
ID: "HS-KUBERNETES-7",
151+
Name: "Host IPC",
152+
Description: "Sharing the host's IPC namespace allows container processes to communicate with processes on the host.",
153+
Severity: severities.Medium.ToString(),
154+
Confidence: confidence.Low.ToString(),
155+
SafeExample: SampleSafeHSKUBERNETES7,
156+
UnsafeExample: SampleVulnerableHSKUBERNETES7,
143157
},
144158
Type: text.OrMatch,
145159
Expressions: []*regexp.Regexp{
@@ -151,11 +165,13 @@ func NewHostIPC() *text.Rule {
151165
func NewHostPID() *text.Rule {
152166
return &text.Rule{
153167
Metadata: engine.Metadata{
154-
ID: "HS-KUBERNETES-8",
155-
Name: "Host PID",
156-
Description: "Sharing the host's PID namespace allows visibility of processes on the host, potentially leaking information such as environment variables and configuration.",
157-
Severity: severities.Medium.ToString(),
158-
Confidence: confidence.Low.ToString(),
168+
ID: "HS-KUBERNETES-8",
169+
Name: "Host PID",
170+
Description: "Sharing the host's PID namespace allows visibility of processes on the host, potentially leaking information such as environment variables and configuration.",
171+
Severity: severities.Medium.ToString(),
172+
Confidence: confidence.Low.ToString(),
173+
SafeExample: SampleSafeHSKUBERNETES8,
174+
UnsafeExample: SampleVulnerableHSKUBERNETES8,
159175
},
160176
Type: text.OrMatch,
161177
Expressions: []*regexp.Regexp{
@@ -167,11 +183,13 @@ func NewHostPID() *text.Rule {
167183
func NewHostNetwork() *text.Rule {
168184
return &text.Rule{
169185
Metadata: engine.Metadata{
170-
ID: "HS-KUBERNETES-9",
171-
Name: "Host Network",
172-
Description: "Sharing the host's network namespace permits processes in the pod to communicate with processes bound to the host's loopback adapter.",
173-
Severity: severities.Medium.ToString(),
174-
Confidence: confidence.Low.ToString(),
186+
ID: "HS-KUBERNETES-9",
187+
Name: "Host Network",
188+
Description: "Sharing the host's network namespace permits processes in the pod to communicate with processes bound to the host's loopback adapter.",
189+
Severity: severities.Medium.ToString(),
190+
Confidence: confidence.Low.ToString(),
191+
SafeExample: SampleSafeHSKUBERNETES9,
192+
UnsafeExample: SampleVulnerableHSKUBERNETES9,
175193
},
176194
Type: text.OrMatch,
177195
Expressions: []*regexp.Regexp{

0 commit comments

Comments
 (0)