Skip to content

Commit

Permalink
setup system_indices_superuser on remote cluster too, if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger committed Mar 4, 2022
1 parent 34c4c0a commit 8a28dfd
Showing 1 changed file with 29 additions and 15 deletions.
44 changes: 29 additions & 15 deletions test/common/services/security/system_indices_user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,18 @@
* Side Public License, v 1.
*/

import { systemIndicesSuperuser, createEsClientForFtrConfig } from '@kbn/test';
import { Client } from '@elastic/elasticsearch';
import { ToolingLog } from '@kbn/dev-utils';
import {
systemIndicesSuperuser,
createEsClientForFtrConfig,
createRemoteEsClientForFtrConfig,
} from '@kbn/test';
import { FtrProviderContext } from '../../ftr_provider_context';

const SYSTEM_INDICES_SUPERUSER_ROLE = 'system_indices_superuser';

export async function createSystemIndicesUser(ctx: FtrProviderContext) {
const log = ctx.getService('log');
const config = ctx.getService('config');

const enabled = !config
.get('esTestCluster.serverArgs')
.some((arg: string) => arg === 'xpack.security.enabled=false');

if (!enabled) {
return;
}

const es = createEsClientForFtrConfig(config);

async function ensureSystemIndicesUser(es: Client, log: ToolingLog) {
// There are cases where the test config file doesn't have security disabled
// but tests are still executed on ES without security. Checking this case
// by trying to fetch the users list.
Expand Down Expand Up @@ -67,3 +60,24 @@ export async function createSystemIndicesUser(ctx: FtrProviderContext) {

await es.close();
}

export async function createSystemIndicesUser(ctx: FtrProviderContext) {
const log = ctx.getService('log');
const config = ctx.getService('config');

const enabled = !config
.get('esTestCluster.serverArgs')
.some((arg: string) => arg === 'xpack.security.enabled=false');

if (!enabled) {
return;
}

const localEs = createEsClientForFtrConfig(config);
await ensureSystemIndicesUser(localEs, log);

if (config.get('esTestCluster.ccs')) {
const remoteEs = createRemoteEsClientForFtrConfig(config);
await ensureSystemIndicesUser(remoteEs, log);
}
}

0 comments on commit 8a28dfd

Please sign in to comment.