• Bug#1100572: sudo: fails to parse regular expressions in sudoers file

    From fhomps@21:1/5 to All on Sat Mar 15 15:50:01 2025
    UGFja2FnZTogc3VkbwpWZXJzaW9uOiAxLjkuMTNwMy0xK2RlYjEydTEKU2V2ZXJpdHk6IG5vcm1h bApYLURlYmJ1Z3MtQ2M6IGZyYW5jb2lzQGhvbXBzLmZyCgpEZWFyIE1haW50YWluZXIsCgpzdWRv IGRvZXMgbm90IHNlZW0gdG8gcGFyc2UgcmVndWxhciBleHByZXNzaW9ucyBpbiBzdWRvZXJzIGZp bGVzIHByb3Blcmx5LgptYW4gc3VkbyBzdGF0ZXMgaXQgc2hvdWxkIGJlIGFibGUgdG8gZG8gc28g c2luY2UgMS45LjEwLgpJIGhhdmUgbm90IHRlc3RlZCB0aGUgZGViaWFuIHRlc3RpbmcgdmVyc2lv biAoMS45LjE2KSBhcyBJIGFtIG5vdCBjb21mb3J0YWJsZSByZXBsYWNpbmcgYW4gaW1wb3J0YW50 IHNlY3VyaXR5IGJpbmFyeSB3aXRoIGEgdGVzdGluZyB2ZXJzaW9uLgoKSSBmb3VuZCB0aGlzIHdo aWxlIGJ1aWxkaW5nIGFuIGluc3RhbmNlZCBzeXN0ZW1kIHNlcnZpY2UgZm9yIG1pbmVjcmFmdCBz ZXJ2ZXJzLgpJZGVhbGx5LCBJIHdhbnQgdXNlcnMgb2YgdGhlIGdyb3VwICJtaW5lY3JhZnQiIHRv IGJlIGFibGUgdG8gc3RhcnQgLyBzdG9wIC8gcmVzdGFydCBhbnkgaW5zdGFuY2Ugb2YgdGhlIHNl cnZpY2UuCk9uZSBzdWNoIGluc3RhbmNlIChmb3IgZXhhbXBsZSBwdXJwb3NlcykgaXMgbmFtZWQg InZhbmlsbGEiLgoKSSB0cmllZCB0byBwdXQgdGhlIGZvbGxvd2luZyBpbiAvZXRjL3N1ZG9lcnMu ZC9taW5lY3JhZnQ6CgolbWluZWNyYWZ0IEFMTD0gTk9QQVNTV0Q6IC9iaW4vc3lzdGVtY3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X3B0 eQpyb290CUFMTD0oQUxMOkFMTCkgQUxMCiVzdWRvCUFMTD0oQUxMOkFMTCkgQUxMCkBpbmNsdWRl ZGlyIC9ldGMvc3Vkb2Vycy5kCgoKLS0gbm8gZGViY29uZiBpbmZvcm1hdGlvbgo=

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Marc Haber@21:1/5 to fhomps on Sat Mar 15 16:20:01 2025
    On Sat, Mar 15, 2025 at 03:43:00PM +0100, fhomps wrote:
    sudo does not seem to parse regular expressions in sudoers files properly. >man sudo states it should be able to do so since 1.9.10.
    I have not tested the debian testing version (1.9.16) as I am not comfortable replacing an important security binary with a testing version.

    You should not install binary packages from testing on stable anyway.
    Good decision.

    If it is a bug in sudo, it is not going to be addressed in Debian 12,
    though, and I apologize for that.

    I found this while building an instanced systemd service for minecraft servers.
    Ideally, I want users of the group "minecraft" to be able to start / stop / restart any instance of the service.
    One such instance (for example purposes) is named "vanilla".

    I tried to put the following in /etc/sudoers.d/minecraft:

    %minecraft ALL= NOPASSWD: /bin/systemctl start minecraft@^[a-zA-Z0-9_]+$
    (and equivalent for stop and restart)

    I have not tried this myself, but the man page says:

    | A command is a fully qualified file name, which may include shell-style
    | wildcards (see the “Wildcards” section below), or a regular expression
    | that starts with ‘^’ and ends with ‘$’ (see the “Regular expressions”
    | section below).

    It doesn't say that you can arbitrarily mix string literals and regexps.

    Did you try

    %minecraft ALL= NOPASSWD: ^/bin/systemctl start minecraft@[a-zA-Z0-9_]+$

    I don't know whether the @ or the + need escaping. Try all variants
    please.

    There is also language saying

    | Command line arguments can
    | include wildcards or be a regular expression that starts with ‘^’ and
    | ends with ‘$’. If the command line arguments consist of ‘""’, the com‐
    | mand may only be run with no arguments.

    So

    %minecraft ALL= NOPASSWD: /bin/systemctl ^start minecraft@[a-zA-Z0-9_]+$

    might also work, but this still doesn't give any indication that your
    mixture of a regexp and a string literal works.

    Greetings
    Marc


    -- ----------------------------------------------------------------------------- Marc Haber | "I don't trust Computers. They | Mailadresse im Header Leimen, Germany | lose things." Winona Ryder | Fon: *49 6224 1600402 Nordisch by Nature | How to make an American Quilt | Fax: *49 6224 1600421

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?utf-8?Q?Fran=C3=A7ois_Homps?=@21:1/5 to Marc Haber on Sat Mar 15 18:00:01 2025
    Hi Marc,

    Thanks for the lightning fast reply.

    Did you try

    %minecraft ALL= NOPASSWD: ^/bin/systemctl start minecraft@[a-zA-Z0-9_]+$

    This does not work, but...

    %minecraft ALL= NOPASSWD: /bin/systemctl ^start minecraft@[a-zA-Z0-9_]+$

    ...this does. Thus, problem solved for my use case. Thanks a lot!

    Digging deeper, if I understand the EBNF notation in the manpage properly:

    command name ::= regex |
    file name

    command ::= command name |
    command name args |
    command name regex |
    command name '""' |
    ALL

    then "command name" should be able to be a regex too.
    Since in your first suggestion command name and args are part of the same regex, I tried splitting them:

    %minecraft ALL= NOPASSWD: ^/bin/systemctl$ ^start minecraft@[a-zA-Z0-9_]+$

    However, this still does not work.
    Just in case, I also tried forfeiting the second regex, which did not help:

    %minecraft ALL= NOPASSWD: ^/bin/systemctl$ start minecraft@vanilla

    Thus I'd argue there is still a bug.

    Best,
    François

    On Saturday, March 15th, 2025 at 4:12 PM, Marc Haber <mh+debian-packages@zugschlus.de> wrote:



    On Sat, Mar 15, 2025 at 03:43:00PM +0100, fhomps wrote:

    sudo does not seem to parse regular expressions in sudoers files properly. man sudo states it should be able to do so since 1.9.10.
    I have not tested the debian testing version (1.9.16) as I am not comfortable replacing an important security binary with a testing version.


    You should not install binary packages from testing on stable anyway.
    Good decision.

    If it is a bug in sudo, it is not going to be addressed in Debian 12,
    though, and I apologize for that.

    I found this while building an instanced systemd service for minecraft servers.
    Ideally, I want users of the group "minecraft" to be able to start / stop / restart any instance of the service.
    One such instance (for example purposes) is named "vanilla".

    I tried to put the following in /etc/sudoers.d/minecraft:

    %minecraft ALL= NOPASSWD: /bin/systemctl start minecraft@^[a-zA-Z0-9_]+$ (and equivalent for stop and restart)


    I have not tried this myself, but the man page says:

    | A command is a fully qualified file name, which may include shell-style
    | wildcards (see the “Wildcards” section below), or a regular expression | that starts with ‘^’ and ends with ‘$’ (see the “Regular expressions”
    | section below).

    It doesn't say that you can arbitrarily mix string literals and regexps.

    Did you try

    %minecraft ALL= NOPASSWD: ^/bin/systemctl start minecraft@[a-zA-Z0-9_]+$

    I don't know whether the @ or the + need escaping. Try all variants
    please.

    There is also language saying

    | Command line arguments can
    | include wildcards or be a regular expression that starts with ‘^’ and
    | ends with ‘$’. If the command line arguments consist of ‘""’, the com‐
    | mand may only be run with no arguments.

    So

    %minecraft ALL= NOPASSWD: /bin/systemctl ^start minecraft@[a-zA-Z0-9_]+$

    might also work, but this still doesn't give any indication that your
    mixture of a regexp and a string literal works.

    Greetings
    Marc


    -- ----------------------------------------------------------------------------- Marc Haber | "I don't trust Computers. They | Mailadresse im Header
    Leimen, Germany | lose things." Winona Ryder | Fon: *49 6224 1600402
    Nordisch by Nature | How to make an American Quilt | Fax: *49 6224 1600421

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Marc Haber@21:1/5 to All on Sat Mar 15 18:30:01 2025
    On Sat, Mar 15, 2025 at 04:48:10PM +0000, François Homps wrote:
    Thus I'd argue there is still a bug.

    Would you mind taking this to the upstream mailing list? Todd might be
    helpful here, and probably develop a fix.

    That fix will, however, NOT go into Debian 12. It might be in Debian 13.

    Greetings
    Marc


    -- ----------------------------------------------------------------------------- Marc Haber | "I don't trust Computers. They | Mailadresse im Header Leimen, Germany | lose things." Winona Ryder | Fon: *49 6224 1600402 Nordisch by Nature | How to make an American Quilt | Fax: *49 6224 1600421

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)