Skip to content

Commit 1a456ce

Browse files
committed
Add support for sudo-rs
Telepresence now supports running the root daemon using `sudo-rs`. This is necessary on Ubuntu where `sudo-rs` has become the default for `sudo`. Closes #3992 Signed-off-by: Thomas Hallgren <thomas@tada.se>
1 parent 395f185 commit 1a456ce

File tree

6 files changed

+38
-15
lines changed

6 files changed

+38
-15
lines changed

CHANGELOG.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ items:
2727
- version: 2.26.0
2828
date: (TBD)
2929
notes:
30+
- type: bugfix
31+
title: Add support for sudo-rs
32+
body: >-
33+
Telepresence now supports running the root daemon using `sudo-rs`. This is necessary on Ubuntu where `sudo-rs` has become the
34+
default for `sudo`.
3035
- type: feature
3136
title: Add ability for cluster admins to revoke other users' intercepts.
3237
body: |-

docs/release-notes.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
[comment]: # (Code generated by relnotesgen. DO NOT EDIT.)
33
# <img src="images/logo.png" height="64px"/> Telepresence Release Notes
44
## Version 2.26.0
5+
## <div style="display:flex;"><img src="images/bugfix.png" alt="bugfix" style="width:30px;height:fit-content;"/><div style="display:flex;margin-left:7px;">Add support for sudo-rs</div></div>
6+
<div style="margin-left: 15px">
7+
8+
Telepresence now supports running the root daemon using `sudo-rs`. This is necessary on Ubuntu where `sudo-rs` has become the default for `sudo`.
9+
</div>
10+
511
## <div style="display:flex;"><img src="images/feature.png" alt="feature" style="width:30px;height:fit-content;"/><div style="display:flex;margin-left:7px;">Add ability for cluster admins to revoke other users' intercepts.</div></div>
612
<div style="margin-left: 15px">
713

docs/release-notes.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ import { Note, Title, Body } from '@site/src/components/ReleaseNotes'
88

99
# Telepresence Release Notes
1010
## Version 2.26.0
11+
<Note>
12+
<Title type="bugfix">Add support for sudo-rs</Title>
13+
<Body>
14+
Telepresence now supports running the root daemon using `sudo-rs`. This is necessary on Ubuntu where `sudo-rs` has become the default for `sudo`.
15+
</Body>
16+
</Note>
1117
<Note>
1218
<Title type="feature">Add ability for cluster admins to revoke other users' intercepts.</Title>
1319
<Body>

pkg/client/cli/connect/connector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ func findHostConnectorInfo(ctx context.Context) (*daemon.Info, error) {
8585
}
8686

8787
func quitHostConnector(ctx context.Context) {
88-
progress.Working(ctx, "Quitting")
8988
info, err := findHostConnectorInfo(ctx)
9089
if err == nil {
9190
ctx, err = ExistingDaemon(ctx, info)
9291
}
92+
progress.Working(ctx, "Quitting")
9393
var errs error
9494
rootWillContinue := false
9595
if err != nil {

pkg/client/cli/connect/init_command.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ func InitCommand(cmd *cobra.Command) (err error) {
5858
flags.DeprecationIfChanged(cmd, global.FlagDocker, "use telepresence connect to initiate the connection")
5959
flags.DeprecationIfChanged(cmd, global.FlagContext, "use telepresence connect to initiate the connection")
6060
}
61-
progress.Start(ctx, "Connecting")
62-
progressStarted = true
6361
ctx, err = EnsureUserDaemon(ctx, v == ann.Required)
6462
if err != nil {
6563
if v == ann.Optional && (errors.Is(err, daemon.ErrNoUserDaemon) || errcat.GetCategory(err) == errcat.Config) {
@@ -80,10 +78,8 @@ func InitCommand(cmd *cobra.Command) (err error) {
8078
}
8179

8280
if v := as[ann.Session]; v == ann.Optional || v == ann.Required {
83-
if !progressStarted {
84-
progress.Start(ctx, "Connecting")
85-
progressStarted = true
86-
}
81+
progress.Start(ctx, "Connecting")
82+
progressStarted = true
8783
ctx, err = EnsureSession(ctx, cmd.UseLine(), v == ann.Required)
8884
defer progress.Stop(ctx)
8985
if err != nil {

pkg/proc/exec_unix.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"fmt"
88
"os"
99
"os/exec" //nolint:depguard // We want no logging and no soft-context signal handling
10+
"slices"
11+
"strings"
1012

1113
"golang.org/x/sys/unix"
1214

@@ -41,18 +43,26 @@ func startInBackground(includeEnv bool, args ...string) error {
4143
return nil
4244
}
4345

44-
func startInBackgroundAsRoot(_ context.Context, args ...string) error {
46+
func startInBackgroundAsRoot(ctx context.Context, args ...string) error {
4547
if isAdmin() {
4648
return startInBackground(false, args...)
4749
}
4850
// Run sudo with a prompt explaining why root credentials are needed.
49-
cmd := exec.Command("sudo", append([]string{
50-
"-b", "-p",
51-
fmt.Sprintf(
52-
"Need root privileges to run: %s\nPassword:",
53-
shellquote.ShellString(args[0], args[1:])),
54-
}, args...)...)
55-
return cmd.Run()
51+
const promptContext = "telepresence network daemon"
52+
err := exec.Command("sudo", append([]string{"-b", "-p", fmt.Sprintf("[sudo: %s] Password: ", promptContext)}, args...)...).Run()
53+
if err == nil {
54+
return nil
55+
}
56+
// Are we using sudo-rs?
57+
out, err2 := exec.Command("sudo", "--version").CombinedOutput()
58+
if err2 != nil || !strings.Contains(string(out), "sudo-rs") {
59+
// return the original error
60+
return err
61+
}
62+
// sudo-rs does not support the "-b" (background) option. We need it to start a shell command that backgrounds the executable
63+
// once the user has entered their password.
64+
cmdString := shellquote.ShellArgsString(slices.Insert(args, 0, "setsid")) + "</dev/null >/dev/null 2>&1 &"
65+
return exec.Command("sudo", "-p", promptContext, "sh", "-c", cmdString).Run()
5666
}
5767

5868
func terminate(p *os.Process) error {

0 commit comments

Comments
 (0)