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

[Forwardport main] Switch to supportsImpersonation check for http auth backend and add Privileged Action for JwtParserBuilder #3579

Merged
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 @@ -61,7 +61,6 @@
import org.opensearch.security.filter.SecurityRequest;
import org.opensearch.security.filter.SecurityRequestChannel;
import org.opensearch.security.filter.SecurityResponse;
import org.opensearch.security.http.OnBehalfOfAuthenticator;
import org.opensearch.security.http.XFFResolver;
import org.opensearch.security.securityconf.DynamicConfigModel;
import org.opensearch.security.support.ConfigConstants;
Expand Down Expand Up @@ -619,8 +618,7 @@ private User impersonate(final SecurityRequest request, final User originalUser)
for (final AuthDomain authDomain : restAuthDomains) {
final AuthenticationBackend authenticationBackend = authDomain.getBackend();

// Skip over the OnBehalfOfAuthenticator since it is not compatible for user impersonation
if (authDomain.getHttpAuthenticator() instanceof OnBehalfOfAuthenticator) {
if (!authDomain.getHttpAuthenticator().supportsImpersonation()) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,13 @@ public interface HTTPAuthenticator {
* @return Optional response if is not supported/necessary, response object otherwise.
*/
Optional<SecurityResponse> reRequestAuthentication(final SecurityRequest request, AuthCredentials credentials);

/**
* Indicates whether this authenticator supports user impersonation.
*
* @return true if impersonation is supported, false otherwise.
*/
default boolean supportsImpersonation() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,18 @@
String oboEnabledSetting = settings.get("enabled", "true");
oboEnabled = Boolean.parseBoolean(oboEnabledSetting);
encryptionKey = settings.get("encryption_key");
JwtParserBuilder builder = initParserBuilder(settings.get("signing_key"));
jwtParser = builder.build();

final SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(new SpecialPermission());
}
jwtParser = AccessController.doPrivileged(new PrivilegedAction<JwtParser>() {
@Override
public JwtParser run() {
JwtParserBuilder builder = initParserBuilder(settings.get("signing_key"));
return builder.build();
}
});

this.clusterName = clusterName;
this.encryptionUtil = new EncryptionDecryptionUtil(encryptionKey);
Expand Down Expand Up @@ -244,4 +254,8 @@
return "onbehalfof_jwt";
}

@Override
public boolean supportsImpersonation() {
return false;

Check warning on line 259 in src/main/java/org/opensearch/security/http/OnBehalfOfAuthenticator.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/http/OnBehalfOfAuthenticator.java#L259

Added line #L259 was not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ public void testSecurityManagerCheck() {
System.setSecurityManager(null);
}

verify(mockSecurityManager, times(2)).checkPermission(any(SpecialPermission.class));
verify(mockSecurityManager, times(3)).checkPermission(any(SpecialPermission.class));
}

@Test
Expand Down
Loading