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

Fix TraceableTcpTransportChannel classcast exception #3514

Closed
Show file tree
Hide file tree
Changes from 2 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 @@ -18,7 +18,6 @@

import javax.net.ssl.SSLEngine;

import org.opensearch.http.netty4.Netty4HttpChannel;
import org.opensearch.rest.RestRequest;
import org.opensearch.rest.RestRequest.Method;

Expand All @@ -42,21 +41,11 @@ public Map<String, List<String>> getHeaders() {

@Override
public SSLEngine getSSLEngine() {
if (underlyingRequest == null
|| underlyingRequest.getHttpChannel() == null
|| !(underlyingRequest.getHttpChannel() instanceof Netty4HttpChannel)) {
if (underlyingRequest == null || underlyingRequest.getHttpChannel() == null) {
return null;
}

// We look for Ssl_handler called `ssl_http` in the outbound pipeline of Netty channel first, and if its not
// present we look for it in inbound channel. If its present in neither we return null, else we return the sslHandler.
final Netty4HttpChannel httpChannel = (Netty4HttpChannel) underlyingRequest.getHttpChannel();
SslHandler sslhandler = (SslHandler) httpChannel.getNettyChannel().pipeline().get("ssl_http");
if (sslhandler == null && httpChannel.inboundPipeline() != null) {
sslhandler = (SslHandler) httpChannel.inboundPipeline().get("ssl_http");
}

return sslhandler != null ? sslhandler.engine() : null;
return underlyingRequest.getHttpChannel().get("ssl_http", SslHandler.class).map(SslHandler::engine).orElse(null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,9 @@
import org.opensearch.security.support.ConfigConstants;
import org.opensearch.tasks.Task;
import org.opensearch.threadpool.ThreadPool;
import org.opensearch.transport.TaskTransportChannel;
import org.opensearch.transport.TcpChannel;
import org.opensearch.transport.TcpTransportChannel;
import org.opensearch.transport.TransportChannel;
import org.opensearch.transport.TransportRequest;
import org.opensearch.transport.TransportRequestHandler;
import org.opensearch.transport.netty4.Netty4TcpChannel;

public class SecuritySSLRequestHandler<T extends TransportRequest> implements TransportRequestHandler<T> {

Expand Down Expand Up @@ -108,21 +104,7 @@ public final void messageReceived(T request, TransportChannel channel, Task task
}

try {

Netty4TcpChannel nettyChannel = null;

DarshitChanpura marked this conversation as resolved.
Show resolved Hide resolved
if (channel instanceof TaskTransportChannel) {
final TransportChannel inner = ((TaskTransportChannel) channel).getChannel();
nettyChannel = (Netty4TcpChannel) ((TcpTransportChannel) inner).getChannel();
} else if (channel instanceof TcpTransportChannel) {
final TcpChannel inner = ((TcpTransportChannel) channel).getChannel();
nettyChannel = (Netty4TcpChannel) inner;
} else {
throw new Exception("Invalid channel of type " + channel.getClass() + " (" + channel.getChannelType() + ")");
}

final SslHandler sslhandler = (SslHandler) nettyChannel.getNettyChannel().pipeline().get("ssl_server");

final SslHandler sslhandler = channel.get("ssl_server", SslHandler.class).orElse(null);
if (sslhandler == null) {
if (SSLConfig.isDualModeEnabled()) {
log.info("Communication in dual mode. Skipping SSL handler check");
Expand Down
Loading