[GH-ISSUE #830] PR to support using .netrc file for basic auth? #588

Open
opened 2026-05-07 00:25:38 +02:00 by BreizhHardware · 0 comments

Originally created by @tomeon on GitHub (Aug 2, 2023).
Original GitHub issue: https://github.com/binwiederhier/ntfy/issues/830

💡 Support loading basic auth credentials from the .netrc file

Curious whether you'd be interested in a pull request adding support for loading basic auth credentials from the .netrc file when running ntfy {pub,sub}.

Proposal:

# ~/.netrc

machine ntfy.sh
    login someuser
    password hunter2
    
machine ntfy.internal.net
    login otheruser
    password 53c437!
---
# ~/.config/ntfy/client.yml

subscribe:
  - topic: https://ntfy.internal.net/general # uses credentials from the `machine ntfy.internal.net` block
  - topic: huntsman-reword-guiding-baggy-stainless # uses credentials from the `machine ntfy.sh` block

Load .netrc from the standard location (~/.netrc):

$ ntfy sub --from-config --netrc

Or, for a netrc somewhere other than ~/.netrc:

$ ntfy sub --from-config --netrc --netrc-file ~/.config/netrc/netrc

Or, equivalently:

$ NETRC="${XDG_CONFIG_HOME}/netrc/netrc" ntfy sub --from-config --netrc

Some pluses:

  1. Permits host-specific credentials reuse. Currently, ntfy {pub,sub} supports global default-user and default-password values. Supporting .netrc faciliates host-specific defaults, so that, if your client configurations lists multiple subscriptions each for multiple ntfy hosts, you don't have to re-specify user and password for each subscription that doesn't use default-user or default-password. Note also that this fixes, or at least works around, #829.
  2. Improves interoperability with / reuse by other tools. For instance, curl supports the --netrc and --netrc-file <filename> options.

Some minuses:

  1. Added complexity, when ntfy {pub,sub} already supports managing basic auth credentials by other means.
  2. Go modules for interacting with .netrc (at least, those hosted on GitHub) seem to have low development activity and maybe also low uptake, as judged by the number of stargazers.1

💻 Target components

  1. ntfy pub
  2. ntfy sub
  3. Any other ntfy client subcommands that support basic auth.

🙏 Thanks for your consideration!


  1. On the other hand, the .netrc format is pretty simple and has been stable for a while, so maybe "low development activity" just means "essentially complete"? ↩︎

Originally created by @tomeon on GitHub (Aug 2, 2023). Original GitHub issue: https://github.com/binwiederhier/ntfy/issues/830 :bulb: **Support loading basic auth credentials from the `.netrc` file** Curious whether you'd be interested in a pull request adding support for loading basic auth credentials from [the `.netrc` file](https://www.gnu.org/software/inetutils/manual/html_node/The-_002enetrc-file.html) when running `ntfy {pub,sub}`. Proposal: ``` # ~/.netrc machine ntfy.sh login someuser password hunter2 machine ntfy.internal.net login otheruser password 53c437! ``` ```yaml --- # ~/.config/ntfy/client.yml subscribe: - topic: https://ntfy.internal.net/general # uses credentials from the `machine ntfy.internal.net` block - topic: huntsman-reword-guiding-baggy-stainless # uses credentials from the `machine ntfy.sh` block ``` Load `.netrc` from the standard location (`~/.netrc`): ```shell-session $ ntfy sub --from-config --netrc ``` Or, for a netrc somewhere other than `~/.netrc`: ```shell-session $ ntfy sub --from-config --netrc --netrc-file ~/.config/netrc/netrc ``` Or, equivalently: ```shell-session $ NETRC="${XDG_CONFIG_HOME}/netrc/netrc" ntfy sub --from-config --netrc ``` Some pluses: 1. Permits host-specific credentials reuse. Currently, `ntfy {pub,sub}` supports global `default-user` and `default-password` values. Supporting `.netrc` faciliates host-specific defaults, so that, if your client configurations lists multiple subscriptions each for multiple `ntfy` hosts, you don't have to re-specify `user` and `password` for each subscription that doesn't use `default-user` or `default-password`. Note also that this fixes, or at least works around, #829. 2. Improves interoperability with / reuse by other tools. For instance, `curl` supports the `--netrc` and `--netrc-file <filename>` options. Some minuses: 1. Added complexity, when `ntfy {pub,sub}` already supports managing basic auth credentials by other means. 2. Go modules for interacting with `.netrc` (at least, [those hosted on GitHub](https://github.com/search?q=netrc+language%3Ago&type=repositories)) seem to have low development activity and maybe also low uptake, as judged by the number of stargazers.[^otoh] [^otoh]: On the other hand, the `.netrc` format is pretty simple and has been stable for a while, so maybe "low development activity" just means "essentially complete"? <!-- Share your thoughts; try to be detailed if you can --> :computer: **Target components** 1. `ntfy pub` 3. `ntfy sub` 4. Any other `ntfy` client subcommands that support basic auth. :pray: Thanks for your consideration!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ntfy#588
No description provided.