Closed dwatrous closed 5 years ago
From the example
curl -k -v -sb -X POST -H "Content-type: application/json" "https://forgerock-proxy.sonar-cube-front-end-cicd:443/myauth/services/v1.0/authentication/signon?realm=sw_hrp"
- backend: serviceName: forgerock-proxy servicePort: 443 path: /myauth
that service requires an https connection. You need to create a different ingress rule for that path, for the same host and add the annotation https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#backend-protocol (without this annotation, nginx uses http to reach the service)
I just added the annotation you mention, but I'm still getting a 502. This is what I have.
[centos@k8s-master-0 ~]$ kubectl get ing sonar-cube-front-end-ingress-master -o yaml -n sonar-cube-front-end-cicd
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
ingress.kubernetes.io/secure-backends: "true"
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/backend-protocol: HTTPS
creationTimestamp: "2019-06-02T14:23:17Z"
generation: 6
name: sonar-cube-front-end-ingress-master
namespace: sonar-cube-front-end-cicd
resourceVersion: "37463793"
selfLink: /apis/extensions/v1beta1/namespaces/sonar-cube-front-end-cicd/ingresses/sonar-cube-front-end-ingress-master
uid: f720041c-8541-11e9-a17d-fa163ed6baf9
spec:
rules:
- host: master.sonar-cube-front-end-cicd.dc.k8s.com
http:
paths:
- backend:
serviceName: sonar-cube-front-end-service-master
servicePort: 81
path: /sonar-cube-front-end
- backend:
serviceName: msweb-service-master
servicePort: 80
path: /
- backend:
serviceName: loginproxy-service-master
servicePort: 5000
path: /loginproxy
- backend:
serviceName: forgerock-proxy
servicePort: 443
path: /myauth
tls:
- hosts:
- master.sonar-cube-front-end-cicd.dc.k8s.com
secretName: sonar-cube-front-end-cicd-tls-secret-autogen
status:
loadBalancer: {}
I also see that when I add that annotation, all of the paths return 502, not just the /myauth
path.
I see that this annotation changes the nginx.conf by making these all https proxy_pass https://upstream_balancer;
I also see that when I add that annotation, all of the paths return 502, not just the /myauthpath.
Well, you added the backend-protocol protocol to the ingress where you have all the paths. that means nginx will try to use https to reach any of those paths.
I see that this annotation changes the nginx.conf by making these all https proxy_pass https://upstream_balancer;
This is a common question. For that reason, we added a comment https://github.com/kubernetes/ingress-nginx/blob/master/rootfs/etc/nginx/template/nginx.tmpl#L411
Is there some way to annotate only one backend for HTTPS?
Also, is there some way to tell it not to validate SSL? I see this annotation nginx.ingress.kubernetes.io/proxy-ssl-verify
, but the default is 'off', so would that help to set it?
Like I posted in my first comment, you need to create a new ingress for that path
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/backend-protocol: HTTPS
name: forgerock-proxy-sonar-cube-front-end-ingress-master
namespace: sonar-cube-front-end-cicd
spec:
rules:
- host: master.sonar-cube-front-end-cicd.dc.k8s.com
http:
paths:
- backend:
serviceName: forgerock-proxy
servicePort: 443
path: /myauth
Also, is there some way to tell it not to validate SSL? I see this annotation nginx.ingress.kubernetes.io/proxy-ssl-verify, but the default is 'off', so would that help to set it?
That feature is not released yet https://github.com/kubernetes/ingress-nginx/pull/4327
In the meantime, you can use the configuration-snippet
annotation to set proxy_ssl_verify off;
The requests are now being proxied. Thank you.
However, the request is being modified in a way that is causing it to fail. From the requests above, I know the service is working with this curl request when operating directly against the service and not going through the nginx proxy.
curl -k -v \
-X POST \
-H "Content-type: application/json" \
-H "Accept: application/json" \
"https://master.sonar-cube-front-end-cicd.dc.k8s.com/myauth/services/v1.0/authentication/signon?realm=sw_hrp" \
--data "{\"emplid\":\"00001239829\",\"userpassword\":\"1234\"}"
Does nginx pass through the headers or modifies them?
I see header_filter_by_lua_block
, but I'm not sure what it does.
Is it possible to disable all the proxy_set_header
directives for that path?
Is it possible to disable all the proxy_set_header directives for that path?
Not really.
How are you testing this and what's the output in the log? The error is in your service?
I'm testing it with the exact curl commands I show above. When I access the service directly, I get a 200 valid response back. When I go through the nginx proxy, I get a 302 redirect, which means that the auth endpoint didn't like the request. That can happen if I don't set the content-type and accept headers. It may happen if other headers are set, but I'm not sure. Is there some way to know exactly what is included in the request from nginx to my service?
Hi @dwatrous Did you manage to solve your problem? I am facing the same issue now
facing the same issue too now
This issue is very similar to https://github.com/kubernetes/ingress-nginx/issues/1600, but the solution on that issue hasn't worked for me.
I have an Ingress with multiple paths and a mix of traditional Service resources for container workloads and ExternalName Service. I have confirmed the ExternalName Service is working, but the nginx Ingress is not working.
I have the following Service resources
And the ExternalName Service is defined as follows
I have confirmed this works by creating an Alpine container in the same namespace and executing a request, as follows
I then updated my Ingress as follows
But when I try to make a request, it fails with a
502 Bad Gateway
errorI started a shell in the nginx container and see that it has this configuration
NGINX Ingress controller version: quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.24.1
Kubernetes version (use
kubectl version
): [centos@k8s-master-0 ~]$ kubectl version Client Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.1", GitCommit:"b7394102d6ef778017f2ca4046abbaa23b88c290", GitTreeState:"clean", BuildDate:"2019-04-08T17:02:58Z", GoVersion:"go1.12.1", Compiler:"gc", Platform:"linux/amd64"} Server Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.1", GitCommit:"b7394102d6ef778017f2ca4046abbaa23b88c290", GitTreeState:"clean", BuildDate:"2019-04-08T17:02:58Z", GoVersion:"go1.12.1", Compiler:"gc", Platform:"linux/amd64"}Environment:
uname -a
): Linux k8s-master-0 3.10.0-957.12.1.el7.x86_64 #1 SMP Mon Apr 29 14:59:59 UTC 2019 x86_64 x86_64 x86_64 GNU/LinuxWhat you expected to happen: I expect the Ingress to allow traffic to flow through to the External service.
How to reproduce it (as minimally and precisely as possible): see above