Skip to content
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 Solution] Cleanup graphiql #82595

Merged
Merged
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
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@
"apollo-server-core": "^1.3.6",
"apollo-server-errors": "^2.0.2",
"apollo-server-hapi": "^1.3.6",
"apollo-server-module-graphiql": "^1.3.4",
"archiver": "^3.1.1",
"axios": "^0.19.2",
"bluebird": "3.5.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ import { EndpointAppContext } from '../../endpoint/types';
export function compose(
core: CoreSetup,
plugins: SetupPlugins,
isProductionMode: boolean,
endpointContext: EndpointAppContext
): AppBackendLibs {
const framework = new KibanaBackendFrameworkAdapter(core, plugins, isProductionMode);
const framework = new KibanaBackendFrameworkAdapter(core, plugins);
const sources = new Sources(new ConfigurationSourcesAdapter());
const sourceStatus = new SourceStatus(new ElasticsearchSourceStatusAdapter(framework));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/

import * as GraphiQL from 'apollo-server-module-graphiql';
import { GraphQLSchema } from 'graphql';
import { runHttpQuery } from 'apollo-server-core';
import { schema as configSchema } from '@kbn/config-schema';
Expand All @@ -31,7 +30,7 @@ export class KibanaBackendFrameworkAdapter implements FrameworkAdapter {
private router: IRouter;
private security: SetupPlugins['security'];

constructor(core: CoreSetup, plugins: SetupPlugins, private isProductionMode: boolean) {
constructor(core: CoreSetup, plugins: SetupPlugins) {
this.router = core.http.createRouter();
this.security = plugins.security;
}
Expand Down Expand Up @@ -90,35 +89,6 @@ export class KibanaBackendFrameworkAdapter implements FrameworkAdapter {
}
}
);

if (!this.isProductionMode) {
this.router.get(
{
path: `${routePath}/graphiql`,
validate: false,
options: {
tags: ['access:securitySolution'],
},
},
async (context, request, response) => {
const graphiqlString = await GraphiQL.resolveGraphiQLString(
request.query,
{
endpointURL: routePath,
passHeader: "'kbn-xsrf': 'graphiql'",
},
request
);

return response.ok({
body: graphiqlString,
headers: {
'content-type': 'text/html',
},
});
}
);
}
}

private async getCurrentUserInfo(request: KibanaRequest): Promise<AuthenticatedUser | null> {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/security_solution/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ export class Plugin implements IPlugin<PluginSetup, PluginStart, SetupPlugins, S
});
}

const libs = compose(core, plugins, this.context.env.mode.prod, endpointContext);
const libs = compose(core, plugins, endpointContext);
initServer(libs);

core.getStartServices().then(([_, depsStart]) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ const introspectionQuery = gql`
`;

export default function ({ getService }: FtrProviderContext) {
const config = getService('config');
const supertest = getService('supertestWithoutAuth');
const security = getService('security');
const spaces = getService('spaces');
const clientFactory = getService('securitySolutionGraphQLClientFactory');
Expand All @@ -38,18 +36,6 @@ export default function ({ getService }: FtrProviderContext) {
expect(result.response.data).to.be.an('object');
};

const expectGraphIQL404 = (result: any) => {
expect(result.error).to.be(undefined);
expect(result.response).not.to.be(undefined);
expect(result.response).to.have.property('statusCode', 404);
};

const expectGraphIQLResponse = (result: any) => {
expect(result.error).to.be(undefined);
expect(result.response).not.to.be(undefined);
expect(result.response).to.have.property('statusCode', 200);
};

const executeGraphQLQuery = async (username: string, password: string, spaceId?: string) => {
const queryOptions = {
query: introspectionQuery,
Expand All @@ -71,23 +57,7 @@ export default function ({ getService }: FtrProviderContext) {
};
};

const executeGraphIQLRequest = async (username: string, password: string, spaceId?: string) => {
const basePath = spaceId ? `/s/${spaceId}` : '';

return supertest
.get(`${basePath}/api/security_solution/graphql/graphiql`)
.auth(username, password)
.then((response: any) => ({ error: undefined, response }))
.catch((error: any) => ({ error, response: undefined }));
};

describe('feature controls', () => {
let isProdOrCi = false;
before(() => {
const kbnConfig = config.get('servers.kibana');
isProdOrCi =
!!process.env.CI || !(kbnConfig.hostname === 'localhost' && kbnConfig.port === 5620);
});
it(`APIs can't be accessed by user with no privileges`, async () => {
const username = 'logstash_read';
const roleName = 'logstash_read';
Expand All @@ -103,9 +73,6 @@ export default function ({ getService }: FtrProviderContext) {

const graphQLResult = await executeGraphQLQuery(username, password);
expectGraphQL403(graphQLResult);

const graphQLIResult = await executeGraphIQLRequest(username, password);
expectGraphIQL404(graphQLIResult);
} finally {
await security.role.delete(roleName);
await security.user.delete(username);
Expand Down Expand Up @@ -134,13 +101,6 @@ export default function ({ getService }: FtrProviderContext) {

const graphQLResult = await executeGraphQLQuery(username, password);
expectGraphQLResponse(graphQLResult);

const graphQLIResult = await executeGraphIQLRequest(username, password);
if (!isProdOrCi) {
expectGraphIQLResponse(graphQLIResult);
} else {
expectGraphIQL404(graphQLIResult);
}
} finally {
await security.role.delete(roleName);
await security.user.delete(username);
Expand Down Expand Up @@ -172,9 +132,6 @@ export default function ({ getService }: FtrProviderContext) {

const graphQLResult = await executeGraphQLQuery(username, password);
expectGraphQL403(graphQLResult);

const graphQLIResult = await executeGraphIQLRequest(username, password);
expectGraphIQL404(graphQLIResult);
} finally {
await security.role.delete(roleName);
await security.user.delete(username);
Expand Down Expand Up @@ -233,21 +190,11 @@ export default function ({ getService }: FtrProviderContext) {
it('user_1 can access APIs in space_1', async () => {
const graphQLResult = await executeGraphQLQuery(username, password, space1Id);
expectGraphQLResponse(graphQLResult);

const graphQLIResult = await executeGraphIQLRequest(username, password, space1Id);
if (!isProdOrCi) {
expectGraphIQLResponse(graphQLIResult);
} else {
expectGraphIQL404(graphQLIResult);
}
});

it(`user_1 can't access APIs in space_2`, async () => {
const graphQLResult = await executeGraphQLQuery(username, password, space2Id);
expectGraphQL403(graphQLResult);

const graphQLIResult = await executeGraphIQLRequest(username, password, space2Id);
expectGraphIQL404(graphQLIResult);
});
});
});
Expand Down