-
Notifications
You must be signed in to change notification settings - Fork 25.7k
Do not fetch reserved roles from native store when Get Role API is called #121971
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
Do not fetch reserved roles from native store when Get Role API is called #121971
Conversation
…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.
|
Hi @slobodanadamovic, I've created a changelog YAML for you. |
| Files.delete(rolesFile); | ||
| Files.copy(distributionDir.resolve("config").resolve("roles.yml"), rolesFile); | ||
| writeRolesFile(); | ||
| updateRolesFileAtomically(); |
There was a problem hiding this comment.
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.
|
Pinging @elastic/es-security (Team:Security) |
| return; | ||
| } | ||
|
|
||
| final Set<String> rolesToGet = filterReservedRoleNames(names); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
n1v0lg
left a comment
There was a problem hiding this 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); |
There was a problem hiding this comment.
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).
the native roles store should never be called to resolve reserved built-in roles
…r-reserved-roles-from-get-roles-api
n1v0lg
left a comment
There was a problem hiding this 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 + "]")); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
…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.
…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.
💚 All backports created successfully
Questions ?Please refer to the Backport tool documentation |
…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)
The reserved roles are already returned directly from the
ReservedRolesStoreinTransportGetRolesAction.There is no need to query and deserialize reserved roles from the
.securityindex just to be merged with static definitions.