From nobody Wed Nov 26 20:31:58 2025 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4dGrnv2VMDz6HNxb for ; Wed, 26 Nov 2025 20:32:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4dGrnv1fZtz3RZN for ; Wed, 26 Nov 2025 20:32:03 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1764189123; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=akQekX37cypbo8O+I9ig0+4e5IGn3acotHh4jBTGRxY=; b=YChv4mkFC/cVWWrkn/GcGebE3cvcpyIa+OG8MsFiFFVaSa0n1aAIlkxkDjmKqnPO0CCMyc sH3HnRyP4+hYZWlHYQUWLL7mDBgO6nWhl2rqMlAgNK1Xv+wDCzuyeiwBNmhUd4iE0J/Lc1 EnKYzSJ8fxqR/9L7jMy7Z3Dg5sUn6rzCkw2db+4X4VIjMG/ZGuCnqXUYgobXvEicOBQRFc arK4PA6u6rYs9bx7ADDHhe1dBeoM1xTrTy9OlNbVjqsvlfH+JKXCNI0vlL7awc/XVWmPVA jLhWhQ6ptfeozobYcBlhhJAA50iTDMi25zHH/0wsQJxO5PJf/mVt66/d+VRsFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1764189123; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=akQekX37cypbo8O+I9ig0+4e5IGn3acotHh4jBTGRxY=; b=Mgvmxr7dcVse52EWYngXnLKM7eQIDuhDShf/MsLmhAhwmhUY0cgkazWkEvcuaTBXT+itzw d8Jk5ogMJyva86WoYVUmvXPuC0kdp2eEJdci89gZIQ28ziIDiWvGsLKuwQoxNKGwu1NBbw Q6TGjvpAQMn8purmR8Km0VMgAJuhw571mbzsBogR/bcs5LflUsA+LbpvB/o1XdsV6SBP9L iphan9Yxzcgi8Fang+Kf5mvXoWmpWNCeW6u99nvXk74g+oZMqCop6VgN0xYhD2C8v8C6I6 ZHaaMNEeW39J5rwDRIv8zsSWOn1ajPASJGoE/npqTJriO94qFvNNCyqLby+zdg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1764189123; a=rsa-sha256; cv=none; b=sWLIS477lfgs1PqyPn9QXk+19CZI9KDcl+xe8rTW3BKyJWd/hPKF3c/yn7e9qU2br2sMNA QV+yLtqlCmsCazLfRbcRWFQGfA4IcV7njKoZ2K8w/dNuVz5gVfHSbRVWltrd/VxBslfuSI jZTlCaqcPkuCevL3HBE5TYYKL1StiUGi1Xl/ETSYwSEXhsrwwdhP81e5FiQSH8063rF2v9 d4BbmifTnzaE07hfbZy8DCp4WS4fudOHPXlfqKNlR1syIYijp3FEalUB+6sqOtWKQKfWoF WLTLNZLQh6G6eCItkshVgSrPI/xRvM2bZul28c+bhSB5QrfB+Iir0b3Wq1fTWA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4dGrnv0pnKz12Nx for ; Wed, 26 Nov 2025 20:32:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 30e89 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 26 Nov 2025 20:31:58 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Olivier Certner Subject: git: dc7503479273 - stable/15 - mdo.1: Document group-related and fine-grained control functionalities List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: olce X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: dc75034792739a638edf3d7b756e7175e5a79bf7 Auto-Submitted: auto-generated Date: Wed, 26 Nov 2025 20:31:58 +0000 Message-Id: <692763be.30e89.730c648f@gitrepo.freebsd.org> The branch stable/15 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=dc75034792739a638edf3d7b756e7175e5a79bf7 commit dc75034792739a638edf3d7b756e7175e5a79bf7 Author: Olivier Certner AuthorDate: 2025-09-01 15:24:54 +0000 Commit: Olivier Certner CommitDate: 2025-11-26 20:31:23 +0000 mdo.1: Document group-related and fine-grained control functionalities This is a manual page update describing the functionality that was added to mdo(1) in commit 3ca1e69028ac ("mdo(1): Add support and shortcuts for fully specifying users and groups"). Please either refer to that commit or the new manual page's content for more information. While here: - Add to the introduction a description of process credentials and some specific vocabulary that is used throughout the page, as well as the relationship between mdo(1) and mac_do(4). - Update the HISTORY section. - Add AUTHORS and SECURITY CONSIDERATIONS sections. Reviewed by: ziaee MFC after: 1 minute Sponsored by: The FreeBSD Foundation Sponsored by: Google LLC (GSoC 2025) Co-authored-by: Kushagra Srivastava Differential Revision: https://reviews.freebsd.org/D53905 (cherry picked from commit 73dd00f2fd7de2a5d8dda8fa25ebcd7c8964ff52) --- usr.bin/mdo/mdo.1 | 269 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 245 insertions(+), 24 deletions(-) diff --git a/usr.bin/mdo/mdo.1 b/usr.bin/mdo/mdo.1 index c4586f628661..1de694c69e40 100644 --- a/usr.bin/mdo/mdo.1 +++ b/usr.bin/mdo/mdo.1 @@ -1,49 +1,270 @@ .\"- -.\" Copyright(c) 2024 Baptiste Daroussin -.\" .\" SPDX-License-Identifier: BSD-2-Clause .\" -.Dd May 26, 2025 +.\" Copyright (c) 2024 Baptiste Daroussin +.\" Copyright (c) 2025 Kushagra Srivastava +.\" Copyright (c) 2025 The FreeBSD Foundation +.\" +.\" Portions of this documentation were written by Olivier Certner +.\" at Kumacom SARL under sponsorship from the FreeBSD +.\" Foundation. +.\" +.Dd November 26, 2025 .Dt MDO 1 .Os .Sh NAME .Nm mdo -.Nd execute commands as another user +.Nd execute commands with specific credentials .Sh SYNOPSIS .Nm -.Op Fl u Ar username +.Op Fl u Ar user | Fl k .Op Fl i -.Op command Op args +.Op Fl g Ar group +.Op Fl G Ar group1,group2,... +.Op Fl s Ar groups_mod1,groups_mod2,... +.Op Fl h +.Op Fl -ruid Ar user +.Op Fl -svuid Ar user +.Op Fl -euid Ar user +.Op Fl -rgid Ar group +.Op Fl -svgid Ar group +.Op Fl -egid Ar group +.Op -- +.Op Ar command Op Ar args ... .Sh DESCRIPTION The .Nm -utility executes the specified +utility executes the passed .Ar command -as user -.Ar username . -.Pp -If no -.Ar username -is provided it defaults to the -.Va root -user. -If no +with the requested process credentials or, if no .Ar command -is specified, it will execute the shell specified as -.Va SHELL -environnement variable, falling back on -.Pa /bin/sh . +was specified, the program whose path is the value of the +.Ev SHELL +environment variable or +.Pa /bin/sh +if that variable is unset. +The calling user must either be the superuser +.Pq effective user ID of 0 +or the credentials transition from the caller's to the requested ones must be +authorized by a MAC module such as +.Xr mac_do 4 . +The target process credentials are applied atomically using +.Xr setcred 2 . .Pp +Process credentials comprise the real, effective and saved user IDs, the real, +effective and saved group IDs, hereby called the +.Dq primary +groups, and the supplementary groups as a set of group IDs. +Below, the +.Dq user +phrase implies that the real, effective and saved user IDs all have or are going +to be set to the same value. The +.Dq primary group +phrase is used similarly with respect to primary groups. +.Pp +The target process credentials have to be fully specified, either explicitly by +listing all attributes and their requested values, or indirectly by establishing +a baseline that provides a default value for each attribute, which can then be +amended by additional options. +.Pp +Possible baselines are either the full set of credentials established at login +for a specific named user, the current credentials, or the current credentials' +primary and supplementary groups which implies some user is specified +explicitly. +They are respectively established by using either option +.Fl u +with a named user argument, option +.Fl k , +or option .Fl i -option can be used to only call -.Fn setuid -and keep the group from the calling user. +in conjunction with +.Fl u +or no other options. +If no other option than +.Fl i +appears, a default of +.Fl u Cm root +is implied. +.Pp +The primary group can be set or amended with option +.Fl g , +whereas the supplementary groups can be either fully replaced with an explicit +list using option +.Fl G +or amended through set-like operations with option +.Fl s . +.Pp +Any of the individual real, effective and saved user and group IDs can be +overridden separately if desired through the options +.Fl -ruid , +.Fl -euid , +and +.Fl -svuid +for users, and +.Fl -rgid , +.Fl -egid , +and +.Fl -svgid +for groups respectively. +.Pp +The options are: +.Bl -tag -width indent +.It Fl -euid Ar user +Override the effective user. +As for +.Fl u , +.Ar user +may either be a name or a numerical ID. +.It Fl -egid Ar group +Override the effective group. +As for +.Fl g , +.Ar group +may either be a name or a numerical ID. +.It Fl G Ar group1,group2,... +Set or replace the full set of supplementary groups. +As for +.Fl g , +groups can be specified by name or numerical ID. +Groups must be separated by commas, and spaces around commas are not allowed. +.It Fl g Ar group +Set or amend the primary group. +.Ar group +may be the name of a group in the group database, else will be interpreted as +a numerical group ID. +.It Fl h +Display usage information and exit. +.It Fl i +Uses the current credentials' primary and supplementary groups as the baseline. +If no other option is present, the target user is assumed to be +.Dq root . +Otherwise, +.Fl u +or +.Fl k +must be specified. +.It Fl k +Use the current credentials as the baseline. +Incompatible with +.Fl u . +Implies +.Fl i . +.It Fl -ruid Ar user +Override the real user. +As for +.Fl u , +.Ar user +may either be a name or a numerical ID. +.It Fl -rgid Ar group +Override the real group. +As for +.Fl g , +.Ar group +may either be a name or a numerical ID. +.It Fl s Ar groups_mod1,groups_mod2,... +Incrementally modify the supplementary groups set. +The argument is a comma-separated list of directives: +.Bl -tag -width indent -compact +.It Cm @ +Reset the set to the empty set. +When present, must be the first directive. +.It Cm + Ns Ar group +Include a group. +.It Cm - Ns Ar group +Exclude a group. +.El +If +.Fl G +is also specified, +.Fl s +applies on the list installed by it. +In this case, the +.Cm @ +directive cannot be used +.Pq this limitation may be lifted in the future . +.It Fl -svuid Ar user +Override the saved user. +As for +.Fl u , +.Ar user +may either be a name or a numerical ID. +.It Fl -svgid Ar group +Override the saved group. +As for +.Fl g , +.Ar group +may either be a name or a numerical ID. +.It Fl u Ar user +Specify a target user. +If +.Ar user +is the name of some user in the user database, +this option establishes his full login credentials, as specified by the user and +group databases, as the baseline. +Else, +.Ar user +is interpreted as a numerical user ID, and that ID is used to set the target +user only. +.El +.Sh EXAMPLES +Run a command as another user: +.Bd -literal -offset indent +mdo -u alice id +.Ed +.Pp +Run with explicit primary and supplementary groups: +.Bd -literal -offset indent +mdo -u 1001 -g wheel -G staff,operator /bin/sh +.Ed +.Pp +Modify only supplementary groups for the current user: +.Bd -literal -offset indent +mdo -k -s +wheel,+operator /usr/bin/id +.Ed +.Pp +Emulate the effect of a set-user-ID bit on the process image file, assuming its +user ID is +.Dq root : +.Bd -literal -offset indent +mdo -k --euid root --svuid root id +.Ed .Sh SEE ALSO .Xr su 1 , +.Xr setcred 2 , .Xr mac_do 4 .Sh HISTORY The .Nm -command appeared in +command first appeared in .Fx 14.2 . +.Pp +Support for specifying or amending groups, group-only transitions and +fine-grained control of real, effective and saved variants of user and primary +group first appeared in +.Fx 15.0 . +.Sh AUTHORS +The +.Nm +program was originally created by +.An -nosplit +.An Baptiste Daroussin Aq Mt bapt@FreeBSD.org . +It was modified to use the +.Xr setcred 2 +system call by +.An Olivier Certner Aq Mt olce@FreeBSD.org , +who designed the group-related and fine-grained-control-of-target-credentials +functionalities and supervised +.An Kushagra Srivastava Aq Mt kushagra1403@gmail.com +to add them during Google Summer of Code 2025. +.Sh SECURITY CONSIDERATIONS +The +.Nm +program is geared to role-based scenarios. +Consequently, it does not ask for any password or request other form of +authentication before trying to establish new credentials, instead relying +solely on the requester's credentials for this purpose. +.Pp +Specific unprivileged uses may be enabled by using the +.Xr mac_do 4 +security policy.