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

Log remote addrs for layer4 servers #22

Closed
melink14 opened this issue Jun 3, 2021 · 5 comments
Closed

Log remote addrs for layer4 servers #22

melink14 opened this issue Jun 3, 2021 · 5 comments

Comments

@melink14
Copy link

melink14 commented Jun 3, 2021

I'm currently trying out caddy-l4 for SSL passthrough to backend service and trying to debug remote address problems throughout the stack.

In this process, I noticed that even with top level logging config set to DEBUG my logs I see logs from my routes but they don't contain any information about the remote client which would be useful for ascertaining what IP caddy thinks is hitting me and implementing remote IP based routing.

logging:
  logs:
    default:
      level: "DEBUG"
@mholt
Copy link
Owner

mholt commented Jun 3, 2021

Are you referring to these log emissions specifically, which occur at the end of every connection?

caddy-l4/layer4/server.go

Lines 103 to 106 in ddf050b

s.logger.Debug("connection stats",
zap.Uint64("read", cx.bytesRead),
zap.Uint64("written", cx.bytesWritten),
zap.Duration("duration", duration),

If so, it will be pretty easy to add the client's IP address.

@melink14
Copy link
Author

melink14 commented Jun 3, 2021

That would be a great step for debugging alone but I was also looking for it on the layer4 specific lines like:

layer4.matchers.tls matched...

@mholt
Copy link
Owner

mholt commented Jun 3, 2021

I don't understand. "matched ..." then what? Please be clear about what you're requesting.

@melink14
Copy link
Author

melink14 commented Jun 3, 2021

Ah, I was trying to be clear of course, but there's no way to know if one suceeded until the other party consumes the message. In this case, it seems I failed, so I'll try again.

Logging in caddy-l4 is split up by module. The generic connection stats you mention come from the top level layer4 logger but there also module specific loggers like layer4.matchers.tls or layer4.handlers.proxy.

For example here's one log output:
{"level":"debug","ts":1622757064.589788,"logger":"layer4.handlers.proxy","msg":"dial upstream","address":"localhost:4433"}

The idea then is to be able to add a connecting IP field to these module specific log lines since it's a key property of each step of the processing.

That being said, the top level connection stats contain IP goes a long way in debugging general problems but wanted to describe the more general idea as well.

@mholt mholt closed this as completed in 3cfcafe Jun 4, 2021
@mholt
Copy link
Owner

mholt commented Jun 4, 2021

Ok, gotcha. Thanks. I added the remote IP to a bunch of logs in 3cfcafe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants