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

[Feature Request]: Record the requesting end IP in the log #167

Open
wx2020 opened this issue Feb 7, 2025 · 12 comments
Open

[Feature Request]: Record the requesting end IP in the log #167

wx2020 opened this issue Feb 7, 2025 · 12 comments

Comments

@wx2020
Copy link

wx2020 commented Feb 7, 2025

Hi bro,
Thank you very much for your work!

Is there any chance to log the request to the log file? Maybe an environment variable option can be provided.

Hope to get your reply~

@m13253
Copy link
Owner

m13253 commented Feb 7, 2025

Thanks for contacting us.
However, if I am remembering correctly, isn’t the IP already in the log?

@wx2020
Copy link
Author

wx2020 commented Feb 7, 2025

My logs are all 127.0.0.1:

Image

This is my front-end web server settings, I use caddy:

dns.wx2020.fun {
   reverse_proxy /dns-query* localhost:8053
   tls [email protected]
   try_files {path} {path}/index.php /index.php?{query}
}

Does caddy need to set up more details to achieve its goal?

@m13253
Copy link
Owner

m13253 commented Feb 7, 2025

Oh I see!

The code uses gorilla.CombinedLoggingHandler to print out the log.
This handler doesn’t use X-Forwarded-For to retrieve the client IP address, therefore, the log shows 127.0.0.1.

I believe the developers of Gorilla library don’t intend to change this behavior due to security concerns.
Perhaps I need to implement a version of logging myself… But it’s a feature many servers choose to opt-out, I’m hesitating to spend time developing it right now…

@wx2020
Copy link
Author

wx2020 commented Feb 7, 2025

ah, just do it when you want to do it.

@m13253
Copy link
Owner

m13253 commented Feb 7, 2025

ah, just do it when you want to do it.

Thank you for understanding!
If many people ask for this feature, I will do it.
Meanwhile, Pull Requests are welcome!

@wx2020
Copy link
Author

wx2020 commented Feb 7, 2025

Okey, i will try it!

@m13253
Copy link
Owner

m13253 commented Feb 7, 2025

Oh I found it!
It’s already in the configuration file, called log_guessed_client_ip.

https://github.com/m13253/dns-over-https/blob/master/doh-server/doh-server.conf#L53

Have you tried it out?

@wx2020
Copy link
Author

wx2020 commented Feb 7, 2025

I use it with docker, but when I mount the config file and restart the container after modifying the config file, the configuration file will become the file before the modification. . . Is it a problem with the docker image?

There are my docker-compose file:

  doh-server:
    container_name: doh-server
    image: satishweb/doh-server
    hostname: doh-server
    user: root
    network_mode: host
    volumes:
      - ./config/doh-server/doh-server.conf:/server/doh-server.conf
    restart: unless-stopped
    logging:
      driver: json-file
      options:
        max-size: 1m

@m13253
Copy link
Owner

m13253 commented Feb 7, 2025

Try this:

    volumes:
      - ./config/doh-server/doh-server.conf:/doh-server.conf

I’m not sure if this is the fix, but worth trying it.

@wx2020
Copy link
Author

wx2020 commented Feb 7, 2025

I tried to mount it like this, but the file didn't take effect😂...

Image

My docker-compose file:
Image

@m13253
Copy link
Owner

m13253 commented Feb 7, 2025

Looks like you are using a Docker image provided by satishweb/doh-server.
I didn’t author that container image, so you might need to check its Dockerfile to determine the correct way to supply configurations.

@satishweb
Copy link
Collaborator

satishweb commented Feb 7, 2025

Hi @wx2020,

Mounting the custom doh-server.conf at /server/doh-server.conf (reference) should work as expected. I’ve tested it with log_guessed_client_ip set to true, and it’s functioning correctly. Let me know if you’re still encountering any issues—I’d be happy to help troubleshoot further.

Corrected volume mount line:

volumes:
  - ./config/doh-server/doh-server.conf:/server/doh-server.conf

Additionally, in the next release of the container image, I’ll be adding environment configuration variables for the following DoH config keys:

log_guessed_client_ip
ecs_allow_non_global_ip
ecs_use_precise_ip
tls_client_auth
tls_client_auth_ca
local_addr
cert
key

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

3 participants