Skip to content

Commit c55f2ca

Browse files
committed
Fix privileges check when security is not enabled (#67308)
1 parent 49f7bc0 commit c55f2ca

5 files changed

Lines changed: 26 additions & 21 deletions

File tree

x-pack/plugins/ingest_pipelines/kibana.json

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,7 @@
33
"version": "kibana",
44
"server": true,
55
"ui": true,
6-
"requiredPlugins": [
7-
"licensing",
8-
"management"
9-
],
10-
"optionalPlugins": [
11-
"usageCollection"
12-
],
13-
"configPath": [
14-
"xpack",
15-
"ingest_pipelines"
16-
]
6+
"requiredPlugins": ["licensing", "management"],
7+
"optionalPlugins": ["security", "usageCollection"],
8+
"configPath": ["xpack", "ingest_pipelines"]
179
}

x-pack/plugins/ingest_pipelines/server/plugin.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class IngestPipelinesPlugin implements Plugin<void, void, any, any> {
2525
this.apiRoutes = new ApiRoutes();
2626
}
2727

28-
public setup({ http, elasticsearch }: CoreSetup, { licensing }: Dependencies) {
28+
public setup({ http }: CoreSetup, { licensing, security }: Dependencies) {
2929
this.logger.debug('ingest_pipelines: setup');
3030

3131
const router = http.createRouter();
@@ -47,6 +47,9 @@ export class IngestPipelinesPlugin implements Plugin<void, void, any, any> {
4747
this.apiRoutes.setup({
4848
router,
4949
license: this.license,
50+
config: {
51+
isSecurityEnabled: security !== undefined && security.license.isEnabled(),
52+
},
5053
lib: {
5154
isEsError,
5255
},

x-pack/plugins/ingest_pipelines/server/routes/api/privileges.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,31 @@ const extractMissingPrivileges = (privilegesObject: { [key: string]: boolean } =
1515
return privileges;
1616
}, []);
1717

18-
export const registerPrivilegesRoute = ({ license, router }: RouteDependencies) => {
18+
export const registerPrivilegesRoute = ({ license, router, config }: RouteDependencies) => {
1919
router.get(
2020
{
2121
path: `${API_BASE_PATH}/privileges`,
2222
validate: false,
2323
},
2424
license.guardApiRoute(async (ctx, req, res) => {
25-
const {
26-
core: {
27-
elasticsearch: { dataClient },
28-
},
29-
} = ctx;
30-
3125
const privilegesResult: Privileges = {
3226
hasAllPrivileges: true,
3327
missingPrivileges: {
3428
cluster: [],
3529
},
3630
};
3731

32+
// Skip the privileges check if security is not enabled
33+
if (!config.isSecurityEnabled) {
34+
return res.ok({ body: privilegesResult });
35+
}
36+
37+
const {
38+
core: {
39+
elasticsearch: { dataClient },
40+
},
41+
} = ctx;
42+
3843
try {
3944
const { has_all_requested: hasAllPrivileges, cluster } = await dataClient.callAsCurrentUser(
4045
'transport.request',
@@ -55,7 +60,7 @@ export const registerPrivilegesRoute = ({ license, router }: RouteDependencies)
5560

5661
return res.ok({ body: privilegesResult });
5762
} catch (e) {
58-
return res.internalError(e);
63+
return res.internalError({ body: e });
5964
}
6065
})
6166
);

x-pack/plugins/ingest_pipelines/server/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,21 @@
66

77
import { IRouter } from 'src/core/server';
88
import { LicensingPluginSetup } from '../../licensing/server';
9+
import { SecurityPluginSetup } from '../../security/server';
910
import { License } from './services';
1011
import { isEsError } from './lib';
1112

1213
export interface Dependencies {
14+
security: SecurityPluginSetup;
1315
licensing: LicensingPluginSetup;
1416
}
1517

1618
export interface RouteDependencies {
1719
router: IRouter;
1820
license: License;
21+
config: {
22+
isSecurityEnabled: boolean;
23+
};
1924
lib: {
2025
isEsError: typeof isEsError;
2126
};

x-pack/plugins/snapshot_restore/server/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export class SnapshotRestoreServerPlugin implements Plugin<void, void, any, any>
9292
router,
9393
license: this.license,
9494
config: {
95-
isSecurityEnabled: security !== undefined,
95+
isSecurityEnabled: security !== undefined && security.license.isEnabled(),
9696
isCloudEnabled: cloud !== undefined && cloud.isCloudEnabled,
9797
isSlmEnabled: pluginConfig.slm_ui.enabled,
9898
},

0 commit comments

Comments
 (0)