Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions packages/kbn-mock-idp-plugin/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,11 @@ export const plugin: PluginInitializer<void, void, PluginSetupDependencies> = as
const [{ elasticsearch }] = await core.getStartServices();

// Get scoped client with UIAM headers
const scopedClient = elasticsearch.client.asScoped({
headers: { authorization: `ApiKey ${request.body.apiKey}` },
});
// TODO REVIEW
const scopedClient = elasticsearch.client.asScoped(
{ headers: { authorization: `ApiKey ${request.body.apiKey}` } },
{ projectRouting: 'origin-only' }
);

if (!scopedClient) {
return response.badRequest({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ export class AnonymousAccessService {
*/
private async canAuthenticateAnonymousServiceAccount(clusterClient: IClusterClient) {
try {
// TODO REVIEW
await clusterClient
.asScoped(this.createFakeAnonymousRequest({ authenticateRequest: true }))
.asScoped(this.createFakeAnonymousRequest({ authenticateRequest: true }), { projectRouting: 'origin-only' })
.asCurrentUser.security.authenticate();
} catch (err) {
this.logger.warn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ export class APIKeys implements NativeAPIKeysType {
return null;
}
const { type, expiration, name, metadata } = createParams;
const scopedClusterClient = this.clusterClient.asScoped(request);
// TODO REVIEW
const scopedClusterClient = this.clusterClient.asScoped(request, { projectRouting: 'space' });

this.logger.debug('Trying to create an API key');

Expand Down Expand Up @@ -215,7 +216,8 @@ export class APIKeys implements NativeAPIKeysType {
}

const { type, id, metadata } = updateParams;
const scopedClusterClient = this.clusterClient.asScoped(request);
// TODO REVIEW
const scopedClusterClient = this.clusterClient.asScoped(request, { projectRouting: 'space' });

this.logger.debug('Trying to edit an API key');

Expand Down Expand Up @@ -338,7 +340,8 @@ export class APIKeys implements NativeAPIKeysType {
let result: InvalidateAPIKeyResult;
try {
// User needs `manage_api_key` privilege to use this API
result = await this.clusterClient.asScoped(request).asCurrentUser.security.invalidateApiKey({
// TODO REVIEW
result = await this.clusterClient.asScoped(request, { projectRouting: 'space' }).asCurrentUser.security.invalidateApiKey({
ids: params.ids,
});
this.logger.debug(
Expand Down Expand Up @@ -398,7 +401,8 @@ export class APIKeys implements NativeAPIKeysType {

this.logger.debug(`Trying to validate an API key`);
try {
await this.clusterClient.asScoped(fakeRequest).asCurrentUser.security.authenticate();
// TODO REVIEW
await this.clusterClient.asScoped(fakeRequest, { projectRouting: 'origin-only' }).asCurrentUser.security.authenticate();
this.logger.debug(`API key was validated successfully`);
return true;
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ export function checkPrivilegesFactory(
{ requireLoginAction }
);

const clusterClient = (await getClusterClient()).asScoped(request);
// TODO REVIEW
const clusterClient = (await getClusterClient()).asScoped(request, { projectRouting: 'space' });
const hasPrivilegesResponse = await clusterClient.asCurrentUser.security.hasPrivileges({
cluster: privileges.elasticsearch?.cluster as estypes.SecurityClusterPrivilege[],
index: Object.entries(privileges.elasticsearch?.index ?? {}).map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ export class UserProfileService {
request: UserProfileGetCurrentParams['request']
): Promise<string | undefined> {
try {
const response = await clusterClient.asScoped(request).asCurrentUser.security.getApiKey({
// TODO REVIEW
const response = await clusterClient.asScoped(request, { projectRouting: 'space' }).asCurrentUser.security.getApiKey({
with_profile_uid: true,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,15 @@ export function initRoutes(

let scopedClient;
if (request.body.client === 'start-contract') {
scopedClient = (await core.getStartServices())[0].elasticsearch.client.asScoped(request);
// TODO REVIEW
scopedClient = (await core.getStartServices())[0].elasticsearch.client.asScoped(request, { projectRouting: 'space' });
} else if (request.body.client === 'request-context') {
scopedClient = (await context.core).elasticsearch.client;
} else {
scopedClient = (await core.getStartServices())[0].elasticsearch
.createClient('custom')
.asScoped(request);
// TODO REVIEW
.asScoped(request, { projectRouting: 'space' });
}

await scopedClient.asCurrentUser.security.authenticate();
Expand Down