Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http types blocks trigger various analyser failures #101

Open
chrisnovakovic opened this issue Jul 18, 2022 · 0 comments · May be fixed by #104
Open

http types blocks trigger various analyser failures #101

chrisnovakovic opened this issue Jul 18, 2022 · 0 comments · May be fixed by #104

Comments

@chrisnovakovic
Copy link

Describe the bug

The analyser doesn't take into account the special syntax of http types blocks, in which directives are arbitrary MIME types. This means that crossplane doesn't recognise Nginx configurations containing types blocks as valid when running in strict mode, which verifies that directive names are present in the analyser's allowlist. A similar problem occurs when check_ctx=True is set via the API.

To Reproduce

Run crossplane parse --strict on the following Nginx configuration:

http {
    types {
        text/html  html;
        image/gif  gif;
        image/jpeg jpg jpeg;
    }
}

This outputs:

{"status":"failed","errors":[{"file":"nginx.conf","error":"unknown directive \"text/html\" in nginx.conf:3","line":3},{"file":"nginx.conf","error":"unknown directive \"image/gif\" in nginx.conf:4","line":4},{"file":"nginx.conf","error":"unknown directive \"image/jpeg\" in nginx.conf:5","line":5}],"config":[{"file":"nginx.conf","status":"failed","errors":[{"error":"unknown directive \"text/html\" in nginx.conf:3","line":3},{"error":"unknown directive \"image/gif\" in nginx.conf:4","line":4},{"error":"unknown directive \"image/jpeg\" in nginx.conf:5","line":5}],"parsed":[{"directive":"http","line":1,"args":[],"block":[{"directive":"types","line":2,"args":[],"block":[]}]}]}]}

Expected behavior

No errors are encountered, and an AST is printed.

Your environment

crossplane v0.5.7 (although the problem also exists on master)

chrisnovakovic added a commit to chrisnovakovic/crossplane that referenced this issue Jul 18, 2022
The syntax of `http` `types` blocks is distinct, in that their child
directives are arbitrary MIME types - they therefore can't be analysed
when `strict` or `check_ctx` are enabled, and no meaningful analysis can
be performed when `check_args` is enabled because the arity of child
directives is unknown. Skip the checks performed when `strict` and
`check_ctx` are enabled, and hint to the analyser that all directives
inside a `types` block accept one or more arguments so that a meaningful
check can be performed when `check_args` is enabled.

Fixes nginxinc#101.
@chrisnovakovic chrisnovakovic changed the title http types blocks trigger various analyser failures http types blocks trigger various analyser failures Jul 18, 2022
chrisnovakovic added a commit to chrisnovakovic/crossplane that referenced this issue Jul 19, 2022
The `map` directive (from ngx_http_map_module and ngx_stream_map_module)
and `types` directive (from ngx_http_core_module) are distinct from
other directives, in that their child directives may be arbitrary
strings that aren't known to Nginx. This causes crossplane to report
unrecognised/misused directive errors when analysing them with `strict`
or `check_ctx` enabled; it also means that no meaningful analysis can be
be performed when `check_args` is enabled because the arity of child
directives is unknown.

Add support for `map`'s special directives (`default`, `hostnames`, and
`volatile`) to the analyser. Recognise that arbitrary directive names
inside a `map` or `types` block are valid and that they accept either
one argument (if used in `map`) or one or more arguments (if used in
`types`).

Fixes nginxinc#101 and nginxinc#103.
chrisnovakovic added a commit to chrisnovakovic/crossplane that referenced this issue Jul 19, 2022
The `map` directive (from ngx_http_map_module and ngx_stream_map_module)
and `types` directive (from ngx_http_core_module) are distinct from
other directives, in that their child directives may be arbitrary
strings that aren't known to Nginx. This causes crossplane to report
unrecognised/misused directive errors when analysing them with `strict`
or `check_ctx` enabled; it also means that no meaningful analysis can be
performed when `check_args` is enabled because the arity of child
directives is unknown.

Add support for `map`'s special directives (`default`, `hostnames`, and
`volatile`) to the analyser. Recognise that arbitrary directive names
inside a `map` or `types` block are valid and that they accept either
one argument (if used in `map`) or one or more arguments (if used in
`types`).

Fixes nginxinc#101 and nginxinc#103.
@chrisnovakovic chrisnovakovic linked a pull request Jul 19, 2022 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant