YARP simple direct forwarding configuration - asp.net-web-api

I have a web api application built with yarp support listening on port 443.
I know it is up and running because postman says so when https://myserver/info. 'Info' is a simple http GET returning some strings from a simple controller.
I also have a web api project listening on port 5002 which I know is functioning because postman says so when https://myserver:5002/myotherapp/info.
I would like postman to tell me that https://myserver/myotherapp/info is also valid, but have not been able to configure it so.
I have tried numerous different combinations in the appsettings.json to achieve this but to no avail. All I am trying to do is direct to localhost:5002 on the server. In my current setup I am seeing 503 Service Unavailable in postman.
It may not be a configuration issue but could someone assist me by confirming what the ReverseProxy element of appsettings.json should look like in this simplest of cases?

Related

Socket.io with YARP

I am trying to build a system using Socket.io and YARP. Yarp is functioning has a Reverse Proxy to all my Services.
When trying establish a connection to my socket.io service, through yarp, I am getting connection_error:
I noticed there are proper configurations used in other Reversed Proxy solutions that are well documented in Socket.io website:
https://socket.io/docs/v4/reverse-proxy/
However, I can't "translate" what they are doing to YARP. Does anyone know if this is possible?
Thanks in advance
I guess stackoverflow was my rubberduck this time...
I checked in postman the request that was being made through my Yarp Server and turns out it wasn't even hitting the correct path. For yarp to connect to a socket.io server you have to use this kind of path in your configuration file:
It seems that a sokcetio request uses it's own path, so you have to make your reverse proxy match the beggining "socket.io/"

How to use forward proxy for HTTPS?

I have a use case where I have to put a middle server or relay or tunnel to do network communication with the following points:
I have a web server running, let say when I hit an API /request hosted my web server, it creates a post request to https://www.google.com and gives me a response through the endpoint.
I want a middle server (proxy etc.) which I will call while creating this post request instead of communicating through my webserver,
the call goes to the middle server and gives me the same response as I was getting directly.
For this, the SQUID proxy worked for me.
I came across NGINX, but we can not use NGINX as a forward proxy, also there are some observations that might be useful with this regard.
SQUID proxy also uses the conf file as similar to NGINX,
HTTPS traffic is encrypted, the proxy server need to do some more work to get something with Https requests,
For intercepting, and creating ACL rules, someone will need to have a dummy certificate to be used by the server to act as the owner of the requested content through the proxy,
a list of rules can be incorporated within SQUID.conf to achieve the filtering.
I hope this could be useful to achieve something like this.

Neo4j HTTPS only?

there doesn't seem to exist any configuration that enables HTTPS only access to neo4j databases.
I've tried disabling the HTTP connectors but neo4j needs at least one HTTP connector otherwise it wouldn't start the service at all.
I found that commenting out the HTTP connector would let the neo4j service start but triggers an error in all browsers except chrome that wouldn't let you connect to the database.
As far as my research has brought me. There is no neo4j-only solution to this problem at the moment.
From what I've read and found out there might be several possibilities like limiting http access to port 7474 from outside of your network and redirecting http to https.
I was not able to test them personally but it seems that there's no different way to do this.
For now http has to be enabled and configured for https to work.

Why does requiresSecure() cause redirect loop in Spring Security?

I am using Spring Boot v1.1.9.RELEASE and I deploy my app to Heroku. I have just added an SSL certificate and it works fine, if I manually change the URL to HTTPS.
The problem is that after login, Spring Security switches back to HTTP. I've read-up on this and found that adding the following forces HTTPS for all requests which sounds like exactly what I want:
.and().requiresChannel().anyRequest().requiresSecure()
However, when I try this, I get a redirect loop error. I don't understand why the server would constantly redirect. I want every request to be HTTPS. So the above code tells the server to redirect to HTTPS if the request is HTTP which seems to work. But then it retries the redirect over and over. Does anyone know why it does this? The logs don't seem to be providing any insight into the behaviour.
Note: I also read somewhere that port-mapping may be the culprit but the suggested solution was to set a port mapping of 80 to 443 which as far as I know is the default setting. I tried it anyway and it made no difference.
The most likely reason is that the HTTPS connection is not terminated at the servlet container and the container is unable to differentiate between connections which are over HTTPS or HTTP.
Check whether the isSecure method on HttpServletRequest returns true when you make a request over HTTPS. If it doesn't then you need to find some way of configuring a Heroku application to allow the container to tell the difference. Most likely the router will set a header such as HTTP_X_FORWARDED_PROTO which the container can be configured to make use of. You can do this in tomcat using the RemoteIpValve but I don't know how much control you have over this in Heroku.
In Spring Boot the usage of the Forwarded-Headers (RFC 7239) can be activated in application.properties:
server.forward-headers-strategy=native
Reference: Spring Boot Documentation

HTTP GET requests work but POST requests do not

Our Spring application is running on several different servers. For one of those servers POST requests do not seem to be working. All site functionality that uses GET requests works completely fine; however, as soon as I hit something that uses a POST request (ex. form submit) the site just hangs permanently. The server won't give any response. We can see the requests in Tomcat Manager but they don't time out.
Has anyone ever seen this?
We have found the problem. Our DBA accidentally deleted the MySQL database files on that particular server (/sigh). In our Spring application we use GET requests for record retrieval and the records we were trying to retrieve must have been cached by MySQL. This made it seem as if GET requests were working. When trying to add new data to the database, which we use POST requests to do, Tomcat would wait for a response, which never came, from MySQL.
In my experience if you're getting a timeout error it's almost always due to not having correct ports open for your application. For example, go into your virtual machine's rules and insure port 8080, 8443 or 80, 443 are open for http and https traffic.
In google cloud platform: its under VPC networking -> firewall rules. Azure and AWS are similar.

Resources