Skip to content

Require Datasource WRITE authorization for Supervisor and Task access#11718

Merged
abhishekagarwal87 merged 20 commits intoapache:masterfrom
kfaraz:fix_supervisor_api_auth
Oct 8, 2021
Merged

Require Datasource WRITE authorization for Supervisor and Task access#11718
abhishekagarwal87 merged 20 commits intoapache:masterfrom
kfaraz:fix_supervisor_api_auth

Conversation

@kfaraz
Copy link
Copy Markdown
Contributor

@kfaraz kfaraz commented Sep 17, 2021

Follow up PR for #11680

Description

Supervisor and Task APIs are related to ingestion and must always require Datasource WRITE
authorization even if they are purely informative.

Changes

  • Check Datasource WRITE in SystemSchema for tables "supervisors" and "tasks"
  • Check Datasource WRITE for APIs /supervisor/history and /supervisor/{id}/history
  • Check Datasource for all Indexing Task APIs

This PR has:

  • been self-reviewed.
  • added documentation for new or modified features or behaviors.
  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • added or updated version, license, or notice information in licenses.yaml
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.
  • added integration tests.
  • been tested in a test Druid cluster.

@kfaraz kfaraz changed the title [WIP] Require Datasource WRITE authorization for Supervisor and Task access Require Datasource WRITE authorization for Supervisor and Task access Sep 17, 2021
Copy link
Copy Markdown
Member

@clintropolis clintropolis left a comment

Choose a reason for hiding this comment

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

makes sense to me that these should be WRITE permissions, but I think we need to tag this design review and release notes (incompatible?) since based on the state of things, it seems like these were all maybe intentionally using READ permissions for the 'reading' ingestion APIs that use HTTP GET, and WRITE to run or otherwise actually control jobs.

)
{
IndexTaskUtils.datasourceAuthorizationCheck(req, Action.READ, getDataSource(), authorizerMapper);
IndexTaskUtils.datasourceAuthorizationCheck(req, Action.WRITE, getDataSource(), authorizerMapper);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

IndexTaskUtils.datasourceAuthorizationCheck should be modified to no longer accept an Action since I think after this PR every caller will be using Action.WRITE, and it can just be hard coded in the method.

I've also noticed that no callers seem to ever be using the return value, so it could probably be changed to void since we seem to mostly be using it to explode if not authorized and otherwise ignore the return value.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

* @return authorization result
*/
private Access authorizationCheck(final HttpServletRequest req, Action action)
private Access datasourceWriteAuthCheck(final HttpServletRequest req)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nearly this same method is also in ParallelIndexSupervisorTask, maybe consider moving it to AbstractTask and calling it authorizeRequest, then here can just return task.authorizeRequest(req); (or dropping this wrapper method and calling the new task.authorizeRequest(req); method directly in the http api methods of SeekableStreamIndexTaskRunner)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Thanks for the suggestion. 👍

Copy link
Copy Markdown
Member

@clintropolis clintropolis left a comment

Choose a reason for hiding this comment

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

cool, lgtm 👍

Copy link
Copy Markdown
Contributor

@suneet-s suneet-s left a comment

Choose a reason for hiding this comment

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

Code changes LGTM - but can we add some tests to catch any changes in behavior around authorization for these endpoints? At least for the endpoints where the authorization requirements have changed.

It looks like there are some integration tests for things like this in ITBasicAuthConfigurationTest. If you think integration tests are overkill for this, I am open to unit tests being written to cover these cases instead.

@kfaraz
Copy link
Copy Markdown
Contributor Author

kfaraz commented Sep 22, 2021

Thanks for the review, @suneet-s . I will add some UTs/ITs as applicable today.

@clintropolis
Copy link
Copy Markdown
Member

I think we also need to update the system table docs here https://github.com/apache/druid/blob/master/docs/operations/security-user-auth.md#sql-permissions to indicate that some of these system tables now require write permissions. I haven't found any other places yet in docs where a READ should be changed to a WRITE, yet at least...

Copy link
Copy Markdown
Member

@clintropolis clintropolis left a comment

Choose a reason for hiding this comment

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

👍

Copy link
Copy Markdown
Contributor

@suneet-s suneet-s left a comment

Choose a reason for hiding this comment

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

None of my comments are blocking - it would be nice to get a better understanding of what the lockGranularity if statement in IndexTaskTest#testAuthorizeResource does

public void testAuthorizeRequest() throws Exception
{
// Need to run this only once
if (lockGranularity == LockGranularity.SEGMENT) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't understand this part of the test.

Copy link
Copy Markdown
Contributor Author

@kfaraz kfaraz Oct 6, 2021

Choose a reason for hiding this comment

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

This is a parameterized unit test class. So every test method is run once for SEGMENT granularity and once for TIME_CHUNK. Since this test method does not depend on granularity, figured we should run it only once.

We could explain this part better in the comment or just remove the check.
Please let me know what you think would be better.

case Datasources.WIKIPEDIA:
// All users can read wikipedia but only writer can write
return new Access(
action == Action.READ || Users.WIKI_WRITER.equals(username)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
action == Action.READ || Users.WIKI_WRITER.equals(username)
action == Action.READ || (action == Action.WRITE && Users.WIKI_WRITER.equals(username))

I think a similar change is needed on line 132

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Should we include this for readability? Because the logic would remain the same.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Primarily, yes.

Since there are only 2 actions, I suppose this is equivalent. If a new action was added later, this logic may not match what is described in the comment above.

@kfaraz
Copy link
Copy Markdown
Contributor Author

kfaraz commented Oct 6, 2021

@clintropolis , I have made some modifications to AbstractAuthConfigurationTestand the corresponding bootstrap.ldif as some auth integration tests were failing and I had missed updating them. Please review these changes.

Copy link
Copy Markdown
Contributor

@techdocsmith techdocsmith left a comment

Choose a reason for hiding this comment

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

I'm changing the language around those docs in another PR. Otherwise LGTM.

Comment thread docs/operations/security-user-auth.md Outdated
Co-authored-by: Charles Smith <techdocsmith@gmail.com>
Copy link
Copy Markdown
Contributor

@suneet-s suneet-s left a comment

Choose a reason for hiding this comment

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

+1 after CI

@abhishekagarwal87 abhishekagarwal87 merged commit f2d6100 into apache:master Oct 8, 2021
clintropolis added a commit that referenced this pull request Oct 8, 2021
* security recommendation

* Update docs/operations/security-overview.md

Co-authored-by: Victoria Lim <vtlim@users.noreply.github.com>

* Update docs/operations/security-user-auth.md

Co-authored-by: Victoria Lim <vtlim@users.noreply.github.com>

* Update docs/operations/security-user-auth.md

Co-authored-by: Victoria Lim <vtlim@users.noreply.github.com>

* Update security-user-auth.md

add newline

* Update docs/operations/security-overview.md

Co-authored-by: Victoria Lim <vtlim@users.noreply.github.com>

* Update security-overview.md

add suggestion for environment variable dynamic config provider

Co-authored-by: Victoria Lim <vtlim@users.noreply.github.com>
Co-authored-by: Clint Wylie <cwylie@apache.org>
kfaraz added a commit to kfaraz/druid that referenced this pull request Oct 20, 2021
abhishekagarwal87 pushed a commit that referenced this pull request Oct 25, 2021
* Revert "Require Datasource WRITE authorization for Supervisor and Task access (#11718)"

This reverts commit f2d6100.

* Revert "Require DATASOURCE WRITE access in SupervisorResourceFilter and TaskResourceFilter (#11680)"

This reverts commit 6779c46.

* Fix docs for the reverted commits

* Fix and restore deleted tests

* Fix and restore SystemSchemaTest
jon-wei pushed a commit to jon-wei/druid that referenced this pull request Nov 22, 2021
@abhishekagarwal87 abhishekagarwal87 added this to the 0.23.0 milestone May 11, 2022
@kfaraz kfaraz deleted the fix_supervisor_api_auth branch August 1, 2023 04:51
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.

5 participants