Spring Boot actuator page returning http links instead of https

Viewed 599

I have a Spring Boot 2.0.2 application. When I browse to the following URL: https://my-domain-name/my-application-name/actuator, I'm getting the following output:

{
    "_links": {
        "self": {
            "href": "http://my-domain-name/my-application-name/actuator",
            "templated": false
        },
        "health": {
            "href": "http://my-domain-name/my-application-name/actuator/health",
            "templated": false
        },
        "info": {
            "href": "http://my-domain-name/my-application-name/actuator/info",
            "templated": false
        }
    }
}

As you can see, the content is OK but all links start with 'http', and not with https. Nevertheless, I'm accessing the URL with HTTPS.

The domain name I'm trying to reach is an AWS Route 53 record, with an alias to an AWS ELB. This ELB redirects the call to a target which is a K8S cluster. The pod itself is running Nginx which redirects the URL to another pod which runs Spring Boot with an embedded Tomcat and it's serving its content using HTTP and port 8080.

For the Nginx, there's a proxy pass configuration:

location /my-application-name { proxy_pass http://my-application-name; }

The following headers are being added:

proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;

... so that Spring Boot will know the 'original' request.

Anybody an idea what I'm doing wrong? It seems like the actuator implementation is not taking into account the HTTPS protocol

1 Answers

I solved the issue by adding this code block in a configuration class:

@Bean
public FilterRegistrationBean forwardedHeaderFilterRegistration() {
    ForwardedHeaderFilter filter = new ForwardedHeaderFilter();
    FilterRegistrationBean<ForwardedHeaderFilter> registration = new FilterRegistrationBean<>(filter);
    registration.setName("forwardedHeaderFilter");
    registration.setOrder(10000);
    return registration;
}

It seems like the ForwardedHeaderFilterdoes take the X-Forwarded-Proto header into account. Although it's still very unclear why the actuator implementation doesn't do this by default (because the other X-Forwarded headers are being treated correctly)

Related