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

Replaced uses of SecurityRoles by Set<String> mappedRoles where the SecurityRoles functionality is not needed #4432

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@
"No cluster-level perm match for {} [Action [{}]] [RolesChecked {}]. No permissions for {}",
user,
action0,
securityRoles.getRoleNames(),
mappedRoles,
presponse.missingPrivileges
);
} else {
Expand Down Expand Up @@ -333,7 +333,7 @@
}

// Protected index access
if (protectedIndexAccessEvaluator.evaluate(request, task, action0, requestedResolved, presponse, securityRoles).isComplete()) {
if (protectedIndexAccessEvaluator.evaluate(request, task, action0, requestedResolved, presponse, mappedRoles).isComplete()) {
return presponse;
}

Expand Down Expand Up @@ -374,7 +374,7 @@
user,
requestedResolved,
action0,
securityRoles.getRoleNames(),
mappedRoles,
presponse.missingPrivileges
);
return presponse;
Expand Down Expand Up @@ -471,7 +471,7 @@

if (isDebugEnabled) {
log.debug("Requested resolved index types: {}", requestedResolved);
log.debug("Security roles: {}", securityRoles.getRoleNames());
log.debug("Security roles: {}", mappedRoles);

Check warning on line 474 in src/main/java/org/opensearch/security/privileges/PrivilegesEvaluator.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/privileges/PrivilegesEvaluator.java#L474

Added line #L474 was not covered by tests
}

// TODO exclude Security index
Expand Down Expand Up @@ -561,7 +561,7 @@
user,
requestedResolved,
action0,
securityRoles.getRoleNames()
mappedRoles
);
log.info("No permissions for {}", presponse.missingPrivileges);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -23,7 +24,6 @@
import org.opensearch.common.settings.Settings;
import org.opensearch.security.auditlog.AuditLog;
import org.opensearch.security.resolver.IndexResolverReplacer;
import org.opensearch.security.securityconf.SecurityRoles;
import org.opensearch.security.support.ConfigConstants;
import org.opensearch.security.support.WildcardMatcher;
import org.opensearch.tasks.Task;
Expand Down Expand Up @@ -73,31 +73,29 @@ public PrivilegesEvaluatorResponse evaluate(
final String action,
final IndexResolverReplacer.Resolved requestedResolved,
final PrivilegesEvaluatorResponse presponse,
final SecurityRoles securityRoles
final Set<String> mappedRoles
) {
if (!protectedIndexEnabled) {
return presponse;
}
if (!requestedResolved.isLocalAll()
&& indexMatcher.matchAny(requestedResolved.getAllIndices())
&& deniedActionMatcher.test(action)
&& !allowedRolesMatcher.matchAny(securityRoles.getRoleNames())) {
&& !allowedRolesMatcher.matchAny(mappedRoles)) {
auditLog.logMissingPrivileges(action, request, task);
log.warn("{} for '{}' index/indices is not allowed for a regular user", action, indexMatcher);
presponse.allowed = false;
return presponse.markComplete();
}

if (requestedResolved.isLocalAll()
&& deniedActionMatcher.test(action)
&& !allowedRolesMatcher.matchAny(securityRoles.getRoleNames())) {
if (requestedResolved.isLocalAll() && deniedActionMatcher.test(action) && !allowedRolesMatcher.matchAny(mappedRoles)) {
auditLog.logMissingPrivileges(action, request, task);
log.warn("{} for '_all' indices is not allowed for a regular user", action);
presponse.allowed = false;
return presponse.markComplete();
}
if ((requestedResolved.isLocalAll() || indexMatcher.matchAny(requestedResolved.getAllIndices()))
&& !allowedRolesMatcher.matchAny(securityRoles.getRoleNames())) {
&& !allowedRolesMatcher.matchAny(mappedRoles)) {

final boolean isDebugEnabled = log.isDebugEnabled();
if (request instanceof SearchRequest) {
Expand Down
Loading