containrrr / watchtower

A process for automating Docker container base image updates.
https://containrrr.dev/watchtower/
Apache License 2.0
19.33k stars 854 forks source link

Quoted env variables don't work when containing comma #1896

Open ehaehner opened 10 months ago

ehaehner commented 10 months ago

Describe the bug

Hi. I want to set multiple recipients for email notifications. PR #436 should have included this but it seems that the commit linked below removed it again.

https://github.com/containrrr/watchtower/commit/35490c853d95f9ead6799bd2a16c991a0e1a0ddf#diff-bd0b1fd9ac0e1afadce1d756b31f0160ff2f61a788a085316599fd7997721bb4

Is it possible to reinclude this feature?

Steps to reproduce

  1. Set "WATCHTOWER_NOTIFICATION_EMAIL_TO" to "test@example.org,test2@example.org" (multiple mail addresses)
  2. start watchtower
  3. Error: "Failed to send shoutrrr notification" error="error sending message to recipient: error setting RCPT: 501 5.1.3 Bad recipient address syntax" index=0 notify=no service=smtp

Expected behavior

notification is send to all configured email addresses

Screenshots

No response

Environment

Your logs

level=error msg="Failed to send shoutrrr notification" error="error sending message to recipient: error setting RCPT: 501 5.1.3 Bad recipient address syntax" index=0 notify=no service=smtp

Additional context

No response

github-actions[bot] commented 10 months ago

Hi there! 👋🏼 As you're new to this repo, we'd like to suggest that you read our code of conduct as well as our contribution guidelines. Thanks a bunch for opening your first issue! 🙏

piksel commented 10 months ago

Multiple recipients should work fine for shoutrrr. It might be something with the legacy notifications adapter that encodes the commas, perhaps?

Try using a shoutrrr URL directly instead:

WATCHTOWER_NOTIFICATION_URL: smtp://username:password@host:port/?from=fromAddress&to=recipient1,recipient2

(you can see what the adapter transforms your notification configuration to if you run watchtower with --trace)

ehaehner commented 10 months ago

Setting this environment variable fixed the issue so I could find the issue on my side.

I used the following compose notation:

version: "3"
services:
  watchtower:
    environment:
      - WATCHTOWER_MONITOR_ONLY=true
      - WATCHTOWER_NOTIFICATIONS=email
      - WATCHTOWER_NOTIFICATIONS_LEVEL=info
      - WATCHTOWER_NO_STARTUP_MESSAGE=true
      - WATCHTOWER_NOTIFICATION_EMAIL_SERVER=mail
      - WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PORT=25
      - WATCHTOWER_NOTIFICATION_EMAIL_DELAY=2
      - WATCHTOWER_NOTIFICATION_EMAIL_SERVER_TLS_SKIP_VERIFY=true
      - WATCHTOWER_NOTIFICATION_EMAIL_FROM="from@example.com"
      - WATCHTOWER_NOTIFICATION_EMAIL_TO="to1@example.com,to2@example.com"
      - WATCHTOWER_LOG_LEVEL=trace
[...]

Removing the quotes fixed the issue. Quotes are fine for one recipient but with a comma the mentioned error is printed. Thank you for the support @piksel

piksel commented 9 months ago

Interesting! So this was caused by docker compose's environment parsing... Or perhaps it's due to our attempts at cleaning extra quotes that split the input into addresses before removing quotes...

I'll reopen this until it's properly investigated.

ehaehner commented 9 months ago

I just want to add another thing. This behavior seems to depend on the compose notation. I switched environment definition from a list to a map and then it is possible to use quotes.

The following two definitions are working: