Skip to content

Commit b80485a

Browse files
committed
WIP on Creating Kibana admin level that's different then write and allows settings to be updated
Signed-off-by: Craig Perkins <[email protected]>
1 parent 5212eed commit b80485a

File tree

4 files changed

+45
-4
lines changed

4 files changed

+45
-4
lines changed

src/main/java/org/opensearch/security/configuration/PrivilegesInterceptorImpl.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.opensearch.action.admin.indices.refresh.RefreshRequest;
3333
import org.opensearch.action.bulk.BulkRequest;
3434
import org.opensearch.action.delete.DeleteRequest;
35+
import org.opensearch.action.get.GetRequest;
3536
import org.opensearch.action.get.MultiGetRequest;
3637
import org.opensearch.action.get.MultiGetRequest.Item;
3738
import org.opensearch.action.index.IndexRequest;
@@ -141,13 +142,19 @@ public ReplaceResult replaceDashboardsIndex(
141142
&& resolveToDashboardsIndexOrAlias(requestedResolved, dashboardsIndexName);
142143
final boolean isTraceEnabled = log.isTraceEnabled();
143144

145+
144146
TenantPrivileges.ActionType actionType = getActionTypeForAction(action);
145147

146148
if (requestedTenant == null || requestedTenant.length() == 0) {
147149
if (isTraceEnabled) {
148150
log.trace("No tenant, will resolve to " + dashboardsIndexName);
149151
}
150152

153+
// Intercept when request is dashboards user and request is to get advanced settings. No replacement.
154+
if ("osd:admin/advanced_settings".equals(action)) {
155+
return ACCESS_GRANTED_REPLACE_RESULT;
156+
}
157+
151158
if (dashboardsIndexOnly && !tenantPrivileges.hasTenantPrivilege(context, "global_tenant", actionType)) {
152159
return ACCESS_DENIED_REPLACE_RESULT;
153160
}
@@ -199,6 +206,20 @@ public ReplaceResult replaceDashboardsIndex(
199206

200207
final String tenantIndexName = toUserIndexName(dashboardsIndexName, requestedTenant);
201208

209+
System.out.println("tenantIndexName: " + tenantIndexName);
210+
System.out.println("user: " + user);
211+
System.out.println("action: " + action);
212+
System.out.println("requestResolved: " + requestedResolved.getAllIndices());
213+
if (request instanceof GetRequest gr) {
214+
System.out.println("GetRequest: " + gr.id());
215+
} else if (request instanceof SearchRequest sr) {
216+
System.out.println("SearchRequest: " + sr.source().toString());
217+
}
218+
// Intercept when request is dashboards user and request is to get advanced settings
219+
if ("osd:admin/advanced_settings".equals(action)) {
220+
return newAccessGrantedReplaceResult(replaceIndex(request, dashboardsIndexName, tenantIndexName, action));
221+
}
222+
202223
// The new DLS/FLS implementation defaults to a "deny all" pattern in case no roles are configured
203224
// for an index. As the PrivilegeInterceptor grants access to indices bypassing index privileges,
204225
// we need to allow-list these indices.
@@ -233,7 +254,9 @@ private void applyDocumentAllowList(String indexName) {
233254
}
234255

235256
static TenantPrivileges.ActionType getActionTypeForAction(String action) {
236-
if (READ_ONLY_ALLOWED_ACTIONS.contains(action)) {
257+
if ("osd:admin/advanced_settings".equals(action)) {
258+
return TenantPrivileges.ActionType.ADMIN;
259+
} else if (READ_ONLY_ALLOWED_ACTIONS.contains(action)) {
237260
return TenantPrivileges.ActionType.READ;
238261
} else {
239262
return TenantPrivileges.ActionType.WRITE;

src/main/java/org/opensearch/security/privileges/TenantPrivileges.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ public class TenantPrivileges {
5050
*/
5151
public enum ActionType {
5252
READ,
53-
WRITE;
53+
WRITE,
54+
ADMIN;
5455
}
5556

5657
public static final TenantPrivileges EMPTY = new TenantPrivileges(
@@ -61,6 +62,7 @@ public enum ActionType {
6162

6263
private static final List<ActionType> READ = ImmutableList.of(ActionType.READ);
6364
private static final List<ActionType> READ_WRITE = ImmutableList.of(ActionType.READ, ActionType.WRITE);
65+
private static final List<ActionType> READ_WRITE_ADMIN = ImmutableList.of(ActionType.READ, ActionType.WRITE, ActionType.ADMIN);
6466

6567
private static final Logger log = LogManager.getLogger(TenantPrivileges.class);
6668

@@ -245,7 +247,9 @@ public Map<String, Boolean> tenantMap(PrivilegesEvaluationContext context) {
245247

246248
static List<ActionType> resolveActionType(Collection<String> allowedActions, FlattenedActionGroups actionGroups) {
247249
ImmutableSet<String> permissions = actionGroups.resolve(allowedActions);
248-
if (permissions.contains("kibana:saved_objects/*/write")) {
250+
if (permissions.contains("osd:admin/advanced_settings")) {
251+
return READ_WRITE_ADMIN;
252+
} else if (permissions.contains("kibana:saved_objects/*/write")) {
249253
return READ_WRITE;
250254
} else {
251255
return READ;

src/main/resources/static_config/static_action_groups.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,17 @@ kibana_all_write:
88
static: true
99
allowed_actions:
1010
- "kibana:saved_objects/*/write"
11+
- "osd:admin/advanced_settings"
1112
type: "kibana"
12-
description: "Allow writing in all OpenSearch Dashboards apps"
13+
description: "Allow writing in all OpenSearch Dashboards apps including advanced settings"
14+
kibana_only_write:
15+
reserved: true
16+
hidden: false
17+
static: true
18+
allowed_actions:
19+
- "kibana:saved_objects/*/write"
20+
type: "kibana"
21+
description: "Allow writing in OpenSearch Dashboards apps except config (advanced settings)"
1322
kibana_all_read:
1423
reserved: true
1524
hidden: false

src/main/resources/static_config/static_roles.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ kibana_server:
116116
- "*"
117117
allowed_actions:
118118
- "indices:admin/aliases*"
119+
tenant_permissions:
120+
- tenant_patterns:
121+
- "*"
122+
allowed_actions:
123+
- "kibana_all_write"
119124

120125
logstash:
121126
reserved: true

0 commit comments

Comments
 (0)