openshift-roadshow / parksmap-web

This is the web and service gateway component. It's implemented in SpringBoot
Apache License 2.0
46 stars 119 forks source link

Added functionality to use https for backend routes. #9

Closed olaf-meyer closed 4 years ago

olaf-meyer commented 5 years ago

So far the backend routes in the parksmap application could only use HTTP and not HTTPS. I added code to check for the protocol in the RouteWatcher whether the route is using http or https. To avoid error messages that the certificate of the backend route can not be trusted (i.e. the signer is unknown), I added a class that will skip the SSL and host name verification.

jdob commented 4 years ago

I'm going to keep looking into this, but when I ran it against a secure route, I got the following errors. I'm not 100% sure it's related to these changes. Can you tell me how you configured the secure route? I don't need certificates or anything, just looking for things like the termination and insecure traffic settings.

2020-06-04 14:03:04.281 INFO 1 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@722c41f4: startup date [Thu Jun 04 14:03:04 UTC 2020]; root of context hierarchy 2020-06-04 14:03:05.073 INFO 1 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$90ec60ed] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

. _ _ /\ / '_ () \ \ \ \ ( ( )\ | ' | '| | ' \/ ` | \ \ \ \ \/ _)| |)| | | | | || (| | ) ) ) ) ' |__| .|| ||| |\, | / / / / =========|_|==============|__/=//// :: Spring Boot :: (v1.5.19.RELEASE)

2020-06-04 14:03:05.672 INFO 1 --- [ main] c.o.evg.roadshow.ParksMapApplication : No active profile set, falling back to default profiles: default 2020-06-04 14:03:05.696 INFO 1 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@97e1986: startup date [Thu Jun 04 14:03:05 UTC 2020]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@722c41f4 2020-06-04 14:03:06.433 INFO 1 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=67a277c1-b629-3c76-ac0e-460b573ae06f 2020-06-04 14:03:06.579 INFO 1 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$90ec60ed] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2020-06-04 14:03:12.106 INFO 1 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http) 2020-06-04 14:03:12.154 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2020-06-04 14:03:12.155 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.37 2020-06-04 14:03:12.424 INFO 1 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2020-06-04 14:03:12.424 INFO 1 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 6728 ms 2020-06-04 14:03:12.704 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/] 2020-06-04 14:03:12.722 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/] 2020-06-04 14:03:12.723 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/] 2020-06-04 14:03:12.723 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/] 2020-06-04 14:03:12.724 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/] 2020-06-04 14:03:14.003 INFO 1 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'clientInboundChannelExecutor' 2020-06-04 14:03:14.030 INFO 1 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'clientOutboundChannelExecutor' 2020-06-04 14:03:14.070 INFO 1 --- [ main] c.o.e.r.rest.AbstractResourceWatcher : [INFO] com.openshift.evg.roadshow.rest.RouteWatcher is watching for resources started in namespace roadshow 2020-06-04 14:03:14.882 INFO 1 --- [ main] c.o.e.r.r.g.helpers.EndpointWatcher : EndpointWatcher created for: endpoints/secure -n roadshow 2020-06-04 14:03:14.899 WARN 1 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'backendsController': Invocation of init method failed; nested exception is java.lang.NullPointerException 2020-06-04 14:03:14.899 INFO 1 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'clientOutboundChannelExecutor' 2020-06-04 14:03:14.899 INFO 1 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'clientInboundChannelExecutor' 2020-06-04 14:03:14.900 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat] 2020-06-04 14:03:14.945 INFO 1 --- [ main] utoConfigurationReportLoggingInitializer :

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled. 2020-06-04 14:03:14.955 ERROR 1 --- [ main] o.s.boot.SpringApplication : Application startup failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'backendsController': Invocation of init method failed; nested exception is java.lang.NullPointerException at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:137) ~[spring-beans-4.3.22.RELEASE.jar!/:4.3.22.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:407) ~[spring-beans-4.3.22.RELEASE.jar!/:4.3.22.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1623) ~[spring-beans-4.3.22.RELEASE.jar!/:4.3.22.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) ~[spring-beans-4.3.22.RELEASE.jar!/:4.3.22.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:481) ~[spring-beans-4.3.22.RELEASE.jar!/:4.3.22.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312) ~[spring-beans-4.3.22.RELEASE.jar!/:4.3.22.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.22.RELEASE.jar!/:4.3.22.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308) ~[spring-beans-4.3.22.RELEASE.jar!/:4.3.22.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.22.RELEASE.jar!/:4.3.22.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) ~[spring-beans-4.3.22.RELEASE.jar!/:4.3.22.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-4.3.22.RELEASE.jar!/:4.3.22.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-4.3.22.RELEASE.jar!/:4.3.22.RELEASE] at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:124) ~[spring-boot-1.5.19.RELEASE.jar!/:1.5.19.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.19.RELEASE.jar!/:1.5.19.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.19.RELEASE.jar!/:1.5.19.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.19.RELEASE.jar!/:1.5.19.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.19.RELEASE.jar!/:1.5.19.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.19.RELEASE.jar!/:1.5.19.RELEASE] at com.openshift.evg.roadshow.ParksMapApplication.main(ParksMapApplication.java:15) [classes!/:1.0.0-SNAPSHOT] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_131] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_131] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_131] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_131] at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [app.jar:1.0.0-SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [app.jar:1.0.0-SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [app.jar:1.0.0-SNAPSHOT] at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) [app.jar:1.0.0-SNAPSHOT] Caused by: java.lang.NullPointerException: null at com.openshift.evg.roadshow.rest.gateway.helpers.EndpointWatcher.getEndpointsAddressSize(EndpointWatcher.java:66) ~[classes!/:1.0.0-SNAPSHOT] at com.openshift.evg.roadshow.rest.gateway.helpers.EndpointWatcher.hasEndpoints(EndpointWatcher.java:56) ~[classes!/:1.0.0-SNAPSHOT] at com.openshift.evg.roadshow.rest.gateway.helpers.EndpointWatcher.hasEndpoints(EndpointWatcher.java:52) ~[classes!/:1.0.0-SNAPSHOT] at com.openshift.evg.roadshow.rest.gateway.helpers.EndpointWatcher.(EndpointWatcher.java:41) ~[classes!/:1.0.0-SNAPSHOT] at com.openshift.evg.roadshow.rest.AbstractResourceWatcher.init(AbstractResourceWatcher.java:119) ~[classes!/:1.0.0-SNAPSHOT] at com.openshift.evg.roadshow.rest.BackendsController.init(BackendsController.java:63) ~[classes!/:1.0.0-SNAPSHOT] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_131] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_131] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_131] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_131] at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:366) ~[spring-beans-4.3.22.RELEASE.jar!/:4.3.22.RELEASE] at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:311) ~[spring-beans-4.3.22.RELEASE.jar!/:4.3.22.RELEASE] at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:134) ~[spring-beans-4.3.22.RELEASE.jar!/:4.3.22.RELEASE] ... 26 common frames omitted

jdob commented 4 years ago

That log output reads pretty poorly, here's a gist of it: https://gist.github.com/jdob/8f4f87022a280e46fff1c15562287864

olaf-meyer commented 4 years ago

Hello Jason,

I found the root of the problem. For the parksmap application, the service (and by this the endpoint) and the route of the national park app need to have the same name. I got the same error when I added a secure route to the national parks app. For my tests I just changed the type of national park route to edge. By this I kept the name of the route. This is why the error didn't occur for my tests.

From what I get, the parksmap app can use the service or route to fetch the national parks. I'm not sure if this is used for other programming languages.

Does this help you with the exception?

jdob commented 4 years ago

Yup, that did it. Thanks :)

olaf-meyer commented 4 years ago

Your welcome.