callWithRequest executes requests against Elasticsearch using the authentication credentials of the Kibana end-user. So, if you log into Kibana with the user of foo when callWithRequest is used, Kibana execute the request against Elasticsearch as the user foo. Historically, callWithRequest has been used extensively to perform actions that are initiated at the request of Kibana end-users.

callWithInternalUser executes requests against Elasticsearch using the internal Kibana server user, and has historically been used for performing actions that aren’t initiated by Kibana end users; for example, creating the initial .kibana index or performing health checks against Elasticsearch.

However, with the changes that role-based access control (RBAC) introduces, this is no longer cut and dry. Kibana now requires all access to the .kibana index goes through the SavedObjectsClient. This used to be a best practice, as the SavedObjectsClient was responsible for translating the documents stored in Elasticsearch to and from Saved Objects, but RBAC is now taking advantage of this abstraction to implement access control and determine when to use callWithRequest versus callWithInternalUser.

Role-based access control

Role-based access control (RBAC) in Kibana relies upon the application privileges that Elasticsearch exposes. This allows Kibana to define the privileges that Kibana wishes to grant to users, assign them to the relevant users using roles, and then authorize the user to perform a specific action. This is handled within a secured instance of the SavedObjectsClient and available transparently to consumers when using request.getSavedObjectsClient() or savedObjects.getScopedSavedObjectsClient().

Kibana Privilegesedit

When Kibana first starts up, it executes the following POST request against Elasticsearch. This synchronizes the definition of the privileges with various actions which are later used to authorize a user:

The application is created by concatenating the prefix of kibana- with the value of kibana.index from the kibana.yml, so different Kibana tenants are isolated from one another.

Assigning Kibana Privilegesedit

Kibana privileges are assigned to specific roles using the applications element. For example, the following role assigns the privilege at * resources (which will in the future be used to secure spaces) to the default Kibana application:

  1. "new_kibana_user": {
  2. "applications": [
  3. {
  4. "application": "kibana-.kibana",
  5. "privileges": [
  6. "all"
  7. ],
  8. "resources": [
  9. "*"
  10. ]
  11. }
  12. ]
  13. }

Roles that grant Kibana privileges should be managed using the or the Management → Security → Roles page, not directly using the Elasticsearch role management API. This role can then be assigned to users using the Elasticsearch .

Authorization

The Elasticsearch has privileges API determines whether the user is authorized to perform a specific action:

  1. POST /_security/user/_has_privileges
  2. Content-Type: application/json
  3. Authorization: Basic foo_read_only_user password
  4. {
  5. "applications":[
  6. {
  7. "application":"kibana-.kibana",
  8. "resources":["*"],
  9. "privileges":[
  10. "saved_object:dashboard/save",
  11. ]
  12. }
  13. ]

Elasticsearch checks if the user is granted a specific action. If the user is assigned a role that grants a privilege, Elasticsearch uses the definition to associate this with the actions, which makes authorizing users more intuitive and flexible programatically.

Once we have authorized the user to perform a specific action, we can execute the request using callWithInternalUser.

If your plugin will be used with Kibana’s default distribution, then you have the ability to register the features that your plugin provides. Features are typically apps in Kibana; once registered, you can toggle them via Spaces, and secure them via Roles when security is enabled.

UI Capabilities

Registering features also gives your plugin access to “UI Capabilities”. These capabilities are boolean flags that you can use to conditionally render your interface, based on the current user’s permissions. For example, you can hide or disable a Save button if the current user is not authorized.

Registering a feature

Feature registration is controlled via the built-in xpack_main plugin. To register a feature, call xpack_main‘s registerFeature function from your plugin’s init function, and provide the appropriate details:

Feature details

Registering a feature consists of the following fields. For more information, consult the .

Privilege definition

The privileges section of feature registration allows plugins to implement read/write and read-only modes for their applications.

For a full explanation of fields and options, consult the feature registry interface.

Using UI Capabilities

UI Capabilities are available to your public (client) plugin code. These capabilities are read-only, and are used to inform the UI. This object is namespaced by feature id. For example, if your feature id is “foo”, then your UI Capabilities are stored at uiCapabilities.foo. To access capabilities, import them from ui/capabilities:

  1. import { uiCapabilities } from 'ui/capabilities';
  2. const canUserSave = uiCapabilities.foo.save;
  3. if (canUserSave) {
  4. // show save button
  5. }

Example 1: Canvas Application

  1. init(server) {
  2. const xpackMainPlugin = server.plugins.xpack_main;
  3. xpackMainPlugin.registerFeature({
  4. id: 'canvas',
  5. name: 'Canvas',
  6. icon: 'canvasApp',
  7. navLinkId: 'canvas',
  8. app: ['canvas', 'kibana'],
  9. catalogue: ['canvas'],
  10. privileges: {
  11. all: {
  12. savedObject: {
  13. all: ['canvas-workpad'],
  14. read: ['index-pattern'],
  15. },
  16. ui: ['save'],
  17. },
  18. read: {
  19. savedObject: {
  20. all: [],
  21. read: ['index-pattern', 'canvas-workpad'],
  22. },
  23. ui: [],
  24. },
  25. },
  26. });
  27. }

This shows how the Canvas application might register itself as a Kibana feature. Note that it specifies different savedObject access levels for each privilege:

  • Users with read/write access (all privilege) need to be able to read/write canvas-workpad saved objects, and they need read-only access to index-pattern saved objects.
  • Users with read-only access ( privilege) do not need to have read/write access to any saved objects, but instead get read-only access to index-pattern and canvas-workpad saved objects.

Additionally, Canvas registers the canvas UI app and canvas catalogue entry. This tells Kibana that these entities are available for users with either the read or all privilege.

The all privilege defines a single “save” UI Capability. To access this in the UI, Canvas could:

Because the read privilege does not define the save capability, users with read-only access will have their uiCapabilities.canvas.save flag set to false.

Example 2: Dev Tools

  1. init(server) {
  2. const xpackMainPlugin = server.plugins.xpack_main;
  3. xpackMainPlugin.registerFeature({
  4. id: 'dev_tools',
  5. name: i18n.translate('xpack.features.devToolsFeatureName', {
  6. defaultMessage: 'Dev Tools',
  7. icon: 'devToolsApp',
  8. navLinkId: 'dev_tools',
  9. app: ['kibana'],
  10. catalogue: ['console', 'searchprofiler', 'grokdebugger'],
  11. privileges: {
  12. all: {
  13. api: ['console'],
  14. savedObject: {
  15. all: [],
  16. read: [],
  17. },
  18. ui: ['show'],
  19. },
  20. read: {
  21. api: ['console'],
  22. savedObject: {
  23. all: [],
  24. read: [],
  25. },
  26. ui: ['show'],
  27. },
  28. },
  29. privilegesTooltip: i18n.translate('xpack.features.devToolsPrivilegesTooltip', {
  30. defaultMessage:
  31. 'User should also be granted the appropriate {es} cluster and index privileges',
  32. }),
  33. });
  34. }
  1. server.route({
  2. path: '/api/console/proxy',
  3. method: 'POST',
  4. config: {
  5. tags: ['access:console'],
  6. handler: async (req, h) => {
  7. // ...
  8. }
  9. }
  10. });

Example 3: Discover

Discover takes advantage of subfeature privileges to allow fine-grained access control. In this example, a single “Create Short URLs” subfeature privilege is defined, which allows users to grant access to this feature without having to grant the all privilege to Discover. In other words, you can grant read access to Discover, and also grant the ability to create short URLs.

Most Popular