Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Gatekeeper Policies
Manage
Activity
Members
Labels
Plan
Issues
1
Issue boards
Milestones
Wiki
Jira
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IT Common Platform
platform-support
helm-charts
Gatekeeper Policies
Merge requests
!72
[
PLATFORM-2185
] Configure Image Provenance admission control with Gatekeeper
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
[
PLATFORM-2185
] Configure Image Provenance admission control with Gatekeeper
PLATFORM-2207-aatemnke2
into
master
Overview
3
Commits
7
Pipelines
14
Changes
4
Merged
Alain Atemnkeng
requested to merge
PLATFORM-2207-aatemnke2
into
master
11 months ago
Overview
3
Commits
7
Pipelines
14
Changes
4
Expand
[
PLATFORM-2185
] Configure Image Provenance admission control with Gatekeeper
0
0
Merge request reports
Compare
master
version 6
d811c0ef
10 months ago
version 5
5480721e
10 months ago
version 4
7930e42f
10 months ago
version 3
79d6e2f0
10 months ago
version 2
26e1cbbd
11 months ago
version 1
d405de20
11 months ago
master (base)
and
latest version
latest version
cf3bea00
7 commits,
10 months ago
version 6
d811c0ef
6 commits,
10 months ago
version 5
5480721e
5 commits,
10 months ago
version 4
7930e42f
4 commits,
10 months ago
version 3
79d6e2f0
3 commits,
10 months ago
version 2
26e1cbbd
2 commits,
11 months ago
version 1
d405de20
1 commit,
11 months ago
4 files
+
188
−
1
Expand all files
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
4
Search (e.g. *.vue) (Ctrl+P)
rego/image_admission_control/policy.rego
0 → 100644
+
64
−
0
Options
package
k8simageprovenance
# List of exactly allowed repositories
allowed_repos
:=
{
"docker.io"
,
"quay.io"
,
"public.ecr.aws"
,
"gcr.io"
,
"ghcr.io"
,
"harbor.io"
,
"harbor.it.vt.edu"
,
"gitlab.com"
,
"code.vt.edu"
,
"registry-1.docker.io"
,
"602401143452.dkr.ecr.us-east-1.amazonaws.com"
,
"code.vt.edu:5005"
,
"docker.elastic.co"
,
"harbor.platform.it.vt.edu"
,
"registry.gitlab.com"
,
"registry.k8s.io"
}
# Function to extract hostname from image (GPT4.0 assisted)
get_hostname
(
image
)
=
hostname
{
trace
(
sprintf
(
"Checking hostname for image: %v"
,
[
image
]))
contains
(
image
,
"/"
)
parts
:=
split
(
image
,
"/"
)
# If the first part contains a '.', assume it's a hostname
contains
(
parts
[
0
],
"."
)
hostname
:=
parts
[
0
]
trace
(
sprintf
(
"Extracted hostname: %v"
,
[
hostname
]))
}
else
=
"docker.io"
{
# Default to Docker Hub if no hostname is identifiable
not
contains
(
image
,
"/"
)
trace
(
"Defaulting to docker.io (no hostname found)"
)
}
else
=
"docker.io"
{
# Default if no '.' in the first part of the name
contains
(
image
,
"/"
)
parts
:=
split
(
image
,
"/"
)
not
contains
(
parts
[
0
],
"."
)
trace
(
"Defaulting to docker.io (no '.' in first part of hostname)"
)
}
# Check if image is from an allowed repository
is_from_allowed_repo
(
image
)
{
trace
(
sprintf
(
"Checking if image %v is from an allowed repo"
,
[
image
]))
hostname
:=
get_hostname
(
image
)
allowed
:=
[
repo
|
repo
:=
allowed_repos
[
_
];
hostname
==
repo
]
result
:=
count
(
allowed
)
>
0
trace
(
sprintf
(
"Image %v allowed: %v"
,
[
image
,
result
]))
result
}
# Main violation logic for all container types
violation
[{
"msg"
:
msg
}]
{
trace
(
"Evaluating violation"
)
input
.
review
.
object
.
kind
==
"Pod"
# Check initContainers and ephemeralContainers alongside containers
container_types
:=
[
"containers"
,
"initContainers"
,
"ephemeralContainers"
]
container_type
:=
container_types
[
_
]
container
:=
input
.
review
.
object
.
spec
[
container_type
][
_
]
trace
(
sprintf
(
"Checking %v image: %v"
,
[
container_type
,
container
.
image
]))
not
is_from_allowed_repo
(
container
.
image
)
msg
:=
sprintf
(
"Image %v in %v is not from an allowed repository. Please contact the platform team"
,
[
container
.
image
,
container_type
])
trace
(
sprintf
(
"Violation found: %v"
,
[
msg
]))
}