Skip to content

Commit 9792d21

Browse files
AlexTugarevroboquat
authored andcommitted
Revert "[supervisor] Support envvars from OTS"
This reverts commit 438d878.
1 parent 9e44565 commit 9792d21

File tree

4 files changed

+29
-106
lines changed

4 files changed

+29
-106
lines changed

components/supervisor/pkg/supervisor/config.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,6 @@ type WorkspaceConfig struct {
240240
// DotfileRepo is a user-configurable repository which contains their dotfiles to customise
241241
// the in-workspace epxerience.
242242
DotfileRepo string `env:"SUPERVISOR_DOTFILE_REPO"`
243-
244-
// EnvvarOTS points to a URL from which environment variables for child processes can be downloaded from.
245-
// This provides a safer means to transport environment variables compared to shipping them on the Kubernetes pod.
246-
//
247-
// The format of the content downloaded from this URL is expected to be JSON in the form of [{"name":"name", "value":"value"}]
248-
EnvvarOTS string `env:"SUPERVISOR_ENVVAR_OTS"`
249243
}
250244

251245
// WorkspaceGitpodToken is a list of tokens that should be added to supervisor's token service.

components/supervisor/pkg/supervisor/ssh.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"github.com/gitpod-io/gitpod/common-go/process"
2121
)
2222

23-
func newSSHServer(ctx context.Context, cfg *Config, envvars []string) (*sshServer, error) {
23+
func newSSHServer(ctx context.Context, cfg *Config) (*sshServer, error) {
2424
bin, err := os.Executable()
2525
if err != nil {
2626
return nil, xerrors.Errorf("cannot find executable path: %w", err)
@@ -33,23 +33,21 @@ 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 = writeSSHEnv(cfg)
3737
if err != nil {
3838
return nil, xerrors.Errorf("unexpected error creating SSH env: %w", err)
3939
}
4040

4141
return &sshServer{
42-
ctx: ctx,
43-
cfg: cfg,
44-
sshkey: sshkey,
45-
envvars: envvars,
42+
ctx: ctx,
43+
cfg: cfg,
44+
sshkey: sshkey,
4645
}, nil
4746
}
4847

4948
type sshServer struct {
50-
ctx context.Context
51-
cfg *Config
52-
envvars []string
49+
ctx context.Context
50+
cfg *Config
5351

5452
sshkey string
5553
}
@@ -116,7 +114,7 @@ func (s *sshServer) handleConn(ctx context.Context, conn net.Conn) {
116114
log.WithField("args", args).Debug("sshd flags")
117115
cmd := exec.CommandContext(ctx, openssh, args...)
118116
cmd = runAsGitpodUser(cmd)
119-
cmd.Env = s.envvars
117+
cmd.Env = buildChildProcEnv(s.cfg, nil)
120118
cmd.ExtraFiles = []*os.File{socketFD}
121119
cmd.Stderr = os.Stderr
122120
cmd.Stdin = bufio.NewReader(socketFD)
@@ -192,7 +190,7 @@ func prepareSSHKey(ctx context.Context, sshkey string) error {
192190
return nil
193191
}
194192

195-
func writeSSHEnv(cfg *Config, envvars []string) error {
193+
func writeSSHEnv(cfg *Config) error {
196194
home, err := os.UserHomeDir()
197195
if err != nil {
198196
return err
@@ -205,7 +203,8 @@ func writeSSHEnv(cfg *Config, envvars []string) error {
205203
}
206204

207205
fn := filepath.Join(d, "supervisor_env")
208-
err = os.WriteFile(fn, []byte(strings.Join(envvars, "\n")), 0o644)
206+
env := strings.Join(buildChildProcEnv(cfg, nil), "\n")
207+
err = os.WriteFile(fn, []byte(env), 0o644)
209208
if err != nil {
210209
return xerrors.Errorf("cannot write %s: %w", fn, err)
211210
}

components/supervisor/pkg/supervisor/supervisor.go

Lines changed: 17 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,12 @@ func Run(options ...RunOption) {
153153
return
154154
}
155155

156-
// BEWARE: we can only call buildChildProcEnv once, because it might download env vars from a one-time-secret
157-
// URL, which would fail if we tried another time.
158-
childProcEnvvars := buildChildProcEnv(cfg, nil)
159-
160156
err = AddGitpodUserIfNotExists()
161157
if err != nil {
162158
log.WithError(err).Fatal("cannot ensure Gitpod user exists")
163159
}
164160
symlinkBinaries(cfg)
165-
configureGit(cfg, childProcEnvvars)
161+
configureGit(cfg)
166162

167163
tokenService := NewInMemoryTokenService()
168164
tkns, err := cfg.GetTokens(true)
@@ -250,7 +246,7 @@ func Run(options ...RunOption) {
250246
return ""
251247
}
252248
}
253-
termMuxSrv.Env = childProcEnvvars
249+
termMuxSrv.Env = buildChildProcEnv(cfg, nil)
254250
termMuxSrv.DefaultCreds = &syscall.Credential{
255251
Uid: gitpodUID,
256252
Gid: gitpodGID,
@@ -287,15 +283,15 @@ func Run(options ...RunOption) {
287283

288284
// We need to checkout dotfiles first, because they may be changing the path which affects the IDE.
289285
// TODO(cw): provide better feedback if the IDE start fails because of the dotfiles (provide any feedback at all).
290-
installDotfiles(ctx, cfg, childProcEnvvars)
286+
installDotfiles(ctx, termMuxSrv, cfg)
291287
}
292288

293289
var ideWG sync.WaitGroup
294290
ideWG.Add(1)
295-
go startAndWatchIDE(ctx, cfg, &cfg.IDE, childProcEnvvars, &ideWG, ideReady, WebIDE)
291+
go startAndWatchIDE(ctx, cfg, &cfg.IDE, &ideWG, ideReady, WebIDE)
296292
if cfg.DesktopIDE != nil {
297293
ideWG.Add(1)
298-
go startAndWatchIDE(ctx, cfg, cfg.DesktopIDE, childProcEnvvars, &ideWG, desktopIdeReady, DesktopIDE)
294+
go startAndWatchIDE(ctx, cfg, cfg.DesktopIDE, &ideWG, desktopIdeReady, DesktopIDE)
299295
}
300296

301297
var wg sync.WaitGroup
@@ -304,7 +300,7 @@ func Run(options ...RunOption) {
304300
wg.Add(1)
305301
go startAPIEndpoint(ctx, cfg, &wg, apiServices, tunneledPortsService, apiEndpointOpts...)
306302
wg.Add(1)
307-
go startSSHServer(ctx, cfg, &wg, childProcEnvvars)
303+
go startSSHServer(ctx, cfg, &wg)
308304
wg.Add(1)
309305
tasksSuccessChan := make(chan taskSuccess, 1)
310306
go taskManager.Run(ctx, &wg, tasksSuccessChan)
@@ -340,7 +336,7 @@ func Run(options ...RunOption) {
340336
}()
341337

342338
cmd := runAsGitpodUser(exec.Command("git", "fetch", "--unshallow", "--tags"))
343-
cmd.Env = childProcEnvvars
339+
cmd.Env = buildChildProcEnv(cfg, nil)
344340
cmd.Dir = cfg.RepoRoot
345341
cmd.Stdout = os.Stdout
346342
cmd.Stderr = os.Stderr
@@ -374,7 +370,7 @@ func Run(options ...RunOption) {
374370
wg.Wait()
375371
}
376372

377-
func installDotfiles(ctx context.Context, cfg *Config, childProcEnvvars []string) {
373+
func installDotfiles(ctx context.Context, term *terminal.MuxTerminalService, cfg *Config) {
378374
repo := cfg.DotfileRepo
379375
if repo == "" {
380376
return
@@ -389,7 +385,7 @@ func installDotfiles(ctx context.Context, cfg *Config, childProcEnvvars []string
389385
prep := func(cfg *Config, out io.Writer, name string, args ...string) *exec.Cmd {
390386
cmd := exec.Command(name, args...)
391387
cmd.Dir = "/home/gitpod"
392-
cmd.Env = childProcEnvvars
388+
cmd.Env = buildChildProcEnv(cfg, nil)
393389
cmd.SysProcAttr = &syscall.SysProcAttr{
394390
// All supervisor children run as gitpod user. The environment variables we produce are also
395391
// gitpod user specific.
@@ -592,7 +588,7 @@ func symlinkBinaries(cfg *Config) {
592588
}
593589
}
594590

595-
func configureGit(cfg *Config, childProcEnvvars []string) {
591+
func configureGit(cfg *Config) {
596592
settings := [][]string{
597593
{"push.default", "simple"},
598594
{"alias.lg", "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"},
@@ -608,7 +604,7 @@ func configureGit(cfg *Config, childProcEnvvars []string) {
608604
for _, s := range settings {
609605
cmd := exec.Command("git", append([]string{"config", "--global"}, s...)...)
610606
cmd = runAsGitpodUser(cmd)
611-
cmd.Env = childProcEnvvars
607+
cmd.Env = buildChildProcEnv(cfg, nil)
612608
cmd.Stdout = os.Stdout
613609
cmd.Stderr = os.Stderr
614610
err := cmd.Run()
@@ -709,7 +705,7 @@ const (
709705
statusShouldShutdown
710706
)
711707

712-
func startAndWatchIDE(ctx context.Context, cfg *Config, ideConfig *IDEConfig, childProcEnvvars []string, wg *sync.WaitGroup, ideReady *ideReadyState, ide IDEKind) {
708+
func startAndWatchIDE(ctx context.Context, cfg *Config, ideConfig *IDEConfig, wg *sync.WaitGroup, ideReady *ideReadyState, ide IDEKind) {
713709
defer wg.Done()
714710
defer log.WithField("ide", ide.String()).Debug("startAndWatchIDE shutdown")
715711

@@ -731,7 +727,7 @@ supervisorLoop:
731727
}
732728

733729
ideStopped = make(chan struct{}, 1)
734-
cmd = prepareIDELaunch(cfg, ideConfig, childProcEnvvars)
730+
cmd = prepareIDELaunch(cfg, ideConfig)
735731
launchIDE(cfg, ideConfig, cmd, ideStopped, ideReady, &ideStatus, ide)
736732

737733
select {
@@ -812,7 +808,7 @@ func launchIDE(cfg *Config, ideConfig *IDEConfig, cmd *exec.Cmd, ideStopped chan
812808
}()
813809
}
814810

815-
func prepareIDELaunch(cfg *Config, ideConfig *IDEConfig, childProcEnvvars []string) *exec.Cmd {
811+
func prepareIDELaunch(cfg *Config, ideConfig *IDEConfig) *exec.Cmd {
816812
args := ideConfig.EntrypointArgs
817813

818814
// Add default args for IDE (not desktop IDE) to be backwards compatible
@@ -840,7 +836,7 @@ func prepareIDELaunch(cfg *Config, ideConfig *IDEConfig, childProcEnvvars []stri
840836
Gid: gitpodGID,
841837
},
842838
}
843-
cmd.Env = childProcEnvvars
839+
cmd.Env = buildChildProcEnv(cfg, nil)
844840

845841
// Here we must resist the temptation to "neaten up" the IDE output for headless builds.
846842
// This would break the JSON parsing of the headless builds.
@@ -858,8 +854,6 @@ func prepareIDELaunch(cfg *Config, ideConfig *IDEConfig, childProcEnvvars []stri
858854

859855
// buildChildProcEnv computes the environment variables passed to a child process, based on the total list
860856
// of envvars. If envvars is nil, os.Environ() is used.
861-
//
862-
// Beware: if config contains an OTS URL the results may differ on subsequent calls.
863857
func buildChildProcEnv(cfg *Config, envvars []string) []string {
864858
if envvars == nil {
865859
envvars = os.Environ()
@@ -882,20 +876,6 @@ func buildChildProcEnv(cfg *Config, envvars []string) []string {
882876
}
883877
envs["SUPERVISOR_ADDR"] = fmt.Sprintf("localhost:%d", cfg.APIEndpointPort)
884878

885-
if cfg.EnvvarOTS != "" {
886-
es, err := downloadEnvvarOTS(cfg.EnvvarOTS)
887-
if err != nil {
888-
log.WithError(err).Warn("unable to download environment variables from OTS")
889-
}
890-
for k, v := range es {
891-
if isBlacklistedEnvvar(k) {
892-
continue
893-
}
894-
895-
envs[k] = v
896-
}
897-
}
898-
899879
// We're forcing basic environment variables here, because supervisor acts like a login process at this point.
900880
// The gitpod user might not have existed when supervisor was started, hence the HOME coming
901881
// from the container runtime is probably wrong ("/" to be exact).
@@ -931,31 +911,6 @@ func buildChildProcEnv(cfg *Config, envvars []string) []string {
931911
return env
932912
}
933913

934-
func downloadEnvvarOTS(url string) (res map[string]string, err error) {
935-
client := &http.Client{Timeout: 10 * time.Second}
936-
resp, err := client.Get(url)
937-
if err != nil {
938-
return nil, err
939-
}
940-
941-
defer resp.Body.Close()
942-
943-
var dl []struct {
944-
Name string `json:"name"`
945-
Value string `json:"value"`
946-
}
947-
err = json.NewDecoder(resp.Body).Decode(&dl)
948-
if err != nil {
949-
return nil, err
950-
}
951-
952-
res = make(map[string]string)
953-
for _, e := range dl {
954-
res[e.Name] = e.Value
955-
}
956-
return res, nil
957-
}
958-
959914
func runIDEReadinessProbe(cfg *Config, ideConfig *IDEConfig, ide IDEKind) (desktopIDEStatus *DesktopIDEStatus) {
960915
defer log.WithField("ide", ide.String()).Info("IDE is ready")
961916

@@ -1224,15 +1179,15 @@ func stopWhenTasksAreDone(ctx context.Context, wg *sync.WaitGroup, shutdown chan
12241179
shutdown <- ShutdownReasonSuccess
12251180
}
12261181

1227-
func startSSHServer(ctx context.Context, cfg *Config, wg *sync.WaitGroup, childProcEnvvars []string) {
1182+
func startSSHServer(ctx context.Context, cfg *Config, wg *sync.WaitGroup) {
12281183
defer wg.Done()
12291184

12301185
if cfg.isHeadless() {
12311186
return
12321187
}
12331188

12341189
go func() {
1235-
ssh, err := newSSHServer(ctx, cfg, childProcEnvvars)
1190+
ssh, err := newSSHServer(ctx, cfg)
12361191
if err != nil {
12371192
log.WithError(err).Error("err starting SSH server")
12381193
}

components/supervisor/pkg/supervisor/supervisor_test.go

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ package supervisor
66

77
import (
88
"fmt"
9-
"net/http"
10-
"net/http/httptest"
119
"os"
1210
"sort"
1311
"testing"
@@ -28,7 +26,6 @@ func TestBuildChildProcEnv(t *testing.T) {
2826
Name string
2927
Input []string
3028
Expectation []string
31-
OTS string
3229
Assert func(t *testing.T, act []string)
3330
}{
3431
{
@@ -84,18 +81,6 @@ func TestBuildChildProcEnv(t *testing.T) {
8481
}
8582
},
8683
},
87-
{
88-
Name: "ots",
89-
Input: []string{},
90-
OTS: `[{"name":"foo","value":"bar"},{"name":"GITPOD_TOKENS","value":"foobar"}]`,
91-
Expectation: []string{"HOME=/home/gitpod", "SUPERVISOR_ADDR=localhost:8080", "USER=gitpod", "foo=bar"},
92-
},
93-
{
94-
Name: "failed ots",
95-
Input: []string{},
96-
OTS: `invalid json`,
97-
Expectation: []string{"HOME=/home/gitpod", "SUPERVISOR_ADDR=localhost:8080", "USER=gitpod"},
98-
},
9984
}
10085

10186
for _, test := range tests {
@@ -112,17 +97,7 @@ func TestBuildChildProcEnv(t *testing.T) {
11297
}
11398
}
11499

115-
cfg := &Config{StaticConfig: StaticConfig{APIEndpointPort: 8080}}
116-
if test.OTS != "" {
117-
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
118-
w.WriteHeader(http.StatusOK)
119-
w.Header().Set("Content-Type", "application/json")
120-
w.Write([]byte(test.OTS))
121-
}))
122-
cfg.EnvvarOTS = srv.URL
123-
}
124-
125-
act := buildChildProcEnv(cfg, test.Input)
100+
act := buildChildProcEnv(&Config{StaticConfig: StaticConfig{APIEndpointPort: 8080}}, test.Input)
126101
assert(t, act)
127102
})
128103
}

0 commit comments

Comments
 (0)