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

(2.8.0-beta.1) CEL expressions in Caddyfile not processed properly #6287

Closed
inetol opened this issue May 1, 2024 · 5 comments · Fixed by #6288
Closed

(2.8.0-beta.1) CEL expressions in Caddyfile not processed properly #6287

inetol opened this issue May 1, 2024 · 5 comments · Fixed by #6288
Labels
needs info 📭 Requires more information

Comments

@inetol
Copy link

inetol commented May 1, 2024

Expressions written in heredoc such as:

@cel_tld_net <<CEL
    {http.request.host.labels.0} == "net"
    CEL

...or with backticks:

@cel_tld_net `{http.request.host.labels.0} == "net"`

...are not processed correctly in Caddyfiles as of 2.8.0-beta.1, leading to this error:

Error: adapting config using caddyfile: wrong argument count or unexpected line ending after 'expression', at /path/to/config

But it does work correctly if you explicitly specify the expression parameter, like so:

@cel_tld_net expression {http.request.host.labels.0} == "net"

Anyway, thanks for your amazing work!

@francislavoie
Copy link
Member

francislavoie commented May 1, 2024

Works fine for me.

:8881 {
    @test `{http.request.host.labels.0} == "net"`
    respond @test "hello"
}

👇 caddy adapt -p

{
	"apps": {
		"http": {
			"servers": {
				"srv0": {
					"listen": [
						":8881"
					],
					"routes": [
						{
							"match": [
								{
									"expression": {
										"expr": "{http.request.host.labels.0} == \"net\"",
										"name": "test"
									}
								}
							],
							"handle": [
								{
									"body": "hello",
									"handler": "static_response"
								}
							]
						}
					]
				}
			}
		}
	}
}

@francislavoie francislavoie added the needs info 📭 Requires more information label May 1, 2024
@francislavoie
Copy link
Member

Please share your full Caddyfile, the problem must be caused by something else (or in combination with something else).

@inetol
Copy link
Author

inetol commented May 1, 2024

It seems that the error only manifests itself if used in conjunction with import 😓, here is a minimal example to reproduce the issue:

# Caddyfile
:8080 {
	import expression.cel

	handle @cel_tld_net {
		respond ":)"
	}

	handle {
		respond ":("
	}
}
# expression.cel
@cel_tld_net <<CEL
	{http.request.host.labels.0} == "net"
	CEL

@francislavoie
Copy link
Member

Okay, thanks, I can replicate that. Looking into it.

@francislavoie
Copy link
Member

francislavoie commented May 1, 2024

Got a fix! #6288

The crux of the issue is with how we make a fake expression token which we insert just before the backtick-quoted CEL expression. This worked fine in the base case with no import. But when there's imports, the tokens carry their inheritance path through snippets/files. The fake expression token wasn't using the CEL expression token's inheritance, so the token dispenser got confused because they didn't make sense consecutively. Now I'm literally cloning the token (preserving all the context) and just replacing its text with expression and using that. It works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs info 📭 Requires more information
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants