Skip to content

Create a role per api key #35546

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

Closed
wants to merge 3 commits into from

Conversation

jaymode
Copy link
Member

@jaymode jaymode commented Nov 14, 2018

This commit changes how we handle roles for api keys. Previously, the
role descriptors were stored inside of the api key document as a
dynamic field. Storing roles this way meant that a new method for role
resolution and caching would be needed, which further complicates this
feature. Instead we can take the descriptors, merge them into a single
descriptor, and create a specific role for the api key. This allows us
to reuse the existing framework and APIs to view the permissions that
a api key grants.

This commit changes how we handle roles for api keys. Previously, the
role descriptors were stored inside of the api key document as a
dynamic field. Storing roles this way meant that a new method for role
resolution and caching would be needed, which further complicates this
feature. Instead we can take the descriptors, merge them into a single
descriptor, and create a specific role for the api key. This allows us
to reuse the existing framework and APIs to view the permissions that
a api key grants.
@jaymode jaymode added >non-issue :Security/Authentication Logging in, Usernames/passwords, Realms (Native/LDAP/AD/SAML/PKI/etc) labels Nov 14, 2018
@jaymode jaymode requested review from bizybot and tvernum November 14, 2018 15:02
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-security

Copy link
Contributor

@bizybot bizybot left a comment

Choose a reason for hiding this comment

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

LGTM, once the CI goes green, Thank you

/**
* Combines the provided role descriptors into a put role request with the specified name
*/
private PutRoleRequest mergeRoleDescriptors(String name, List<RoleDescriptor> descriptors) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess we will test creation of role after merging in integTest or do we want to add a unit test for this?

@jaymode
Copy link
Member Author

jaymode commented Nov 16, 2018

run gradle build tests

final List<RoleDescriptor.ApplicationResourcePrivileges> applicationResourcePrivileges = new ArrayList<>();
final List<ConditionalClusterPrivilege> conditionalClusterPrivileges = new ArrayList<>();
for (RoleDescriptor descriptor : descriptors) {
indicesPrivileges.addAll(Arrays.asList(descriptor.getIndicesPrivileges()));
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @jaymode, I think I missed this and while working on subset code I realized whether we should be merging the indices privileges if the index names match? (Something on the lines that we do with MergeableIndicesPrivileges)

Copy link
Contributor

@tvernum tvernum 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 on the fence about whether this is the right direction to go in.

I see the value in making everything the same, but at the same time, these aren't just "roles", they permission sets that are represented as a role, and I think we're blurring the line here.

I just feel a bit uneasy about it.

throw new IllegalStateException("index request cannot be null");
}

client.execute(PutRoleAction.INSTANCE, putRoleRequest, ActionListener.wrap(response ->
Copy link
Contributor

Choose a reason for hiding this comment

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

Why isn't this execute performed withOrigin?
We shouldn't assume/require that all users who can create API keys can Put Roles.

Copy link
Member Author

Choose a reason for hiding this comment

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

👍 good call

clusterPrivileges.addAll(Arrays.asList(descriptor.getClusterPrivileges()));
runAsPrivileges.addAll(Arrays.asList(descriptor.getRunAs()));
applicationResourcePrivileges.addAll(Arrays.asList(descriptor.getApplicationPrivileges()));
conditionalClusterPrivileges.addAll(Arrays.asList(descriptor.getConditionalClusterPrivileges()));
Copy link
Contributor

Choose a reason for hiding this comment

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

This could create a role descriptor that cannot be converted to XContent.
If two role descriptors have

  • global: { application: { manage: { applications: [ "app1" ] } } }
  • global: { application: { manage: { applications: [ "app2 "] } } }

then the merged role descriptor cannot produce valid XContent.

The GetUserPrivileges action had this problem and had to use a different output format to accommodate the potential for multivariate fields.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a good point and would break the get api once implemented.

@jaymode
Copy link
Member Author

jaymode commented Nov 26, 2018

@tvernum do you have any thoughts or suggestions about an alternative?

@tvernum
Copy link
Contributor

tvernum commented Nov 29, 2018

Sorry for not replying earlier. I'll review the alternative proposed in #35970.

My other thought on how to do this would be:

  1. Pick a naming scheme for "roles that come from API Keys" (e.g. "%api-key-${key.id}.${sequence}", %api-key-eb295dae65de460a89f828fc77c1871c-1)
  2. Deprecate native + file roles that start with that character (%) in 6.x, remove support for them in 7.0
  3. Create a ApiKeyRoleStore that can load roles using that naming scheme.
  4. Change the CompositeRolesStore to use the ApiKeyRoleStore

@jaymode
Copy link
Member Author

jaymode commented Nov 29, 2018

Closing this in favor of #35970

@jaymode jaymode closed this Nov 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>non-issue :Security/Authentication Logging in, Usernames/passwords, Realms (Native/LDAP/AD/SAML/PKI/etc)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants