Skip to content

🌊 Streams: Permission handling#217353

Merged
flash1293 merged 6 commits intoelastic:mainfrom
flash1293:flash1293/missing-permissions-handling
Apr 8, 2025
Merged

🌊 Streams: Permission handling#217353
flash1293 merged 6 commits intoelastic:mainfrom
flash1293:flash1293/missing-permissions-handling

Conversation

@flash1293
Copy link
Contributor

@flash1293 flash1293 commented Apr 7, 2025

Currently, the streams UI doesn't deal well with partial permissions. This PR improves that. As a lot of things come together in streams, we could do even better, but I think it's OK to draw a line somewhere.

The logic is now as follows:
When reading a stream, the privileges of the current user are returned along with the stream itself. These are grouped like this:

interface IngestStreamPrivileges {
  // User can change everything about the stream
  manage: boolean;
  // User can read stats (like size in bytes) about the stream
  monitor: boolean;
  // User can change the retention policy of the stream
  lifecycle: boolean;
  // User can simulate changes to the processing or the mapping of the stream
  simulate: boolean;
}

This is part of the definition response and is passed around to the components and disabled buttons and similar in the places where this is necessary.

The "advanced" tab is only shown when full manage permissions are present - there constellations of permissions that would allow some access but not all (e.g. having read_pipelines but not manage_index_templates), but these should be rather rare and not worth the additional effort.

Conditions

In the following places privileges are checked:

  • Overview
    • Without monitor, the overall stats are not shown
  • Enrichment
    • Without manage, you can't save changes
    • Without simulate, the UI is readonly
  • Partitioning
    • Without manage, you can't save changes
    • Without simulate, the UI is readonly
  • Schema editor
    • Without manage, the UI is readonly
  • Retention
    • Without monitor, the ingest stats are not shown
    • Without lifecycle, the retention can't be changed and ILM breakdown is not rendered
  • Advanced
    • Without manage, the tab is hidden completely

Drive-by fix

I noticed that we still register the app header action menu which adds an empty bar on serverless, removed that code.

Testing

Check https://github.com/elastic/kibana/pull/217353/files#diff-d8f33d7021058bf90cbeea908bf399da2af50d8b8bfac8a07f160ddc0cdff12bR747 for which Elasticsearch level privileges you need for different permutations. Then set up a role and a user and log in as that user.

Also test the different pre-defined roles on serverless.

@flash1293 flash1293 added release_note:skip Skip the PR/issue when compiling release notes Team:obs-onboarding Observability Onboarding Team backport:version Backport to applied version labels Feature:Streams This is the label for the Streams Project v9.1.0 v8.19.0 labels Apr 7, 2025
@flash1293
Copy link
Contributor Author

/ci

@flash1293 flash1293 marked this pull request as ready for review April 8, 2025 07:30
@flash1293 flash1293 requested review from a team as code owners April 8, 2025 07:30
@elasticmachine
Copy link
Contributor

Pinging @elastic/obs-ux-logs-team (Team:obs-ux-logs)

@tonyghiani
Copy link
Contributor

Did you consider using the core capabilities feature provided by Kibana to register these privileges? It looks like an established pattern and would decouple the whole privileges management from a single API response, in this case the single stream request.

@flash1293
Copy link
Contributor Author

@tonyghiani Maybe I'm misunderstanding how the privileges work, but aren't they global for the user and about the Kibana level of things? I'm checking for privileges on the Elasticsearch level which can be different per data stream. I chatted with @yngrdyn about the approach and it's mirroring which we do for the data set quality page which is pretty similar.

We will need a Kibana level feature for streams eventually to allow disabling the whole feature on-prem, but we have a different issue for that (and it's not relevant for serverless)

@elasticmachine
Copy link
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #6 / X-Pack Accessibility Tests - Group 1 Kibana Home Accessibility Observability overview page meets a11y requirements

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
streamsApp 447 445 -2

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/streams-schema 374 376 +2

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
streamsApp 428.2KB 426.5KB -1.7KB
Unknown metric groups

API count

id before after diff
@kbn/streams-schema 388 390 +2

async chunk count

id before after diff
streamsApp 9 8 -1

ESLint disabled line counts

id before after diff
streamsApp 7 6 -1

References to deprecated APIs

id before after diff
streamsApp 4 2 -2

Total ESLint disabled count

id before after diff
streamsApp 11 10 -1

History

Copy link
Contributor

@tonyghiani tonyghiani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good and limits the available features when privileges are lacking. As discussed offline, not sure if there is a more established practice to consume ES privileges client side than attaching them to the API response, but at this point of our needs it looks ok.

@flash1293 flash1293 merged commit fd37446 into elastic:main Apr 8, 2025
9 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x

https://github.com/elastic/kibana/actions/runs/14335116322

@kibanamachine
Copy link
Contributor

💔 All backports failed

Status Branch Result
8.x Backport failed because of merge conflicts

You might need to backport the following PRs to 8.x:
- feat(streams): add significant events and queries API (#216221)

Manual backport

To create the backport manually run:

node scripts/backport --pr 217353

Questions ?

Please refer to the Backport tool documentation

@flash1293
Copy link
Contributor Author

💚 All backports created successfully

Status Branch Result
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

flash1293 added a commit to flash1293/kibana that referenced this pull request Apr 8, 2025
Currently, the streams UI doesn't deal well with partial permissions.
This PR improves that. As a lot of things come together in streams, we
could do even better, but I think it's OK to draw a line somewhere.

The logic is now as follows:
When reading a stream, the privileges of the current user are returned
along with the stream itself. These are grouped like this:
```
interface IngestStreamPrivileges {
  // User can change everything about the stream
  manage: boolean;
  // User can read stats (like size in bytes) about the stream
  monitor: boolean;
  // User can change the retention policy of the stream
  lifecycle: boolean;
  // User can simulate changes to the processing or the mapping of the stream
  simulate: boolean;
}
```

This is part of the definition response and is passed around to the
components and disabled buttons and similar in the places where this is
necessary.

The "advanced" tab is only shown when full `manage` permissions are
present - there constellations of permissions that would allow some
access but not all (e.g. having `read_pipelines` but not
`manage_index_templates`), but these should be rather rare and not worth
the additional effort.

## Conditions

In the following places privileges are checked:
* Overview
  * Without `monitor`, the overall stats are not shown
* Enrichment
  * Without `manage`, you can't save changes
  * Without `simulate`, the UI is readonly
* Partitioning
  * Without `manage`, you can't save changes
  * Without `simulate`, the UI is readonly
* Schema editor
  * Without `manage`, the UI is readonly
* Retention
  * Without `monitor`, the ingest stats are not shown
* Without `lifecycle`, the retention can't be changed and ILM breakdown
is not rendered
* Advanced
  * Without `manage`, the tab is hidden completely

## Drive-by fix

I noticed that we still register the app header action menu which adds
an empty bar on serverless, removed that code.

## Testing

Check
https://github.com/elastic/kibana/pull/217353/files#diff-d8f33d7021058bf90cbeea908bf399da2af50d8b8bfac8a07f160ddc0cdff12bR747
for which Elasticsearch level privileges you need for different
permutations. Then set up a role and a user and log in as that user.

Also test the different pre-defined roles on serverless.

(cherry picked from commit fd37446)

# Conflicts:
#	x-pack/platform/plugins/shared/streams/server/routes/streams/crud/read_stream.ts
flash1293 added a commit that referenced this pull request Apr 8, 2025
# Backport

This will backport the following commits from `main` to `8.x`:
- [🌊 Streams: Permission handling
(#217353)](#217353)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Joe
Reuter","email":"johannes.reuter@elastic.co"},"sourceCommit":{"committedDate":"2025-04-08T13:42:29Z","message":"🌊
Streams: Permission handling (#217353)\n\nCurrently, the streams UI
doesn't deal well with partial permissions.\nThis PR improves that. As a
lot of things come together in streams, we\ncould do even better, but I
think it's OK to draw a line somewhere.\n\nThe logic is now as
follows:\nWhen reading a stream, the privileges of the current user are
returned\nalong with the stream itself. These are grouped like
this:\n```\ninterface IngestStreamPrivileges {\n // User can change
everything about the stream\n manage: boolean;\n // User can read stats
(like size in bytes) about the stream\n monitor: boolean;\n // User can
change the retention policy of the stream\n lifecycle: boolean;\n //
User can simulate changes to the processing or the mapping of the
stream\n simulate: boolean;\n}\n```\n\nThis is part of the definition
response and is passed around to the\ncomponents and disabled buttons
and similar in the places where this is\nnecessary.\n\nThe \"advanced\"
tab is only shown when full `manage` permissions are\npresent - there
constellations of permissions that would allow some\naccess but not all
(e.g. having `read_pipelines` but not\n`manage_index_templates`), but
these should be rather rare and not worth\nthe additional effort.\n\n##
Conditions\n\nIn the following places privileges are checked:\n*
Overview\n * Without `monitor`, the overall stats are not shown\n*
Enrichment\n * Without `manage`, you can't save changes\n * Without
`simulate`, the UI is readonly\n* Partitioning\n * Without `manage`, you
can't save changes\n * Without `simulate`, the UI is readonly\n* Schema
editor\n * Without `manage`, the UI is readonly\n* Retention\n * Without
`monitor`, the ingest stats are not shown\n* Without `lifecycle`, the
retention can't be changed and ILM breakdown\nis not rendered\n*
Advanced\n * Without `manage`, the tab is hidden completely\n\n##
Drive-by fix\n\nI noticed that we still register the app header action
menu which adds\nan empty bar on serverless, removed that code.\n\n##
Testing\n\nCheck\nhttps://github.com//pull/217353/files#diff-d8f33d7021058bf90cbeea908bf399da2af50d8b8bfac8a07f160ddc0cdff12bR747\nfor
which Elasticsearch level privileges you need for
different\npermutations. Then set up a role and a user and log in as
that user.\n\nAlso test the different pre-defined roles on
serverless.","sha":"fd374463f74caac17b07120c34d2fc6c8e5e2754","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:obs-ux-logs","backport:version","Feature:Streams","v9.1.0","v8.19.0"],"title":"🌊
Streams: Permission
handling","number":217353,"url":"https://github.com/elastic/kibana/pull/217353","mergeCommit":{"message":"🌊
Streams: Permission handling (#217353)\n\nCurrently, the streams UI
doesn't deal well with partial permissions.\nThis PR improves that. As a
lot of things come together in streams, we\ncould do even better, but I
think it's OK to draw a line somewhere.\n\nThe logic is now as
follows:\nWhen reading a stream, the privileges of the current user are
returned\nalong with the stream itself. These are grouped like
this:\n```\ninterface IngestStreamPrivileges {\n // User can change
everything about the stream\n manage: boolean;\n // User can read stats
(like size in bytes) about the stream\n monitor: boolean;\n // User can
change the retention policy of the stream\n lifecycle: boolean;\n //
User can simulate changes to the processing or the mapping of the
stream\n simulate: boolean;\n}\n```\n\nThis is part of the definition
response and is passed around to the\ncomponents and disabled buttons
and similar in the places where this is\nnecessary.\n\nThe \"advanced\"
tab is only shown when full `manage` permissions are\npresent - there
constellations of permissions that would allow some\naccess but not all
(e.g. having `read_pipelines` but not\n`manage_index_templates`), but
these should be rather rare and not worth\nthe additional effort.\n\n##
Conditions\n\nIn the following places privileges are checked:\n*
Overview\n * Without `monitor`, the overall stats are not shown\n*
Enrichment\n * Without `manage`, you can't save changes\n * Without
`simulate`, the UI is readonly\n* Partitioning\n * Without `manage`, you
can't save changes\n * Without `simulate`, the UI is readonly\n* Schema
editor\n * Without `manage`, the UI is readonly\n* Retention\n * Without
`monitor`, the ingest stats are not shown\n* Without `lifecycle`, the
retention can't be changed and ILM breakdown\nis not rendered\n*
Advanced\n * Without `manage`, the tab is hidden completely\n\n##
Drive-by fix\n\nI noticed that we still register the app header action
menu which adds\nan empty bar on serverless, removed that code.\n\n##
Testing\n\nCheck\nhttps://github.com//pull/217353/files#diff-d8f33d7021058bf90cbeea908bf399da2af50d8b8bfac8a07f160ddc0cdff12bR747\nfor
which Elasticsearch level privileges you need for
different\npermutations. Then set up a role and a user and log in as
that user.\n\nAlso test the different pre-defined roles on
serverless.","sha":"fd374463f74caac17b07120c34d2fc6c8e5e2754"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/217353","number":217353,"mergeCommit":{"message":"🌊
Streams: Permission handling (#217353)\n\nCurrently, the streams UI
doesn't deal well with partial permissions.\nThis PR improves that. As a
lot of things come together in streams, we\ncould do even better, but I
think it's OK to draw a line somewhere.\n\nThe logic is now as
follows:\nWhen reading a stream, the privileges of the current user are
returned\nalong with the stream itself. These are grouped like
this:\n```\ninterface IngestStreamPrivileges {\n // User can change
everything about the stream\n manage: boolean;\n // User can read stats
(like size in bytes) about the stream\n monitor: boolean;\n // User can
change the retention policy of the stream\n lifecycle: boolean;\n //
User can simulate changes to the processing or the mapping of the
stream\n simulate: boolean;\n}\n```\n\nThis is part of the definition
response and is passed around to the\ncomponents and disabled buttons
and similar in the places where this is\nnecessary.\n\nThe \"advanced\"
tab is only shown when full `manage` permissions are\npresent - there
constellations of permissions that would allow some\naccess but not all
(e.g. having `read_pipelines` but not\n`manage_index_templates`), but
these should be rather rare and not worth\nthe additional effort.\n\n##
Conditions\n\nIn the following places privileges are checked:\n*
Overview\n * Without `monitor`, the overall stats are not shown\n*
Enrichment\n * Without `manage`, you can't save changes\n * Without
`simulate`, the UI is readonly\n* Partitioning\n * Without `manage`, you
can't save changes\n * Without `simulate`, the UI is readonly\n* Schema
editor\n * Without `manage`, the UI is readonly\n* Retention\n * Without
`monitor`, the ingest stats are not shown\n* Without `lifecycle`, the
retention can't be changed and ILM breakdown\nis not rendered\n*
Advanced\n * Without `manage`, the tab is hidden completely\n\n##
Drive-by fix\n\nI noticed that we still register the app header action
menu which adds\nan empty bar on serverless, removed that code.\n\n##
Testing\n\nCheck\nhttps://github.com//pull/217353/files#diff-d8f33d7021058bf90cbeea908bf399da2af50d8b8bfac8a07f160ddc0cdff12bR747\nfor
which Elasticsearch level privileges you need for
different\npermutations. Then set up a role and a user and log in as
that user.\n\nAlso test the different pre-defined roles on
serverless.","sha":"fd374463f74caac17b07120c34d2fc6c8e5e2754"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:version Backport to applied version labels Feature:Streams This is the label for the Streams Project release_note:skip Skip the PR/issue when compiling release notes Team:obs-onboarding Observability Onboarding Team v8.19.0 v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants