Skip to content

Commit b9d240b

Browse files
Unauthorized route migration for routes owned by kibana-core (#214780)
### Authz API migration for unauthorized routes This PR migrates last unauthorized routes owned by your team to a new security configuration. Please refer to the documentation for more information: [Authorization API](https://docs.elastic.dev/kibana-dev-docs/key-concepts/security-api-authorization) ### **Before migration:** ```ts router.get({ path: '/api/path', ... }, handler); ``` ### **After migration:** ```ts router.get({ path: '/api/path', security: { authz: { enabled: false, reason: 'This route is opted out from authorization because ...', }, }, ... }, handler); ```
1 parent caaea10 commit b9d240b

File tree

10 files changed

+84
-4
lines changed

10 files changed

+84
-4
lines changed

src/core/packages/apps/server-internal/src/core_app.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,17 @@ export class CoreAppsService {
143143
const resources = coreSetup.httpResources.createRegistrar(router);
144144

145145
router.get(
146-
{ path: '/', validate: false, options: { access: 'public' } },
146+
{
147+
path: '/',
148+
validate: false,
149+
options: { access: 'public' },
150+
security: {
151+
authz: {
152+
enabled: false,
153+
reason: 'This route is only used for serving the default route.',
154+
},
155+
},
156+
},
147157
async (context, req, res) => {
148158
const { uiSettings } = await context.core;
149159
let defaultRoute = await uiSettings.client.get<string>('defaultRoute', { request: req });

src/core/packages/deprecations/server-internal/src/deprecations_service.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,17 @@ describe('DeprecationsService', () => {
5858
// registers get route '/'
5959
expect(router.get).toHaveBeenCalledTimes(1);
6060
expect(router.get).toHaveBeenCalledWith(
61-
{ options: { access: 'public' }, path: '/', validate: false },
61+
{
62+
options: { access: 'public' },
63+
path: '/',
64+
validate: false,
65+
security: {
66+
authz: {
67+
enabled: false,
68+
reason: expect.any(String),
69+
},
70+
},
71+
},
6272
expect.any(Function)
6373
);
6474
});

src/core/packages/deprecations/server-internal/src/routes/get.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ export const registerGetRoute = (router: InternalDeprecationRouter) => {
1414
router.get(
1515
{
1616
path: '/',
17+
security: {
18+
authz: {
19+
enabled: false,
20+
reason: 'This route delegates authorization to the Core Deprecations Client',
21+
},
22+
},
1723
options: {
1824
access: 'public',
1925
},

src/core/packages/i18n/server-internal/src/routes/translations.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ export const registerTranslationsRoute = ({
3838
router.get(
3939
{
4040
path: routePath,
41+
security: {
42+
authz: {
43+
enabled: false,
44+
reason: 'This route is only used for serving i18n translations.',
45+
},
46+
},
4147
validate: {
4248
params: schema.object({
4349
locale: schema.string(),

src/core/packages/rendering/server-internal/src/bootstrap/register_bootstrap_route.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ export const registerBootstrapRoute = ({
2020
router.get(
2121
{
2222
path: '/bootstrap.js',
23+
security: {
24+
authz: {
25+
enabled: false,
26+
reason: 'This route is only used for serving the bootstrap script.',
27+
},
28+
},
2329
options: {
2430
tags: ['api'],
2531
access: 'public',
@@ -43,6 +49,12 @@ export const registerBootstrapRoute = ({
4349
router.get(
4450
{
4551
path: '/bootstrap-anonymous.js',
52+
security: {
53+
authz: {
54+
enabled: false,
55+
reason: 'This route is only used for serving the bootstrap script.',
56+
},
57+
},
4658
options: {
4759
authRequired: 'optional',
4860
tags: ['api'],

src/core/packages/saved-objects/server-internal/src/routes/deprecations/delete_unknown_types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ export const registerDeleteUnknownTypesRoute = (
2424
{
2525
path: '/deprecations/_delete_unknown_types',
2626
validate: false,
27+
security: {
28+
authz: {
29+
enabled: false,
30+
reason: 'This route delegates authorization to the Saved Objects Client',
31+
},
32+
},
2733
},
2834
catchAndReturnBoomErrors(async (context, req, res) => {
2935
const { elasticsearch, savedObjects } = await context.core;

src/core/packages/status/server-internal/src/routes/status.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ export const registerStatusRoute = ({
8282
router.get(
8383
{
8484
path: '/api/status',
85+
security: {
86+
authz: {
87+
enabled: false,
88+
reason: 'Status route should be accessible without authorization.',
89+
},
90+
},
8591
options: {
8692
authRequired: 'optional',
8793
// The `api` tag ensures that unauthenticated calls receive a 401 rather than a 302 redirect to login page.

src/core/packages/status/server-internal/src/routes/status_preboot.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,17 @@ export const registerPrebootStatusRoute = ({ router }: { router: IRouter }) => {
1515
router.get(
1616
{
1717
path: '/api/status',
18+
security: {
19+
authz: {
20+
enabled: false,
21+
reason: 'Preboot status route should be accessible without authorization.',
22+
},
23+
authc: {
24+
enabled: false,
25+
reason: 'Preboot status route should be accessible without authentication.',
26+
},
27+
},
1828
options: {
19-
authRequired: false,
2029
tags: ['api'],
2130
access: 'public', // needs to be public to allow access from "system" users like k8s readiness probes.
2231
excludeFromRateLimiter: true,

src/core/packages/status/server-internal/src/status_service.test.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,21 @@ describe('StatusService', () => {
101101
{
102102
path: '/api/status',
103103
options: {
104-
authRequired: false,
105104
tags: ['api'],
106105
access: 'public',
107106
excludeFromRateLimiter: true,
108107
},
109108
validate: false,
109+
security: {
110+
authz: {
111+
enabled: false,
112+
reason: expect.any(String),
113+
},
114+
authc: {
115+
enabled: false,
116+
reason: expect.any(String),
117+
},
118+
},
110119
},
111120
expect.any(Function)
112121
);

x-pack/platform/plugins/shared/cloud/server/routes/get_cloud_data_route.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ export const setGetCloudSolutionDataRoute = ({ router }: RouteOptions) => {
1414
router.versioned
1515
.get({
1616
path: `/internal/cloud/solution`,
17+
security: {
18+
authz: {
19+
enabled: false,
20+
reason: 'This route delegates authorization to the saved objects client',
21+
},
22+
},
1723
access: 'internal',
1824
summary: 'Get cloud data for solutions',
1925
})

0 commit comments

Comments
 (0)