Skip to content

Commit 52be29c

Browse files
committed
[supervisor] support multi-line environment variable in ssh
1 parent c67e609 commit 52be29c

File tree

4 files changed

+15
-28
lines changed

4 files changed

+15
-28
lines changed

Diff for: components/supervisor/openssh/BUILD.yaml

-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,5 @@ packages:
99
- ["rm", "-rf", "components-supervisor-openssh--docker-build"]
1010
- name: docker-build
1111
type: docker
12-
srcs:
13-
- "*.patch"
1412
config:
1513
dockerfile: leeway.Dockerfile

Diff for: components/supervisor/openssh/leeway.Dockerfile

-2
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,10 @@ RUN ./configure \
5454
--with-privsep-user=nobody \
5555
--with-ssl-engine
5656

57-
COPY supervisorenv.patch .
5857
ENV aports=https://raw.githubusercontent.com/alpinelinux/aports/master/main/openssh
5958
RUN curl -fsSL \
6059
"${aports}/{avoid-redefined-warnings-when-building-with-utmps,disable-forwarding-by-default,fix-utmp,fix-verify-dns-segfault,gss-serv.c,sftp-interactive}.patch" \
6160
| patch -p1
62-
RUN cat supervisorenv.patch | patch -p1
6361
RUN make install-nosysconf exec_prefix=/openssh
6462

6563
RUN TEST_SSH_UNSAFE_PERMISSIONS=1 \

Diff for: components/supervisor/openssh/supervisorenv.patch

-14
This file was deleted.

Diff for: components/supervisor/pkg/supervisor/ssh.go

+15-10
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ func newSSHServer(ctx context.Context, cfg *Config, envvars []string) (*sshServe
3333
return nil, xerrors.Errorf("unexpected error creating SSH key: %w", err)
3434
}
3535
}
36-
err = writeSSHEnv(cfg, envvars)
36+
err = ensureSSHDir(cfg)
3737
if err != nil {
38-
return nil, xerrors.Errorf("unexpected error creating SSH env: %w", err)
38+
return nil, xerrors.Errorf("unexpected error creating SSH dir: %w", err)
3939
}
4040

4141
return &sshServer{
@@ -103,6 +103,18 @@ func (s *sshServer) handleConn(ctx context.Context, conn net.Conn) {
103103
"-oLogLevel DEBUG", // enabled DEBUG mode by default
104104
}
105105

106+
envs := make([]string, 0)
107+
for _, env := range s.envvars {
108+
s := strings.SplitN(env, "=", 2)
109+
if len(s) != 2 {
110+
continue
111+
}
112+
envs = append(envs, fmt.Sprintf("%s=%s", s[0], fmt.Sprintf("\"%s\"", strings.ReplaceAll(s[1], "\"", "\\\""))))
113+
}
114+
if len(envs) > 0 {
115+
args = append(args, fmt.Sprintf("-oSetEnv %s", strings.Join(envs, " ")))
116+
}
117+
106118
socketFD, err := conn.(*net.TCPConn).File()
107119
if err != nil {
108120
log.WithError(err).Error("cannot start SSH server")
@@ -189,21 +201,14 @@ func prepareSSHKey(ctx context.Context, sshkey string) error {
189201
return nil
190202
}
191203

192-
func writeSSHEnv(cfg *Config, envvars []string) error {
204+
func ensureSSHDir(cfg *Config) error {
193205
home := "/home/gitpod"
194206

195207
d := filepath.Join(home, ".ssh")
196208
err := os.MkdirAll(d, 0o700)
197209
if err != nil {
198210
return xerrors.Errorf("cannot create $HOME/.ssh: %w", err)
199211
}
200-
201-
fn := filepath.Join(d, "supervisor_env")
202-
err = os.WriteFile(fn, []byte(strings.Join(envvars, "\n")), 0o644)
203-
if err != nil {
204-
return xerrors.Errorf("cannot write %s: %w", fn, err)
205-
}
206-
207212
_ = exec.Command("chown", "-R", fmt.Sprintf("%d:%d", gitpodUID, gitpodGID), d).Run()
208213

209214
return nil

0 commit comments

Comments
 (0)