@@ -30,6 +30,7 @@ import (
30
30
"path/filepath"
31
31
"runtime"
32
32
"slices"
33
+ "syscall"
33
34
"time"
34
35
35
36
"github.com/gravitational/trace"
@@ -57,6 +58,9 @@ const (
57
58
reservedFreeDisk = 10_000_000
58
59
// debugSocketFileName is the name of Teleport's debug socket in the data dir.
59
60
debugSocketFileName = "debug.sock" // 10 MB
61
+ // requiredUmask must be set before this package can be used.
62
+ // Use syscall.Umask to set when no other goroutines are running.
63
+ requiredUmask = 0o022
60
64
)
61
65
62
66
// Log keys
@@ -67,6 +71,20 @@ const (
67
71
errorKey = "error"
68
72
)
69
73
74
+ // SetRequiredUmask sets the umask to match the systemd umask that the teleport-update service will execute with.
75
+ // This ensures consistent file permissions.
76
+ // NOTE: This must be run in main.go before any goroutines that create files are started.
77
+ func SetRequiredUmask (ctx context.Context , log * slog.Logger ) {
78
+ warnUmask (ctx , log , syscall .Umask (requiredUmask ))
79
+ }
80
+
81
+ func warnUmask (ctx context.Context , log * slog.Logger , old int ) {
82
+ if old &^requiredUmask != 0 {
83
+ log .WarnContext (ctx , "Restrictive umask detected. Umask has been changed to 0022 for teleport-update and all child processes." )
84
+ log .WarnContext (ctx , "All files created by teleport-update will have permissions set according to this umask." )
85
+ }
86
+ }
87
+
70
88
// NewLocalUpdater returns a new Updater that auto-updates local
71
89
// installations of the Teleport agent.
72
90
// The AutoUpdater uses an HTTP client with sane defaults for downloads, and
@@ -174,6 +192,7 @@ type LocalUpdaterConfig struct {
174
192
}
175
193
176
194
// Updater implements the agent-local logic for Teleport agent auto-updates.
195
+ // SetRequiredUmask must be called before any methods are executed, except for Status.
177
196
type Updater struct {
178
197
// Log contains a logger.
179
198
Log * slog.Logger
@@ -545,6 +564,7 @@ func isActiveOrEnabled(ctx context.Context, s Process) (bool, error) {
545
564
546
565
// Status returns all available local and remote fields related to agent auto-updates.
547
566
// Status is safe to run concurrently with other Updater commands.
567
+ // Status does not write files, and therefore does not require SetRequiredUmask.
548
568
func (u * Updater ) Status (ctx context.Context ) (Status , error ) {
549
569
var out Status
550
570
// Read configuration from update.yaml.
0 commit comments