[Authz] Added section for migration routes created by utility function (#198401)

## Summary

- Added section for migrating routes created by utility function.
- Added `patch` method to route methods in eslint rule.


### Checklist
- [x]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
This commit is contained in:
Elena Shostak 2024-10-30 19:05:38 +01:00 committed by GitHub
parent 3c5319f215
commit 71a298ef7b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 1 deletions

View file

@ -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.

View file

@ -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';