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

Can API operations that create access tokens include respective full user info in the response? #59685

Closed
azasypkin opened this issue Jul 16, 2020 · 5 comments · Fixed by #62490
Assignees
Labels
>enhancement :Security/Authentication Logging in, Usernames/passwords, Realms (Native/LDAP/AD/SAML/PKI/etc) Team:Security Meta label for security team

Comments

@azasypkin
Copy link
Member

Context: elastic/kibana#68117 (comment)

Currently every Elasticsearch API call that creates an access token made by Kibana is followed by the request to retrieve full user information (GET /_security/_authenticate):

  • /_security/oauth2/token (Kerberos and Token)
  • /_security/delegate_pki (PKI)
  • /_security/saml/authenticate (SAML)
  • /_security/oidc/authenticate (OIDC)

Even though it's not technically required in some cases today we do this for the consistency sake. But soon we're going to implement features that would require this additional round-trip in all cases, e.g. to limit number of currently active sessions based on various criteria (username+realm or specific role name).

Currently /_security/saml/authenticate and /_security/oidc/authenticate return username, but based on the example above in the near future we may need to know user roles and whatnot.

The question we have is, would it make sense to attach full user info right to the response of the operations that produce access tokens (or at least for some of them)?

@elastic/kibana-security

@azasypkin azasypkin added >enhancement :Security/Authentication Logging in, Usernames/passwords, Realms (Native/LDAP/AD/SAML/PKI/etc) team-discuss Team:Security Meta label for security team labels Jul 16, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-security (:Security/Authentication)

@ywangd
Copy link
Member

ywangd commented Aug 4, 2020

It should be relatively straightforward to add response of GET /_security/_authenticate as a field to the responses of "get token" related APIs. The response will be something like the follows:

{
  "access_token": "46ToAxZFNTJubnEwZVRwNmJIc1hUdEFVbGdB",
  "type": "Bearer",
  "expires_in": 1200,
  "refresh_token": "46ToAxZETzA3RElpa1REaXdXYjNqaGNpTkln",
  "authentication": {
    "username": "foo",
    "roles": [
      "user"
    ],
    "full_name": null,
    "email": null,
    "metadata": {},
    "enabled": true,
    "authentication_realm": {
      "name": "native1",
      "type": "native"
    },
    "lookup_realm": {
      "name": "native1",
      "type": "native"
    }
  }
}

NOTE: The authentication object is of the user that the token is created for, not the facilitating user, e.g. kibana.

For SAML and OIDC authenticate calls, there will be some redundancy for username and realm since they will be repeated again in the new authentication field. But I don't think we should remove the fields from either the top level object or the authentication field because:

  • It will be a breaking change if they are removed from the top level object.
  • It should not be removed from the authentication field since some of the top level objects do not have username and realm. I don't think it is worth to conditionally include and exclude these fields from authentication depending on the top level object. It's more trouble than its worth. Also an authentication field without username is weird at least.
  • The redundancy is pretty minimal.

Here are a list of things we need to touch to implement above suggested changes:

  • /_security/oauth2/token - Most changes should be in CreateTokenResponse and its caller, i.e. TransportCreateTokenAction and TransportRefreshTokenAction
  • /_security/delegate_pki - DelegatePkiAuthenticationResponse and TransportDelegatePkiAuthenticationAction
  • /_security/saml/authenticate - SamlAuthenticateResponse and TransportSamlAuthenticateAction
  • /_security/oidc/authenticate - OpenIdConnectAuthenticateResponse and TransportOpenIdConnectAuthenticateAction

@azasypkin
Copy link
Member Author

That would work great for us, thanks for picking this up @ywangd !

@ywangd ywangd removed their assignment Aug 14, 2020
@BigPandaToo BigPandaToo self-assigned this Aug 26, 2020
@tvernum tvernum reopened this Sep 16, 2020
BigPandaToo added a commit to BigPandaToo/elasticsearch that referenced this issue Oct 14, 2020
Adding authentication object to following APIs:
/_security/oauth2/token
/_security/delegate_pki
/_security/saml/authenticate
/_security/oidc/authenticate

Resolves: elastic#59685
(cherry picked from commit 51dbd9e)
BigPandaToo added a commit that referenced this issue Oct 16, 2020
* Adding authentication information to access token create APIs

Adding authentication object to following APIs:
/_security/oauth2/token
/_security/delegate_pki
/_security/saml/authenticate
/_security/oidc/authenticate

Resolves: #59685
(cherry picked from commit 51dbd9e)

* Addressing PR commends, fixing tests

* Returning tokenGroups attribute as SID string instead of byte array (AD metadata)

Addressing PR comments

* Returning tokenGroups attribute as SID string instead of byte array (AD metadata)

Update version check

* Returning tokenGroups attribute as SID string instead of byte array (AD metadata)

Update version check

* Addressing more PR comments

* Adding more to integration tests + some small fixes
BigPandaToo added a commit to BigPandaToo/elasticsearch that referenced this issue Oct 16, 2020
…c#62490)

* Adding authentication information to access token create APIs

Adding authentication object to following APIs:
/_security/oauth2/token
/_security/delegate_pki
/_security/saml/authenticate
/_security/oidc/authenticate

Resolves: elastic#59685
(cherry picked from commit 51dbd9e)

* Addressing PR commends, fixing tests

* Returning tokenGroups attribute as SID string instead of byte array (AD metadata)

Addressing PR comments

* Returning tokenGroups attribute as SID string instead of byte array (AD metadata)

Update version check

* Returning tokenGroups attribute as SID string instead of byte array (AD metadata)

Update version check

* Addressing more PR comments

* Adding more to integration tests + some small fixes
BigPandaToo added a commit that referenced this issue Oct 16, 2020
#63841)

* Adding authentication information to access token create APIs (#62490)

* Adding authentication information to access token create APIs

Adding authentication object to following APIs:
/_security/oauth2/token
/_security/delegate_pki
/_security/saml/authenticate
/_security/oidc/authenticate

Resolves: #59685
(cherry picked from commit 51dbd9e)

* Addressing PR commends, fixing tests

* Returning tokenGroups attribute as SID string instead of byte array (AD metadata)

Addressing PR comments

* Returning tokenGroups attribute as SID string instead of byte array (AD metadata)

Update version check

* Returning tokenGroups attribute as SID string instead of byte array (AD metadata)

Update version check

* Addressing more PR comments

* Adding more to integration tests + some small fixes

* Nit fixes and formatting following #62490 comments (#63797)

* Nit fixes and formatting following #62490 comments

Resolves: #63792

* Nit fixes and formatting following #62490 comments

Resolves: #63792

* Nit fixes and formatting following #62490 comments
Fixing username

* Nit fixes and formatting following #62490 comments
Fixing formatting

* Fixing merge conflicts

* Fixing merge conflicts
@azasypkin
Copy link
Member Author

Thanks for improving this @BigPandaToo ! Filed a Kibana issue to leverage this on our side: elastic/kibana#80952.

@ywangd
Copy link
Member

ywangd commented Oct 21, 2020

I just noticed a minor issue in the new authentication field. The authentication.authentication_type should always be token. But instead it is the type of the original authentication that the token is created for. For example, in the documentation page, the authentication_type is realm, but should be token.

@BigPandaToo The fix will likely be similar to what is needed for the test failure issue. So these two can go in with one PR. I can work on it if you are busy with other things. Just let me know. Thanks!

Scratch that. After team discussion. We agree the current behaviour is more correct.

BigPandaToo added a commit to BigPandaToo/elasticsearch that referenced this issue Oct 22, 2020
BigPandaToo added a commit that referenced this issue Oct 26, 2020
…en refresh (#64031)

* Fixing a problem with potential dirty read of a token document.
Related to #59685

* Fixing a problem with potential dirty read of a token document.
Adding CreateTokenResult to hold authentication object

* Fixing a problem with potential dirty read of a token document.
Adding CreateTokenResult to hold authentication object

Co-authored-by: Elastic Machine <[email protected]>
BigPandaToo added a commit to BigPandaToo/elasticsearch that referenced this issue Oct 26, 2020
…en refresh (elastic#64031)

* Fixing a problem with potential dirty read of a token document.
Related to elastic#59685

* Fixing a problem with potential dirty read of a token document.
Adding CreateTokenResult to hold authentication object

* Fixing a problem with potential dirty read of a token document.
Adding CreateTokenResult to hold authentication object

Co-authored-by: Elastic Machine <[email protected]>
BigPandaToo added a commit that referenced this issue Oct 26, 2020
…en refresh (#64031) (#64178)

* Fixing a problem with potential dirty read of a token document on token refresh (#64031)

* Fixing a problem with potential dirty read of a token document.
Related to #59685

* Fixing a problem with potential dirty read of a token document.
Adding CreateTokenResult to hold authentication object

* Fixing a problem with potential dirty read of a token document.
Adding CreateTokenResult to hold authentication object

Co-authored-by: Elastic Machine <[email protected]>

* Fixing tests failures

Co-authored-by: Elastic Machine <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement :Security/Authentication Logging in, Usernames/passwords, Realms (Native/LDAP/AD/SAML/PKI/etc) Team:Security Meta label for security team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants