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

[8.x] [RsponseOps][Alerting] Explicitly set access to all API routes of actions, connectors, rules, alerts, and cases plugins (#193520) #194111

Merged
merged 1 commit into from
Sep 26, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export const getAllConnectorsIncludingSystemRoute = (
{
path: `${INTERNAL_BASE_ACTION_API_PATH}/connectors`,
validate: {},
options: {
access: 'internal',
},
},
router.handleLegacyErrors(
verifyAccessAndContext(licenseState, async function (context, req, res) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export const listTypesWithSystemRoute = (
validate: {
query: connectorTypesQuerySchemaV1,
},
options: {
access: 'internal',
},
},
router.handleLegacyErrors(
verifyAccessAndContext(licenseState, async function (context, req, res) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ export const getGlobalExecutionKPIRoute = (
validate: {
body: bodySchema,
},
options: {
access: 'internal',
},
},
router.handleLegacyErrors(
verifyAccessAndContext(licenseState, async function (context, req, res) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ export const getGlobalExecutionLogRoute = (
validate: {
body: bodySchema,
},
options: {
access: 'internal',
},
},
router.handleLegacyErrors(
verifyAccessAndContext(licenseState, async function (context, req, res) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ export const getOAuthAccessToken = (
validate: {
body: bodySchema,
},
options: {
access: 'internal',
},
},
router.handleLegacyErrors(
verifyAccessAndContext(licenseState, async function (context, req, res) {
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/alerting/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ export class AlertingPlugin {
getAlertIndicesAlias: createGetAlertIndicesAliasFn(this.ruleTypeRegistry!),
encryptedSavedObjects: plugins.encryptedSavedObjects,
config$: plugins.unifiedSearch.autocomplete.getInitializerContextConfig().create(),
isServerless: !!plugins.serverless,
});

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export const deleteBackfillRoute = (
router.delete(
{
path: `${INTERNAL_BASE_ALERTING_API_PATH}/rules/backfill/{id}`,
options: {
access: 'internal',
},
validate: {
params: deleteParamsSchemaV1,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export const findBackfillRoute = (
validate: {
query: findQuerySchemaV1,
},
options: {
access: 'internal',
},
},
router.handleLegacyErrors(
verifyAccessAndContext(licenseState, async function (context, req, res) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export const getBackfillRoute = (
router.get(
{
path: `${INTERNAL_BASE_ALERTING_API_PATH}/rules/backfill/{id}`,
options: {
access: 'internal',
},
validate: {
params: getParamsSchemaV1,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const scheduleBackfillRoute = (
router.post(
{
path: `${INTERNAL_BASE_ALERTING_API_PATH}/rules/backfill/_schedule`,
options: { access: 'internal' },
validate: {
body: scheduleBodySchemaV1,
},
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/alerting/server/routes/get_action_error_log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ export const getActionErrorLogRoute = (
params: paramSchema,
query: querySchema,
},
options: {
access: 'internal',
},
},
router.handleLegacyErrors(
verifyAccessAndContext(licenseState, async function (context, req, res) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe('getFlappingSettingsRoute', () => {
expect(config).toMatchInlineSnapshot(`
Object {
"options": Object {
"access": "internal",
"tags": Array [
"access:read-flapping-settings",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const getFlappingSettingsRoute = (
path: `${INTERNAL_BASE_ALERTING_API_PATH}/rules/settings/_flapping`,
validate: false,
options: {
access: 'internal',
tags: [`access:${API_PRIVILEGES.READ_FLAPPING_SETTINGS}`],
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export const getGlobalExecutionKPIRoute = (
router.get(
{
path: `${INTERNAL_BASE_ALERTING_API_PATH}/_global_execution_kpi`,
options: {
access: 'internal',
},
validate: {
query: querySchema,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ export const getGlobalExecutionLogRoute = (
router.get(
{
path: `${INTERNAL_BASE_ALERTING_API_PATH}/_global_execution_logs`,
options: {
access: 'internal',
},
validate: {
query: querySchema,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ export const getRuleAlertSummaryRoute = (
router.get(
{
path: `${INTERNAL_BASE_ALERTING_API_PATH}/rule/{id}/_alert_summary`,
options: {
access: 'internal',
},
validate: {
params: paramSchema,
query: querySchema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export const getRuleExecutionKPIRoute = (
router.get(
{
path: `${INTERNAL_BASE_ALERTING_API_PATH}/rule/{id}/_execution_kpi`,
options: {
access: 'internal',
},
validate: {
params: paramSchema,
query: querySchema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ export const getRuleExecutionLogRoute = (
router.get(
{
path: `${INTERNAL_BASE_ALERTING_API_PATH}/rule/{id}/_execution_log`,
options: {
access: 'internal',
},
validate: {
params: paramSchema,
query: querySchema,
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/alerting/server/routes/get_rule_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export const getRuleStateRoute = (
router.get(
{
path: `${INTERNAL_BASE_ALERTING_API_PATH}/rule/{id}/state`,
options: {
access: 'internal',
},
validate: {
params: paramSchema,
},
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/alerting/server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export interface RouteOptions {
getAlertIndicesAlias?: GetAlertIndicesAlias;
usageCounter?: UsageCounter;
config$?: Observable<ConfigSchema>;
isServerless?: boolean;
}

export function defineRoutes(opts: RouteOptions) {
Expand Down
24 changes: 24 additions & 0 deletions x-pack/plugins/alerting/server/routes/legacy/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ describe('createAlertRoute', () => {

expect(config.path).toMatchInlineSnapshot(`"/api/alerts/alert/{id?}"`);

expect(config.options?.access).toBe('public');

rulesClient.create.mockResolvedValueOnce(createResult);

const [context, req, res] = mockHandlerArguments(
Expand Down Expand Up @@ -164,6 +166,28 @@ describe('createAlertRoute', () => {
});
});

it('should have internal access for serverless', async () => {
const licenseState = licenseStateMock.create();
const router = httpServiceMock.createRouter();
const encryptedSavedObjects = encryptedSavedObjectsMock.createSetup({ canEncrypt: true });
const mockUsageCountersSetup = usageCountersServiceMock.createSetupContract();
const mockUsageCounter = mockUsageCountersSetup.createUsageCounter('test');

createAlertRoute({
router,
licenseState,
encryptedSavedObjects,
usageCounter: mockUsageCounter,
isServerless: true,
});

const [config] = router.post.mock.calls[0];

expect(config.path).toMatchInlineSnapshot(`"/api/alerts/alert/{id?}"`);

expect(config.options?.access).toBe('internal');
});

it('allows providing a custom id when space is undefined', async () => {
const expectedResult = {
...createResult,
Expand Down
8 changes: 7 additions & 1 deletion x-pack/plugins/alerting/server/routes/legacy/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ export const bodySchema = schema.object({
notifyWhen: schema.nullable(schema.string({ validate: validateNotifyWhenType })),
});

export const createAlertRoute = ({ router, licenseState, usageCounter }: RouteOptions) => {
export const createAlertRoute = ({
router,
licenseState,
usageCounter,
isServerless,
}: RouteOptions) => {
router.post(
{
path: `${LEGACY_BASE_ALERT_API_PATH}/alert/{id?}`,
Expand All @@ -57,6 +62,7 @@ export const createAlertRoute = ({ router, licenseState, usageCounter }: RouteOp
body: bodySchema,
},
options: {
access: isServerless ? 'internal' : 'public',
summary: 'Create an alert',
tags: ['oas-tag:alerting'],
deprecated: true,
Expand Down
13 changes: 13 additions & 0 deletions x-pack/plugins/alerting/server/routes/legacy/delete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe('deleteAlertRoute', () => {
const [config, handler] = router.delete.mock.calls[0];

expect(config.path).toMatchInlineSnapshot(`"/api/alerts/alert/{id}"`);
expect(config.options?.access).toBe('public');

rulesClient.delete.mockResolvedValueOnce({});

Expand Down Expand Up @@ -65,6 +66,18 @@ describe('deleteAlertRoute', () => {
expect(res.noContent).toHaveBeenCalled();
});

it('should have internal access for serverless', async () => {
const licenseState = licenseStateMock.create();
const router = httpServiceMock.createRouter();

deleteAlertRoute(router, licenseState, undefined, true);

const [config] = router.delete.mock.calls[0];

expect(config.path).toMatchInlineSnapshot(`"/api/alerts/alert/{id}"`);
expect(config.options?.access).toBe('internal');
});

it('ensures the license allows deleting alerts', async () => {
const licenseState = licenseStateMock.create();
const router = httpServiceMock.createRouter();
Expand Down
4 changes: 3 additions & 1 deletion x-pack/plugins/alerting/server/routes/legacy/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const paramSchema = schema.object({
export const deleteAlertRoute = (
router: AlertingRouter,
licenseState: ILicenseState,
usageCounter?: UsageCounter
usageCounter?: UsageCounter,
isServerless?: boolean
) => {
router.delete(
{
Expand All @@ -29,6 +30,7 @@ export const deleteAlertRoute = (
params: paramSchema,
},
options: {
access: isServerless ? 'internal' : 'public',
summary: 'Delete an alert',
tags: ['oas-tag:alerting'],
deprecated: true,
Expand Down
13 changes: 13 additions & 0 deletions x-pack/plugins/alerting/server/routes/legacy/disable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe('disableAlertRoute', () => {
const [config, handler] = router.post.mock.calls[0];

expect(config.path).toMatchInlineSnapshot(`"/api/alerts/alert/{id}/_disable"`);
expect(config.options?.access).toBe('public');

rulesClient.disableRule.mockResolvedValueOnce();

Expand Down Expand Up @@ -64,6 +65,18 @@ describe('disableAlertRoute', () => {
expect(res.noContent).toHaveBeenCalled();
});

it('should have internal access for serverless', async () => {
const licenseState = licenseStateMock.create();
const router = httpServiceMock.createRouter();

disableAlertRoute(router, licenseState, undefined, true);

const [config] = router.post.mock.calls[0];

expect(config.path).toMatchInlineSnapshot(`"/api/alerts/alert/{id}/_disable"`);
expect(config.options?.access).toBe('internal');
});

it('ensures the alert type gets validated for the license', async () => {
const licenseState = licenseStateMock.create();
const router = httpServiceMock.createRouter();
Expand Down
4 changes: 3 additions & 1 deletion x-pack/plugins/alerting/server/routes/legacy/disable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const paramSchema = schema.object({
export const disableAlertRoute = (
router: AlertingRouter,
licenseState: ILicenseState,
usageCounter?: UsageCounter
usageCounter?: UsageCounter,
isServerless?: boolean
) => {
router.post(
{
Expand All @@ -30,6 +31,7 @@ export const disableAlertRoute = (
params: paramSchema,
},
options: {
access: isServerless ? 'internal' : 'public',
summary: 'Disable an alert',
tags: ['oas-tag:alerting'],
deprecated: true,
Expand Down
13 changes: 13 additions & 0 deletions x-pack/plugins/alerting/server/routes/legacy/enable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe('enableAlertRoute', () => {
const [config, handler] = router.post.mock.calls[0];

expect(config.path).toMatchInlineSnapshot(`"/api/alerts/alert/{id}/_enable"`);
expect(config.options?.access).toBe('public');

rulesClient.enableRule.mockResolvedValueOnce();

Expand Down Expand Up @@ -64,6 +65,18 @@ describe('enableAlertRoute', () => {
expect(res.noContent).toHaveBeenCalled();
});

it('should have internal access for serverless', async () => {
const licenseState = licenseStateMock.create();
const router = httpServiceMock.createRouter();

enableAlertRoute(router, licenseState, undefined, true);

const [config] = router.post.mock.calls[0];

expect(config.path).toMatchInlineSnapshot(`"/api/alerts/alert/{id}/_enable"`);
expect(config.options?.access).toBe('internal');
});

it('ensures the alert type gets validated for the license', async () => {
const licenseState = licenseStateMock.create();
const router = httpServiceMock.createRouter();
Expand Down
4 changes: 3 additions & 1 deletion x-pack/plugins/alerting/server/routes/legacy/enable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const paramSchema = schema.object({
export const enableAlertRoute = (
router: AlertingRouter,
licenseState: ILicenseState,
usageCounter?: UsageCounter
usageCounter?: UsageCounter,
isServerless?: boolean
) => {
router.post(
{
Expand All @@ -31,6 +32,7 @@ export const enableAlertRoute = (
params: paramSchema,
},
options: {
access: isServerless ? 'internal' : 'public',
summary: 'Enable an alert',
tags: ['oas-tag:alerting'],
deprecated: true,
Expand Down
Loading