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

Normalize domains in mentix provider authorizer driver #3121

Merged
merged 13 commits into from
Dec 19, 2022

Conversation

mirekys
Copy link
Member

@mirekys mirekys commented Aug 3, 2022

Fixes #3113

@update-docs
Copy link

update-docs bot commented Aug 3, 2022

Thanks for opening this pull request! The maintainers of this repository would appreciate it if you would create a changelog item based on your changes.

@mirekys mirekys requested review from glpatcern and a team as code owners August 3, 2022 08:23
@redblom
Copy link
Contributor

redblom commented Aug 3, 2022

@mirekys This PR is to solve #3113 right? That issue was created because invites could not be accepted because the providers could not be authorized. Please take note of the following:

When the user idp of the sender of the forward invite is a domein rather than a url (eg. cesnet.cz vs. http://cesnet.cz) the provider authorization also fails at the receiving end (where the token has been generated). This is because from the bare domain the host name will not be resolved in the current implementation:

recipientProviderURL, err := url.Parse(recipientProvider)
if err != nil {
WriteError(w, r, APIErrorServerError, fmt.Sprintf("error parseing recipientProvider URL: %s", recipientProvider), err)
return
}
providerInfo := ocmprovider.ProviderInfo{
Domain: recipientProviderURL.Hostname(),
It will result in an empty string (but no error!). So ProviderInfo.Domain will be an empty string. This will make authorization fail as we found out in the tests.
Previously the recipientProvider parameter was actually normalized but this has been removed (#2751). See also #2288.
So I guess this recipientProvider needs to be normalized once more. And solve #2288 in the process.

@mirekys
Copy link
Member Author

mirekys commented Aug 4, 2022

@redblom You're right, it also needs normalization, thanks for pointing that out. If I understood the situation correctly, there is yet no exact specification on how the provider domains should look, and Reva should accept both the bare domain name & full URL, while the full URL is the preferable variant in the future? I'll update the PR accordingly

@mirekys
Copy link
Member Author

mirekys commented Aug 4, 2022

I just simply removed the code and pass the provider as is, as it should be a responsibility of IsProviderAllowed endpoint to normalize value before checking

@redblom
Copy link
Contributor

redblom commented Aug 4, 2022

I just simply removed the code and pass the provider as is, as it should be a responsibility of IsProviderAllowed endpoint to normalize value before checking

Makes sense.
Could IsProviderAllowed also log some meaningful err data like the actual input so it's easier to spot the root of an issue? I guess since we currently have no specification on eg. user idp domain vs. url we can not log suggestions in that regard.
I mean reva/mesh configuration is rather complex so any logging hints that would guide you to where a configuration might be wrong would be really helpful.

@mirekys
Copy link
Member Author

mirekys commented Aug 4, 2022

It already returns errors if domain is not found amongst mesh providers (together with input domain value) here, which then gets logged here, is this insufficient or something else needs to also be logged?

EDIT: udated other current mentix errors to provide more context

@redblom
Copy link
Contributor

redblom commented Aug 4, 2022

EDIT: udated other current mentix errors to provide more context

Yeah I like that ! (there's obviously some personal preference from me here but I like this better ;)

@redblom
Copy link
Contributor

redblom commented Aug 5, 2022

I just simply removed the code and pass the provider as is, as it should be a responsibility of IsProviderAllowed endpoint to normalize value before checking

@mirekys @labkode in the ForwardInvite request the recipientProvider that comes from (is) the context user idp still must be normalized also. This could be done here and here.
But we can also let the user manager normalize the user Idp when setting it in the first place. What would be the preferred way?

@mirekys
Copy link
Member Author

mirekys commented Aug 8, 2022

I just simply removed the code and pass the provider as is, as it should be a responsibility of IsProviderAllowed endpoint to normalize value before checking

@mirekys @labkode in the ForwardInvite request the recipientProvider that comes from (is) the context user idp still must be normalized also. This could be done here and here. But we can also let the user manager normalize the user Idp when setting it in the first place. What would be the preferred way?

I would vote for handling it in a single place (user manager), rather than doing it in all places idp is being used, but not sure whether it won't break something somewhere

@redblom
Copy link
Contributor

redblom commented Aug 8, 2022

I'm also for that. Best to do this in a separate PR though. I can take that one, in 2 weeks as I'm currently on holidays. But would be good to get an opinion from @labkode also, he's back from holidays in 2 weeks as well.

@redblom
Copy link
Contributor

redblom commented Aug 22, 2022

@mirekys

@mirekys @labkode in the ForwardInvite request the recipientProvider that comes from (is) the context user idp still must be normalized also. This could be done here and here. But we can also let the user manager normalize the user Idp when setting it in the first place. What would be the preferred way?

I would vote for handling it in a single place (user manager), rather than doing it in all places idp is being used, but not sure whether it won't break something somewhere

I realized, and tested, that this is not needed after all. So simply removing as you've already done in internal/http/services/ocmd/invites.go will suffice indeed !

Next however the getOCMHost method currently also fails. Here ocmHost.Host will return an empty string after the host field is parsed into a url.
So we must be sure to create a proper url here once more from the input (similar to normalizeDomain) in order to be able to return the host.

@mirekys
Copy link
Member Author

mirekys commented Sep 5, 2022

@antoonp
I must admit that I'm getting kinda confused about acceptable formats of values
of each different provider properties. As I understood from this PR and
cs3org/cs3apis#159 (comment),
we have to deal with the following provider-related properties:

  • Provider Domain
  • Provider service Host
  • User's IDP

that can have 3 possible values:

  • FQDN (without protocol)
  • URI without path
  • full URI

I start thinking it would be cleaner to determine the required formats on each property,
and then validate/convert to a single given format, when setting the property (rather than forcing
normalization from multiple formats to full URLs everywhere such property is used). So it would be safer to expect from
everywhere, that if a given property is set on a provider, it is in an expected format.

I think Domain should be just FQDNs, IDP should be a full URI, and Host is defined as https://github.com/cs3org/cs3apis/blob/main/cs3/ocm/provider/v1beta1/resources.proto#L64, so it should probably also be required to always have a full valid URL there.

But I see a Host as the most specific part of a Domain name (e.g. sciencemesh for a domain of sciencemesh.cesnet.cz, or sciencemesh.cesnet.cz for a domain of cesnet.cz), I wouldn't exactly expect an URL to be there. I believe that if we need URLs in service hosts, the terminology used should be updated to not be confusing

michielbdejong added a commit to michielbdejong/reva that referenced this pull request Dec 9, 2022
@michielbdejong
Copy link
Contributor

Oops, I used the GitHub online merge tool to merge this branch into my debug branch, and apparently it somehow allowed me to add commits to https://github.com/mirekys/reva/commits/fix-3113 - that's scary!

@michielbdejong
Copy link
Contributor

Force push to someone else's GitHub account is also scary but looks like it did put the branch back in its correct state :/

@micbar
Copy link
Member

micbar commented Dec 9, 2022

@michielbdejong The Ci has changed on the master branch. You need to rebase this PR.

@michielbdejong
Copy link
Contributor

I'm still not sure why I'm allowed to push to @mirekys's branch, but I merged origin/master into it as @micbar requested.

@michielbdejong
Copy link
Contributor

While testing this code, I think there is one more change missing:
In this block in the mentix driver for ocm provider authorizer, service.Host is converted from a URL to a FQDN, but looking at for instance this gocdb edit screen:
Screenshot 2022-12-09 at 16 41 32

I think the "service host" is already a FQDN, and parsing it in this way changes it to "". So I think it's better to just return s.Host, nil here (and same for the json and open drivers).

@michielbdejong
Copy link
Contributor

@labkode I think we should merge this PR asap

@labkode labkode merged commit 9bfe2ae into cs3org:master Dec 19, 2022
vascoguita pushed a commit to vascoguita/reva that referenced this pull request Dec 19, 2022
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.

Mentix OCM Auth Provider Normalization
5 participants