-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
checks for sudo in entrypoint & registry deprecated (#28)
- Loading branch information
Showing
6 changed files
with
279 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
internal/builtins/general/M-408_sudo_container_entrypoint.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Copyright 2023 Undistro Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
id: M-408 | ||
slug: sudo-container-entrypoint | ||
severity: Medium | ||
message: "Sudo in container entrypoint" | ||
match: | ||
resources: | ||
- group: "" | ||
version: v1 | ||
resource: pods | ||
- group: apps | ||
version: v1 | ||
resource: deployments | ||
- group: apps | ||
version: v1 | ||
resource: daemonsets | ||
- group: apps | ||
version: v1 | ||
resource: statefulsets | ||
- group: apps | ||
version: v1 | ||
resource: replicasets | ||
- group: batch | ||
version: v1 | ||
resource: cronjobs | ||
- group: batch | ||
version: v1 | ||
resource: jobs | ||
validations: | ||
- expression: > | ||
allContainers.all(container, | ||
!has(container.command) || | ||
size(container.command) == 0 || | ||
container.command.all(cmd, | ||
!cmd.contains("sudo")) | ||
) |
64 changes: 64 additions & 0 deletions
64
internal/builtins/general/M-408_sudo_container_entrypoint_test.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Copyright 2023 Undistro Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
- name: "command not set" | ||
pass: true | ||
input: | | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: nginx | ||
labels: | ||
app: nginx | ||
spec: | ||
containers: | ||
- name: nginx | ||
image: nginx | ||
- name: "command without sudo" | ||
pass: true | ||
input: | | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: nginx | ||
labels: | ||
app: nginx | ||
spec: | ||
containers: | ||
- name: nginx | ||
image: nginx | ||
command: ["printenv"] | ||
resources: | ||
requests: | ||
cpu: 5m | ||
- name: "command with sudo on entrypoint" | ||
pass: false | ||
input: | | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: nginx | ||
labels: | ||
app: nginx | ||
spec: | ||
containers: | ||
- name: nginx | ||
image: nginx | ||
command: ["sudo printenv"] | ||
resources: | ||
limits: | ||
memory: 128Mi |
45 changes: 45 additions & 0 deletions
45
internal/builtins/general/M-409_deprecated_image_registry.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Copyright 2023 Undistro Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
id: M-409 | ||
slug: depŕecated image registry | ||
severity: Medium | ||
message: "Deprecated image registry" | ||
match: | ||
resources: | ||
- group: "" | ||
version: v1 | ||
resource: pods | ||
- group: apps | ||
version: v1 | ||
resource: deployments | ||
- group: apps | ||
version: v1 | ||
resource: daemonsets | ||
- group: apps | ||
version: v1 | ||
resource: statefulsets | ||
- group: apps | ||
version: v1 | ||
resource: replicasets | ||
- group: batch | ||
version: v1 | ||
resource: cronjobs | ||
- group: batch | ||
version: v1 | ||
resource: jobs | ||
validations: | ||
- expression: > | ||
allContainers.all(container, | ||
!container.image.contains("k8s.grc.io")) |
85 changes: 85 additions & 0 deletions
85
internal/builtins/general/M-409_deprecated_image_registry_test.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Copyright 2023 Undistro Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
- name: "registry not defined" | ||
pass: true | ||
input: | | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: nginx | ||
labels: | ||
app: nginx | ||
spec: | ||
containers: | ||
- name: nginx | ||
image: nginx | ||
- name: "registry deprecated" | ||
pass: false | ||
input: | | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: nginx | ||
labels: | ||
app: nginx | ||
spec: | ||
containers: | ||
- name: registry | ||
image: registry.com:80/nginx@sha256:asdf | ||
- name: ok2 | ||
image: registry.com:80/nginx@sha256:asdf | ||
- name: wrong | ||
image: k8s.grc.io/pause | ||
- name: "registry deprecated middle" | ||
pass: false | ||
input: | | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: nginx | ||
labels: | ||
app: nginx | ||
spec: | ||
containers: | ||
- name: registry | ||
image: registry.com:80/nginx@sha256:asdf | ||
- name: wrong | ||
image: k8s.grc.io/pause | ||
- name: ok2 | ||
image: registry.com:80/nginx@sha256:asdf | ||
- name: "registry deprecated" | ||
pass: false | ||
input: | | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: nginx | ||
labels: | ||
app: nginx | ||
spec: | ||
containers: | ||
- name: registry | ||
image: registry.com:80/nginx@sha256:asdf | ||
- name: registryOK | ||
image: registry.com:80/nginx@sha256:asdf | ||
- name: wrong | ||
image: k8s.grc.io/pause |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters