Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Failure Store] Has Privileges API #125329

Merged
merged 30 commits into from
Mar 26, 2025

Conversation

n1v0lg
Copy link
Contributor

@n1v0lg n1v0lg commented Mar 20, 2025

This PR adds support for checking access to the failure store via the Has Privileges API.

To check access for a data stream logs, a request must query for a concrete named privilege, read_failure_store or manage_failure_store, e.g., a request to the HasPrivileges API by a user with read_failure_store over logs:

POST /_security/user/_has_privileges
{
    "index": [
        {
            "names": ["logs"],
            "privileges": ["read_failure_store", "read", "indices:data/read/*"]
        }
    ]
}

Returns:

{
    "username": "<...>",
    "has_all_requested": false,
    "cluster": {},
    "index": {
        "logs": {
            "read_failure_store": true,
            "read": false, <1>
            "indices:data/read/*": false <2>
        }
    },
    "application": {}
}

Note that <1> and <2> are both false since read is not covered by read_failure_store and neither are any raw actions like indices:data/read/* since these implicitly correspond to data access.

Selectors are not allowed in the index patterns of HasPrivileges requests to avoid ambiguities such as checking read on logs::failures as well as the ambiguity of index patterns that are regular expressions.

@n1v0lg n1v0lg added >non-issue :Security/Authorization Roles, Privileges, DLS/FLS, RBAC/ABAC auto-backport Automatically create backport pull requests when merged v8.19.0 v9.1.0 labels Mar 20, 2025
@n1v0lg n1v0lg self-assigned this Mar 20, 2025
@n1v0lg n1v0lg added the Team:Security Meta label for security team label Mar 24, 2025
if (resourcePrivilegesMapBuilder != null) {
resourcePrivilegesMapBuilder.addResourcePrivilege(forIndexPattern, privilege, Boolean.TRUE);
}
} else {
} else if (checkWithFailuresSelector
&& allowedPrivilegesAutomatonForFailuresSelector != null
Copy link
Contributor

Choose a reason for hiding this comment

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

one optimization to consider: we could wrap getIndexPrivilegesAutomaton calls into CachedSupplier and make allowedPrivilegesAutomatonForFailuresSelector and allowedPrivilegesAutomatonForDataSelector be computed lazily when checkWithDataSelector or checkWithFailuresSelector is true - respectively

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking about this too but CachedSupplier involves a synchronized block and might be a little too heavy for the context here (since we don't need synchronization here, I don't think) -- at least I can't immediately say if it would provide an actual gain or not. My thinking here is:

  1. Most calls will be checking for data selectors privileges (there are more of them, and it's the "normal" workflow to access regular data)
  2. This means we'll need the data selectors automata most of the time, which is why I added short-circuiting failures-only selector computation via containsPrivilegesForFailuresSelector. We could do the same for data selectors but that's another pass over the privileges with another set of Map look-ups, or something slightly more complicated

Let me know if you have a stronger intuition here. I'd love to benchmark this and get some real performance numbers but would not want to block on that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point - we don't want synchronization here. FWIW We could implement a non-blocking version of cached supplier, but I don't feel this is something we should block on. My intuition is the same, we would be mostly checking data selectors and the optimization you already have could be sufficient.

@n1v0lg n1v0lg marked this pull request as ready for review March 25, 2025 12:28
@n1v0lg n1v0lg requested a review from slobodanadamovic March 25, 2025 12:28
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-security (Team:Security)

Copy link
Contributor

@slobodanadamovic slobodanadamovic left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@n1v0lg n1v0lg added the auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) label Mar 26, 2025
@elasticsearchmachine elasticsearchmachine merged commit 0e0214d into elastic:main Mar 26, 2025
22 checks passed
@n1v0lg n1v0lg deleted the failure-store-has-privileges branch March 26, 2025 12:21
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
8.x Commit could not be cherrypicked due to conflicts

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 125329

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Automatically create backport pull requests when merged auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) backport pending >non-issue :Security/Authorization Roles, Privileges, DLS/FLS, RBAC/ABAC Team:Security Meta label for security team v8.19.0 v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants