forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
User Profile - Add new action origin and internal user (elastic#86026)
Profile documents are stored in a separate system index from the main security index. Hence a more scoped origin and internal user is better than the all powerful _xpack_security user. This PR adds _security_profile user that has privileges only over the profile index and updates all profile related actions to use it.
- Loading branch information
Showing
14 changed files
with
240 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pr: 86026 | ||
summary: User Profile - Add new action origin and internal user | ||
area: Security | ||
type: enhancement | ||
issues: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...in/core/src/main/java/org/elasticsearch/xpack/core/security/user/SecurityProfileUser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
package org.elasticsearch.xpack.core.security.user; | ||
|
||
import org.elasticsearch.xpack.core.security.authz.RoleDescriptor; | ||
import org.elasticsearch.xpack.core.security.support.MetadataUtils; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* internal user that manages the security profile index. Has no cluster permission. | ||
*/ | ||
public class SecurityProfileUser extends User { | ||
|
||
public static final String NAME = UsernamesField.SECURITY_PROFILE_NAME; | ||
public static final SecurityProfileUser INSTANCE = new SecurityProfileUser(); | ||
private static final String ROLE_NAME = UsernamesField.SECURITY_PROFILE_ROLE; | ||
public static final RoleDescriptor ROLE_DESCRIPTOR = new RoleDescriptor( | ||
ROLE_NAME, | ||
null, | ||
new RoleDescriptor.IndicesPrivileges[] { | ||
RoleDescriptor.IndicesPrivileges.builder() | ||
.indices(".security-profile", "/\\.security-profile-[0-9].*/") | ||
.privileges("all") | ||
.allowRestrictedIndices(true) | ||
.build() }, | ||
null, | ||
null, | ||
null, | ||
MetadataUtils.DEFAULT_RESERVED_METADATA, | ||
Map.of() | ||
); | ||
|
||
private SecurityProfileUser() { | ||
super(NAME, ROLE_NAME); | ||
// the following traits, and especially the run-as one, go with all the internal users | ||
// TODO abstract in a base `InternalUser` class | ||
assert false == isRunAs() : "cannot run-as the system user"; | ||
assert enabled(); | ||
assert roles() != null && roles().length == 1; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
return INSTANCE == o; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return System.identityHashCode(this); | ||
} | ||
|
||
public static boolean is(User user) { | ||
return INSTANCE.equals(user); | ||
} | ||
|
||
public static boolean is(String principal) { | ||
return NAME.equals(principal); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.