13

In switching from Spring Cloud Brixton.M5 to Brixton.RC1 my ZuulProxy no longer passes Authorization headers downstream to my proxied services.

There's various actors in play in my setup, but most all of them are fairly simple: - AuthorizationServer: runs separately; hands out JWTs to clients - Clients: get JWTs from OAuth server; each with access to a subset of resources. - ResourceServers: consume JWTs for access decisions - MyZuulProxy: proxies various resource servers; should relay JWTs.

It should be noted that MyZuulProxy has no security dependencies whatsoever; It passed the Authorization: Bearer {JWT} header it receives to the ResourceServers, pre-RC1. MyZuulProxy is explicitly not a Client itself, and does not use @EnableOAuth2SSO or similar at the moment.

What could I do to get MyZuulProxy to relay the JWTs to the ResourceServers again when using Spring Cloud Brixton.RC1?

There's very little code to post: It's just @EnableZuulProxy, @EnableAuthorizationServer and @EnableResourceServer in three different jars. My Clients are not Spring applications.

Tim
  • 19,793
  • 8
  • 70
  • 95

2 Answers2

38

Update: Fixed in https://github.com/spring-cloud/spring-cloud-netflix/pull/963/files

Sensitive headers can also be set globally setting zuul.sensitiveHeaders. If sensitiveHeaders is set on a route, this will override the global sensitiveHeaders setting.

So use:

# Pass Authorization header downstream
zuul:
  sensitiveHeaders: Cookie,Set-Cookie

So pending a fix for https://github.com/spring-cloud/spring-cloud-netflix/issues/944, jebeaudet was kind enough to provide a workaround:

@Component
public class RelayTokenFilter extends ZuulFilter {

    @Override
    public Object run() {
        RequestContext ctx = RequestContext.getCurrentContext();

        // Alter ignored headers as per: https://gitter.im/spring-cloud/spring-cloud?at=56fea31f11ea211749c3ed22
        Set<String> headers = (Set<String>) ctx.get("ignoredHeaders");
        // We need our JWT tokens relayed to resource servers
        headers.remove("authorization");

        return null;
    }

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

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

    @Override
    public int filterOrder() {
        return 10000;
    }
}
mibrahim.iti
  • 1,928
  • 5
  • 22
  • 50
Tim
  • 19,793
  • 8
  • 70
  • 95
  • 1
    zuul configuration really solved my problem. Custom Authentication Provider was not getting invoked in the microservice. Thanks in loads! – Harihara_K Sep 14 '21 at 08:15
  • I tried this and tho I get how it is supposed to be working, I'm expecting to receive the header Authorization in my redirected app and yet I'm not getting it...can't seem to make my app send the header even adding this zuul config in the yml archive..help – Lille Nov 17 '21 at 14:21
12

Set the sensitiveHeaders globally helped me solve the issue

 zuul:
  sensitiveHeaders: Cookie,Set-Cookie

Please note that the property name is sensitiveHeaders not sensitive-headers [I use spring-cloud-starter-zuul version:1.3.1.RELEASE ]

Abhilash
  • 761
  • 7
  • 8