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

Ignore intermediate unauthenticated session during repeated authentication attempt. #79300

Merged

Conversation

azasypkin
Copy link
Member

@azasypkin azasypkin commented Oct 2, 2020

Basically what title says + a bunch of test-only changes, see more details and reasoning in #75338.

The current behavior is quite annoying when you have multiple providers, start SSO, but then change your mind (or realize that you don't have proper credentials for IdP) and want to login with a different provider.

Fixes: #75338


Release note: previously when user started SAML or OpenID authentication handshake, but didn't or couldn't finish it they weren't able to access Login Selector easily (e.g. to log in with another authentication provider) unless they used /login URL directly or manually cleared the session cookies. That was a very confusing user experience. The reason was that unauthenticated intermediate session that was created to support handshake forced Kibana to automatically restart the same handshake whenever user accessed Kibana. We fixed that and now in certain cases we ignore unauthenticated intermediate session allowing user to easily access Login Selector whenever they need it.

@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 v8.0.0 v7.10.0 labels Oct 2, 2020
@@ -31,16 +31,16 @@ const onlyNotInCoverageTests = [
require.resolve('../test/plugin_api_integration/config.ts'),
require.resolve('../test/kerberos_api_integration/config.ts'),
require.resolve('../test/kerberos_api_integration/anonymous_access.config.ts'),
require.resolve('../test/saml_api_integration/config.ts'),
require.resolve('../test/security_api_integration/saml.config.ts'),
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: slowly moving security related integration tests to a single folder.

await supertest
.get('/login')
.ca(CA_CERT)
.set('Cookie', intermediateAuthCookie.cookieString())
.expect(200);

// When user tries to access any other page in Kibana.
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: that is the main test in this PR, I made sure it fails without my change.

@azasypkin azasypkin force-pushed the issue-75338-ignore-intermediate-cookie branch from 5790f55 to 899f8e1 Compare October 2, 2020 16:53
@@ -30,7 +30,9 @@ export default function ({ getService }: FtrProviderContext) {
}

async function getNumberOfSessionDocuments() {
return (await es.search({ index: '.kibana_security_session*' })).hits.total.value;
return (((await es.search({ index: '.kibana_security_session*' })).hits.total as unknown) as {
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: typechecker suddenly started to complain about these return types (types are invalid indeed).

@azasypkin
Copy link
Member Author

@kibanamachine merge upstream

@azasypkin azasypkin marked this pull request as ready for review October 2, 2020 19:07
@azasypkin azasypkin requested a review from a team as a code owner October 2, 2020 19:07
@elasticmachine
Copy link
Contributor

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

@legrego
Copy link
Member

legrego commented Oct 2, 2020

note: the referenced issue is marked as enhancement, but the pr is marked as release_note:fix. If we treat this as a fix, then there's a chance we can also backport to 7.9.3 if we want to.

@azasypkin
Copy link
Member Author

note: the referenced issue is marked as enhancement, but the pr is marked as release_note:fix. If we treat this as a fix, then there's a chance we can also backport to 7.9.3 if we want to.

Thanks for calling this out! I've relabeled issue to bug, it reflects what it's in fact more precisely.

@azasypkin
Copy link
Member Author

Hey Team/@elastic/kibana-security,

PR is ready for review whenever you have time. Essentially it's just a one-liner, the rest are just test changes. I'm also planning to backport this fix to 7.9.3+.

Thanks!

@@ -637,7 +637,7 @@ export class Authenticator {
// 4. Request isn't attributed with HTTP Authorization header
return (
canRedirectRequest(request) &&
!sessionValue &&
(!sessionValue || !sessionValue.username) &&
Copy link
Member

Choose a reason for hiding this comment

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

nit: what do you think about introducing a isSessionAuthenticated function (or similar) for this? I know it's a very basic check, but since this will be the second place for such a check (

const isExistingSessionAuthenticated = !!existingSessionValue?.username;
), it might make sense to consolidate the logic, if nothing else for readability.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I think it makes sense, will do, thanks!

Copy link
Member Author

Choose a reason for hiding this comment

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

While fixing this I realized that I cannot backport it to 7.9.x since we started to store username in the session for all providers only in 7.10 (with server-side sessions) that means we don't have an easy way to distinguish authenticated session from unauthenticated in 7.9 😢

@azasypkin azasypkin removed the v7.9.3 label Oct 5, 2020
@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 dca9e70 into elastic:master Oct 5, 2020
@azasypkin azasypkin deleted the issue-75338-ignore-intermediate-cookie branch October 5, 2020 18:07
@azasypkin
Copy link
Member Author

7.x/7.10.0: 9beebb0

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.10.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ignore intermediate unauthenticated session during repeated authentication attempt
4 participants