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

Adjust required permissions for system schema #7579

Merged
merged 8 commits into from
May 2, 2019

Conversation

jon-wei
Copy link
Contributor

@jon-wei jon-wei commented Apr 30, 2019

This PR implements the following change described in #7563:

The permissions needed for system table access could be adjusted to not require additional permissions beyond datasource-specific permissions for non-server related info (segments, tasks) and to require STATE-read permissions for server-related tables (servers, server_segments) to be consistent with the non-SQL APIs.

A STATE.READ permission check is added to server_segments sys table handling (servers already had one, and #7567 removed the unnecessary sys datasource check).

This PR also adds integration tests for sys schema + auth. A new segment and task for auth_test datasource are inserted directly into metadata during IT setup, and this datasource is used for testing the auth checks.

@jon-wei
Copy link
Contributor Author

jon-wei commented Apr 30, 2019

will need to adjust tests to handle when the full IT test suite is run (since cluster state is not isolated across tests, things like "total stored segment size on historicals" change)

@jon-wei jon-wei added the WIP label Apr 30, 2019
Copy link
Contributor

@gianm gianm left a comment

Choose a reason for hiding this comment

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

Could you also update the sql.md docs to describe what permissions are needed for what SQL queries?

authorizerMapper
);
if (!stateAccess.isAllowed()) {
throw new ForbiddenException("Insufficient permission to view servers :" + stateAccess);
Copy link
Contributor

Choose a reason for hiding this comment

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

Whitespace should be after the colon here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed


final Access stateAccess = AuthorizationUtils.authorizeAllResourceActions(
authenticationResult,
Collections.singletonList(new ResourceAction(new Resource("STATE", ResourceType.STATE), Action.READ)),
Copy link
Contributor

Choose a reason for hiding this comment

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

new Resource("STATE", ResourceType.STATE) is a very specific thing and should probably be a constant in some file or other.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made this a constant in Resource

authenticationResult,
Collections.singletonList(new ResourceAction(new Resource("STATE", ResourceType.STATE), Action.READ)),
authorizerMapper
);

Choose a reason for hiding this comment

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

Since authenticationResult and stateAccess are being used in ServersTable as well as here in ServerSegmentsTable, may be this part can be placed in a common method like

private static boolean accessAllowed(DataContext root, AuthorizerMapper authorizerMapper)
{
    final AuthenticationResult authenticationResult =
        (AuthenticationResult) root.get(PlannerContext.DATA_CTX_AUTHENTICATION_RESULT);
    final Access access = AuthorizationUtils.authorizeAllResourceActions(
        authenticationResult,
        Collections.singletonList(new ResourceAction(new Resource("STATE", ResourceType.STATE), Action.READ)),
        authorizerMapper
    );
    return access.isAllowed();
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved this to a checkStateReadAccessForServers method

@jon-wei
Copy link
Contributor Author

jon-wei commented Apr 30, 2019

I updated the SQL docs with info on necessary permissions, also added tests for a user without access to the auth_test datasource

@jon-wei jon-wei removed the WIP label Apr 30, 2019
Copy link
Contributor

@gianm gianm left a comment

Choose a reason for hiding this comment

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

By the way, it's a bit weird that the Druid permissions model is documented in the druid-basic-security extension, which isn't responsible for defining the permissions model. It makes it sound like the model is not a core thing. I think it'd be good to fix this at some point - would you mind raising an issue (or, better, a new PR)?


Queries on Druid datasources require DATASOURCE READ permissions for the specified datasource.

Queries on the [information schema tables](../../querying/sql.html#information-schema) require DATASOURCE READ access for the specified datasource.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please adjust the language a bit- there is not necessarily any 'specified datasource' with the information schema. The query might just be SELECT * FROM INFORMATION_SCHEMA.COLUMNS. I'd suggest:

Queries on the [INFORMATION_SCHEMA tables](../../querying/sql.html#information-schema) will
return information about datasources that the caller has DATASOURCE READ access to. Other
datasources will be omitted.

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, reworded

@gianm
Copy link
Contributor

gianm commented May 1, 2019

LGTM other than the comment about doc wording.

Copy link

@surekhasaharan surekhasaharan left a comment

Choose a reason for hiding this comment

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

LGTM thanks @jon-wei

@jon-wei
Copy link
Contributor Author

jon-wei commented May 1, 2019

Fixed tests:

  • Updated to handle changes from is_overshadowed patch
  • Changed the created year for the inserted task to 2030 so it doesn't fall out of the completed tasks window

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

Successfully merging this pull request may close these issues.

None yet

4 participants