Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b9cfc6f
add user attributes to thread context
markdboyd May 9, 2025
4e28c1b
re-add base64 encoding of serialized user custom attributes & null wh…
markdboyd Jul 21, 2025
8522ea3
add entry to CHANGELOG
markdboyd Jul 21, 2025
3e685e1
remove extraneous edits to CHANGELOG
markdboyd Jul 21, 2025
050583b
remove change to add null requested tenant
markdboyd Jul 21, 2025
1e1e1dd
add ImmutableMap to SAFE_ASSIGNABLE_FROM_CLASSES in SafeSerialization…
markdboyd Jul 21, 2025
032d72d
add plugins.security.user_attribute_serialization.enabled setting to …
markdboyd Jul 21, 2025
bf43965
add PrivilegesEvaluator.isUserAttributeSerializationEnabled() to chec…
markdboyd Jul 21, 2025
9235d09
apply feedback and spotless formatting
markdboyd Jul 21, 2025
067c8fb
re-add null requested tenant to keep number of items in thread contex…
markdboyd Jul 21, 2025
6db2e3f
fix typo
markdboyd Jul 21, 2025
d5065c9
update TestSecurityConfig.User to have custom user attributes
markdboyd Jul 23, 2025
aff3e5d
log parsed user in CreateResourceTransportAction.doExecute
markdboyd Jul 23, 2025
34f6166
update SafeSerializationUtils.SAFE_CLASS_NAMES
markdboyd Jul 23, 2025
5c8db0a
update common_utils_version for sample-resource-plugin
markdboyd Jul 23, 2025
6f98bf5
add integrationTestImplementation for sample-resource-plugin
markdboyd Jul 23, 2025
13551e9
apply spotless formatting
markdboyd Jul 23, 2025
5703faf
move user serialization/deserialization integration tests to a separa…
markdboyd Jul 24, 2025
d7ba240
remove debugging output
markdboyd Jul 24, 2025
69ad91e
fix bad CHANGELOG merge
markdboyd Jul 29, 2025
41a4b02
fix bad CHANGELOG merge
markdboyd Jul 29, 2025
5217e14
add spotlessApply fixes
markdboyd Aug 4, 2025
5baf96b
apply spotless formatting
markdboyd Aug 4, 2025
5f195ca
fix bad CHANGELOG merge
markdboyd Aug 4, 2025
55a401e
fix bad merge in setUserInfoInThreadContext
markdboyd Aug 4, 2025
47dbec7
revert special handling of requested tenant when setting user info in…
markdboyd Aug 6, 2025
c161d33
remove unnecessary plugin tests
markdboyd Aug 6, 2025
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
* Fix usage of jwt_clock_skew_tolerance_seconds in HTTPJwtAuthenticator ([#5506](https://github.com/opensearch-project/security/pull/5506))
* Always install demo certs if configured with demo certs ([#5517](https://github.com/opensearch-project/security/pull/5517))
* [Resource Sharing] Restores client accessor pattern to fix compilation issues when security plugin is not installed ([#5541](https://github.com/opensearch-project/security/pull/5541))
* Add serialized user custom attributes to the the thread context ([#5491](https://github.com/opensearch-project/security/pull/5491))

### Refactoring

Expand Down
3 changes: 2 additions & 1 deletion sample-resource-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ ext {
licenseFile = rootProject.file('LICENSE.txt')
noticeFile = rootProject.file('NOTICE.txt')

common_utils_version = System.getProperty("common_utils.version", "3.1.0.0")
common_utils_version = System.getProperty("common_utils.version", "3.2.0.0-SNAPSHOT")
}

repositories {
Expand Down Expand Up @@ -80,6 +80,7 @@ dependencies {
integrationTestImplementation rootProject.sourceSets.integrationTest.output
integrationTestImplementation rootProject.sourceSets.main.output
integrationTestImplementation "org.opensearch.client:opensearch-rest-high-level-client:${opensearch_version}"
integrationTestImplementation 'org.ldaptive:ldaptive:1.2.3'

// To be removed once integration test framework supports extended plugins
integrationTestImplementation project(path: ":${rootProject.name}-spi", configuration: 'shadow')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,8 @@ public int hashCode() {

public static final class User implements UserCredentialsHolder, ToXContentObject {

public final static TestSecurityConfig.User USER_ADMIN = new User("admin").roles(
new Role("allaccess").indexPermissions("*").on("*").clusterPermissions("*")
);
public final static TestSecurityConfig.User USER_ADMIN = new User("admin").attr("attr1", "val1")
.roles(new Role("allaccess").indexPermissions("*").on("*").clusterPermissions("*"));

String name;
private String password;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2230,6 +2230,15 @@ public List<Setting<?>> getSettings() {
Property.Final
)
);

settings.add(
Setting.boolSetting(
ConfigConstants.USER_ATTRIBUTE_SERIALIZATION_ENABLED,
ConfigConstants.USER_ATTRIBUTE_SERIALIZATION_ENABLED_DEFAULT,
Property.NodeScope,
Property.Filtered
)
);
}

return settings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

package org.opensearch.security.privileges;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -103,6 +104,7 @@
import org.opensearch.security.securityconf.impl.v7.ActionGroupsV7;
import org.opensearch.security.securityconf.impl.v7.RoleV7;
import org.opensearch.security.securityconf.impl.v7.TenantV7;
import org.opensearch.security.support.Base64Helper;
import org.opensearch.security.support.ConfigConstants;
import org.opensearch.security.support.WildcardMatcher;
import org.opensearch.security.user.User;
Expand All @@ -113,6 +115,8 @@

import static org.opensearch.security.OpenSearchSecurityPlugin.traceAction;
import static org.opensearch.security.support.ConfigConstants.OPENDISTRO_SECURITY_USER_INFO_THREAD_CONTEXT;
import static org.opensearch.security.support.ConfigConstants.USER_ATTRIBUTE_SERIALIZATION_ENABLED;
import static org.opensearch.security.support.ConfigConstants.USER_ATTRIBUTE_SERIALIZATION_ENABLED_DEFAULT;
import static org.opensearch.security.support.SecurityUtils.escapePipe;

public class PrivilegesEvaluator {
Expand Down Expand Up @@ -283,6 +287,10 @@ public boolean isInitialized() {
return configModel != null && dcm != null && actionPrivileges.get() != null;
}

private boolean isUserAttributeSerializationEnabled() {
return this.settings.getAsBoolean(USER_ATTRIBUTE_SERIALIZATION_ENABLED, USER_ATTRIBUTE_SERIALIZATION_ENABLED_DEFAULT);
}

private void setUserInfoInThreadContext(PrivilegesEvaluationContext context) {
if (threadContext.getTransient(OPENDISTRO_SECURITY_USER_INFO_THREAD_CONTEXT) == null) {
StringJoiner joiner = new StringJoiner("|");
Expand All @@ -293,9 +301,15 @@ private void setUserInfoInThreadContext(PrivilegesEvaluationContext context) {

String requestedTenant = context.getUser().getRequestedTenant();
joiner.add(requestedTenant);

String tenantAccessToCheck = getTenancyAccess(context);
joiner.add(tenantAccessToCheck);
log.debug(joiner);

if (this.isUserAttributeSerializationEnabled()) {
joiner.add(Base64Helper.serializeObject((Serializable) context.getUser().getCustomAttributesMap()));
}

threadContext.putTransient(OPENDISTRO_SECURITY_USER_INFO_THREAD_CONTEXT, joiner.toString());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,9 @@ public enum RolesMappingResolution {
public static final String SECURITY_CONFIG_VERSION_RETENTION_COUNT = SECURITY_SETTINGS_PREFIX + "config_version.retention_count";
public static final int SECURITY_CONFIG_VERSION_RETENTION_COUNT_DEFAULT = 10;

public static final String USER_ATTRIBUTE_SERIALIZATION_ENABLED = SECURITY_SETTINGS_PREFIX + "user_attribute_serialization.enabled";
public static final boolean USER_ATTRIBUTE_SERIALIZATION_ENABLED_DEFAULT = false;

// On-behalf-of endpoints settings
// CS-SUPPRESS-SINGLE: RegexpSingleline get Extensions Settings
public static final String EXTENSIONS_BWC_PLUGIN_MODE = "bwcPluginMode";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Pattern;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;

import com.amazon.dlic.auth.ldap.LdapUser;
Expand Down Expand Up @@ -58,10 +58,15 @@ public final class SafeSerializationUtils {
Number.class,
Collection.class,
Map.class,
Enum.class
Enum.class,
ImmutableMap.class
);

private static final Set<String> SAFE_CLASS_NAMES = Collections.singleton("org.ldaptive.LdapAttribute$LdapAttributeValues");
private static final Set<String> SAFE_CLASS_NAMES = Set.of(
"org.ldaptive.LdapAttribute$LdapAttributeValues",
"com.google.common.collect.ImmutableBiMap$SerializedForm",
"com.google.common.collect.ImmutableMap$SerializedForm"
);
static final Map<Class<?>, Boolean> safeClassCache = new ConcurrentHashMap<>();

static boolean isSafeClass(Class<?> cls) {
Expand Down
Loading