kibana/dev_docs/key_concepts
Elena Shostak 504510b92b
[Hardening] Kibana Feature API Privileges Names (#208067)
## Summary

As part of our effort to harden API action definitions and enforce
standards this PR adds an utility `ApiPrivileges` class.
It is supposed to be used for both feature registration and API route
definition to construct the privilege name.
```ts
plugins.features.registerKibanaFeature({
  privileges: {
    all: {
      app: [...],
      catalogue: [...],
      api: [ApiPrivileges.manage('subject_name')],
      ...
    },
    read: {
      ...
      api: [ApiPrivileges.read('subject_name')],
      ...
    },
  },
})
....

// route definition
router.get(
  {
    path: 'api_path',
    security: {
      authz: {
        requiredPrivileges: [ApiPrivileges.manage('subject_name')],
      },
    },
  },
  async (ctx, req, res) => {}
);
```

`require_kibana_feature_privileges_naming` eslint rule has been added to
show warning if the API privilege name doesn't satisfy the naming
convention.

### Naming convention

- API privilege should start with valid `ApiOperation`: `manage`,
`read`, `update`, `delete`, `create`
- API privilege should use `_` as separator

 `read-entity-a`
 `delete_entity-a`
 `entity_manage`
 `read_entity_a`
 `delete_entity_a`
 `manage_entity`

> [!IMPORTANT]  
> Serverless ZDT update scenario:
>
> - version N has an endpoint protected with the `old_privilege_read`.
> - version N+1 has the same endpoint protected with a new
`read_privilege`.
> 
> There might be a short period between the time the UI pod N+1 passes
SO migrations and updates privileges and the time it's marked as
ready-to-handle-requests by k8s, and when UI pod N is terminated.
>
> After discussion with @legrego and @azasypkin we decided to ignore it
due to the perceived risk-to-cost ratio:
> 1. The time window users might be affected is very narrow because we
register privileges late in the Kibana startup flow (e.g., after SO
migrations).
> 2. The transient 403 errors users might get won't result in session
termination and shouldn't lead to data loss.
> 3. The roll-out will be performed in batches over the course of
multiple weeks and implemented by different teams. This means the impact
per release shouldn't be significant.

### Checklist

- [x]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

__Relates: https://github.com/elastic/kibana/issues/198716__

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
2025-02-03 15:22:29 +01:00
..
performance SKA: Update broken references and URLs (#206836) 2025-01-28 03:32:48 +00:00
anatomy_of_a_plugin.mdx async-import plugins in the server side (#170856) 2023-11-15 00:55:56 -07:00
api_authorization.mdx [Hardening] Kibana Feature API Privileges Names (#208067) 2025-02-03 15:22:29 +01:00
audit_logging.mdx [api-docs] follow the correct schema for frontmatter (#138348) 2022-08-10 17:17:50 -05:00
building_blocks.mdx [Discover] Rename Saved Search to Discover Session (#202217) 2024-12-18 13:45:32 +01:00
data_views.mdx [api-docs] follow the correct schema for frontmatter (#138348) 2022-08-10 17:17:50 -05:00
embeddables.mdx SKA: Update broken references and URLs (#206836) 2025-01-28 03:32:48 +00:00
encrypted_saved_objects.mdx Implements 'Key concepts' developer documentation for Encrypted Saved Objects (#184334) 2024-06-07 14:34:58 +02:00
feature_privileges.mdx [Docs] Update feature privilege docs to reflect new route authorization (#201017) 2024-11-20 14:52:58 -06:00
kibana_platform_plugin_intro.mdx [api-docs] follow the correct schema for frontmatter (#138348) 2022-08-10 17:17:50 -05:00
kibana_system_user.mdx [Docs] Security Route Configuration (#193994) 2024-10-22 06:30:53 -05:00
navigation.mdx SKA: Update broken references and URLs (#206836) 2025-01-28 03:32:48 +00:00
persistable_state.mdx SKA: Update broken references and URLs (#206836) 2025-01-28 03:32:48 +00:00
saved_objects.mdx Updates internal dev docs for Saved Objects (#178058) 2024-03-07 08:16:28 -07:00