From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1E6351FBCAE; Wed, 12 Feb 2025 11:00:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739358039; cv=none; b=Doc2jVrncPurznRgC+D/8+WkZNnoihIoTOGMgGXkCzhVI9gYccAIQUNmDNwkYSoHcriUE3KbXpqqwHjHXR/Np14eddEHwj9g9gCXo+ro6eBOsHo6jbfpwJq7pYB0tFEqa76xt8kxSmV1TorT1u5KuCrq16nTGgcXKDZWcOOFAwM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739358039; c=relaxed/simple; bh=E804ZwOiCTNhddYYVX+ou/FxeDAYreu1N4qFP54OhB8=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=TZhdhIOsnlBa81tAXeVyFVmt7juMAuX2+nc3spGHfXMbq2Jl/3WEV0Yt54aRNwas4BlLvXjVLb2zx3QMVyDetxdT92BsZJ+Py8kxDmGqcQP8t16O37/og08vqxV5XVfNiPxHdMqg041HmVhys74X3g7vOTaLMYNxVIZ8hZ5lvcM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZXbD4JaU; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZXbD4JaU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BEBC8C4CEDF; Wed, 12 Feb 2025 11:00:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739358038; bh=E804ZwOiCTNhddYYVX+ou/FxeDAYreu1N4qFP54OhB8=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=ZXbD4JaUtuLUGXRJYWJ7d6a9x3V5nV6A2Q82MMjQG8tC0agfnDCKw8w1TJfw5naDB 6mpPssTUBo25aOeunMqtZR2ygUDv+aH3XkbOY2N2e788mwfvL8asQD2kc0QJbfqRjw 8R8Dpvj6ncLzxCaned8JhTIXX3SQFCye+hIAYQv8+HLxbWE39EbQd6ZPlxZ90rITJ0 dGcXnnwo4PVyQM4CugO0b7rX7q5nFIIPZnAdtoXGQG0LorbzipY/Ti37CKHzfTlcXN qY4lJt3jbHvWqpmFvmsGu0itHZdNhYe7/8qMTtZBSiuMsqZqSZsCAHY+AwKmcdf2Bj gc4ZLrPT95wJw== Message-ID: <97fd1bbb-1261-4af5-9321-27353547dbf7@kernel.org> Date: Wed, 12 Feb 2025 11:00:34 +0000 Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH bpf-next] bpftool: bash-completion: Add nopasswd sudo prefix for bpftool To: Rong Tao , ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org Cc: rongtao@cest.ccn, Rong Tao , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Tao Chen , Mykyta Yatsenko , Daniel Xu , "open list:BPF [TOOLING] (bpftool)" , open list References: From: Quentin Monnet Content-Language: en-GB In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 2025-02-12 18:14 UTC+0800 ~ Rong Tao > From: Rong Tao > > In the bpftool script of bash-completion, many bpftool commands require > superuser privileges to execute. Otherwise, Operation not permission will > be displayed. Here, we check whether ordinary users are exempt from > entering the sudo password. If so, we need to add the sudo prefix to the > bpftool command to be executed. In this way, we can obtain the correct > command completion content instead of the wrong one. > > For example, when updating array_of_maps, the wrong 'hex' is completed: > > $ sudo bpftool map update name arr_maps key 0 0 0 0 value [tab] > $ sudo bpftool map update name arr_maps key 0 0 0 0 value hex > > However, what we need is "id name pinned". Similarly, there is the same > problem in getting the map 'name' and 'id': > > $ sudo bpftool map show name [tab] < get nothing > $ sudo bpftool map show id [tab] < get nothing > > This commit fixes the issue. > > $ sudo bpftool map update name arr_maps key 0 0 0 0 value [tab] > id name pinned > > $ sudo bpftool map show name > arr_maps cgroup_hash inner_arr1 inner_arr2 > > $ sudo bpftool map show id > 11 1383 4091 4096 > > Signed-off-by: Rong Tao Hi, thanks for the patch. I agree it's annoying to have a partially-working completion for non-root users, however, I don't feel very comfortable introducing calls to "sudo" in bash completion, without the user noticing. For what it's worth, I searched other bash completion files (from https://github.com/scop/bash-completion/) and I can't find any of them running sudo to help complete commands, so it doesn't seem to be something usual in completion. I think I'd rather keep the current state (or fix the first example to have the right keywords displayed but without running sudo). Quentin