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

Add extension point for file-based role validation #107177

Merged
merged 6 commits into from
Apr 12, 2024

Conversation

gwbrown
Copy link
Contributor

@gwbrown gwbrown commented Apr 6, 2024

This commit adds an extension point for Security extensions to add a file-based role validator, which will be used to apply rules to the roles provided in roles.yml. If this validation fails, the system will treat it like the roles YAML file could not be read: if this happens at startup, the node will fail to start, while if the roles.yml file is changed at runtime and fails validation, the failure will be logged and the active roles not updated. There is no change to the default behavior of Elasticsearch.

This commit adds an extension point for Security extensions to add a file-based role validator,
which will be used to apply rules to the roles provided in `roles.yml`.
There is no change to the default behavior of Elasticsearch.
@gwbrown gwbrown added >non-issue :Security/Authorization Roles, Privileges, DLS/FLS, RBAC/ABAC labels Apr 6, 2024
@gwbrown gwbrown requested a review from n1v0lg April 6, 2024 02:31
@elasticsearchmachine elasticsearchmachine added Team:Security Meta label for security team v8.14.0 labels Apr 6, 2024
@elasticsearchmachine
Copy link
Collaborator

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

@gwbrown
Copy link
Contributor Author

gwbrown commented Apr 6, 2024

@n1v0lg I came around to your way of thinking and didn't change the plumbing we discussed around the file roles store and name checker - it turned out much less awkward to break this out in a different way than I had when we last spoke.

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 clarification about the PR description just to make sure I understand the intended behavior correctly:

If this validation fails, the system will treat it like the YAML failed to parse: if this happens at startup, the node will fail to start, while if the roles.yml file is changed at runtime and fails validation, the failure will be logged and the active roles not updated.

Before this change when the YAML fails to parse, we simply skip defining roles from file, instead of the node failing to start.

With this PR, that doesn't change. We only fail if the new validator returns an exception, during node start. I think that's indeed the behavior we want but just want to double-check with you since the PR description above makes it sound like parsing failures also result in node start failure (and I don't think that's true).

@@ -374,6 +382,10 @@ private static RoleDescriptor checkDescriptor(
}
}
}
ActionRequestValidationException ex = roleValidator.validatePredefinedRole(descriptor);
Copy link
Contributor

Choose a reason for hiding this comment

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

Might add a test to FileRoleStoreTests with a mocked validator that throws

* Provides a check which will be applied to roles in the file-based roles store.
*/
@FunctionalInterface
public interface FileRoleValidator {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, I think this came out quite clean!

) {
return parseFile(path, logger, true, settings, licenseState, xContentRegistry);
// EMPTY & default role validator are safe here because we never use namedObject as we are just parsing role names
return parseRoleDescriptors(path, logger, false, Settings.EMPTY, new FileRoleValidator.Default(), NamedXContentRegistry.EMPTY)
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional nit: parseRoleDescriptors with the above invocation is only used in one place now, so might as well inline it.

@gwbrown
Copy link
Contributor Author

gwbrown commented Apr 8, 2024

@n1v0lg I dug into the behavior a bit and you're right, most other times we only skip parsing the role that's broken, unless the file is severely mashed. I've updated the PR description to account for that, as I agree that the current behavior of this PR is what we want. Good catch, thanks!

@gwbrown
Copy link
Contributor Author

gwbrown commented Apr 11, 2024

Opened #107387 for the failure - it's been popping up in multiple PRs.

@gwbrown
Copy link
Contributor Author

gwbrown commented Apr 11, 2024

@elasticmachine update branch

@gwbrown
Copy link
Contributor Author

gwbrown commented Apr 11, 2024

Failure is #105331.

Someday, CI will pass, and on that day, I will leap with joy and shout from the rooftops, lo, CI has passed.

@gwbrown
Copy link
Contributor Author

gwbrown commented Apr 11, 2024

@elasticmachine test this please

@gwbrown gwbrown merged commit adb6aa9 into elastic:main Apr 12, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>non-issue :Security/Authorization Roles, Privileges, DLS/FLS, RBAC/ABAC Team:Security Meta label for security team v8.14.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants