binwiederhier / ntfy

Send push notifications to your phone or desktop using PUT/POST
https://ntfy.sh
Apache License 2.0
18.54k stars 729 forks source link

config ignored for non-root users, no debug output!? #1192

Closed bobemoe closed 1 month ago

bobemoe commented 1 month ago

:lady_beetle: Describe the bug

I have set /etc/ntfy/client.yml with a custom default-host and default-token and when i run as root ntfy pub test test it works just fine!

The issue is when I run as a normal user it seems to be ignoring /etc/ntfy/client.yml and publishing to ntfy.sh rather than my custom server.

I have confirmed my normal user can read /etc/ntfy/client.yml and that no ~/.config/ntfy/client.yml or ENV vars are overriding the config.

Additionally I try to debug with --debug and --trace but these add no extra output.

It works if I:

mkdir ~/.config/ntfy
cp /etc/ntfy/client.yml ~/.config/ntfy/

But I dont want to have to do that for all users :/

:computer: Components impacted

Devuan Linux, server running in docker and client using static binaries. ntfy 2.11.0 (d11b100), runtime go1.22.2, built at 2024-05-13T20:16:12Z

:bulb: Screenshots and/or logs

$ ntfy --debug --trace pub test test
{"id":"ABga54IscnkW","time":1727711598,"expires":1727754798,"event":"message","topic":"test","message":"test"}

:crystal_ball: Additional context

services:
  ntfy:
    image: binwiederhier/ntfy
    restart: unless-stopped
    environment:
      NTFY_BASE_URL: http://ntfy.xxxx.co.uk
      NTFY_CACHE_FILE: /var/lib/ntfy/cache.db
      NTFY_AUTH_FILE: /var/lib/ntfy/auth.db
      NTFY_AUTH_DEFAULT_ACCESS: deny-all
      NTFY_BEHIND_PROXY: true
      NTFY_ATTACHMENT_CACHE_DIR: /var/lib/ntfy/attachments
      NTFY_ENABLE_LOGIN: true
    volumes:
      - ./data/:/var/lib/ntfy
    ports:
      - 9753:80
    command: serve
wunter8 commented 1 month ago

It is mentioned briefly in the first paragraph of this section (https://docs.ntfy.sh/subscribe/cli/#install-configure), but the client CLI is only configured to look at /etc/ntfy/client.yml for the root user. When the ntfy client CLI is run as a non-profit user, the CLI looks in ~/.config/ntfy/client.yml.

You can tell the CLI to load a non-default config file by including it as a command line parameter: ntfy pub --config /etc/ntfy/client.yml test test

bobemoe commented 1 month ago

Ok, I was beginning to think it was expected behaviour. Your --config trick is useful but still a bit of a pain to implement for all users, I liked the idea of the CLI being simpler than curl where I have to include a -H Authorise... line. If I have to include a --config it is adding back a similar complexity.

Its not really the end of the world and I'm happy now I have the hang of it.

Maybe convert this to a feature request for a global "all users" config? Otherwise close as working.

Thanks.

wunter8 commented 1 month ago

It is expected that each user would have their own config (e.g., their own default server, their own default auth credentials, their own subscriptions, their own set of commands to run when a message is received, etc.). That's why, by default, the client CLI looks in the user's config directory.

If you want to easily use the /etc/ntfy/client.yml file, you can sudo ntfy pub test test or you can set up a command alias/function in your terminal to automatically include "--config /etc/ntfy/client.yml" (but I recognize that is also something you'd need to do/configure for each individual user)

bobemoe commented 1 month ago

All good suggestions, thanks :)