Zuul for AWS ELB over HTTPS / SSL

I have AWS Elastic Load Balancerwith certificates for my domain and which terminates traffic SSL. ELBhas a listener on the port httpsand forwards it as httpto Zuul.

When I use Spring Boot HATEOAS, Zuul will replace the links with the correct address, but httpinstead https:

"_links": {
  "self": {
    "href": "http://my.domain.com:80/rest/foo/bar"
  }
}

but I want:

"_links": {
  "self": {
    "href": "https://my.domain.com/rest/foo/bar"
  }
}

A request generating this response is being executed on https

Because Zuulit is behind the ELB, I assume that it cannot know that it should receive traffic through https.

Is there any way to say Zuulreplace links with help https, even if it receives unencrypted traffic through http?

, Zuul https , , .

+4
1

Zuul, , pre Zuul, PreDecorationFilter ( 5):

new ZuulFilter() {
        @Override
        public String filterType() {
            return "pre";
        }

        @Override
        public int filterOrder() {
            return 6; //PreDecorationFilter=5 + 1
        }

        @Override
        public boolean shouldFilter() {
            return true;
        }

        @Override
        public Object run() {
            RequestContext ctx = RequestContext.getCurrentContext();
            log.info(String.format("Before filter ['%s': '%s', '%s': '%s']",
                    ZuulHeaders.X_FORWARDED_PROTO.toLowerCase(),
                    ctx.getZuulRequestHeaders().get(ZuulHeaders.X_FORWARDED_PROTO.toLowerCase()),
                    "X-Forwarded-Port",
                    ctx.getZuulRequestHeaders().get("x-forwarded-port")));


            final String originalXForwardedProto = ctx.getRequest().getHeader(ZuulHeaders.X_FORWARDED_PROTO.toLowerCase());
            final String originalXForwardedPort = ctx.getRequest().getHeader("x-forwarded-port");

            if (!StringUtils.isEmpty(originalXForwardedProto)) {
                ctx.addZuulRequestHeader(ZuulHeaders.X_FORWARDED_PROTO.toLowerCase(), originalXForwardedProto);
            }

            if (!StringUtils.isEmpty(originalXForwardedPort)) {
                ctx.addZuulRequestHeader("x-forwarded-port", originalXForwardedPort);
            }

            log.info(String.format("After filter ['%s': '%s', '%s': '%s']",
                    ZuulHeaders.X_FORWARDED_PROTO.toLowerCase(),
                    ctx.getZuulRequestHeaders().get(ZuulHeaders.X_FORWARDED_PROTO.toLowerCase()),
                    "X-Forwarded-Port",
                    ctx.getZuulRequestHeaders().get("x-forwarded-port")));

            return null;
        }
    };
}
+1

Source: https://habr.com/ru/post/1648404/


All Articles