@@ -16,15 +16,23 @@ package v1
16
16
17
17
import (
18
18
"path/filepath"
19
+ "regexp"
19
20
"strings"
20
21
21
22
"github.com/pkg/errors"
22
23
"k8s.io/apimachinery/pkg/util/version"
23
24
)
24
25
26
+ const sha256RE = "@sha256:[0-9a-f]{64}$"
27
+
25
28
// common functions for webhooks
26
29
27
30
func validatePluginImage (image , expectedImageName string , expectedMinVersion * version.Version ) error {
31
+ imageRe := regexp .MustCompile (expectedImageName + sha256RE )
32
+ if imageRe .MatchString (image ) {
33
+ return nil
34
+ }
35
+
28
36
// Ignore registry, vendor and extract the image name with the tag
29
37
parts := strings .SplitN (filepath .Base (image ), ":" , 2 )
30
38
if len (parts ) != 2 {
@@ -34,13 +42,14 @@ func validatePluginImage(image, expectedImageName string, expectedMinVersion *ve
34
42
imageName := parts [0 ]
35
43
versionStr := parts [1 ]
36
44
37
- if imageName != expectedImageName {
38
- return errors .Errorf ("incorrect image name %q. Make sure you use '<vendor>/%s:<version>'" , imageName , expectedImageName )
45
+ // If user provided faulty SHA digest, the image name may include @sha256 suffix so strip it
46
+ if strings .TrimSuffix (imageName , "@sha256" ) != expectedImageName {
47
+ return errors .Errorf ("incorrect image name %q. Make sure you use '<vendor>/%s'." , imageName , expectedImageName )
39
48
}
40
49
41
50
ver , err := version .ParseSemantic (versionStr )
42
51
if err != nil {
43
- return errors .Wrapf (err , "unable to parse version %q" , versionStr )
52
+ return errors .Wrapf (err , "unable to parse version %q. Make sure it's either valid SHA digest or semver tag. " , versionStr )
44
53
}
45
54
46
55
if ! ver .AtLeast (expectedMinVersion ) {
0 commit comments