Skip to content

Conversation

@slobodanadamovic
Copy link
Contributor

The reserved roles are already returned directly from the ReservedRolesStore in TransportGetRolesAction.
There is no need to query and deserialize reserved roles from the .security index just to be merged with static definitions.

…lled

The reserved roles are already returned from the `ReservedRolesStore`
in `TransportGetRolesAction`. There is no need to query and deserialize
reserved roles from the `.security` index when Get Roles API is called.
@slobodanadamovic slobodanadamovic added >enhancement :Security/Authorization Roles, Privileges, DLS/FLS, RBAC/ABAC Team:Security Meta label for security team auto-backport Automatically create backport pull requests when merged v8.18.1 v9.0.1 labels Feb 6, 2025
@slobodanadamovic slobodanadamovic self-assigned this Feb 6, 2025
@elasticsearchmachine
Copy link
Collaborator

Hi @slobodanadamovic, I've created a changelog YAML for you.

@elasticsearchmachine elasticsearchmachine added the serverless-linked Added by automation, don't add manually label Feb 6, 2025
Files.delete(rolesFile);
Files.copy(distributionDir.resolve("config").resolve("roles.yml"), rolesFile);
writeRolesFile();
updateRolesFileAtomically();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a fix for Serverless tests.

@slobodanadamovic slobodanadamovic marked this pull request as ready for review February 7, 2025 09:54
@elasticsearchmachine
Copy link
Collaborator

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

return;
}

final Set<String> rolesToGet = filterReservedRoleNames(names);
Copy link
Contributor Author

@slobodanadamovic slobodanadamovic Feb 7, 2025

Choose a reason for hiding this comment

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

Filtering all roles here to avoid that reserved roles get resolved by NativeRolesStore. The getRoleDescriptors is called from accept method to resolve roles which are later used during authorization.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm I'm not sure that's necessary:

We remove already resolved roles out before handing off to the next resolver in the chain.

So if we are resolving e.g. viewer in stateful, it'll get returned by the reserved role store, and won't get checked by the native role store. Similarly, the file store will come first so any role that gets resolved there won't get resolved by the native role store.

We could make this an assertion here (i.e., no reserved roles ever make it to this point).

Copy link
Contributor Author

@slobodanadamovic slobodanadamovic Feb 14, 2025

Choose a reason for hiding this comment

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

Nice catch! I've missed the fact that resolved roles are removed. It makes sense to change it to an assertion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The filtering is still needed for Serverless, which was the main reason I've added it.
I've introduced it back in the TransportGetRolesAction. I think this is okay given that we already do filtering of reserved roles there. The main change is using the ReservedRoleNameChecker instead of ReservedRolesStore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would you mind taking another look?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yikes, sorry about that. You're totally right -- we hit a different path when fetching by name. Adding the check sounds good to me. Taking a quick look now 👀

import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder;
import static org.hamcrest.Matchers.equalTo;

public class GetRolesIT extends SecurityInBasicRestTestCase {
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've added this integration test mostly for sanity check that GET _security/roles works as expected in Stateful and returns reserved roles as well.

Copy link
Contributor

@n1v0lg n1v0lg left a comment

Choose a reason for hiding this comment

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

LGTM -- one suggestion around redundant code.

return;
}

final Set<String> rolesToGet = filterReservedRoleNames(names);
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm I'm not sure that's necessary:

We remove already resolved roles out before handing off to the next resolver in the chain.

So if we are resolving e.g. viewer in stateful, it'll get returned by the reserved role store, and won't get checked by the native role store. Similarly, the file store will come first so any role that gets resolved there won't get resolved by the native role store.

We could make this an assertion here (i.e., no reserved roles ever make it to this point).

Copy link
Contributor

@n1v0lg n1v0lg left a comment

Choose a reason for hiding this comment

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

LGTM!

if (rd != null) {
reservedRoles.add(rd);
} else {
listener.onFailure(new IllegalStateException("unable to obtain reserved role [" + role + "]"));
Copy link
Contributor

Choose a reason for hiding this comment

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

We're getting rid of this branch because now reservedRoleNameChecker.isReserved(...) can also match on file-based roles in Serverless, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's correct. The failure makes sense as a sanity check when the ReservedRolesStore is the only source of reserved roles. This just is not the case in Serverless.

@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
8.18
9.0

slobodanadamovic added a commit to slobodanadamovic/elasticsearch that referenced this pull request Feb 17, 2025
…lled (elastic#121971)

The reserved roles are already returned from the `ReservedRolesStore`
in `TransportGetRolesAction`. There is no need to query and deserialize
reserved roles from the `.security` index just to be merged with "static" definitions.
slobodanadamovic added a commit to slobodanadamovic/elasticsearch that referenced this pull request Feb 17, 2025
…lled (elastic#121971)

The reserved roles are already returned from the `ReservedRolesStore`
in `TransportGetRolesAction`. There is no need to query and deserialize
reserved roles from the `.security` index just to be merged with "static" definitions.
@slobodanadamovic
Copy link
Contributor Author

💚 All backports created successfully

Status Branch Result
8.x

Questions ?

Please refer to the Backport tool documentation

slobodanadamovic added a commit to slobodanadamovic/elasticsearch that referenced this pull request Feb 17, 2025
…lled (elastic#121971)

The reserved roles are already returned from the `ReservedRolesStore`
in `TransportGetRolesAction`. There is no need to query and deserialize
reserved roles from the `.security` index just to be merged with "static" definitions.

(cherry picked from commit 5c54c5f)
elasticsearchmachine pushed a commit that referenced this pull request Feb 17, 2025
…lled (#121971) (#122759)

The reserved roles are already returned from the `ReservedRolesStore`
in `TransportGetRolesAction`. There is no need to query and deserialize
reserved roles from the `.security` index just to be merged with "static" definitions.

(cherry picked from commit 5c54c5f)
elasticsearchmachine pushed a commit that referenced this pull request Feb 19, 2025
…lled (#121971) (#122753)

The reserved roles are already returned from the `ReservedRolesStore`
in `TransportGetRolesAction`. There is no need to query and deserialize
reserved roles from the `.security` index just to be merged with "static" definitions.
elasticsearchmachine pushed a commit that referenced this pull request Feb 20, 2025
…lled (#121971) (#122752)

The reserved roles are already returned from the `ReservedRolesStore`
in `TransportGetRolesAction`. There is no need to query and deserialize
reserved roles from the `.security` index just to be merged with "static" definitions.
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 >enhancement :Security/Authorization Roles, Privileges, DLS/FLS, RBAC/ABAC serverless-linked Added by automation, don't add manually Team:Security Meta label for security team v8.18.1 v8.19.0 v9.0.1 v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants