dns-over-https icon indicating copy to clipboard operation
dns-over-https copied to clipboard

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

Open wx2020 opened this issue 10 months ago • 13 comments

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~

wx2020 avatar Feb 07 '25 12:02 wx2020

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

m13253 avatar Feb 07 '25 12:02 m13253

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?

wx2020 avatar Feb 07 '25 12:02 wx2020

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…

m13253 avatar Feb 07 '25 12:02 m13253

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

wx2020 avatar Feb 07 '25 12:02 wx2020

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!

m13253 avatar Feb 07 '25 12:02 m13253

Okey, i will try it!

wx2020 avatar Feb 07 '25 12:02 wx2020

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?

m13253 avatar Feb 07 '25 13:02 m13253

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

wx2020 avatar Feb 07 '25 13:02 wx2020

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.

m13253 avatar Feb 07 '25 13:02 m13253

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

Image

My docker-compose file: Image

wx2020 avatar Feb 07 '25 13:02 wx2020

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.

m13253 avatar Feb 07 '25 14:02 m13253

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

satishweb avatar Feb 07 '25 20:02 satishweb

It looks like the issue has been fixed on the Dockerfile side. @wx2020 Do you still experience the issue? If not, feel free to close.

m13253 avatar Jun 12 '25 04:06 m13253