Skip to content

Commit

Permalink
runtime/internal: Avoid use of os/user to generate default blessing
Browse files Browse the repository at this point in the history
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
  • Loading branch information
asimshankar committed Mar 26, 2016
1 parent 8ccb1d0 commit f84dc43
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions runtime/internal/rt/security.go
Expand Up @@ -6,8 +6,9 @@ package rt

import (
"fmt"
"math/rand"
"os"
"os/user"
"time"

"v.io/v23/context"
"v.io/v23/security"
Expand Down Expand Up @@ -86,20 +87,17 @@ func ipcAgent() (agent.Principal, error) {
}

func defaultBlessingName() string {
var name string
if user, _ := user.Current(); user != nil && len(user.Username) > 0 {
name = user.Username
} else {
name = "anonymous"
options := []string{
"apple", "banana", "cherry", "dragonfruit", "elderberry", "fig", "grape", "honeydew",
}
name := fmt.Sprintf("anonymous-%s-%d",
options[rand.New(rand.NewSource(time.Now().Unix())).Intn(len(options))],
os.Getpid())
host, _ := os.Hostname()
if host == "(none)" {
// (none) is a common default hostname and contains parentheses,
// which are invalid blessings characters.
host = "anonymous"
}
if len(host) > 0 {
name = name + "@" + host
// (none) is a common default hostname and contains parentheses,
// which are invalid blessings characters.
if host == "(none)" || len(host) == 0 {
return name
}
return fmt.Sprintf("%s-%d", name, os.Getpid())
return name + "@" + host
}

0 comments on commit f84dc43

Please sign in to comment.