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

Filter root path according to the agent that makes the request #2212

Merged
merged 24 commits into from
Nov 17, 2021

Conversation

gmgigi96
Copy link
Member

No description provided.

@update-docs
Copy link

update-docs bot commented Oct 27, 2021

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.

glpatcern
glpatcern previously approved these changes Oct 27, 2021
Copy link
Contributor

@ishank011 ishank011 left a comment

Choose a reason for hiding this comment

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

Can you confirm once that contexts from web requests are propagated here? We do pass the same context (https://github.com/cs3org/reva/blob/master/internal/http/services/owncloud/ocdav/get.go#L63) but let's confirm it once

Also please look at my review from the last PR

pkg/storage/registry/static/static.go Outdated Show resolved Hide resolved
Copy link
Contributor

@ishank011 ishank011 left a comment

Choose a reason for hiding this comment

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

I meant moving the IsUserAgentAllowed method to a separate package 😅

@gmgigi96 gmgigi96 force-pushed the filter-root-paths branch 2 times, most recently from cb14ff3 to b570bd9 Compare October 28, 2021 15:15
Copy link
Contributor

@dragotin dragotin left a comment

Choose a reason for hiding this comment

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

Can anybody elaborate what that is used for? For me, this looks error prone and maybe incomplete, depending on what should be achieved. I think this kind of code will never catch all UserAgents (not talking about simply spoofing the UA) and should be avoided whenever possible.

@gmgigi96
Copy link
Member Author

@dragotin The aim of this is to filter the root path view based on the agent that make the request. For example we would like to just view the home directory from the directory, while still see the home and shares from the sync client.

@gmgigi96
Copy link
Member Author

@ishank011 I have just tested and the user agent from the http request is not propagated into the grpc requests

@gmgigi96 gmgigi96 force-pushed the filter-root-paths branch 2 times, most recently from 97f6f9d to f2edb06 Compare November 1, 2021 13:11
@lgtm-com
Copy link

lgtm-com bot commented Nov 1, 2021

This pull request introduces 1 alert when merging f2edb06 into 867d1e2 - view on LGTM.com

new alerts:

  • 1 for Useless assignment to local variable

@gmgigi96 gmgigi96 changed the title Fix desktop and add mobile filters for root path [WIP] Filter root path according to the agent that makes the request Nov 1, 2021
@gmgigi96 gmgigi96 changed the title [WIP] Filter root path according to the agent that makes the request Filter root path according to the agent that makes the request Nov 1, 2021
@gmgigi96 gmgigi96 marked this pull request as ready for review November 1, 2021 15:35
internal/grpc/services/gateway/gateway.go Outdated Show resolved Hide resolved
internal/grpc/services/gateway/gateway.go Outdated Show resolved Hide resolved
internal/grpc/services/gateway/storageprovider.go Outdated Show resolved Hide resolved
pkg/ctx/agentctx.go Show resolved Hide resolved
pkg/rgrpc/rgrpc.go Outdated Show resolved Hide resolved
@ishank011
Copy link
Contributor

Why don't we use this here?
grpc/grpc-go#1100 (comment)

server := grpc.Dial(grpc_server, WithUserAgent("user-agent",))

@gmgigi96
Copy link
Member Author

gmgigi96 commented Nov 9, 2021

Why don't we use this here? grpc/grpc-go#1100 (comment)

server := grpc.Dial(grpc_server, WithUserAgent("user-agent",))

I will leave a comment here to keep track on what we discussed yesterday and other thought I have after playing with user agents in GRPC.

Actually this is the way of specifying a user agent in a grpc call, that internally updates the outcoming metadata in the context when you will call a grpc method, and you can find the user agent in the incoming metadata in the context server-side. But, even if you specify your own user agent, this will be concatenated with the string "grpc-go/". I do not know if this can broke the library we use to parse the user agents, maybe not. But the main problem of using this approach is that for each time you want to get a grpc client for a service you need to specify the user agent that will do the request, if not specified, grpc automatically will set its default ("grpc-go/"). This means that we should modify all the methods in the pool pkg to receive a user agent. But I do not like this approach as we cannot cache anymore the grpc connection for each endpoint address, but we should cache also the user agent. In fact after a dial, there is no way to override it after creating a new connection (I tried also modifying the internal metadata of a context before a call, but apparently grpc reset it with the user agent passed to the Dial method).

So I preferred to define my own user agent token that will be managed internally by reva and not by grpc. With this approach we do not have the cons mentioned above. Of course the user agent log did not work, as it was reading the grpc user-agent metadata, and not the new one. Now it’s fixed and you should see the correct user agent in the log.

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.

4 participants