Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Ensures that all trusted builder image prefixes end in a slash so that registry identifiers can't be spoofed with name extensions.

/kind fix

Signed-off-by: Lance Ball <lball@redhat.com>

Signed-off-by: Lance Ball <lball@redhat.com>
  • Loading branch information
lance committed Nov 18, 2022
1 parent 399d2ab commit 1d22cb2
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
13 changes: 10 additions & 3 deletions buildpacks/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ var (
"springboot": "gcr.io/paketo-buildpacks/builder:base",
}

// Ensure that all entries in this list are terminated with a trailing "/"
// See GHSA-5336-2g3f-9g3m for details
trustedBuilderImagePrefixes = []string{
"quay.io/boson",
"gcr.io/paketo-buildpacks",
"docker.io/paketobuildpacks",
"quay.io/boson/",
"gcr.io/paketo-buildpacks/",
"docker.io/paketobuildpacks/",
"ghcr.io/vmware-tanzu/function-buildpacks-for-knative/",
}
)

Expand Down Expand Up @@ -121,6 +124,10 @@ func (b *Builder) Build(ctx context.Context, f fn.Function) (err error) {
// only trust our known builders
opts.TrustBuilder = func(_ string) bool {
for _, v := range trustedBuilderImagePrefixes {
// Ensure that all entries in this list are terminated with a trailing "/"
if !strings.HasSuffix(v, "/") {
v = v + "/"
}
if strings.HasPrefix(opts.Builder, v) {
return true
}
Expand Down
37 changes: 37 additions & 0 deletions buildpacks/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,43 @@ import (
"knative.dev/func/builders"
)

// Test_BuilderImageUntrusted ensures that only known builder images
// are to be considered trusted.
func Test_BuilderImageUntrusted(t *testing.T) {
var (
i = &mockImpl{}
b = NewBuilder(WithImpl(i))
f = fn.Function{Runtime: "node"}
)

var untrusted = []string{
// Check prefixes that end in a slash
"quay.io/bosonhack/",
"gcr.io/paketo-buildpackshack/",
// And those that don't
"docker.io/paketobuildpackshack",
"ghcr.io/vmware-tanzu/function-buildpacks-for-knativehack",
}

for _, builder := range untrusted {
f.Build = fn.BuildSpec{
BuilderImages: map[string]string{
builders.Pack: builder,
},
}
i.BuildFn = func(ctx context.Context, opts pack.BuildOptions) error {
if opts.TrustBuilder("") != false {
t.Fatalf("expected pack builder image %v to be untrusted", f.Build.BuilderImages[builders.Pack])
}
return nil
}

if err := b.Build(context.Background(), f); err != nil {
t.Fatal(err)
}
}
}

// Test_BuilderImageTrusted ensures that only known builder images
// are to be considered trusted.
func Test_BuilderImageTrusted(t *testing.T) {
Expand Down

0 comments on commit 1d22cb2

Please sign in to comment.