-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Read user environment when creating child session #1020
Conversation
lib/srv/exec.go
Outdated
// readEnvironmentFile will read environment variables from a passed in location. | ||
// Lines that start with "#" or empty lines are ignored. Assignments are in the | ||
// form name=value and no variable expansion occurs. | ||
func readEnvironmentFile(filename string) ([]string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move this to utils
lib/srv/exec.go
Outdated
func readEnvironmentFile(filename string) ([]string, error) { | ||
file, err := os.Open(filename) | ||
if err != nil { | ||
return nil, trace.Wrap(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trace.ConvertSystemError
lib/srv/exec.go
Outdated
// follow the lead of OpenSSH and don't allow more than 1,000 environment variables | ||
// https://github.com/openssh/openssh-portable/blob/master/session.c#L873-L874 | ||
lineno = lineno + 1 | ||
if lineno > 1000 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move to constant
@@ -81,6 +81,9 @@ type CommandLineFlags struct { | |||
GopsAddr string | |||
// DiagnosticAddr is listen address for diagnostic endpoint | |||
DiagnosticAddr string | |||
// PermitUserEnvironment enables reading of ~/.tsh/environment | |||
// when creating a new session. | |||
PermitUserEnvironment bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not make this a boolean flag, rather than a list with files to read with default to .tsh/environment
so folks can actually set to something else if they want, e.g. will close the issue #1011
@@ -105,6 +105,8 @@ func Run(cmdlineArgs []string, testRun bool) (executedCommand string, conf *serv | |||
"Specify gops addr to listen on").Hidden().StringVar(&ccf.GopsAddr) | |||
start.Flag("diag-addr", | |||
"Start diangonstic endpoint on this address").Hidden().StringVar(&ccf.DiagnosticAddr) | |||
start.Flag("permit-user-env", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would make this a flag that accepts values with paths to read, defaulting to ~/.tsh/environment
ad0b82e
to
397fbcd
Compare
lib/srv/exec.go
Outdated
// if the server allows reading in of ~/.tsh/environment read it in | ||
// and pass environment variables along to new session | ||
if ctx.srv.PermitUserEnvironment() { | ||
filename := osUser.HomeDir + "/.tsh/environment" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filepath.Join() instead of +
397fbcd
to
e0ee27b
Compare
creating a new child session from ~/.tsh/environment.
e0ee27b
to
78ee5d0
Compare
Purpose
As covered in #1014, at the moment a new Teleport session only gives you a limited number of environment variables. This PR adds support for reading in of a
~./tsh/environment
that contains environment variables that will be loaded before the shell is executed.Implementation
--permit-user-env
CLI flag forteleport
.permit_user_env
field underssh_service
for Teleport file configuration.~/.tsh/environment
is read when creating a new child session. Variables in this file are not expanded and lines that start with#
or are empty are ignored.Related Issue
Fixes #1014