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

REST API changes for manage-own-api-key privilege #44936

Merged

Conversation

bizybot
Copy link
Contributor

@bizybot bizybot commented Jul 29, 2019

This commit adds a flag that can be set to true if the
API key request (Get or Invalidate) is for the API keys owned
by the currently authenticated user only.
These only interface changes and once the actual cluster privilege
manage_own_api_key is done, we will have another PR to make the
interface work.

The Get API behavior would be:

  • when owner is set to true
    GET /_security/api_key?id=abcd&owner=true
    the Rest controller will take care of setting realm_name and username to the
    values for the authenticated user and only return results if it finds one owned by
    the currently authenticated user.

  • when owner is set to false (default)
    GET /_security/api_key?id=abcd
    the Rest controller will assume realm_name and username to be unspecified
    meaning it will try to search for the API key across users and realms.
    This will fail if the user has only manage_own_api_key privilege.

Similarly, for Delete API key behavior:

  • when owner is set to true
    DELETE /_security/api_key

    {
      "id" : "VuaCfGcBCdbkQm-e5aOx",
      "owner": "true"
    }
    

    the Rest controller will take care of setting realm_name and username to the values
    for the authenticated user and only invalidate key if it finds one owned by
    the currently authenticated user.

  • when my_api_keys_only is set to false (default)
    DELETE /_security/api_key

    {
      "id" : "VuaCfGcBCdbkQm-e5aOx",
      "owner": "false"
    }
    

    the Rest controller will assume realm_name and username to be unspecified meaning it will
    try to search for the API key across users and realms. This will fail if the user has only
    manage_own_api_key privilege.

TODO:

  • HLRC changes - these will be done in a separate PR
  • Actual enforcement of my_api_keys_only in a separate PR

Relates #40031

This commit adds a flag that can be set to `true` if the
API key request (Get or Invalidate) is for the API keys owned
by the current authenticated user only.

The Get API behavior would be:
- when `my_api_keys_only` is set to `true`
  `GET /_security/api_key?id=abcd&my_api_keys_only=true`
        the Rest controller will take care of setting `realm_name` and `username` to the
        values for authenticated user and only return results if it finds one owned by
        the currently authenticated user.

- when `my_api_keys_only` is set to `false` (default)
  `GET /_security/api_key?id=abcd`
        the Rest controller will assume `realm_name` and `username` to be unspecified
        meaning it will try to search for the API key across users and realms.
        This will fail if the user has only `manage_own_api_key` privilege.

Similarly, for Delete API key behavior:
- when `my_api_keys_only` is set to `true`
   `DELETE /_security/api_key`
   ```
   {
     "id" : "VuaCfGcBCdbkQm-e5aOx",
     "my_api_keys_only": "true"
   }
   ```

   the Rest controller will take care of setting `realm_name` and `username` to the values
   for authenticated user and only invalidate key if it finds one owned by
   the currently authenticated user.

- when `my_api_keys_only` is set to `false` (default)
   `DELETE /_security/api_key`
   ```
   {
     "id" : "VuaCfGcBCdbkQm-e5aOx",
     "my_api_keys_only": "true"
   }
   ```

    the Rest controller will assume `realm_name` and `username` to be unspecified meaning it will
    try to search for the API key across users and realms. This will fail if the user has only
    `manage_own_api_key` privilege.
@bizybot bizybot added :Security/Authorization Roles, Privileges, DLS/FLS, RBAC/ABAC v8.0.0 v7.4.0 labels Jul 29, 2019
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-security

Copy link
Contributor

@albertzaharovits albertzaharovits left a comment

Choose a reason for hiding this comment

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

LGTM save for the lack of version guards.

@bizybot
Copy link
Contributor Author

bizybot commented Jul 30, 2019

Connection to 127.0.0.1 closed by remote host.
@elasticmachine run elasticsearch-ci/1 elasticsearch-ci/packaging-sample

@bizybot
Copy link
Contributor Author

bizybot commented Jul 30, 2019

@elasticmachine run elasticsearch-ci/packaging-sample

@tvernum
Copy link
Contributor

tvernum commented Aug 1, 2019

Did you consider alternatives for the parameter name? I don't love it (it's a bit verbose), but I don't want to go back over old ground if you've worked through a bunch of options already.

I would think that owned=true would be fine.

@bizybot
Copy link
Contributor Author

bizybot commented Aug 1, 2019

Did you consider alternatives for the parameter name? I don't love it (it's a bit verbose), but I don't want to go back over old ground if you've worked through a bunch of options already.

I would think that owned=true would be fine.

I did consider but went with verbose as the intent was clear with the name, I agree it is too verbose now that I look at it. I like owned but by whom is not clear. Is it okay as the documentation for the API would have that information or do we want to be little more specific like owned_by_me instead? Thank you for your comments.

@tvernum
Copy link
Contributor

tvernum commented Aug 1, 2019

I'm personally not that worried about whether the meaning of the parameter is 100% obvious from its name - we have docs.
I'm OK with owned_by_me but we could do own=true or owner=true if they seemed clear enough to you.

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 didn't get to finish my review, but I left some comments...

bizybot and others added 5 commits August 2, 2019 07:49
…security/action/GetApiKeyRequestTests.java

Co-Authored-By: Tim Vernum <[email protected]>
…security/action/GetApiKeyRequestTests.java

Co-Authored-By: Tim Vernum <[email protected]>
…security/action/GetApiKeyRequestTests.java

Co-Authored-By: Tim Vernum <[email protected]>
…security/action/GetApiKeyRequestTests.java

Co-Authored-By: Tim Vernum <[email protected]>
@bizybot
Copy link
Contributor Author

bizybot commented Aug 2, 2019

could not download artifacts
@elasticmachine run elasticsearch-ci/packaging-sample

@tvernum tvernum self-requested a review August 6, 2019 07:16
@bizybot bizybot requested a review from tvernum August 6, 2019 12:52
@bizybot
Copy link
Contributor Author

bizybot commented Aug 6, 2019

@elasticmachine run elasticsearch-ci/1

@codebrain
Copy link
Contributor

@bizybot - PR looks good, we had to patch the REST API specification to add the "owner" flag. I will open an issue for this.

@codebrain
Copy link
Contributor

#48499

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.

7 participants