Comment 1 for bug 911207

Revision history for this message
James Hunt (jamesodhunt) wrote :

Most stanzas currently operate on all script/exec sections (with the notable exception of 'respawn').

A fix would be for job_process_run() to pass its ProcessType parameter to job_process_spawn() so that for example:

    if (class->setuid) { ... }

would become:

    if (class->setuid && process == PROCESS_MAIN) { ... }

However, if we did make setuid+setgid only apply to the main script/exec section:

1) it could be confusing to users expecting that stanza to "apply" to all script/exec sections.
2) it would be potentially dangerous if users create files in a pre-start for example thinking they will be
    owned by the setuid user when in fact they'd be owned by root. It would also be slightly annoying
    since users would need to remember to chown any files created in a pre-start section for example
    to make sure their ownership matched the user specified in the setuid stanza.

That said, we can of course document the behaviour to guard against misunderstandings since maybe the only common scenario where setuid/setgid support is required is for the main script/exec section?

We could modify the setuid/setgid syntax to take an optional list of section names to apply the setuid/setgid to:

    setuid USERNAME [<section>]
    setgid GROUPNAME [<section>]

Example:

    setuid james pre-start post-start
    setgid james pre-stop

... but there is no "name" for the main section since it is either "exec" or "script". We could accept both but that's not very elegant in these scenarios:

    setuid james pre-start exec
    script
      echo hello
    end script

    setuid james pre-start script
    exec echo hello

We should also think ahead: what if we introduce 'mkdir', 'chown', and 'chmod' stanzas? Who would they run as if setuid is specified?