Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zuul -> Eureka Server, Basic Authentication issue

I am able to hit the service, if the flow doesn't contain Basic Authorization.

If i use Basic Authorization, it throws "message": "Full authentication is required to access this resource"

Below are my observations:

In ZuulFilter, run() method, i get value for request.getHeader("Authorization") --> Basic c29tOnNvbzz==

but once it reaches the Micro Service, i am getting value as 'null', request.getHeader("Authorization") --> null

Using Spring Boot version : 1.4.0.RELEASE

This is my flow:
------------------

Zuul -> Service Discovery (Eureka Server) -> Service

Kindly help, not sure where the Authorization header is vanishing.

Eureka Server yml file:
-------------------------
server.port:4001
eureka.instance.hostname=localhost
eureka.client.fetch-registry:false
eureka.client.register-with-eureka:false
eureka.client.serviceUrl.defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
eureka.client.healthcheck.enabled=true

Zuul yml file:
-----------------
server:
  port: 8765
info:
  component: Edge Server
eureka:
  instance:
    leaseRenewalIntervalInSeconds: 3
    metadataMap:
      instanceId: ${spring.application.name}:${random.value}
  client:
    # Default values comes from org.springframework.cloud.netflix.eurek.EurekaClientConfigBean
    registryFetchIntervalSeconds: 5
    instanceInfoReplicationIntervalSeconds: 5
    initialInstanceInfoReplicationIntervalSeconds: 5

endpoints:
  restart:
    enabled: true
  shutdown:
    enabled: true
  health:
    sensitive: false

zuul.sensitive-headers: Cookie,Set-Cookie,Authorization

logging:
  level:
    ROOT: WARN
    se.callista: INFO

    # Get info regarding connection to the cofig server and retries if required
    org.springframework.cloud.config.client.ConfigServicePropertySourceLocator: INFO
    org.springframework.retry.support.RetryTemplate: DEBUG

    # Set INFO to see the allocated port
    org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer: INFO
---
eureka:
  instance:
    preferIpAddress: true
  client:
    serviceUrl:
      defaultZone: http://localhost:4001/eureka,http://localhost:4002/eureka
like image 652
Molay Avatar asked Aug 23 '16 13:08

Molay


People also ask

How do Zuul and Eureka work together?

Zuul acts as the API gateway, providing a uniform, single point of entry into the set of microservices, while Eureka is essentially used as a “meta data” transport. Each client application instance (read microservice) registers its instance information (location, port, etc.) with the Eureka server.

What is difference between Zuul and Eureka?

Eureka belongs to "Open Source Service Discovery" category of the tech stack, while Zuul can be primarily classified under "Microservices Tools". Eureka is an open source tool with 8.16K GitHub stars and 2.27K GitHub forks.

Does Zuul use Eureka?

Internally, Zuul uses Netflix Ribbon to look up for all instances of the service from the service discovery (Eureka Server).


1 Answers

Authorization is by default a sensitive header, this means Zuul will not forward them. If you leave it out of the sensitive headers, Zuul will forward the header.

zuul.sensitiveHeaders: Cookie,Set-Cookie

It should also be camelCase instead of hyphenated.

Extra info: https://github.com/spring-cloud/spring-cloud-netflix/blob/master/docs/src/main/asciidoc/spring-cloud-netflix.adoc#cookies-and-sensitive-headers

like image 121
Jeff Avatar answered Sep 28 '22 02:09

Jeff