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

Prevent Kerberos and PKI providers from initiating a new session for unauthenticated XHR/API requests. #82817

Merged

Conversation

azasypkin
Copy link
Member

@azasypkin azasypkin commented Nov 6, 2020

See the detailed description of the problem in #78260. But in short the idea is following:

  • PKI and Kerberos should always try to initiate a new session for a non-API requests that require authentication.
  • PKI and Kerberos should NOT try to initiate a new session for an API requests unless there is a session associated with them.

When we re-initiate session because of expired access/refresh token it doesn't matter if it's an API request or not since the user-facing session is still valid and the fact that we're internally using tokens is just an implementation detail. Same for requests that don't require authentication, if we have a valid Kibana session and we can re-acquire tokens without user involvement then we should do it.

Fixes: #78260


Release note: previously API request could create a new PKI or Kerberos session without user even realizing it. With this fix we use a bit more sophisticated heuristic to know when a new session is really desired.

@azasypkin azasypkin added release_note:fix Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! Feature:Security/Authentication Platform Security - Authentication v7.11.0 labels Nov 6, 2020
@@ -253,9 +253,6 @@
/x-pack/test/ui_capabilities/ @elastic/kibana-security
/x-pack/test/encrypted_saved_objects_api_integration/ @elastic/kibana-security
/x-pack/test/functional/apps/security/ @elastic/kibana-security
/x-pack/test/kerberos_api_integration/ @elastic/kibana-security
Copy link
Member Author

Choose a reason for hiding this comment

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

note: just continue moving the remaining tests whenever I have chance.

@azasypkin azasypkin force-pushed the issue-78260-new-session-pki-kerberos branch 3 times, most recently from 9430012 to 1291abb Compare November 6, 2020 13:53
@@ -75,11 +77,8 @@ export class KerberosAuthenticationProvider extends BaseAuthenticationProvider {
return AuthenticationResult.notHandled();
}

let authenticationResult = authorizationHeader
Copy link
Member Author

@azasypkin azasypkin Nov 6, 2020

Choose a reason for hiding this comment

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

note: I'm not sure why we weren't checking the canStartNewSession here before, but I cannot find any reason why we shouldn't do it now. And we also should give a higher priority to the current session as well.

@@ -399,55 +408,102 @@ describe('PKIAuthenticationProvider', () => {
LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error())
)
// In response to a call with a new token.
.mockResolvedValueOnce(user) // In response to call with an expired token.
Copy link
Member Author

Choose a reason for hiding this comment

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

note: I'll remove this stupid setup in the scope of #80952 soon.

});
});

describe('finishing SPNEGO', () => {
it('should properly set cookie and authenticate user', async () => {
const response = await supertest
.get('/internal/security/me')
.get('/security/account')
Copy link
Member Author

Choose a reason for hiding this comment

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

note: recently we started to treat all /internal/.... as API requests (canRedirectRequest === false).

@azasypkin azasypkin marked this pull request as ready for review November 6, 2020 15:46
@azasypkin azasypkin requested a review from a team as a code owner November 6, 2020 15:46
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-security (Team:Security)

@azasypkin azasypkin force-pushed the issue-78260-new-session-pki-kerberos branch from 1291abb to 0b6369e Compare November 6, 2020 16:30
@azasypkin
Copy link
Member Author

Took the liberty of force-pushing to this branch to resolve conflicts with the most recent master as likely no one is reviewing this yet, but that was the last force-push in this PR 🙈

@legrego
Copy link
Member

legrego commented Nov 6, 2020

ACK: will review on Monday or Tuesday next week

@legrego legrego self-requested a review November 6, 2020 17:10
Copy link
Member

@legrego legrego left a comment

Choose a reason for hiding this comment

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

LGTM!

@@ -264,12 +267,12 @@ export class KerberosAuthenticationProvider extends BaseAuthenticationProvider {
return AuthenticationResult.failed(err);
}

// If refresh token is no longer valid, then we should clear session and renegotiate using SPNEGO.
// If refresh token is no longer valid, let's check if the request is allowed to start a new session, and if so try
Copy link
Member

Choose a reason for hiding this comment

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

Is this comment still valid? It seems like we don't have to check if the request is allowed to start a new session anymore, since authentication via refresh token is extending an existing session.

Copy link
Member Author

Choose a reason for hiding this comment

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

You're absolutely right! This looks like a leftover from one of my initial WIPs, will fix, thanks!

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@azasypkin azasypkin merged commit 45ddd69 into elastic:master Nov 9, 2020
@azasypkin azasypkin deleted the issue-78260-new-session-pki-kerberos branch November 9, 2020 16:34
azasypkin added a commit to azasypkin/kibana that referenced this pull request Nov 9, 2020
…unauthenticated XHR/API requests. (elastic#82817)

* Prevent Kerberos and PKI providers from initiating a new session for unauthenticated XHR requests.

* Review#1: fix comment.
# Conflicts:
#	.github/CODEOWNERS
#	x-pack/scripts/functional_tests.js
@azasypkin
Copy link
Member Author

7.x/7.11.0: 129f4df

gmmorris added a commit to gmmorris/kibana that referenced this pull request Nov 10, 2020
* master: (39 commits)
  Fix ilm navigation (elastic#81664)
  [Lens] Distinct icons for XY and pie chart value labels toolbar (elastic#82927)
  [data.search.aggs] Throw an error when trying to create an agg type that doesn't exist. (elastic#81509)
  Index patterns api - load field list on server (elastic#82629)
  New events resolver (elastic#82170)
  [App Search] Misc naming tech debt (elastic#82770)
  load empty_kibana in test to have clean starting point (elastic#82772)
  Remove data <--> expressions circular dependencies. (elastic#82685)
  Update 8.0 breaking change template to gather information on how to programmatically detect it. (elastic#82905)
  Add alerting as codeowners to related documentation folder (elastic#82777)
  Add captions to user and space grid pages (elastic#82713)
  add alternate path for x-pack/Cloud test for Lens (elastic#82634)
  Uses asCurrentUser in getClusterUuid (elastic#82908)
  [Alerting][Connectors] Add new executor subaction to get 3rd party case fields (elastic#82519)
  Fix test import objects (elastic#82767)
  [ML] Add option for anomaly charts for metric detector should plot min, mean or max as appropriate (elastic#81662)
  Update alert type selection layout to rows instead of grid (elastic#73665)
  Prevent Kerberos and PKI providers from initiating a new session for unauthenticated XHR/API requests. (elastic#82817)
  Update grunt and related packages (elastic#79327)
  Allow the repository to search across all namespaces (elastic#82863)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backported Feature:Security/Authentication Platform Security - Authentication release_note:fix Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! v7.11.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PKI and Kerberos providers shouldn't automatically log user in if Login Selector is enabled
4 participants