Skip to content

add digest validation utils and examples#20887

Merged
tadelesh merged 10 commits intoAzure:mainfrom
tadelesh:digest_example
May 31, 2023
Merged

add digest validation utils and examples#20887
tadelesh merged 10 commits intoAzure:mainfrom
tadelesh:digest_example

Conversation

@tadelesh
Copy link
Copy Markdown
Member

resolve: #20836

@tadelesh
Copy link
Copy Markdown
Member Author

tadelesh commented May 23, 2023

@jhendrixMSFT @JeffreyRichter please help to review the digest validation utils. You could refer all example files for the usage.

A brief explanation:

  1. GetManifest, GetBlob, GetChunk all use DigestValidationReader to read stream while validate.
  2. if UploadManifest by tag, we could not know the sig alg before service respond, so user need to do the read twice with DigestValidationReader to validate digest.
  3. UploadChunk keep the same with previous version, only some code tidy.

Comment thread sdk/containers/azcontainerregistry/blob_client_example_test.go Outdated
Comment thread sdk/containers/azcontainerregistry/blob_client_example_test.go Outdated
Comment thread sdk/containers/azcontainerregistry/blob_client_example_test.go Outdated
Comment thread sdk/containers/azcontainerregistry/utils.go
@tadelesh tadelesh requested a review from jhendrixMSFT May 25, 2023 03:25
@tadelesh
Copy link
Copy Markdown
Member Author

@JeffreyRichter The latest API view for azcontainerregistry could be found here. The change include removal of useless marshal method and new-added utils for digest validation. Do I need to have a former meeting review with you?

@JeffreyRichter
Copy link
Copy Markdown
Member

I had just 1 comment about hash algorithms

@tadelesh
Copy link
Copy Markdown
Member Author

tadelesh commented May 26, 2023

I had just 1 comment about hash algorithms

Thanks for the quick review. I've replied the comment. The hash algorithm is considered already.

Comment thread sdk/containers/azcontainerregistry/example_download_image_test.go Outdated
@tadelesh tadelesh merged commit 2e91823 into Azure:main May 31, 2023
}

func parseDigestValidator(digest string) (digestValidator, error) {
alg := digest[:strings.Index(digest, ":")]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There might be an "index out of range" issue if digest does not contain a :.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix before GA.

Comment on lines +32 to +36
if v, ok := validatorCtors[alg]; ok {
return v(), nil
} else {
return nil, ErrDigestAlgNotSupported
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It applies to all occurrences in this file.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix before GA.

end = size
}
chunkReader := io.NewSectionReader(f, current, end-current)
uploadResp, err := blobClient.UploadChunk(context.TODO(), location, chunkReader, calculator, &azcontainerregistry.BlobClientUploadChunkOptions{RangeStart: to.Ptr(int32(current)), RangeEnd: to.Ptr(int32(end - 1))})
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious if calculator can be reused in another process or not.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. The calculator will hold the hash calculation status, so one calculator for one upload. I'll added some doc to explain it before GA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add digest validation to all related operations for azcontainerregistry

4 participants