mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
Fix image verification when hostname is present in image
Deal better with the situation where a image name contains a hostname as well. Fixes #30580
This commit is contained in:
parent
8cc31b648e
commit
cc9f41c6d3
@ -167,11 +167,20 @@ func matchImageTagOrSHA(inspected dockertypes.ImageInspect, image string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if isTagged {
|
if isTagged {
|
||||||
|
hostname, _ := dockerref.SplitHostname(named)
|
||||||
// Check the RepoTags for an exact match
|
// Check the RepoTags for an exact match
|
||||||
for _, tag := range inspected.RepoTags {
|
for _, tag := range inspected.RepoTags {
|
||||||
if tag == image {
|
// Deal with image with hostname specified
|
||||||
// We found a specific tag that we were looking for
|
if len(hostname) > 0 {
|
||||||
return true
|
if strings.HasSuffix(image, tag) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if tag == image {
|
||||||
|
// We found a specific tag that we were looking for
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -173,6 +173,16 @@ func TestMatchImageTagOrSHA(t *testing.T) {
|
|||||||
Image: "ubuntu:latest",
|
Image: "ubuntu:latest",
|
||||||
Output: false,
|
Output: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Inspected: dockertypes.ImageInspect{RepoTags: []string{"colemickens/hyperkube-amd64:217.9beff63"}},
|
||||||
|
Image: "colemickens/hyperkube-amd64:217.9beff63",
|
||||||
|
Output: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Inspected: dockertypes.ImageInspect{RepoTags: []string{"colemickens/hyperkube-amd64:217.9beff63"}},
|
||||||
|
Image: "docker.io/colemickens/hyperkube-amd64:217.9beff63",
|
||||||
|
Output: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Inspected: dockertypes.ImageInspect{
|
Inspected: dockertypes.ImageInspect{
|
||||||
ID: "sha256:2208f7a29005d226d1ee33a63e33af1f47af6156c740d7d23c7948e8d282d53d",
|
ID: "sha256:2208f7a29005d226d1ee33a63e33af1f47af6156c740d7d23c7948e8d282d53d",
|
||||||
|
Loading…
Reference in New Issue
Block a user