-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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
[SECURITY] add telemetry on authentication type #119371
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f98c5da
add telemetry on auth type
XavierM 1de4fc9
Merge branch 'main' of github.com:elastic/kibana into telemetry-on-auth
XavierM 392af2f
make sure to keep track who is doing the telemetry
XavierM 9865819
forget to close channel
XavierM a59a2d6
simpler solution
XavierM fbd55ca
Merge branch 'main' of github.com:elastic/kibana into telemetry-on-auth
XavierM 409ff34
clean up
XavierM 5951c4b
Merge branch 'main' of github.com:elastic/kibana into telemetry-on-auth
XavierM f0de52f
add unit test
XavierM d513c46
review I
XavierM c90f3fc
missing type
XavierM ddd8361
fix jest
XavierM File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { Subscription } from 'rxjs'; | ||
|
||
import type { HttpStart } from 'src/core/public'; | ||
|
||
import type { AuthenticatedUser, SecurityLicense } from '../../common'; | ||
|
||
interface SecurityUsageCollectionSetupParams { | ||
securityLicense: SecurityLicense; | ||
} | ||
|
||
interface SecurityUsageCollectionStartParams { | ||
http: HttpStart; | ||
getCurrentUser: () => Promise<AuthenticatedUser>; | ||
} | ||
|
||
interface SecurityUsageCollectionAuthType { | ||
username_hash: string; | ||
timestamp: number; | ||
auth_type: string; | ||
} | ||
|
||
export class SecurityUsageCollectionService { | ||
public static KeyAuthType = 'kibana-user-auth-type'; | ||
private securityLicense!: SecurityLicense; | ||
private securityFeaturesSubscription?: Subscription; | ||
|
||
public setup({ securityLicense }: SecurityUsageCollectionSetupParams) { | ||
this.securityLicense = securityLicense; | ||
} | ||
|
||
public async start({ http, getCurrentUser }: SecurityUsageCollectionStartParams) { | ||
// wait for the user to be authenticated before doing UsageCollection | ||
this.securityFeaturesSubscription = this.securityLicense.features$.subscribe( | ||
({ allowRbac }) => { | ||
if (allowRbac) { | ||
getCurrentUser().then(() => this.recordAuthTypeUsageCollection(http)); | ||
} | ||
} | ||
); | ||
} | ||
|
||
public stop() { | ||
if (this.securityFeaturesSubscription) { | ||
this.securityFeaturesSubscription.unsubscribe(); | ||
this.securityFeaturesSubscription = undefined; | ||
} | ||
} | ||
|
||
private async recordAuthTypeUsageCollection(http: HttpStart) { | ||
try { | ||
const UsageCollectionAuthTypeStringify = localStorage.getItem( | ||
SecurityUsageCollectionService.KeyAuthType | ||
); | ||
const UsageCollectionAuthTypeObj = await http.post<SecurityUsageCollectionAuthType | null>( | ||
'/internal/security/usage_collection/record_auth_type', | ||
{ | ||
body: UsageCollectionAuthTypeStringify, | ||
} | ||
); | ||
if (UsageCollectionAuthTypeObj) { | ||
localStorage.setItem( | ||
SecurityUsageCollectionService.KeyAuthType, | ||
JSON.stringify(UsageCollectionAuthTypeObj) | ||
); | ||
} | ||
} catch (exp) { | ||
// do nothing | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do we do in the event of a promise rejection? I think it's fine to ignore it, but we probably want to explicitly ignore it with a
.catch
block.