question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

add configuration option for Proxy Protocol

See original GitHub issue

Dropwizard currently provides a configuration option to read X-Forwarded-* headers, useForwardedHeaders, but provides no similar configuration option to read HAProxy PROXY protocol data frames, such as those able to be sent through by AWS ELBs. The NGINX blog has a write-up about this as well.

In vanilla Jetty, this is accomplished using the ProxyConnectionFactory, as described in Jetty’s docs on configuring Connectors.

Dropwizard should include a configuration option to support reading the PROXY protocol.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
sseshacommented, Feb 2, 2019

One way around this currently is to create and register another command which is a clone of the Server Command. I just changed the run method to add the ProxyConnectionFactory like so:

protected void run(Environment environment, Namespace namespace, T configuration) throws Exception {
final Server server = configuration.getServerFactory().build(environment);
try {
server.addLifeCycleListener(new LifeCycleListener());
cleanupAsynchronously();

  //Enable proxy protocol parsing for all connectors
  for (Connector connector : server.getConnectors()) {
    if (connector instanceof ServerConnector) {
      ServerConnector serverConnector = (ServerConnector) connector;
      LOGGER.info("proxy protocol parsing enabled on {} port {}", serverConnector.getName() , serverConnector.getLocalPort());
      serverConnector.addFirstConnectionFactory(new ProxyConnectionFactory());
    }
  }

  server.start();
} catch (Exception e) {
  LOGGER.error("Unable to start server, shutting down", e);
  try {
    server.stop();
  } catch (Exception e1) {
    LOGGER.warn("Failure during stop server", e1);
  }
  try {
    cleanup();
  } catch (Exception e2) {
    LOGGER.warn("Failure during cleanup", e2);
  }
  throw e;
}
}

and registered this as a separate command in the initialize phase of my Application

 @Override
  public void initialize (Bootstrap<ProxyConfiguration> configurationBootstrap) {
    configurationBootstrap.addCommand(new ProxyServerCommand<>(this));
  }
0reactions
tyagiakhileshcommented, Mar 26, 2019

I tried the suggested solution but it doesn’t work! If I do as stated above, then not sure, exactly at what point does this break, but with my haproxy setup, I see

Bad Message 400

reason: Illegal character 0x0

I tested this with pure jetty. The above error happens when server side is not able to handle proxy protocol header.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configure proxy protocol support for your Classic Load Balancer
To enable proxy protocol, you must create a policy of type ProxyProtocolPolicyType and then enable the policy on the instance port. Use the...
Read more >
Accepting the PROXY Protocol | NGINX Plus
This article explains how to configure NGINX and NGINX Plus to accept the PROXY protocol, rewrite the IP address of a load balancer...
Read more >
Enable Proxy protocol · Cloudflare Spectrum docs
Locate the application that will use the PROXY protocol and click Configure. From the dropdown, select PROXY Protocol v1.
Read more >
Configuring the HAProxy Router to Use the PROXY Protocol
To simplify subsequent steps, first set some shell variables: · Next, create the ELB with the appropriate listeners, security groups, and subnets. ·...
Read more >
Configure proxy protocol support for your Classic Load Balancer
If you enable proxy protocol, a human-readable header is added to the request header with connection information such as the source IP address,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found