Skip to content

basic security extension ignore permissions that use unknown ResourceType or Action#10896

Merged
clintropolis merged 3 commits intoapache:masterfrom
clintropolis:basic-security-chill-about-unknown-types
Feb 23, 2021
Merged

basic security extension ignore permissions that use unknown ResourceType or Action#10896
clintropolis merged 3 commits intoapache:masterfrom
clintropolis:basic-security-chill-about-unknown-types

Conversation

@clintropolis
Copy link
Member

@clintropolis clintropolis commented Feb 17, 2021

Description

This PR makes the druid-basic-security extension a bit more relaxed across versions by ignoring any permissions which have unknown ResourceType or Action values (they use enums).

A subtle backwards incompatibility was introduced in #10812, if permissions using Resource of type ResourceType.VIEW are added (or created automatically when creating default admin user in a new install), rolling back to a previous version of Druid results in explosions because the enum in the older version does not contain this value. (The same backwards incompatibility would occur with the changes in #10571).

Rather than rework these types to deserialize into strings and then filtering out permissions with unknown resource types or action values from the list (or, i guess null checking everywhere), this PR instead introduces a custom deserializer for the list of permissions stored in a BasicAuthorizerRole, chomping json processing exceptions so it can ignore any permissions which fail to deserialize. I'm open to other approaches to this too if anyone has opinions here.


This PR has:

  • been self-reviewed.
  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • 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.

@clintropolis clintropolis changed the title basic security extension ignore permissions that use unknown ResourceType and Action basic security extension ignore permissions that use unknown ResourceType or Action Feb 17, 2021
@clintropolis clintropolis added this to the 0.21.0 milestone Feb 18, 2021
}
catch (JsonProcessingException e) {
// ignore unparseable, it might be resource types we don't know about
log.warn(e, "Failed to deserialize authorizer role, ignoring");
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we print the string representation of the JsonNode here to aid in debugging?

Copy link
Member Author

Choose a reason for hiding this comment

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

👍, added

}

@Test
public void testPermissionSerdeIsChillAboutUnknownEnumStuffs() throws JsonProcessingException
Copy link
Contributor

@zachjsh zachjsh Feb 18, 2021

Choose a reason for hiding this comment

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

nit: can this be split into a few different tests if not too much trouble?

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't end up splitting this one up yet, since I wasn't quite sure on what way made the most sense after thinking about how it doesn't really take a different code path from the deserializeAuthorizerRoleMap methods perspective here, (the same exception is thrown and same code path taken regardless of which enum failed to deserialize). I put both enums in here because it made me feel better, but from a pure coverage perspective i don't think splitting at least on different enum failures changes much.

Any suggestion on what split makes sense? There are more general tests that cover happier paths with JSON serde of the types involved here in some of the other test classes, I just did this unhappy path test in this test class so I could call the deserializeAuthorizerRoleMap method directly without worrying about the rest of the scaffolding stuff the happy path tests are using.

Copy link
Contributor

Choose a reason for hiding this comment

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

this test seems to test 3 cases: 1 good Permission, one bad resourceType permission and one bad resourceAciont permission. Thought it made sens to split into 3 tests accordingly. Its ok to leave as is too, just a nit, no biggie.

@clintropolis
Copy link
Member Author

thanks for review @jon-wei and @zachjsh 🤘

@clintropolis clintropolis merged commit 0ecc901 into apache:master Feb 23, 2021
@clintropolis clintropolis deleted the basic-security-chill-about-unknown-types branch February 23, 2021 22:49
clintropolis added a commit to clintropolis/druid that referenced this pull request Feb 23, 2021
…Type or Action (apache#10896)

* suppress unknown ResourceType and Action for basic-security authorizer stuff

* fix pom

* print failed role, test logs
clintropolis added a commit that referenced this pull request Mar 30, 2021
…wn ResourceType or Action (#10919)

* basic security extension ignore permissions that use unknown ResourceType or Action (#10896)

* suppress unknown ResourceType and Action for basic-security authorizer stuff

* fix pom

* print failed role, test logs

* fix test for backport
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.

3 participants