Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure read access to the run image selected by extensions #1364

Merged
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
29 changes: 29 additions & 0 deletions cmd/lifecycle/restorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ func (r *restoreCmd) DefineFlags() {
cli.FlagBuildImage(&r.BuildImageRef)
}
cli.FlagAnalyzedPath(&r.AnalyzedPath)
if r.PlatformAPI.AtLeast("0.14") {
cli.FlagRunPath(&r.RunPath)
}
cli.FlagCacheDir(&r.CacheDir)
cli.FlagCacheImage(&r.CacheImageRef)
cli.FlagGID(&r.GID)
Expand Down Expand Up @@ -123,6 +126,15 @@ func (r *restoreCmd) Exec() error {
runImage imgutil.Image
)
runImageName := analyzedMD.RunImageImage() // FIXME: if we have a digest reference available in `Reference` (e.g., in the non-daemon case) we should use it
accessibleRunImage, err := r.runImageAccessCheck(runImageName)
if err != nil {
return err
}
if runImageName != accessibleRunImage {
analyzedMD.RunImage.Image = accessibleRunImage
analyzedMD.RunImage.Reference = accessibleRunImage
}

if r.supportsRunImageExtension() && needsPulling(analyzedMD.RunImage) {
cmd.DefaultLogger.Debugf("Pulling run image metadata for %s...", runImageName)
runImage, err = r.pullSparse(runImageName)
Expand Down Expand Up @@ -192,6 +204,23 @@ func needsPulling(runImage *files.RunImage) bool {
return runImage.Extend
}

func (r *restoreCmd) runImageAccessCheck(runImageName string) (string, error) {
if r.PlatformAPI.LessThan("0.14") {
return runImageName, nil
}

runToml, err := files.Handler.ReadRun(r.RunPath, cmd.DefaultLogger)
if err != nil {
return "", err
}

if !runToml.Contains(runImageName) {
return runImageName, nil
}

return platform.BestRunImageMirrorFor("", runToml.FindByRef(runImageName), r.AccessChecker())
}

func (r *restoreCmd) needsUpdating(runImage *files.RunImage, group buildpack.Group) bool {
if r.PlatformAPI.LessThan("0.10") {
return false
Expand Down
11 changes: 11 additions & 0 deletions platform/files/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,14 @@ func (r *Run) Contains(providedImage string) bool {
}
return false
}

// FindByRef return the RunImageForExport struct which contains the imageRef.
func (r *Run) FindByRef(imageRef string) RunImageForExport {
for _, i := range r.Images {
if i.Contains(imageRef) {
return i
}
}

return RunImageForExport{}
}
Loading