Allow CORS in Spring-xd HTTP source - spring-xd

How do I configure HTTP source in Spring-xd to allow CORS? Setting the following in server.yml doesn't seem to help:
#Config to allow CORS
spring:
profiles: admin
xd:
ui:
allow_origin: "*"

That setting is for the admin only.
The HTTP source is currently a very simple implementation using Netty; it does not use Spring MVC and does not support CORS.
It's intended for simple POST ingestion to a stream.

Related

Equivalent of mod_proxy_html for Spring Cloud Gateway

I'm using Spring Cloud Gateway as a reverse proxy. Behind that proxy I have an Angular Web App the code of which I can't modify.
The problem is that the webapp uses relative hyperlinks so when accessing the proxied web app by URL http://localhost:8080/webapp/ the app omits the webapp part in it's hyperlinks and the hyperlinks look like http://localhost:8080/destination/ instead of http://localhost:8080/webapp/destination.Apache Httpd has module for it called mod_proxy_html that rewrites the paths in HTML content served by the proxy. Is there something similar in Spring Cloud Gateway or maybe one should use reverse proxy functionality only for REST APIs?
try:
application.yml
spring:
cloud:
gateway:
routes:
- id: rewritepath_route
uri: http://localhost:8080
predicates:
- Path=/destination
filters:
- RewritePath=/(?<segment>/?.*), /webapp/$\{segment}
https://cloud.spring.io/spring-cloud-gateway/reference/html/#the-rewritepath-gatewayfilter-factory

Calling resource server with JWT returns HTTP 403 by way of Spring Cloud Gateway

I have two projects. Both are reactive Spring. Project one is a combination of a Javascript application and Spring Cloud Gateway for reverse proxying. The second project is a Spring resource server.
Project one proxies requests from /api/artists to project two at http://localhost:8081/v1/artists.
If I call the resource server (project two) directly with a valid JWT, the response comes back HTTP 200. If I go by way of the reverse proxy in project one, and hit http://localhost:8080/api/artists with the same JWT, I receive an HTTP 403 from project two, which propagates back through project one.
Here is my Spring Cloud Gateway configuration:
spring:
cloud:
gateway:
routes:
- id: experience-api
uri: http://localhost:8081/v1/artists
predicates:
- Path=/api/artists/**
filters:
- TokenRelay=
The HTTP 403 indicates that while the token was valid, it must be lacking some other permission to perform the action. Though, I'm not sure why it works when I call it directly versus calling it by way of the reverse proxy/Spring Cloud Gateway.
After stepping away for a couple days, I realized that my gateway configuration was incorrect. I realized that the original configuration was proxying requests to /v1/artists/api/artists, which doesn't exist on project two, but my security configuration was set up so that /v1/** required authentication. I suspect that is why I saw an HTTP 403 Forbidden before I saw an HTTP 404 Not Found.
I ended up using the below configuration:
spring:
cloud:
gateway:
routes:
- id: experience-api
uri: http://localhost:8081
predicates:
- Path=/v1/artists/**
filters:
- TokenRelay=
Note that I removed /v1/artists from the uri property. Now, requests to project one at http://localhost:8080/v1/artists are getting proxied to http://localhost:8081/v1/artists. I could have used the StripToken predicate filter but it wasn't as clean as this.

Specifying route URI in Spring Cloud Gateway Configuration

Here is the yml for spring cloud gateway. I want to write URI without load balancing. But as I'm using Eureka, I don't think hardcoding something like "localhost:6678" is a good idea. I would like to specify the service name, without the lb prefix. Any way to write it ?
spring:
cloud:
gateway:
routes:
- id: before_route
uri: lb://hello-service
I'm seeing this on the console when I run the gateway:
You already have RibbonLoadBalancerClient on your classpath. It will be used by default. As Spring Cloud Ribbon is in maintenance mode. We recommend switching to BlockingLoadBalancerClient instead. In order to use it, set the value of `spring.cloud.loadbalancer.ribbon.enabled` to `false` or remove spring-cloud-starter-netflix-ribbon from your project.
What is the official alternative of Ribbon? How can I enable it in my project instead of Ribbon?
Edit: I'm trying to avoid load balancing for now because of poor performance. Without lb I'm getting my request served within 150ms whereas lb makes it 500ms+
Thanks in advance!

Read only configuration on the actuator's "logging" endpoint

I want to enable the actuator's "logging" endpoint on a production environment. If I can use it on the production environment, I can check the logging configuration on the Spring-Boot-Admin server.
But if I enable it, LoggersEndpoint accepts configuration overwrite request. When it's rewritable, it causes the security issue.
Is there any way to deny "#WriteEndpoint" request on the "loging" endpoint?
What you can do is to secure your endpoints by spring security otherwise,the only option is to disable the logger endpoint like below.
management.endpoint.loggers.enabled=false

Spring Boot Zuul : Map Multiple Route URLs

We are using Spring Boot with Zuul Proxy to forward the API requests to APIs. Sample Configuration is as below:
zuul.routes.common.url=http://10.0.0.1:8081/common
zuul.routes.meta.url=http://10.0.0.2:8082/meta
Every thing works fine with this. For balancing our load and utilising underlying servers effeciently, we would like to specify multiple URLs as part of the configuration and enable request forwarding for one of the URL. To be precise, we would like to configure the proxy config as given below by providing comma delimited list of endpoints which can handle the requests.
zuul.routes.common.url=http://10.0.0.1:8081/common,http://10.0.0.11:8081/common
zuul.routes.meta.url=http://10.0.0.2:8082/meta,http://10.0.0.12:8082/meta
But unfortunately, such config is resulting in "Resource not found Error".
Questions:
Is this a possible configuration?
if not, Is it possible to achieve this by any other means?
Regards,
Manjunath
Edit : Answer
Its not possible to configure multiple URLs just with Zuul. Request need to be load balanced using Ribbon. Here is the sample configuration with ribbon:
zuul.routes.common.path=/**
zuul.routes.common.serviceId=common
common.ribbon.listOfServers=http://10.0.0.1:8081/common,http://10.0.0.2:8081/common
You want to use Ribbon, and the property client.ribbon.listOfServers. Here is a quick example
zuul:
routes:
users:
path: /myusers/**
serviceId: users
ribbon:
eureka:
enabled: false
users:
ribbon:
listOfServers: example.com,google.com

Resources