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

Flux oci support 12: fix for Unable to use Flux OCI with Harbor robot accounts #5219 #5305

Merged
merged 7 commits into from
Sep 6, 2022

Conversation

gfichtenholt
Copy link
Contributor

@gfichtenholt gfichtenholt commented Sep 6, 2022

implemented fix as described in the issue
#5219 (comment)
fixed 1 and implemented 2b
verified it works with respect to robot account of VMware corporate harbor instance

@gfichtenholt gfichtenholt self-assigned this Sep 6, 2022
@gfichtenholt gfichtenholt linked an issue Sep 6, 2022 that may be closed by this pull request
@netlify
Copy link

netlify bot commented Sep 6, 2022

Deploy Preview for kubeapps-dev canceled.

Built without sensitive environment variables

Name Link
🔨 Latest commit 649de18
🔍 Latest deploy log https://app.netlify.com/sites/kubeapps-dev/deploys/631775b9ecfe980009adc4c1

@gfichtenholt gfichtenholt linked an issue Sep 6, 2022 that may be closed by this pull request
1 task
Copy link
Contributor

@antgamdia antgamdia left a comment

Choose a reason for hiding this comment

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

Great to see we are finally supporting Harbor! 🎉 , thanks for making it possible!

orasregistryauthv2 "oras.land/oras-go/v2/registry/remote/auth"
)

// This flavor of OCI repsitory ister works with respect to to VMware Harbor
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// This flavor of OCI repsitory ister works with respect to to VMware Harbor
// This flavor of OCI repository lister works with respect to VMware Harbor

Also, I don't think it is just for the VMware harbor instance, no? Ah, perhaps you meant the VMware Harbor product? If so, I think Harbor is not -just-a VMware project, but a Harbor is a Cloud Native Computing Foundation one, as it appears as a Graduated project on their website.

Anyway, just being nitpicky, feel free to ignore the comment :P

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will fix comment

)

// This flavor of OCI repsitory ister works with respect to to VMware Harbor
// container registry. The Swagger for the API can be found on an running server
Copy link
Contributor

Choose a reason for hiding this comment

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

Another nitpick: the Swagger name is discouraged in favor of "OpenAPI"

Suggested change
// container registry. The Swagger for the API can be found on an running server
// container registry. The OpenAPI description of the API can be found on a running server

Copy link
Contributor Author

Choose a reason for hiding this comment

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

link to source please?
Harbor certainly did not get the message
Screen Shot 2022-09-06 at 8 18 02 AM

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, here it is: https://www.openapis.org/faq/style-guide.
Besides, my former company was a member of the OpenAPI Initiative and I was somehow also involved in.

But... the reality is that there are plenty of people still using the "Swagger" word. In fact, it can be a synonym, but only if the spec version is 2.0.

In fact, the according to the style guide, the proper term would be OpenAPI Specification document or just OAS document

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks. I will re-word comment

Comment on lines 154 to 158
case http.StatusNotFound:
return errdef.ErrNotFound

case http.StatusForbidden:
return errors.New("forbidden")
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know where both errors are being handled, but it seems we are mixing up the error builder from oras (errdef) and the builtin errors packages. Should we use the same for both cases? Or perhaps it doesn't really matter due to the error hanlding being performed on the call site?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will get rid of lines 157-158. They are not needed.

if plainHTTP {
scheme = "http"
}
return fmt.Sprintf("%s://%s/api/v2.0", scheme, ref.Host())
Copy link
Contributor

Choose a reason for hiding this comment

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

Just thinking: would be a good idea to extract all the templates into const being defined at the bottom? This way we would have all the paths in the same place (in case the change their API.
Anyway, not really important, as I don't foresee that breaking changes for the major (v2) this lister is intended to.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, I don't see them changing v2 API in a backwards incompatible way anywhere soon. Will keep your comment in mind for the next PR(s)

var body struct {
Errors requestErrors `json:"errors"`
}
lr := io.LimitReader(resp.Body, maxErrorBytes)
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious as it seems a good idea for preventing some buffer overflow attacks (and we aren't doing it in the rest of the codebase, AFAIK).
Do you think we should limit the read operations in other places?

Copy link
Contributor Author

@gfichtenholt gfichtenholt Sep 6, 2022

Choose a reason for hiding this comment

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

I think in general it is a good idea, provided you can make this assumption. Normally, you can't really assume anything about the size of the payload you're dealing with. So whatever limit/boundary X you pick, I will probably find a valid use case where receiving X+1 bytes is valid

I just realized by "other places" you may have meant other places where we handle receiving error response. If so, I definitely think its a good idea

@gfichtenholt gfichtenholt merged commit f09692d into vmware-tanzu:main Sep 6, 2022
@gfichtenholt gfichtenholt deleted the flux-oci-support-12 branch September 6, 2022 16:31
Copy link
Collaborator

@beni0888 beni0888 left a comment

Choose a reason for hiding this comment

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

LGTM!

Comment on lines +772 to +774
if err != nil {
t.Fatal(err)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm seeing this pattern repeated a lot through our code base, have you considered using stretchr/testify library, which is already included as a project dependency, and would make tests (IMHO) easier to write, read and maintain? In this case, we'd replace the three lines with just require.NotNil(err).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I haven't considered it due to I did not know it existed. I don't have any objection to using it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Unable to use Flux OCI with Harbor robot accounts Support for Google Artifact registry in Flux plugin
4 participants