Skip to content

Commit

Permalink
update(install): review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Luca Guerra <[email protected]>
  • Loading branch information
LucaGuerra authored and poiana committed Jul 7, 2023
1 parent 316b27b commit 8a3cb3c
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions cmd/artifact/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,21 +255,10 @@ func (o *artifactInstallOptions) RunArtifactInstall(ctx context.Context, args []
o.Printer.Info.Printfln("Installing the following artifacts: %v", refs)

for _, ref := range refs {
var sig *index.Signature
ref, err = o.IndexCache.ResolveReference(ref)
if err != nil {
return err
}
sig, ok := signatures[ref]
if !ok {
// try to get the signature from the index
o.IndexCache.SignatureForIndexRef(ref)
}

repo, err := utils.RepositoryFromRef(ref)
if err != nil {
return err
}

o.Printer.Info.Printfln("Preparing to pull %q", ref)

Expand All @@ -283,12 +272,23 @@ func (o *artifactInstallOptions) RunArtifactInstall(ctx context.Context, args []
return err
}

// In order to prevent TOCTOU issues we'll perform signature verification after we complete a pull
// and obtained a digest but before files are written to disk. This way we ensure that we're verifying
// the exact digest that we just pulled, even if the tag gets overwritten in the meantime.
digestRef := fmt.Sprintf("%s@%s", repo, result.RootDigest)
sig, ok := signatures[ref]
if !ok {
// try to get the signature from the index
sig = o.IndexCache.SignatureForIndexRef(ref)
}

if sig != nil && !o.noVerify {
repo, err := utils.RepositoryFromRef(ref)
if err != nil {
return err
}

// In order to prevent TOCTOU issues we'll perform signature verification after we complete a pull
// and obtained a digest but before files are written to disk. This way we ensure that we're verifying
// the exact digest that we just pulled, even if the tag gets overwritten in the meantime.
digestRef := fmt.Sprintf("%s@%s", repo, result.RootDigest)

o.Printer.Info.Printfln("Verifying signature for %s", digestRef)
err = sign.VerifySignature(digestRef, sig)
if err != nil {
Expand Down

0 comments on commit 8a3cb3c

Please sign in to comment.