Skip to content

Commit 2488cf0

Browse files
authored
fix(agent): don't overwrite existing vscode git auth settings (coder#22871)
OverrideVSCodeConfigs previously unconditionally set `git.useIntegratedAskPass` and `github.gitAuthentication` to false, clobbering any values provided by template authors via module settings (e.g. the vscode-web module's settings block). This change only set these keys when they are not already present, so template-provided values are preserved. Registry PR [coder#758](coder/registry#758) fixed the module side (run.sh merges template-author settings into the existing settings.json instead of overwriting the file). But the agent still unconditionally stamped false onto both keys before the script ran, so the merge base always contained the agent's values and template authors couldn't set them to anything else. This change fixes the agent side by only writing defaults when the keys are absent.
1 parent 3407fa8 commit 2488cf0

2 files changed

Lines changed: 39 additions & 6 deletions

File tree

cli/gitauth/vscode.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,18 @@ func OverrideVSCodeConfigs(fs afero.Fs) error {
1919
return err
2020
}
2121
mutate := func(m map[string]interface{}) {
22-
// This prevents VS Code from overriding GIT_ASKPASS, which
23-
// we use to automatically authenticate Git providers.
24-
m["git.useIntegratedAskPass"] = false
25-
// This prevents VS Code from using it's own GitHub authentication
26-
// which would circumvent cloning with Coder-configured providers.
27-
m["github.gitAuthentication"] = false
22+
// These defaults prevent VS Code from overriding
23+
// GIT_ASKPASS and using its own GitHub authentication,
24+
// which would circumvent cloning with Coder-configured
25+
// providers. We only set them if they are not already
26+
// present so that template authors can override them
27+
// via module settings (e.g. the vscode-web module).
28+
if _, ok := m["git.useIntegratedAskPass"]; !ok {
29+
m["git.useIntegratedAskPass"] = false
30+
}
31+
if _, ok := m["github.gitAuthentication"]; !ok {
32+
m["github.gitAuthentication"] = false
33+
}
2834
}
2935

3036
for _, configPath := range []string{

cli/gitauth/vscode_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,31 @@ func TestOverrideVSCodeConfigs(t *testing.T) {
6161
require.Equal(t, "something", mapping["hotdogs"])
6262
}
6363
})
64+
t.Run("NoOverwrite", func(t *testing.T) {
65+
t.Parallel()
66+
fs := afero.NewMemMapFs()
67+
mapping := map[string]interface{}{
68+
"git.useIntegratedAskPass": true,
69+
"github.gitAuthentication": true,
70+
"other.setting": "preserved",
71+
}
72+
data, err := json.Marshal(mapping)
73+
require.NoError(t, err)
74+
for _, configPath := range configPaths {
75+
err = afero.WriteFile(fs, configPath, data, 0o600)
76+
require.NoError(t, err)
77+
}
78+
err = gitauth.OverrideVSCodeConfigs(fs)
79+
require.NoError(t, err)
80+
for _, configPath := range configPaths {
81+
data, err := afero.ReadFile(fs, configPath)
82+
require.NoError(t, err)
83+
mapping := map[string]interface{}{}
84+
err = json.Unmarshal(data, &mapping)
85+
require.NoError(t, err)
86+
require.Equal(t, true, mapping["git.useIntegratedAskPass"])
87+
require.Equal(t, true, mapping["github.gitAuthentication"])
88+
require.Equal(t, "preserved", mapping["other.setting"])
89+
}
90+
})
6491
}

0 commit comments

Comments
 (0)