Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.8.2] - 2025-03-26
### Fixed
- Fixed wrong image reference handling

## [0.8.1] - 2025-03-17
### Fixed
- Fixed chart pdb rendering
Expand Down
6 changes: 6 additions & 0 deletions internal/webhook/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import (

const BareRegistry = "docker.io"

// CheckImageRefFormat returns a boolean that validates or not the image ref format.
func CheckImageRefFormat(imageReference string) (valid bool) {
_, err := reference.Parse(imageReference)
return err == nil
}

// RegistryFromImageRef returns the registry (and port, if set) from the image reference,
// otherwise returns the default bare registry, "docker.io".
func RegistryFromImageRef(imageReference string) (registry string, err error) {
Expand Down
7 changes: 7 additions & 0 deletions internal/webhook/mutate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ func TestPodContainerProxier_rewriteImage(t *testing.T) {
platform: "amd64",
expected: "harbor.example.com/dockerhub-proxy/library/centos:latest",
},
{
name: "a wrong format image should not be rewritten",
image: "docker.io/library/centos:",
os: "linux",
platform: "amd64",
expected: "docker.io/library/centos:",
},
{
name: "an image from gcr should not be rewritten",
image: "k8s.gcr.io/kubernetes",
Expand Down
6 changes: 6 additions & 0 deletions internal/webhook/transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,12 @@ func (t *ruleTransformer) RewriteImage(imageRef string) (string, error) {
}

func (t *ruleTransformer) doRewriteImage(imageRef string) (rewritten bool, updatedRef string, err error) {
isValidFormat := CheckImageRefFormat(imageRef)
if !isValidFormat {
logger.Info(fmt.Sprintf("Image ref format %s is not valid, skip it", imageRef))
return false, imageRef, nil
}

registry, err := RegistryFromImageRef(imageRef)
if err != nil {
return false, "", err
Expand Down