Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions cmd/aws-sigv4-proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,23 @@ func shouldLogSigning() bool {
}

func roleSessionName() string {
suffix, err := os.Hostname()
return roleSessionNameWithHostname(os.Hostname)
}

if err != nil {
now := time.Now().Unix()
suffix = strconv.FormatInt(now, 10)
func roleSessionNameWithHostname(hostnameFn func() (string, error)) string {
if env := os.Getenv("AWS_ROLE_SESSION_NAME"); env != "" {
return env
}

sessionName := "aws-sigv4-proxy-"
if hostname, err := hostnameFn(); err == nil {
sessionName += hostname
} else {
sessionName += strconv.FormatInt(time.Now().Unix(), 10)
}

return "aws-sigv4-proxy-" + suffix
if len(sessionName) > 64 {
return sessionName[:64]
}
return sessionName
}