[
https://issues.apache.org/jira/browse/ARTEMIS-3915?focusedWorklogId=982677&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-982677
]
ASF GitHub Bot logged work on ARTEMIS-3915:
-------------------------------------------
Author: ASF GitHub Bot
Created on: 10/Sep/25 18:16
Start Date: 10/Sep/25 18:16
Worklog Time Spent: 10m
Work Description: tabish121 commented on code in PR #5908:
URL: https://github.com/apache/activemq-artemis/pull/5908#discussion_r2337553736
##########
artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/HAProxyMessageHandler.java:
##########
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.artemis.core.remoting.impl.netty;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInboundHandlerAdapter;
+import io.netty.handler.codec.haproxy.HAProxyMessage;
+
+import static
org.apache.activemq.artemis.utils.ProxyProtocolUtil.PROXY_PROTOCOL_DESTINATION_ADDRESS;
+import static
org.apache.activemq.artemis.utils.ProxyProtocolUtil.PROXY_PROTOCOL_SOURCE_ADDRESS;
+import static
org.apache.activemq.artemis.utils.ProxyProtocolUtil.PROXY_PROTOCOL_VERSION;
+
+public class HAProxyMessageHandler extends ChannelInboundHandlerAdapter {
Review Comment:
As I understand things the case where an HA Proxy frontend is expected this
handler should not pass through any bytes if the remote has not sent the proxy
header first so I'd expect it would throw on the current path where it checks
the skip bytes tracking. No I get that HAProxyDecoder should have already
failed but it seems at this level we should just build in precautions that
protect against any expected cases that might arise from future code changes.
We could also just add the HAProxyDecoder into the pipeline here and not
have it managed in the NettyAcceptor code which also adds this type into the
pipeline making this fully self contained. Possibly something along the lines
of the following:
```
public class HAProxyMessageHandler extends ChannelInboundHandlerAdapter {
private static final String HA_PROXY_DECODER_ID =
"ARTEMIS_HA_PROXY_DECODER_INSTANCE";
@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
ctx.pipeline().addFirst(HA_PROXY_DECODER_ID, new
HAProxyMessageDecoder());
}
@Override
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
ctx.pipeline().remove(HA_PROXY_DECODER_ID);
}
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws
Exception {
if (msg instanceof HAProxyMessage haProxyMessage) {
ctx.channel().attr(PROXY_PROTOCOL_SOURCE_ADDRESS).set(haProxyMessage.sourceAddress()
+ ":" + Integer.toString(haProxyMessage.sourcePort()));
ctx.channel().attr(PROXY_PROTOCOL_DESTINATION_ADDRESS).set(haProxyMessage.destinationAddress()
+ ":" + Integer.toString(haProxyMessage.destinationPort()));
ctx.channel().attr(PROXY_PROTOCOL_VERSION).set(haProxyMessage.protocolVersion().toString());
// once we get the HAProxyMessage and set the proper attributes our
job is done
ctx.pipeline().remove(this);
// slice off the proxy-related bytes that have already been read so
other protocol handlers don't choke on them
ctx.fireChannelRead(((ByteBuf) msg).slice());
} else {
throw new IOException("Should not processes anything other than
HAProxy messages in this handler");
}
}
}
```
Issue Time Tracking
-------------------
Worklog Id: (was: 982677)
Time Spent: 6h 40m (was: 6.5h)
> Support PROXY Protocol
> ----------------------
>
> Key: ARTEMIS-3915
> URL: https://issues.apache.org/jira/browse/ARTEMIS-3915
> Project: ActiveMQ Artemis
> Issue Type: Improvement
> Components: Broker
> Reporter: João Santos
> Assignee: Justin Bertram
> Priority: Major
> Labels: pull-request-available
> Time Spent: 6h 40m
> Remaining Estimate: 0h
>
> [HAProxy|http://www.haproxy.org/] is a widely known and used TCP Load
> Balancer and especially useful for an ActiveMQ Artemis clustered environment.
> Although possible to functionally implement with both products current
> features, Artemis does not support the PROXY protocol, which prevents it's
> broker nodes from inferring the real remote client IP address when behind an
> HAProxy instance.
> Since Netty sockets implementation already seems to support this protocol
> (discussed w/ [~jbertram] on DEV mailing list), it shouldn't be a big leap to
> adding support for the protocol on Artemis acceptors, thus improving the
> deployment of the use case at hand.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact