-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2010 from sap-contributions/ensure-read-access-ru…
…n-img Ensure read access when resolving run image location
- Loading branch information
Showing
11 changed files
with
179 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package fakes | ||
|
||
type FakeAccessChecker struct { | ||
RegistriesToFail []string | ||
} | ||
|
||
func NewFakeAccessChecker() *FakeAccessChecker { | ||
return &FakeAccessChecker{} | ||
} | ||
|
||
func (f *FakeAccessChecker) Check(repo string) bool { | ||
for _, toFail := range f.RegistriesToFail { | ||
if toFail == repo { | ||
return false | ||
} | ||
} | ||
|
||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package image | ||
|
||
import ( | ||
"github.com/buildpacks/imgutil/remote" | ||
"github.com/google/go-containerregistry/pkg/authn" | ||
|
||
"github.com/buildpacks/pack/pkg/logging" | ||
) | ||
|
||
type Checker struct { | ||
logger logging.Logger | ||
keychain authn.Keychain | ||
} | ||
|
||
func NewAccessChecker(logger logging.Logger, keychain authn.Keychain) *Checker { | ||
checker := &Checker{ | ||
logger: logger, | ||
keychain: keychain, | ||
} | ||
|
||
if checker.keychain == nil { | ||
checker.keychain = authn.DefaultKeychain | ||
} | ||
|
||
return checker | ||
} | ||
|
||
func (c *Checker) Check(repo string) bool { | ||
img, err := remote.NewImage(repo, c.keychain) | ||
if err != nil { | ||
return false | ||
} | ||
|
||
if ok, err := img.CheckReadAccess(); ok { | ||
c.logger.Debugf("CheckReadAccess succeeded for the run image %s", repo) | ||
return true | ||
} else { | ||
c.logger.Debugf("CheckReadAccess failed for the run image %s, error: %s", repo, err.Error()) | ||
return false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package image_test | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/buildpacks/lifecycle/auth" | ||
"github.com/sclevine/spec" | ||
"github.com/sclevine/spec/report" | ||
|
||
"github.com/buildpacks/pack/pkg/image" | ||
"github.com/buildpacks/pack/pkg/logging" | ||
h "github.com/buildpacks/pack/testhelpers" | ||
) | ||
|
||
func TestChecker(t *testing.T) { | ||
spec.Run(t, "Checker", testChecker, spec.Report(report.Terminal{})) | ||
} | ||
|
||
func testChecker(t *testing.T, when spec.G, it spec.S) { | ||
when("#Check", func() { | ||
it("fails when checking dummy image", func() { | ||
buf := &bytes.Buffer{} | ||
|
||
keychain, err := auth.DefaultKeychain("pack.test/dummy") | ||
h.AssertNil(t, err) | ||
|
||
ic := image.NewAccessChecker(logging.NewSimpleLogger(buf), keychain) | ||
|
||
h.AssertFalse(t, ic.Check("pack.test/dummy")) | ||
h.AssertContains(t, buf.String(), "DEBUG: CheckReadAccess failed for the run image pack.test/dummy") | ||
}) | ||
}) | ||
} |
3f1ecb2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible performance regression was detected for benchmark 'Go Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold
2
.BenchmarkBuild/with_Trusted_Builder
2222024575
ns/op876366408
ns/op2.54
This comment was automatically generated by workflow using github-action-benchmark.
CC: @buildpacks/platform-maintainers