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

[Issue-13782] Add Search RBAC config option in settings #17866

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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 @@ -57,6 +57,7 @@
import org.openmetadata.schema.analytics.WebAnalyticEvent;
import org.openmetadata.schema.api.configuration.LoginConfiguration;
import org.openmetadata.schema.api.configuration.profiler.ProfilerConfiguration;
import org.openmetadata.schema.api.rbac.RbacSearchConfiguration;
import org.openmetadata.schema.auth.EmailVerificationToken;
import org.openmetadata.schema.auth.PasswordResetToken;
import org.openmetadata.schema.auth.PersonalAccessToken;
Expand Down Expand Up @@ -4580,6 +4581,8 @@ public static Settings getSettings(SettingsType configType, String json) {
case SLACK_APP_CONFIGURATION, SLACK_INSTALLER, SLACK_BOT, SLACK_STATE -> JsonUtils
.readValue(json, String.class);
case PROFILER_CONFIGURATION -> JsonUtils.readValue(json, ProfilerConfiguration.class);
case RBAC_SEARCH_CONFIGURATION -> JsonUtils.readValue(
json, RbacSearchConfiguration.class);
default -> throw new IllegalArgumentException("Invalid Settings Type " + configType);
};
settings.setConfigValue(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import static org.openmetadata.schema.settings.SettingsType.CUSTOM_UI_THEME_PREFERENCE;
import static org.openmetadata.schema.settings.SettingsType.EMAIL_CONFIGURATION;
import static org.openmetadata.schema.settings.SettingsType.LOGIN_CONFIGURATION;
import static org.openmetadata.schema.settings.SettingsType.RBAC_SEARCH_CONFIGURATION;

import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
Expand All @@ -28,6 +29,7 @@
import org.openmetadata.api.configuration.ThemeConfiguration;
import org.openmetadata.api.configuration.UiThemePreference;
import org.openmetadata.schema.api.configuration.LoginConfiguration;
import org.openmetadata.schema.api.rbac.RbacSearchConfiguration;
import org.openmetadata.schema.email.SmtpSettings;
import org.openmetadata.schema.settings.Settings;
import org.openmetadata.schema.settings.SettingsType;
Expand Down Expand Up @@ -111,6 +113,18 @@ private static void createDefaultConfiguration(OpenMetadataApplicationConfig app
.withJwtTokenExpiryTime(3600));
systemRepository.createNewSetting(setting);
}

// Initialise Rbac Settings
Settings storedRbacSettings =
systemRepository.getConfigWithKey(RBAC_SEARCH_CONFIGURATION.toString());
if (storedRbacSettings == null) {
// Only in case a config doesn't exist in DB we insert it
Settings setting =
new Settings()
.withConfigType(RBAC_SEARCH_CONFIGURATION)
.withConfigValue(new RbacSearchConfiguration().withEnabled(false));
systemRepository.createNewSetting(setting);
}
}

public static <T> T getSetting(SettingsType settingName, Class<T> clazz) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,14 @@
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.jetbrains.annotations.NotNull;
import org.openmetadata.common.utils.CommonUtil;
import org.openmetadata.schema.api.rbac.RbacSearchConfiguration;
import org.openmetadata.schema.dataInsight.DataInsightChartResult;
import org.openmetadata.schema.dataInsight.custom.DataInsightCustomChart;
import org.openmetadata.schema.dataInsight.custom.DataInsightCustomChartResultList;
import org.openmetadata.schema.dataInsight.custom.FormulaHolder;
import org.openmetadata.schema.entity.data.EntityHierarchy__1;
import org.openmetadata.schema.service.configuration.elasticsearch.ElasticSearchConfiguration;
import org.openmetadata.schema.settings.SettingsType;
import org.openmetadata.schema.tests.DataQualityReport;
import org.openmetadata.schema.type.EntityReference;
import org.openmetadata.schema.type.Include;
Expand All @@ -151,6 +153,7 @@
import org.openmetadata.service.Entity;
import org.openmetadata.service.dataInsight.DataInsightAggregatorInterface;
import org.openmetadata.service.jdbi3.DataInsightChartRepository;
import org.openmetadata.service.resources.settings.SettingsCache;
import org.openmetadata.service.search.SearchClient;
import org.openmetadata.service.search.SearchIndexUtils;
import org.openmetadata.service.search.SearchRequest;
Expand Down Expand Up @@ -2310,14 +2313,18 @@ public Object getLowLevelClient() {

private void buildSearchRBACQuery(
SubjectContext subjectContext, SearchSourceBuilder searchSourceBuilder) {
if (subjectContext != null && !subjectContext.isAdmin()) {
if (rbacConditionEvaluator != null) {
OMQueryBuilder rbacQuery = rbacConditionEvaluator.evaluateConditions(subjectContext);
searchSourceBuilder.query(
QueryBuilders.boolQuery()
.must(searchSourceBuilder.query())
.filter(((ElasticQueryBuilder) rbacQuery).build()));
}
if (Boolean.TRUE.equals(
mohityadav766 marked this conversation as resolved.
Show resolved Hide resolved
SettingsCache.getSetting(
SettingsType.RBAC_SEARCH_CONFIGURATION, RbacSearchConfiguration.class)
.getEnabled())
&& subjectContext != null
&& !subjectContext.isAdmin()
&& rbacConditionEvaluator != null) {
OMQueryBuilder rbacQuery = rbacConditionEvaluator.evaluateConditions(subjectContext);
searchSourceBuilder.query(
QueryBuilders.boolQuery()
.must(searchSourceBuilder.query())
.filter(((ElasticQueryBuilder) rbacQuery).build()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,14 @@
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.jetbrains.annotations.NotNull;
import org.openmetadata.common.utils.CommonUtil;
import org.openmetadata.schema.api.rbac.RbacSearchConfiguration;
import org.openmetadata.schema.dataInsight.DataInsightChartResult;
import org.openmetadata.schema.dataInsight.custom.DataInsightCustomChart;
import org.openmetadata.schema.dataInsight.custom.DataInsightCustomChartResultList;
import org.openmetadata.schema.dataInsight.custom.FormulaHolder;
import org.openmetadata.schema.entity.data.EntityHierarchy__1;
import org.openmetadata.schema.service.configuration.elasticsearch.ElasticSearchConfiguration;
import org.openmetadata.schema.settings.SettingsType;
import org.openmetadata.schema.tests.DataQualityReport;
import org.openmetadata.schema.type.EntityReference;
import org.openmetadata.schema.type.Include;
Expand All @@ -75,6 +77,7 @@
import org.openmetadata.service.Entity;
import org.openmetadata.service.dataInsight.DataInsightAggregatorInterface;
import org.openmetadata.service.jdbi3.DataInsightChartRepository;
import org.openmetadata.service.resources.settings.SettingsCache;
import org.openmetadata.service.search.SearchClient;
import org.openmetadata.service.search.SearchIndexUtils;
import org.openmetadata.service.search.SearchRequest;
Expand Down Expand Up @@ -2260,14 +2263,18 @@ public Object getLowLevelClient() {

private void buildSearchRBACQuery(
SubjectContext subjectContext, SearchSourceBuilder searchSourceBuilder) {
if (subjectContext != null && !subjectContext.isAdmin()) {
if (rbacConditionEvaluator != null) {
OMQueryBuilder rbacQuery = rbacConditionEvaluator.evaluateConditions(subjectContext);
searchSourceBuilder.query(
QueryBuilders.boolQuery()
.must(searchSourceBuilder.query())
.filter(((OpenSearchQueryBuilder) rbacQuery).build()));
}
if (Boolean.TRUE.equals(
SettingsCache.getSetting(
SettingsType.RBAC_SEARCH_CONFIGURATION, RbacSearchConfiguration.class)
.getEnabled())
&& subjectContext != null
&& !subjectContext.isAdmin()
&& rbacConditionEvaluator != null) {
OMQueryBuilder rbacQuery = rbacConditionEvaluator.evaluateConditions(subjectContext);
searchSourceBuilder.query(
QueryBuilders.boolQuery()
.must(searchSourceBuilder.query())
.filter(((OpenSearchQueryBuilder) rbacQuery).build()));
}
}
}
mohityadav766 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"$id": "https://open-metadata.org/schema/entity/configuration/rbacSearchConfiguration.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "RbacSearchConfiguration",
"description": "This schema defines the Rbac Search Configuration.",
"type": "object",
"javaType": "org.openmetadata.schema.api.rbac.RbacSearchConfiguration",
"properties": {
"enabled": {
"type": "boolean",
"description": "Flag to enable or disable the RBAC Search Configuration.",
"default": false
}
},
"additionalProperties": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"slackBot",
"slackInstaller",
"slackState",
"profilerConfiguration"
"profilerConfiguration",
"rbacSearchConfiguration"
]
}
},
Expand Down Expand Up @@ -72,6 +73,9 @@
},
{
"$ref": "../configuration/profilerConfiguration.json"
},
{
"$ref": "../configuration/rbacSearchConfiguration.json"
}
]
}
Expand Down
Loading