Skip to content

Commit ba05296

Browse files
author
Maurice Faber
committed
fix: banned image tag policy now checking for empty tag, knative containerPort added
1 parent 829509a commit ba05296

File tree

6 files changed

+39
-7
lines changed

6 files changed

+39
-7
lines changed

charts/team-ns/templates/knative-services.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ spec:
4040
{{- with $k.command }}
4141
command: {{ . | toYaml | nindent 12 }}
4242
{{- end }}
43+
{{- with $k.containerPort }}
44+
ports:
45+
- containerPort: {{ . }}
46+
{{- end }}
4347
{{- with $k.args }}
4448
args: {{ . | toYaml | nindent 12 }}
4549
{{- end }}

policies/banned-image-tags/src.rego

+10
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ import data.lib.pods
1111

1212
policyID = "banned-image-tags"
1313

14+
violation[{"msg": msg}] {
15+
not exceptions.is_exception(policyID)
16+
pods.containers[container]
17+
trace(sprintf("container: %v", [container]))
18+
not exceptions.is_container_exception(container.name, policyID)
19+
tag := [contains(container.image, ":")]
20+
not all(tag)
21+
msg := sprintf("Policy: %s - container <%v> didn't specify an image tag <%v>", [policyID, container.name, container.image])
22+
}
23+
1424
violation[{"msg": msg}] {
1525
not exceptions.is_exception(policyID)
1626
pods.containers[container]

policies/banned-image-tags/src_test.rego

+17-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,16 @@ pod_allowed := {
2222
"spec": {"containers": [{"name": "allowed", "image": "bla:oktag"}]},
2323
}
2424

25-
pod_disallowed := {
25+
pod_disallowed_tag := {
2626
"kind": "Pod",
2727
"metadata": {"name": "disallowed"},
28-
"spec": {"containers": [{"name": "disallowed", "image": "bla:badtag"}]},
28+
"spec": {"containers": [{"name": "disallowed-tag", "image": "bla:badtag"}]},
29+
}
30+
31+
pod_disallowed_notag := {
32+
"kind": "Pod",
33+
"metadata": {"name": "disallowed"},
34+
"spec": {"containers": [{"name": "disallowed-notag", "image": "bla"}]},
2935
}
3036

3137
test_disabled {
@@ -42,8 +48,15 @@ test_pod_allowed {
4248
count(ret) == 0
4349
}
4450

45-
test_pod_disallowed {
46-
ret := violation with input as pod_disallowed
51+
test_pod_disallowed_tag {
52+
ret := violation with input as pod_disallowed_tag
53+
with data.parameters as parameters_enabled
54+
55+
count(ret) == 1
56+
}
57+
58+
test_pod_disallowed_notag {
59+
ret := violation with input as pod_disallowed_notag
4760
with data.parameters as parameters_enabled
4861

4962
count(ret) == 1

tests/fixtures/env/teams/services.demo.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ teamConfig:
4646
id: cb5149c4-8ea5-4c5a-be04-a37258658bd2
4747
domain: tlspass.eks.dev.otomi.cloud
4848
ksvc:
49+
containerPort: 80
4950
image:
5051
repository: nginx
5152
tag: latest

values-schema.yaml

+4-1
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,6 @@ definitions:
434434
- $ref: '#/definitions/containerSpec'
435435
type: object
436436
portNumber:
437-
default: 80
438437
maximum: 32768
439438
minimum: 80
440439
type: number
@@ -664,6 +663,10 @@ definitions:
664663
- glob
665664
title: Glob pattern matching
666665
title: Continuous delivery pipeline
666+
containerPort:
667+
$ref: '#/definitions/portNumber'
668+
description: Container port the knative pod will connect with. Leaving this empty will let knative infer the port from the container, which usually works, but might be problematic when the container does not specifically expose a port. (As is the case with nginx derived images!)
669+
title: Container port
667670
scaleToZero:
668671
default: false
669672
description: Scales to zero after 60 seconds and needs approximately 8 seconds to start back up.

values/otomi-api/otomi-api.gotmpl

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
{{- $version := (readFile "../../package.json") | regexFind "\"version\": \"([0-9.]+)\"" | regexFind "[0-9]+.[0-9]+.[0-9]+" -}}
1010
{{- $sopsEnv := tpl (readFile "../../helmfile.d/snippets/sops-env.gotmpl") ($v | get "kms.sops" dict) }}
1111
{{- $skipVerify := eq ($cm | get "stage") "staging" }}
12+
{{- $giteaValuesUrl := print "https://gitea." $v.cluster.domainSuffix }}
1213

1314
replicaCount: 1
1415

@@ -37,8 +38,8 @@ secrets:
3738

3839
env:
3940
# DEBUG: '*'
40-
GIT_REPO_URL: {{ $o.git.repoUrl }}
41-
GIT_BRANCH: {{ $o.git | get "branch" "main" }}
41+
GIT_REPO_URL: {{ $o | get "git.repoUrl" }}
42+
GIT_BRANCH: {{ $o | get "git.branch" "main" }}
4243
CLUSTER_ID: {{ printf "%s/%s" $c.provider $c.name }}
4344
CLUSTER_NAME: {{ $c.apiName }}
4445
CLUSTER_APISERVER: {{ $c.apiServer }}

0 commit comments

Comments
 (0)