nginxinc / crossplane

Quick and reliable way to convert NGINX configurations into JSON and back.
Apache License 2.0
719 stars 87 forks source link

Nginx ingress controller configuration parse failed #87

Closed RonVider closed 4 years ago

RonVider commented 4 years ago

Describe the bug I’ve created basic Kubernetes Nginx ingress controller following a tutorial from Kubernetes official site (https://kubernetes.io/docs/tasks/access-application-cluster/ingress-minikube/) and then I tried to parse it within crossplan Nginx parser which failed due to not allowed directive.

To Reproduce Steps to reproduce the behavior:

  1. Create an nginx ingress controller by following the guide - https://kubernetes.io/docs/tasks/access-application-cluster/ingress-minikube/
  2. Print generated nginx configuration kubectl exec -n kube-system `kubectl get pods -n kube-system | grep ingress-nginx-controller | cut -d" " -f1` cat /etc/nginx/nginx.conf > nginx.conf
  3. Run crossplane parse nginx.conf
  4. See traceback

Expected behavior The configuration has no issues and should be parsed successfully.

Your environment

Additional context Attached configuration for example nginx.txt

aluttik commented 4 years ago

Interesting bug! Thanks for bringing this up @RonVider.

Get this, it turns out that the problem is because of this embedded lua comment:

        -- load all plugins that'll be used here

Crossplane has really basic support for OpenResty's Lua module because it uses embedded code that's not technically supported by the vanilla NGINX syntax.

Not supporting OpenResty caused us a few headaches though, so we added some basic handling into crossplane that would just grab all of the embedded code and treat it like one big string. In order to do that, we needed to count bracket depth to get the end of the *_by_lua_block block, and we needed to make sure that none of the { or } characters were inside lua strings. This very basic handling caused a bug here, because crossplane has no concept of lua comments, and thought that the ' character in the comment was the beginning of a lua string. This threw the whole parser off.

So if you need an immediate fix before this gets patched, try removing the ' character in the lua comment.