-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Reporting] Use the deprecations service to advise reporting_user
config changes
#100427
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,8 +35,8 @@ export const config: PluginConfigDescriptor<ReportingConfigType> = { | |
addDeprecation({ | ||
message: | ||
`"${fromPath}.roles" is deprecated. Granting reporting privilege through a "reporting_user" role will not be supported ` + | ||
`starting in 8.0. Please set 'xpack.reporting.roles.enabled' to 'false' and grant reporting privilege to users ` + | ||
`through feature controls in Management > Security > Roles`, | ||
`starting in 8.0. Please set 'xpack.reporting.roles.enabled' to 'false' and grant reporting privileges to users ` + | ||
`using Kibana application privileges **Management > Security > Roles**.`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated this text to match the new text, which felt more refined. |
||
}); | ||
} | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,14 +25,14 @@ import { SecurityPluginSetup } from '../../security/server'; | |
import { DEFAULT_SPACE_ID } from '../../spaces/common/constants'; | ||
import { SpacesPluginSetup } from '../../spaces/server'; | ||
import { TaskManagerSetupContract, TaskManagerStartContract } from '../../task_manager/server'; | ||
import { ReportingConfig } from './'; | ||
import { ReportingConfig, ReportingSetup } from './'; | ||
import { HeadlessChromiumDriverFactory } from './browsers/chromium/driver_factory'; | ||
import { ReportingConfigType } from './config'; | ||
import { checkLicense, getExportTypesRegistry, LevelLogger } from './lib'; | ||
import { screenshotsObservableFactory, ScreenshotsObservableFn } from './lib/screenshots'; | ||
import { ReportingStore } from './lib/store'; | ||
import { ExecuteReportTask, MonitorReportsTask, ReportTaskParams } from './lib/tasks'; | ||
import { ReportingPluginRouter, ReportingStart } from './types'; | ||
import { ReportingPluginRouter } from './types'; | ||
|
||
export interface ReportingInternalSetup { | ||
basePath: Pick<BasePath, 'set'>; | ||
|
@@ -69,19 +69,17 @@ export class ReportingCore { | |
private config?: ReportingConfig; // final config, includes dynamic values based on OS type | ||
private executing: Set<string>; | ||
|
||
public getStartContract: () => ReportingStart; | ||
public getContract: () => ReportingSetup; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed because we can call this from setup as well - ReportingStart and ReportingSetup are the same interface. |
||
|
||
constructor(private logger: LevelLogger, context: PluginInitializerContext<ReportingConfigType>) { | ||
const syncConfig = context.config.get<ReportingConfigType>(); | ||
this.deprecatedAllowedRoles = syncConfig.roles.enabled ? syncConfig.roles.allow : false; | ||
this.executeTask = new ExecuteReportTask(this, syncConfig, this.logger); | ||
this.monitorTask = new MonitorReportsTask(this, syncConfig, this.logger); | ||
|
||
this.getStartContract = (): ReportingStart => { | ||
return { | ||
usesUiCapabilities: () => syncConfig.roles.enabled === false, | ||
}; | ||
}; | ||
this.getContract = () => ({ | ||
usesUiCapabilities: () => syncConfig.roles.enabled === false, | ||
}); | ||
|
||
this.executing = new Set(); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* 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 { ReportingCore } from '.'; | ||
import { registerDeprecations } from './deprecations'; | ||
import { createMockConfigSchema, createMockReportingCore } from './test_helpers'; | ||
import { coreMock, elasticsearchServiceMock } from 'src/core/server/mocks'; | ||
import { GetDeprecationsContext, IScopedClusterClient } from 'kibana/server'; | ||
|
||
let reportingCore: ReportingCore; | ||
let context: GetDeprecationsContext; | ||
let esClient: jest.Mocked<IScopedClusterClient>; | ||
|
||
beforeEach(async () => { | ||
const mockReportingConfig = createMockConfigSchema({ roles: { enabled: false } }); | ||
reportingCore = await createMockReportingCore(mockReportingConfig); | ||
esClient = elasticsearchServiceMock.createScopedClusterClient(); | ||
esClient.asCurrentUser.security.getUser = jest.fn().mockResolvedValue({ | ||
body: { xyz: { username: 'normal_user', roles: ['data_analyst'] } }, | ||
}); | ||
context = ({ esClient } as unknown) as GetDeprecationsContext; | ||
}); | ||
|
||
test('logs no deprecations when setup has no issues', async () => { | ||
const { getDeprecations } = await registerDeprecations(reportingCore, coreMock.createSetup()); | ||
expect(await getDeprecations(context)).toMatchInlineSnapshot(`Array []`); | ||
}); | ||
|
||
test('logs a plain message when only a reporting_user role issue is found', async () => { | ||
esClient.asCurrentUser.security.getUser = jest.fn().mockResolvedValue({ | ||
body: { reportron: { username: 'reportron', roles: ['kibana_admin', 'reporting_user'] } }, | ||
}); | ||
|
||
const { getDeprecations } = await registerDeprecations(reportingCore, coreMock.createSetup()); | ||
expect(await getDeprecations(context)).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"correctiveActions": Object { | ||
"manualSteps": Array [ | ||
"Create one or more custom roles that provide Kibana application privileges to reporting features in **Management > Security > Roles**.", | ||
"Assign the custom role(s) as desired, and remove the \\"reporting_user\\" role from the user(s).", | ||
], | ||
}, | ||
"documentationUrl": "https://www.elastic.co/guide/en/kibana/current/secure-reporting.html", | ||
"level": "critical", | ||
"message": "The deprecated \\"reporting_user\\" role has been found for 1 user(s): \\"reportron\\"", | ||
}, | ||
] | ||
`); | ||
}); | ||
|
||
test('logs multiple entries when multiple reporting_user role issues are found', async () => { | ||
esClient.asCurrentUser.security.getUser = jest.fn().mockResolvedValue({ | ||
body: { | ||
reportron: { username: 'reportron', roles: ['kibana_admin', 'reporting_user'] }, | ||
supercooluser: { username: 'supercooluser', roles: ['kibana_admin', 'reporting_user'] }, | ||
}, | ||
}); | ||
|
||
const { getDeprecations } = await registerDeprecations(reportingCore, coreMock.createSetup()); | ||
expect(await getDeprecations(context)).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"correctiveActions": Object { | ||
"manualSteps": Array [ | ||
"Create one or more custom roles that provide Kibana application privileges to reporting features in **Management > Security > Roles**.", | ||
"Assign the custom role(s) as desired, and remove the \\"reporting_user\\" role from the user(s).", | ||
], | ||
}, | ||
"documentationUrl": "https://www.elastic.co/guide/en/kibana/current/secure-reporting.html", | ||
"level": "critical", | ||
"message": "The deprecated \\"reporting_user\\" role has been found for 2 user(s): \\"reportron\\", \\"supercooluser\\"", | ||
}, | ||
] | ||
`); | ||
}); | ||
|
||
test('logs an expanded message when a config issue and a reporting_user role issue is found', async () => { | ||
esClient.asCurrentUser.security.getUser = jest.fn().mockResolvedValue({ | ||
body: { reportron: { username: 'reportron', roles: ['kibana_admin', 'reporting_user'] } }, | ||
}); | ||
|
||
const mockReportingConfig = createMockConfigSchema({ roles: { enabled: true } }); | ||
reportingCore = await createMockReportingCore(mockReportingConfig); | ||
|
||
const { getDeprecations } = await registerDeprecations(reportingCore, coreMock.createSetup()); | ||
expect(await getDeprecations(context)).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"correctiveActions": Object { | ||
"manualSteps": Array [ | ||
"Set \\"xpack.reporting.roles.enabled: false\\" in kibana.yml", | ||
"Create one or more custom roles that provide Kibana application privileges to reporting features in **Management > Security > Roles**.", | ||
"Assign the custom role(s) as desired, and remove the \\"reporting_user\\" role from the user(s).", | ||
], | ||
}, | ||
"documentationUrl": "https://www.elastic.co/guide/en/kibana/current/secure-reporting.html", | ||
"level": "critical", | ||
"message": "The deprecated \\"reporting_user\\" role has been found for 1 user(s): \\"reportron\\"", | ||
}, | ||
] | ||
`); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW I am going to be adding a deprecation action soon for migrating existing reporting indices to the new ILM policy - as part of that I'll probably create a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good to me, as long as we have correct spelling for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed 😄 |
||
* 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 { CoreSetup, DeprecationsDetails, RegisterDeprecationsConfig } from 'src/core/server'; | ||
import { ReportingCore } from '.'; | ||
|
||
const deprecatedRole = 'reporting_user'; | ||
const upgradableConfig = 'xpack.reporting.roles.enabled: false'; | ||
|
||
export async function registerDeprecations( | ||
reporting: ReportingCore, | ||
{ deprecations: deprecationsService }: CoreSetup | ||
) { | ||
const deprecationsConfig: RegisterDeprecationsConfig = { | ||
getDeprecations: async ({ esClient }) => { | ||
const usingDeprecatedConfig = !reporting.getContract().usesUiCapabilities(); | ||
const deprecations: DeprecationsDetails[] = []; | ||
const { body: users } = await esClient.asCurrentUser.security.getUser(); | ||
|
||
const reportingUsers = Object.entries(users) | ||
.filter(([username, user]) => user.roles.includes(deprecatedRole)) | ||
.map(([, user]) => user.username); | ||
const numReportingUsers = reportingUsers.length; | ||
|
||
if (numReportingUsers > 0) { | ||
const usernames = reportingUsers.join('", "'); | ||
deprecations.push({ | ||
message: `The deprecated "${deprecatedRole}" role has been found for ${numReportingUsers} user(s): "${usernames}"`, | ||
documentationUrl: 'https://www.elastic.co/guide/en/kibana/current/secure-reporting.html', | ||
level: 'critical', | ||
correctiveActions: { | ||
manualSteps: [ | ||
...(usingDeprecatedConfig ? [`Set "${upgradableConfig}" in kibana.yml`] : []), | ||
`Create one or more custom roles that provide Kibana application privileges to reporting features in **Management > Security > Roles**.`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the current position on translations in deprecation manual steps or was the accidentally left out? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While working on this, I referenced this Draft PR to add an FAQ: https://github.com/elastic/kibana/pull/99043/files#r636460961 I asked a similar question, and found that it's currently not recommended to use i18n for deprecations: #99072 |
||
`Assign the custom role(s) as desired, and remove the "${deprecatedRole}" role from the user(s).`, | ||
], | ||
}, | ||
}); | ||
} | ||
|
||
return deprecations; | ||
}, | ||
}; | ||
|
||
deprecationsService.registerDeprecations(deprecationsConfig); | ||
|
||
return deprecationsConfig; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import { PLUGIN_ID } from '../common/constants'; | |
import { ReportingCore } from './'; | ||
import { initializeBrowserDriverFactory } from './browsers'; | ||
import { buildConfig, registerUiSettings, ReportingConfigType } from './config'; | ||
import { registerDeprecations } from './deprecations'; | ||
import { LevelLogger, ReportingStore } from './lib'; | ||
import { registerRoutes } from './routes'; | ||
import { setFieldFormats } from './services'; | ||
|
@@ -38,15 +39,13 @@ export class ReportingPlugin | |
// @ts-expect-error null is not assignable to object. use a boolean property to ensure reporting API is enabled. | ||
core.http.registerRouteHandlerContext(PLUGIN_ID, () => { | ||
if (reportingCore.pluginIsStarted()) { | ||
return reportingCore.getStartContract(); | ||
return reportingCore.getContract(); | ||
} else { | ||
this.logger.error(`Reporting features are not yet ready`); | ||
return null; | ||
} | ||
}); | ||
|
||
registerUiSettings(core); | ||
|
||
const { http } = core; | ||
const { screenshotMode, features, licensing, security, spaces, taskManager } = plugins; | ||
|
||
|
@@ -65,6 +64,8 @@ export class ReportingPlugin | |
logger: this.logger, | ||
}); | ||
|
||
registerUiSettings(core); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. put all the |
||
registerDeprecations(reportingCore, core); | ||
registerReportingUsageCollector(reportingCore, plugins); | ||
registerRoutes(reportingCore, this.logger); | ||
|
||
|
@@ -81,7 +82,7 @@ export class ReportingPlugin | |
}); | ||
|
||
this.reportingCore = reportingCore; | ||
return reportingCore.getStartContract(); | ||
return reportingCore.getContract(); | ||
} | ||
|
||
public start(core: CoreStart, plugins: ReportingStartDeps) { | ||
|
@@ -113,6 +114,6 @@ export class ReportingPlugin | |
this.logger.error(e); | ||
}); | ||
|
||
return reportingCore.getStartContract(); | ||
return reportingCore.getContract(); | ||
} | ||
} |
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.
I think we don't have the authority to remove support for the
reporting_user
role in 8.0. The ability to switch off the support is still very new in Kibana and we've seen plenty of cases where configuring things properly stumps users. This text should be changed to say that the support will be removed "in a future version"Edit: filed #113014