Skip to content

fix(support): sanitize manifest #12711

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

Merged
merged 2 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
sanitize harder
  • Loading branch information
johnstcn committed Mar 21, 2024
commit 7e3eeb4090dac06b31c5a86bfda96cd0cda4983f
25 changes: 22 additions & 3 deletions cli/support_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli_test

import (
"archive/zip"
"bytes"
"encoding/json"
"io"
"os"
Expand All @@ -12,6 +13,7 @@ import (

"tailscale.com/ipn/ipnstate"

"github.com/google/uuid"
"github.com/stretchr/testify/require"

"github.com/coder/coder/v2/agent"
Expand All @@ -23,6 +25,7 @@ import (
"github.com/coder/coder/v2/coderd/database/dbtime"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/codersdk/agentsdk"
"github.com/coder/coder/v2/provisionersdk/proto"
"github.com/coder/coder/v2/tailnet"
"github.com/coder/coder/v2/testutil"
)
Expand All @@ -38,10 +41,15 @@ func TestSupportBundle(t *testing.T) {
ctx := testutil.Context(t, testutil.WaitShort)
client, db := coderdtest.NewWithDatabase(t, nil)
owner := coderdtest.CreateFirstUser(t, client)
randSecretValue := uuid.NewString()
r := dbfake.WorkspaceBuild(t, db, database.Workspace{
OrganizationID: owner.OrganizationID,
OwnerID: owner.UserID,
}).WithAgent().Do()
}).WithAgent(func(agents []*proto.Agent) []*proto.Agent {
// This should not show up in the bundle output
agents[0].Env["SECRET_VALUE"] = randSecretValue
return agents
}).Do()
ws, err := client.Workspace(ctx, r.Workspace.ID)
require.NoError(t, err)
tempDir := t.TempDir()
Expand Down Expand Up @@ -81,7 +89,7 @@ func TestSupportBundle(t *testing.T) {
clitest.SetupConfig(t, client, root)
err = inv.Run()
require.NoError(t, err)
assertBundleContents(t, path)
assertBundleContents(t, path, randSecretValue)
})

t.Run("NoWorkspace", func(t *testing.T) {
Expand Down Expand Up @@ -126,12 +134,13 @@ func TestSupportBundle(t *testing.T) {
})
}

func assertBundleContents(t *testing.T, path string) {
func assertBundleContents(t *testing.T, path string, badValues ...string) {
t.Helper()
r, err := zip.OpenReader(path)
require.NoError(t, err, "open zip file")
defer r.Close()
for _, f := range r.File {
assertDoesNotContain(t, f, badValues...)
switch f.Name {
case "deployment/buildinfo.json":
var v codersdk.BuildInfoResponse
Expand Down Expand Up @@ -244,3 +253,13 @@ func readBytesFromZip(t *testing.T, f *zip.File) []byte {
require.NoError(t, err, "read bytes from zip")
return bs
}

func assertDoesNotContain(t *testing.T, f *zip.File, vals ...string) {
t.Helper()
bs := readBytesFromZip(t, f)
for _, val := range vals {
if bytes.Contains(bs, []byte(val)) {
t.Fatalf("file %q should not contain value %q", f.Name, val)
}
}
}
4 changes: 1 addition & 3 deletions coderd/database/dbfake/dbfake.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ func (b WorkspaceBuildBuilder) WithAgent(mutations ...func([]*sdkproto.Agent) []
Auth: &sdkproto.Agent_Token{
Token: b.agentToken,
},
Env: map[string]string{
"SECRET_TOKEN": "supersecret",
},
Env: map[string]string{},
}}
for _, m := range mutations {
agents = m(agents)
Expand Down