Re: need for open-minded help with popularity-contest with systemd timer

2026-08-06 Thread Matthias Urlichs

On 05.08.26 18:35, Andreas Metzler wrote:

Ideally there would be some protocol that could trace the submitted
message back to a user and possibly a process ID. I have wanted that
information for practical reasons before (trying to track down which
service was sending weird mail, for instance).

Time to revive ident / rfc 1413 😉


Actually you get that for free if you use a dbus interface.

Speaking of dbus, there might be a better alternative: simply monitor 
systemd's dbus (or varlink, I presume) interface. If a timer-started 
unit [or possibly any other system unit] fails, you can just pull its 
log from the journal and send the last five minutes' worth via email, or 
whatever other notification mechanism you want.


No cron/timer-specific mechanism, modification to your timer units, 
special privileges, … required.


--
-- regards
--
-- Matthias Urlichs



OpenPGP_signature.asc
Description: OpenPGP digital signature


Re: need for open-minded help with popularity-contest with systemd timer

2026-08-05 Thread Russ Allbery
Richard Lewis  writes:

> Can you give an example package/explanation of how - doing this would be
> useful for a lot of packages (could put it on the wiki / in some kind of
> policy?)

First I configured the SMTP daemon to listen to and allow relaying from
localhost if it didn't already. Then I installed msmtp and I reconfigured
the software to use msmtp instead of sendmail to send mail.

In this case, it was already possible to provide an arbitrary command-line
to override the default of using sendmail. If that's not possible,
obviously more work would be needed.

Specifically, I changed a default of:

/usr/sbin/sendmail -oi -oem %s

to:

/usr/bin/msmtp --host=localhost --read-envelope-from %s

-- 
Russ Allbery ([email protected])  



Re: need for open-minded help with popularity-contest with systemd timer

2026-08-05 Thread Richard Lewis
Russ Allbery  writes:

> "Jonathan Dowland"  writes:
>> On Sun Jul 26, 2026 at 4:56 PM BST, alimiracle wrote:
>
>>> An explicit mail submission service with a well-defined API
>
>> SMTP?
>
> This is what I've personally done with systemd services that I've wanted
> to harden by adding no-new-privileges, for example. I've switched them
> over to submitting messages via SMTP to localhost, and that's been fine
> for me.

Can you give an example package/explanation of how - doing this would be useful 
for
a lot of packages (could put it on the wiki / in some kind of policy?)



Re: need for open-minded help with popularity-contest with systemd timer

2026-08-05 Thread Jan Claeys
On Sun, 2026-07-26 at 08:56 -0700, alimiracle wrote:
> The `sendmail` interface has served Unix systems extremely well
> fordecades, but it was designed around assumptions that modern
> service managers intentionally no longer guarantee. Trying to
> preserve those assumptions inside increasingly hardened systemd units
> feels liketreating the symptom rather than the underlying issue.

> An explicit mail submission service with a well-defined API,
> whetherover D-Bus or another IPC mechanism, would provide a cleaner
> contract between applications and the local MTA. It would also make
> authorization, auditing, and sandboxing much more predictable
> thanrelying on `setuid`/`setgid` behavior.

You seem to assume the “sendmail interface” requires a local MTA (it
doesn’t).

> At the same time, I hope any new interface remains MTA-agnostic
> andsimple to implement. One of the strengths of the traditional
> `sendmail` interface is that applications do not need to know whether
> the underlying MTA is Exim, Postfix, OpenSMTPD, or something else. It
> would be great if we could preserve that portability while
> modernizing the implementation.

I don’t think the “sendmail interface” is the problem here, rather than
many current implementations of it.  Maybe the “sendmail interface”
implementations provided by Exim/Postfix/etc. need to implement
alternative ways to hand over mails on hardened systems though.  Or an
independent “sendmail interface” implementation (possibly provided by
systemd?) needs to act as a bridge.

That said, there might be a good reason to define a more modern API
than the “sendmail interface”, but that’s a separate issue (it would
not solve issues with existing software using the interface).


-- 
Jan Claeys

(please don't CC me when replying to the list)



Re: need for open-minded help with popularity-contest with systemd timer

2026-08-05 Thread Russ Allbery
Andreas Metzler  writes:

> Time to revive ident / rfc 1413 ;-)

I maintained a Kerberos-enabled version of that for years! That actually
would work for the localhost use case, although it has unsolvable security
issues if exposed to an external network, so you'd need to make sure it
was limited to just localhost.

-- 
Russ Allbery ([email protected])  



Re: need for open-minded help with popularity-contest with systemd timer

2026-08-05 Thread Andreas Metzler
On 2026-08-04 Russ Allbery  wrote:
[...]
> This is what I've personally done with systemd services that I've wanted
> to harden by adding no-new-privileges, for example. I've switched them
> over to submitting messages via SMTP to localhost, and that's been fine
> for me. But it is worth noting that this loses information compared to
> using the sendmail interface, specifically the user the process that sent
> the email was running as.

> It also requires running an SMTP listener on localhost, which people don't
> always do on systems with stub SMTP clients. Of course for
> popularity-contest it can submit directly to Debian in the most common
> case, but a general solution to the problem would be useful.

> Ideally there would be some protocol that could trace the submitted
> message back to a user and possibly a process ID. I have wanted that
> information for practical reasons before (trying to track down which
> service was sending weird mail, for instance).

Time to revive ident / rfc 1413 ;-)

cu Andreas
-- 
"You people are noisy," Nia said.
I made the gesture of agreement.



Re: need for open-minded help with popularity-contest with systemd timer

2026-08-04 Thread Russ Allbery
"Jonathan Dowland"  writes:
> On Sun Jul 26, 2026 at 4:56 PM BST, alimiracle wrote:

>> An explicit mail submission service with a well-defined API

> SMTP?

This is what I've personally done with systemd services that I've wanted
to harden by adding no-new-privileges, for example. I've switched them
over to submitting messages via SMTP to localhost, and that's been fine
for me. But it is worth noting that this loses information compared to
using the sendmail interface, specifically the user the process that sent
the email was running as.

It also requires running an SMTP listener on localhost, which people don't
always do on systems with stub SMTP clients. Of course for
popularity-contest it can submit directly to Debian in the most common
case, but a general solution to the problem would be useful.

Ideally there would be some protocol that could trace the submitted
message back to a user and possibly a process ID. I have wanted that
information for practical reasons before (trying to track down which
service was sending weird mail, for instance).

-- 
Russ Allbery ([email protected])  



Re: need for open-minded help with popularity-contest with systemd timer

2026-08-04 Thread Jonathan Dowland

On Sun Jul 26, 2026 at 4:56 PM BST, alimiracle wrote:

An explicit mail submission service with a well-defined API


SMTP?

--
⢀⣴⠾⠻⢶⣦⠀
⣾⠁⢠⠒⠀⣿⡁ Jonathan Dowland
⢿⡄⠘⠷⠚⠋⠀ https://jmtd.net
⠈⠳⣄



signature.asc
Description: PGP signature


Re: need for open-minded help with popularity-contest with systemd timer

2026-08-02 Thread Marco d'Itri

On Jul 30, Simon McVittie  wrote:

No, if you exec /usr/sbin/sendmail, the MTA infrastructure has the 
option to log facts about that sendmail process, such as your uid (and 
in theory other facts like process ID, whether you're in a container 
or cgroup, AppArmor profile and so on), in mail.log or the message 
headers or whatever place its implementor thinks is most appropriate. 

This is true[1], but I do not think that it is the main point.

The big benefit of /usr/sbin/sendmail over connecting to a daemon is 
that mail will not be lost when the daemon is not available.
Or at least I remember that this was part of the rationale for Postfix 
being designed this way 30 years ago: mail can always be queued to 
/var/spool/postfix/maildrop/.
And of course being able to do this from an unprivileged process 
requires to either use a sgid helper (the default) or a 1777 directory 
(not the default, because it allows a local DoS).


[1] but also: UNIX domain sockets and SO_PEERCRED.

--
ciao,
Marco


signature.asc
Description: PGP signature


Re: need for open-minded help with popularity-contest with systemd timer

2026-07-30 Thread Simon McVittie

On Thu, 30 Jul 2026 at 12:26:08 +0100, Richard Lewis wrote:

Simon McVittie  writes:

SMTP over TCP is the lowest-common-denominator email submission
protocol, but any protocol over TCP has the big disadvantage that it's
necessary to be able to authenticate the sender in some way, if you
want any access control beyond "every process on this machine can send
email, and the system can't tell which process/user was responsible".


(isnt the bit in quotes exactly what the current sendmail interface
provides, perhaps changing it should be left for another day?)


No, if you exec /usr/sbin/sendmail, the MTA infrastructure has the 
option to log facts about that sendmail process, such as your uid (and 
in theory other facts like process ID, whether you're in a container or 
cgroup, AppArmor profile and so on), in mail.log or the message headers 
or whatever place its implementor thinks is most appropriate. For 
example:


% ssh people.debian.org
$ mail smcv

results in a mail that says:

Received: from smcv by paradis.debian.org with local (Exim 4.96) ...

because the exim service on p.d.o is in a position to know who I am (it 
can get my uid from the sendmail process that I ran, and then my 
username from /etc/passwd or other NSS mechanisms).


Unlike the envelope-from (which is under my control), this is 
unforgeable, or at least, a MTA author can make it unforgeable - I don't 
know for sure that the authors of Exim did, but I hope so.


But if I had done SMTP to TCP port 25 or 587 then either I would 
have to authenticate (in practice with a username/password), or the mail 
would have to just say something like:


Received: from localhost ([::1]:39364) by paradis.debian.org with smtp 
(Exim 4.96) ...

because the MTA doesn't actually know who I am, and has to believe my 
assertions about my identity (the envelope-from).


smcv



Re: need for open-minded help with popularity-contest with systemd timer

2026-07-30 Thread Richard Lewis
Simon McVittie  writes:

> On Sun, 26 Jul 2026 at 09:52:37 +0100, Richard Lewis wrote:
>>Simon Richter  writes:
>>> Can we create a systemd service that sends a mail, and has its own
>>> lifetime and permissions?
>>
>>I think all you need is:
>>
>>1. a command that takes mail as input, and then passes it to the server
>>(this command is run in the caller's cgroup - it will block only until
>>the "passes off" part is done, and maybe some basic syntax checking -
>>then it can exit)
>>
>>2. a server that waits for input, and then calls mail(1) to deliver
>>it. (I think as long as the server is in a separate systemd .service
>>this will all work, as whatever processes the local mta start wont be
>>killed if the .service is persistent.)
>
> Thinking outside this particular box in the spirit of open-mindedness,
> is there a reason why popcon needs to submit data via email?


dont tbink so - popcon already defaults to http and email is already an
opt-in. 

but there are a lot of other packages that want to email the admin from
a .service where there isnt an alternative (my fav is logcheck, but
there are many)



Re: need for open-minded help with popularity-contest with systemd timer

2026-07-30 Thread Richard Lewis
Simon McVittie  writes:

> On Wed, 29 Jul 2026 at 13:27:05 +0100, Richard Lewis wrote:
>>Simon Richter  writes:
>>> /usr/bin/sendmail is a Unix interface.
>>>
>>> It assumes Unix semantics:
>>>  - runs as the calling user
>>>  - has access to the user home directory
>>>  - additional privileges are defined by the sysadmin through
>>>setuid. The distribution provides a default
>>>  - background tasks can linger
>>>
>>> Systemd explicitly does not want to follow Unix semantics
>
> Perhaps more accurate to say that the traditional Unix semantics
> involved "each program can more or less do what it wants", and by
> default systemd enforces a subset of what was traditionally allowed,
> which has advantages and disadvantages.

> Specifically, the thing that breaks exim seems to be that systemd
> doesn't normally let background tasks linger as part of a service
> after the service "should" have exited, in an effort to make process
> and cgroup lifetimes and ownership on the overall system something
> that is easier to reason abou


thabks - this is very helpful and i agree with all of this

> And, separately, the thing that breaks postfix (and possibly exim, not
> sure) is that systemd encourages authors of service definitions to
> apply a least-privilege level of sandboxing/hardening to each service,
> some of which involves PR_SET_NO_NEW_PRIVS to disarm setuid/setgid,
> and that conflicts with assumptions made by postfix (and possibly
> exim).
>

this but is easy to work round by not applying the appropriate
directives - it would be good if the debian wiki had a page on what
to do for postfix.



>>> So: if there should be a way for a program to send mail, there
>>> needs
>>> to be a dbus service, with proper authorization through the policy
>>> framework.
>>
>>dbus seems a but overkill?
>

> SMTP over TCP is the lowest-common-denominator email submission
> protocol, but any protocol over TCP has the big disadvantage that it's
> necessary to be able to authenticate the sender in some way, if you
> want any access control beyond "every process on this machine can send
> email, and the system can't tell which process/user was responsible".
>

(isnt the bit in quotes exactly what the current sendmail interface
provides, perhaps changing it should be left for another day?)



Re: need for open-minded help with popularity-contest with systemd timer

2026-07-29 Thread Simon McVittie

On Sun, 26 Jul 2026 at 09:52:37 +0100, Richard Lewis wrote:

Simon Richter  writes:

Can we create a systemd service that sends a mail, and has its own
lifetime and permissions?


I think all you need is:

1. a command that takes mail as input, and then passes it to the server
(this command is run in the caller's cgroup - it will block only until
the "passes off" part is done, and maybe some basic syntax checking -
then it can exit)

2. a server that waits for input, and then calls mail(1) to deliver
it. (I think as long as the server is in a separate systemd .service
this will all work, as whatever processes the local mta start wont be
killed if the .service is persistent.)


Thinking outside this particular box in the spirit of open-mindedness, 
is there a reason why popcon needs to submit data via email? Hasn't it 
defaulted to HTTP POST for the last 20+ years, precisely because 
increasingly many systems don't have a fully-configured local MTA, only 
an email client like Thunderbird that is designed to talk directly to 
remote servers, or webmail?


I understand that in principle, e-mail allows popcon to send a message 
at a time convenient to popcon, potentially when the system has no 
network connectivity, and have the message delivered later; but I have 
to wonder how many popcon installations exist where that is practically 
useful.


Similarly, I know that there are probably systems that can reach the 
outside world via an email relay but cannot do "live" HTTP, perhaps 
because of network security restrictions imposed on a locked-down 
network. But how many such systems would enable popcon submissions? If 
your sysadmin team's network control is tight enough to require all HTTP 
to go through proxies or be prevented entirely, then the same sysadmins 
probably don't want end systems to "phone home" to Debian either?


Perhaps it's time to make existing installations switch to submitting 
popcon data via HTTP, with the email transport only used on systems 
where an explicit opt-in has been done?


smcv



Re: need for open-minded help with popularity-contest with systemd timer

2026-07-29 Thread Simon McVittie

On Wed, 29 Jul 2026 at 13:27:05 +0100, Richard Lewis wrote:

Simon Richter  writes:

/usr/bin/sendmail is a Unix interface.

It assumes Unix semantics:
 - runs as the calling user
 - has access to the user home directory
 - additional privileges are defined by the sysadmin through
   setuid. The distribution provides a default
 - background tasks can linger

Systemd explicitly does not want to follow Unix semantics


Perhaps more accurate to say that the traditional Unix semantics 
involved "each program can more or less do what it wants", and by 
default systemd enforces a subset of what was traditionally allowed, 
which has advantages and disadvantages.


Specifically, the thing that breaks exim seems to be that systemd 
doesn't normally let background tasks linger as part of a service after 
the service "should" have exited, in an effort to make process and 
cgroup lifetimes and ownership on the overall system something that is 
easier to reason about: if popcon.service asks to send an email, then 
exits, the worldview that systemd encourages is that it is unexpected to 
have a daemonized exim process still hanging around in popcon.service's 
cgroup ("part of popcon", not "part of exim"!) to carry out the actual 
delivery.


And, separately, the thing that breaks postfix (and possibly exim, not 
sure) is that systemd encourages authors of service definitions to apply 
a least-privilege level of sandboxing/hardening to each service, some of 
which involves PR_SET_NO_NEW_PRIVS to disarm setuid/setgid, and that 
conflicts with assumptions made by postfix (and possibly exim).


If delivering email with exim (or postfix) requires relaxing what 
systemd normally allows, that gives us a scalability problem where each 
service that might send email needs to be reconfigured to have 
sufficiently unrestrictive access to allow everything exim wants to do, 
and also everything that postfix wants to do, and so on.


We'd have similar problems if popcon was running under a restrictive 
AppArmor profile, or any other source of sandboxing/hardening - systemd 
isn't really special here.



cleaning up broken lingering processes is a nice benefit of systemd


Indeed. But systemd can only do this because, by default, it places a 
constraint on the managed service: "lingering processes are assumed to 
be brokenness". If you turn off that constraint for a service (which is 
possible but discouraged) then systemd can no longer give you the 
corresponding benefit, because it can't tell the difference between 
broken lingering processes and intentional lingering processes.



i think just the last one is the issue. but is that really part of the
sendmail interface or an accident of how exim implements it?


The point is that exim makes assumptions that were (accidentally or 
deliberately) true on traditional Unix systems, but as part of systemd 
(or individual systemd service files) giving services a more narrow set 
of constraints, some of those assumptions are no longer true.



So: if there should be a way for a program to send mail, there needs
to be a dbus service, with proper authorization through the policy
framework.


dbus seems a but overkill?


Specifically, what's needed is a way to submit a request in execution 
environment A, such that the request arrives at an exim or postfix 
service in execution environment B, and then exim or postfix can take 
over responsibility for acting on that request (delivering mail).


Often the best way to do that sort of cross-domain communication is to 
have a process listen on an AF_UNIX socket, and make the requester 
connect to the AF_UNIX socket and talk to it, ideally using SO_PEERCRED 
or SCM_CREDS to identify the caller's uid from unforgeable 
kernel-provided information instead of needing to use passwords/secrets 
for authentication. Path-based AF_UNIX sockets have the advantage that 
can be bind-mounted into chroots or containers (if you want to allow 
communication) or not bind-mounted (if you want to deny communication), 
unlike abstract AF_UNIX sockets and networking protocols like TCP/UDP 
(which are difficult to allow/deny for sandboxed services at a level 
that is not all-or-nothing).


D-Bus on the system bus (requests encoded as D-Bus messages and sent 
through an AF_UNIX socket to the message bus, which passes the request 
to the implementor) is one popular way to do this; that removes the need 
to design the low-level messaging protocol and its security model on a 
per-application basis, which is why quite a lot of newer system services 
like NetworkManager and systemd use it.


But it could equally well be SMTP over AF_UNIX (do MTAs implement that?  
perhaps they should?), or SMTP over TCP to 127.0.0.1:587 or [::1]:587 or 
:25, or varlink over AF_UNIX, or some other mail submission protocol 
like LMTP over AF_UNIX or TCP.


SMTP over TCP is the lowest-common-denominator email submission 
protocol, but any protocol over TCP has the big disadvantage that it's 

Re: need for open-minded help with popularity-contest with systemd timer

2026-07-29 Thread Richard Lewis
Simon Richter  writes:

> Hi,
>
> On 7/26/26 18:29, Andreas Metzler wrote:
>
>>> Can we create a systemd service that sends a mail, and has its own
>>> lifetime
>>> and permissions?
>
>> afaiui the important thing when interacting with a local exim is to
>> *not* submit mail from a systemd service via the /usr/sbin/sendmail
>> interface. This avoids having the exim and the respective service in the
>> same cgroup. Submitting by smtp should work avoid this.
>
> /usr/bin/sendmail is a Unix interface.
>
> It assumes Unix semantics:
>  - runs as the calling user
>  - has access to the user home directory
>  - additional privileges are defined by the sysadmin through
>setuid. The distribution provides a default
>  - background tasks can linger
>
> Systemd explicitly does not want to follow Unix semantics

i think just the last one is the issue. but is that really part of the
sendmail interface or an accident of how exim implements it?

cleaning up broken lingering processes is a nice benefit of systemd

> So: if there should be a way for a program to send mail, there needs
> to be a dbus service, with proper authorization through the policy
> framework.

dbus seems a but overkill?



Re: need for open-minded help with popularity-contest with systemd timer

2026-07-26 Thread alimiracle

On Mon, Jul 27, 2026 at 12:34:23AM +0900, Simon Richter wrote:

> Systemd explicitly does not want to follow Unix semantics, so we cannot
> assume that Unix semantics will hold unless there is an explicit
> mechanism for them, and we are seeing breakage precisely where we're
> using a Unix tool inside a non-Unix environment.

Another possibility would be to use an init-inside-init approach. In 
other words, let systemd start a small init wrapper, and have that 
wrapper launch and supervise the actual service.


That way, systemd remains the system's init process, but the service 
itself follows traditional Unix init semantics. Child processes can 
outlive the original process when appropriate, without depending on 
systemd-specific cgroup behavior or options such as `TimeoutStopSec=`.


This might provide better compatibility for software that was originally 
designed with classic Unix process management in mind.


على 7/26/2026 ‫9:36 AM، كتب Florian Lohoff:

On Mon, Jul 27, 2026 at 12:34:23AM +0900, Simon Richter wrote:
Systemd explicitly does not want to follow Unix semantics, so we 
cannot assume that Unix semantics will hold unless there is an 
explicit mechanism for them, and we are seeing breakage precisely 
where we're using a Unix tool inside a non-Unix environment.


It changes the semantics but the creator of the unit chooses how
hardened it should be.

I do have had the same issues with uucico calling systemd. uucico
spawns uuxqt which may linger around processing jobs. Strict
systemd kills all uuxqt when all data has been transferred.

Solved it by giving uuxqt more time to finish its job:

TimeoutStopSec=120s

I remember having a different solution by instructing systemd to not 
kill the whole cgroup when the main process exits, so basically

going back to "good ol days" in not cleaning up behind the job.

Flo
--
Florian Lohoff [email protected]
  Any sufficiently advanced technology is indistinguishable from magic.

Re: need for open-minded help with popularity-contest with systemd timer

2026-07-26 Thread Florian Lohoff

On Mon, Jul 27, 2026 at 12:34:23AM +0900, Simon Richter wrote:
Systemd explicitly does not want to follow Unix semantics, so we 
cannot assume that Unix semantics will hold unless there is an 
explicit mechanism for them, and we are seeing breakage precisely 
where we're using a Unix tool inside a non-Unix environment.


It changes the semantics but the creator of the unit chooses how
hardened it should be.

I do have had the same issues with uucico calling systemd. uucico
spawns uuxqt which may linger around processing jobs. Strict
systemd kills all uuxqt when all data has been transferred.

Solved it by giving uuxqt more time to finish its job:

TimeoutStopSec=120s

I remember having a different solution by instructing systemd to not 
kill the whole cgroup when the main process exits, so basically

going back to "good ol days" in not cleaning up behind the job.

Flo
--
Florian Lohoff [email protected]
  Any sufficiently advanced technology is indistinguishable from magic.


signature.asc
Description: PGP signature


Re: need for open-minded help with popularity-contest with systemd timer

2026-07-26 Thread alimiracle

I think I agree with the direction Simon is describing.

The `sendmail` interface has served Unix systems extremely well for 
decades, but it was designed around assumptions that modern service 
managers intentionally no longer guarantee. Trying to preserve those 
assumptions inside increasingly hardened systemd units feels like 
treating the symptom rather than the underlying issue.


An explicit mail submission service with a well-defined API, whether 
over D-Bus or another IPC mechanism, would provide a cleaner contract 
between applications and the local MTA. It would also make 
authorization, auditing, and sandboxing much more predictable than 
relying on `setuid`/`setgid` behavior.


At the same time, I hope any new interface remains MTA-agnostic and 
simple to implement. One of the strengths of the traditional `sendmail` 
interface is that applications do not need to know whether the 
underlying MTA is Exim, Postfix, OpenSMTPD, or something else. It would 
be great if we could preserve that portability while modernizing the 
implementation.


على 7/26/2026 ‫8:34 AM، كتب Simon Richter:

Hi,

On 7/26/26 18:29, Andreas Metzler wrote:

Can we create a systemd service that sends a mail, and has its own 
lifetime

and permissions?



afaiui the important thing when interacting with a local exim is to
*not* submit mail from a systemd service via the /usr/sbin/sendmail
interface. This avoids having the exim and the respective service in the
same cgroup. Submitting by smtp should work avoid this.


/usr/bin/sendmail is a Unix interface.

It assumes Unix semantics:
 - runs as the calling user
 - has access to the user home directory
 - additional privileges are defined by the sysadmin through setuid. 
The distribution provides a default

 - background tasks can linger

Systemd explicitly does not want to follow Unix semantics, so we 
cannot assume that Unix semantics will hold unless there is an 
explicit mechanism for them, and we are seeing breakage precisely 
where we're using a Unix tool inside a non-Unix environment.


The answer to that isn't to hack something to restore enough of the 
Unix semantics to make it work for another release, but to explicitly 
define an interface that does not rely on implementation details of a 
non-hardened environment, because that is not supportable.


So: if there should be a way for a program to send mail, there needs 
to be a dbus service, with proper authorization through the policy 
framework.


   Simon

Re: need for open-minded help with popularity-contest with systemd timer

2026-07-26 Thread Simon Richter

Hi,

On 7/26/26 18:29, Andreas Metzler wrote:


Can we create a systemd service that sends a mail, and has its own lifetime
and permissions?



afaiui the important thing when interacting with a local exim is to
*not* submit mail from a systemd service via the /usr/sbin/sendmail
interface. This avoids having the exim and the respective service in the
same cgroup. Submitting by smtp should work avoid this.


/usr/bin/sendmail is a Unix interface.

It assumes Unix semantics:
 - runs as the calling user
 - has access to the user home directory
 - additional privileges are defined by the sysadmin through setuid. 
The distribution provides a default

 - background tasks can linger

Systemd explicitly does not want to follow Unix semantics, so we cannot 
assume that Unix semantics will hold unless there is an explicit 
mechanism for them, and we are seeing breakage precisely where we're 
using a Unix tool inside a non-Unix environment.


The answer to that isn't to hack something to restore enough of the Unix 
semantics to make it work for another release, but to explicitly define 
an interface that does not rely on implementation details of a 
non-hardened environment, because that is not supportable.


So: if there should be a way for a program to send mail, there needs to 
be a dbus service, with proper authorization through the policy framework.


   Simon


OpenPGP_signature.asc
Description: OpenPGP digital signature


Re: need for open-minded help with popularity-contest with systemd timer

2026-07-26 Thread Simon McVittie

On Sun, 26 Jul 2026 at 14:38:05 +0200, Marco d'Itri wrote:

On Jul 26, Andreas Metzler  wrote:

(I do not think postfix has this problem, its sendmail writes a
file in the maildrop queue. Further processing happends by
pickup monitoring the maildrop queue and picking it up there, without
fork/exec.)


Correct.


postfix does have a different problem for systemd services that is worth 
bearing in mind, though: the maildrop mechanism described above relies 
on some component having privileges (setgid mail if I remember correctly).


This is fine for a simple, un-hardened systemd service, but if a service 
has the NoNewPrivileges hardening option (or DynamicUser, which implies 
NoNewPrivileges), then that service will be unable to send mail by 
running postfix's sendmail program. See for example 
https://bugs.debian.org/998242, which despite its title did affect both 
exim and postfix.


smcv



Re: need for open-minded help with popularity-contest with systemd timer

2026-07-26 Thread Andy Smith
Hi,

On Sun, Jul 26, 2026 at 11:29:00AM +0200, Andreas Metzler wrote:
> (I do not think postfix has this problem, its sendmail writes a
> file in the maildrop queue. Further processing happends by
> pickup monitoring the maildrop queue and picking it up there, without
> fork/exec.)

We have however seen some posts in debian-user where people are confused
about why their service set up on a new release can no longer send
email, e.g. a monitoring service. When we have dug into it, it's been
because the service gained a systemd service unit with directives that
prevent writing to the postfix spool.

So there is some thought needed if adding protections to a service unit
that sends email, if it is to be run on a system with a setup like
Postfix.

Thanks,
Andy

-- 
https://bitfolk.com/ -- No-nonsense VPS hosting



Re: need for open-minded help with popularity-contest with systemd timer

2026-07-26 Thread Marco d'Itri

On Jul 26, Andreas Metzler  wrote:


(I do not think postfix has this problem, its sendmail writes a
file in the maildrop queue. Further processing happends by
pickup monitoring the maildrop queue and picking it up there, without
fork/exec.)

Correct.

--
ciao,
Marco


signature.asc
Description: PGP signature


Re: need for open-minded help with popularity-contest with systemd timer

2026-07-26 Thread Andreas Metzler
On 2026-07-25 Simon Richter  wrote:
> Hi,

> On 7/25/26 21:14, Richard Lewis wrote:

> > - the timer should start a service that runs new-script, and then does a 
> > "sleep 10" to ensure exim can deliver the email before
> >systemd kills the unit (see #1106030)
> >(better workarounds welcomed)

> Can we create a systemd service that sends a mail, and has its own lifetime
> and permissions?


Hello,

afaiui the important thing when interacting with a local exim is to
*not* submit mail from a systemd service via the /usr/sbin/sendmail
interface. This avoids having the exim and the respective service in the
same cgroup. Submitting by smtp should work avoid this.

(I do not think postfix has this problem, its sendmail writes a
file in the maildrop queue. Further processing happends by
pickup monitoring the maildrop queue and picking it up there, without
fork/exec.)

cu Andreas

-- 
"You people are noisy," Nia said.
I made the gesture of agreement.



Re: need for open-minded help with popularity-contest with systemd timer

2026-07-26 Thread Richard Lewis
Simon Richter  writes:

> Hi,
>
> On 7/25/26 21:14, Richard Lewis wrote:
>
>> - the timer should start a service that runs new-script, and then does a 
>> "sleep 10" to ensure exim can deliver the email before
>>systemd kills the unit (see #1106030)
>>(better workarounds welcomed)
>
> Can we create a systemd service that sends a mail, and has its own
> lifetime and permissions?

yes please!

I think all you need is:

1. a command that takes mail as input, and then passes it to the server
(this command is run in the caller's cgroup - it will block only until
the "passes off" part is done, and maybe some basic syntax checking -
then it can exit)

2. a server that waits for input, and then calls mail(1) to deliver
it. (I think as long as the server is in a separate systemd .service
this will all work, as whatever processes the local mta start wont be
killed if the .service is persistent.)

It would the server would need to cope with multiple concurrent requests
or queue requests (becuase lots of cronjob-type things wanting to send
reports might run at once) (this is the point at which things exceed my
knowledge!), and have some way of bouncing back errors (maybe mail(1)
already does enough? probably just mail the sender like an smtp server
would). Maybe it needs some kind of queue so that if the system is
rebooted before the mail is sent things dont get lost.

I think the server would only need to listen locally (again beyond my
knowledge - the word "socket" springs to mind) and wouldnt need anything
special for permissions - the local mta is already enforcing any
restrictions.

None of this should cause issues on non-systemd systems i wouldnt think
(it would be entirely superfluous, but maybe other init systems putting
things in cgroups would have the same issue. i think it might also
enable sending mail from a container to the host)




Re: need for open-minded help with popularity-contest with systemd timer

2026-07-25 Thread Simon Richter

Hi,

On 7/25/26 21:14, Richard Lewis wrote:


- the timer should start a service that runs new-script, and then does a "sleep 
10" to ensure exim can deliver the email before
   systemd kills the unit (see #1106030)
   (better workarounds welcomed)


Can we create a systemd service that sends a mail, and has its own 
lifetime and permissions?


   Simon


OpenPGP_signature.asc
Description: OpenPGP digital signature


Re: need for open-minded help with popularity-contest with systemd timer

2026-07-25 Thread Richard Lewis
Bill Allombert  writes:

> Dear Debian developers,
>
> I am trying to fix bug #1089172
> popularity-contest: migrate cron job to systemd timer on Linux ports
>
> While this is reasonable thing to do, popcon has a number of unusual 
> requirements,
> hence the open-minded in the subject...

Could you say what the unusual requirements are? i couldnt tell from the bug

i think one issue is that sending email from systemd-timers is harder
than it should be due to an incompatibility between the way exim (and
maybe postfix) fork processes and systemd's assumptions about how things
should work

but generally you can:

- move the code that does the work from the current cron job file to new-script
- the cron job should a) if  [ -d /run/systemd/system ]; then exit 0; else 
new-script;fi
- the timer should start a service that runs new-script, and then does a "sleep 
10" to ensure exim can deliver the email before
  systemd kills the unit (see #1106030)
  (better workarounds welcomed)


the second step means cron is a no-op on systemd but will still operate for 
non-systemd