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

Resource token fix - 1 #19547

Merged
merged 9 commits into from
Mar 5, 2021
Merged

Resource token fix - 1 #19547

merged 9 commits into from
Mar 5, 2021

Conversation

xinlian12
Copy link
Member

@xinlian12 xinlian12 commented Mar 2, 2021

Fix included:

  1. Appendig dbs/ for permission resourcePath compared to using /dbs/
  2. add support for partitionKey
  3. fix query with partition key resource token 403 exception(populate partitionKey for query plan requests)
  4. Ported ResourceTokenTest for new model

Still need to work on:
Query with permissions

@xinlian12
Copy link
Member Author

/azp run java - cosmos - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor

@moderakh moderakh left a comment

Choose a reason for hiding this comment

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

LGTM. thank you.

please ask
@simplynaveen20 @xinlian12 to review as well, as they are familiar with permission

Constants.Properties.RESOURCE_PARTITION_KEY,
BridgeInternal.getPartitionKeyInternal(partitionkey)
.toJson());
if(ModelBridgeInternal.getPartitionKeyObject(partitionkey) != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why the null check is needed?

can the user pass null partition key to the setter? is that a valid scenario?
if we decide to do arg validation here shouldn't we throw NPE?

Copy link
Member

Choose a reason for hiding this comment

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

I agree, good point, having null checks prevent bugs, but they also hide the possible buggy code paths. We should avoid it if this scenario can be validated through the generic code pass.

Copy link
Member

@kushagraThapar kushagraThapar left a comment

Choose a reason for hiding this comment

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

Thanks @xinlian12 @simplynaveen20 for these changes, looks good to me overall, just some minor comments.

Constants.Properties.RESOURCE_PARTITION_KEY,
BridgeInternal.getPartitionKeyInternal(partitionkey)
.toJson());
if(ModelBridgeInternal.getPartitionKeyObject(partitionkey) != null) {
Copy link
Member

Choose a reason for hiding this comment

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

I agree, good point, having null checks prevent bugs, but they also hide the possible buggy code paths. We should avoid it if this scenario can be validated through the generic code pass.

Copy link
Member

@FabianMeiswinkel FabianMeiswinkel left a comment

Choose a reason for hiding this comment

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

LGTM - but I think Bhaskar's comment of adding at least a sanity test using the V4 Client to test the wiring there makes sense

@xinlian12
Copy link
Member Author

xinlian12 commented Mar 2, 2021

LGTM - but I think Bhaskar's comment of adding at least a sanity test using the V4 Client to test the wiring there makes sense

ResourceTokenTests is for v4 model. ResourceTokenTest is for old model. I think the naming might confusing a little. Will change that.

Refactored from ResourceTokenTests to ResourceTokenTestForV4

@FabianMeiswinkel @mbhaskar

@xinlian12
Copy link
Member Author

/azp run java - cosmos - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

collectionRid,
ResourceType.Document,
RequestVerb.GET,
headers,
AuthorizationTokenType.PrimaryMasterKey,
request.properties);
} catch (UnauthorizedException e) {
// User doesn't have rid based resource token. Maybe user has name based.
Copy link
Member

Choose a reason for hiding this comment

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

We are swallowing the exception here. If there is no active action that we can take, we should at least log it for our own purposes.

Copy link
Member Author

Choose a reason for hiding this comment

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

Make sense, since we will retry using name based link next, so will add a debug level message to not confuse the customer

Copy link
Contributor

Choose a reason for hiding this comment

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

seems to me we are throwing UnauthorizedException as part of the logic rather that catching a problem

Why can't we do this with a if/else condition where you check it is rid based use that else use name based.
Why do we need to throw exception can't rely on if/else?

exception throwing is expensive!

Copy link
Member Author

Choose a reason for hiding this comment

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

The intention here seems like: first always try resouceId, then using named based link as fallback. so it make sure we will try both ways.

If we changed to if else, then we will only try one of them.

Currently, the main issue(query does not work with permissions) is that we are mixing using the name based link or the resouceId based link: how we construct the tokenMap and how we consuming it. There could be two possible ways to fix it:
a. using the namedBasedLink/ResourceIdBasedLink consistently
b. try one, if not found, then fallback to another one.

Depending which way we want to choose, this part of logic can be simplified or should keep some similar logic.

@xinlian12 xinlian12 merged commit 8e581dc into Azure:master Mar 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants