Skip to content

Commit f84dc43

Browse files
committed
runtime/internal: Avoid use of os/user to generate default blessing
names. The user of os/user causes trouble with statically linked binaries (see golang/go#13470 and https://sourceware.org/bugzilla/show_bug.cgi?id=19341) The default blessing name generated doesn't really need os/user so remove it. Change-Id: I7105a269f63c855483c0296ac2919a50dff1e7ac
1 parent 8ccb1d0 commit f84dc43

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

runtime/internal/rt/security.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ package rt
66

77
import (
88
"fmt"
9+
"math/rand"
910
"os"
10-
"os/user"
11+
"time"
1112

1213
"v.io/v23/context"
1314
"v.io/v23/security"
@@ -86,20 +87,17 @@ func ipcAgent() (agent.Principal, error) {
8687
}
8788

8889
func defaultBlessingName() string {
89-
var name string
90-
if user, _ := user.Current(); user != nil && len(user.Username) > 0 {
91-
name = user.Username
92-
} else {
93-
name = "anonymous"
90+
options := []string{
91+
"apple", "banana", "cherry", "dragonfruit", "elderberry", "fig", "grape", "honeydew",
9492
}
93+
name := fmt.Sprintf("anonymous-%s-%d",
94+
options[rand.New(rand.NewSource(time.Now().Unix())).Intn(len(options))],
95+
os.Getpid())
9596
host, _ := os.Hostname()
96-
if host == "(none)" {
97-
// (none) is a common default hostname and contains parentheses,
98-
// which are invalid blessings characters.
99-
host = "anonymous"
100-
}
101-
if len(host) > 0 {
102-
name = name + "@" + host
97+
// (none) is a common default hostname and contains parentheses,
98+
// which are invalid blessings characters.
99+
if host == "(none)" || len(host) == 0 {
100+
return name
103101
}
104-
return fmt.Sprintf("%s-%d", name, os.Getpid())
102+
return name + "@" + host
105103
}

0 commit comments

Comments
 (0)