Skip to content

Commit

Permalink
[Authz] Added section for migration routes created by utility function
Browse files Browse the repository at this point in the history
  • Loading branch information
elena-shostak committed Oct 30, 2024
1 parent 6a50066 commit 005b9d9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions dev_docs/key_concepts/api_authorization.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,23 @@ Routes without a compelling reason to opt-out of authorization should plan to in
MIGRATE_DISABLED_AUTHZ=true MIGRATE_ENABLED_AUTHZ=true npx eslint --ext .ts --fix path/to/your/folder
```

**How to migrate if you have an utility function for route creation?**
If you have utility function that creates routes, i.e `createApmServerRoute` or `createObservabilityOnboardingServerRoute`, you can easily modify the eslint rule to handle your case.
For example, you register the route with `access` tags in your utility function:
```ts
createApmServerRoute({
endpoint: 'GET /your/route/path',
options: { tags: ['access:apm'] },
handler: async (resources): => {
// your handler logic
},
})
```
You can modify [the rule](https://github.com/elastic/kibana/blob/6a50066e00ae38a64c5365fd66b4dc32857ba1fc/packages/kbn-eslint-plugin-eslint/rules/no_deprecated_authz_config.js#L312-#L315) to handle your case by adding the following code:
```ts
callee.type === 'Identifier' && callee.name === 'createApmServerRoute'
```

## Questions?
If you have any questions or need help with API authorization, please reach out to the `@elastic/kibana-security` team.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

const routeMethods = ['get', 'put', 'delete', 'post'];
const routeMethods = ['get', 'put', 'delete', 'post', 'patch'];
const ACCESS_TAG_PREFIX = 'access:';

const isStringLiteral = (el) => el.type === 'Literal' && typeof el.value === 'string';
Expand Down

0 comments on commit 005b9d9

Please sign in to comment.