Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ pkg/portaudio/pa_src/** linguist-vendored
# core.autocrlf — the default on Windows, including the CI runners — rewrites
# them to CRLF and every frame mismatches.
cmd/lk/testdata/vrt/*.txt text eol=lf

# The same holds for the testscript scripts: their expected stdout and stderr
# are compared byte for byte against lk's LF output.
cmd/lk/testdata/script/*.txtar text eol=lf
10 changes: 1 addition & 9 deletions cmd/lk/script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ import (
"os"
"path/filepath"
"regexp"
"runtime"
"slices"
"strconv"
"strings"
Expand All @@ -80,14 +79,6 @@ func TestMain(m *testing.M) {
}

func TestScripts(t *testing.T) {
if runtime.GOOS == "windows" {
// Three things stop the scripts on Windows: Go reports mode 0666 for
// every file there, so config.LoadOrCreate warns on each run that the
// config file should be 0600; testscript sets the home directory
// through USERPROFILE, which setupScript doesn't; and a Windows
// checkout writes the .txtar files with CRLF endings.
t.Skip("lk warns about the config file's permissions on every Windows run, and the scripts need USERPROFILE and LF checkouts")
}
testscript.Run(t, testscript.Params{
Dir: filepath.Join("testdata", "script"),
Setup: setupScript,
Expand All @@ -107,6 +98,7 @@ type fakeCloudKey struct{}
func setupScript(env *testscript.Env) error {
home := filepath.Join(env.WorkDir, "home")
env.Setenv("HOME", home)
env.Setenv("USERPROFILE", home) // the home directory on Windows
// lk warns about a config file anyone else can read, and txtar files are
// written 0644.
err := os.Chmod(filepath.Join(home, ".livekit", "cli-config.yaml"), 0o600)
Expand Down
14 changes: 14 additions & 0 deletions cmd/lk/testdata/script/config-permissions-warning.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# A config file others can read gets a warning, since it holds API secrets,
# except on Windows, where file modes don't say who can read it.
chmod 0644 home/.livekit/cli-config.yaml
exec lk project list
[!windows] stderr 'should have permissions 600'
[windows] ! stderr 'should have permissions'

-- home/.livekit/cli-config.yaml --
projects:
- name: one
project_id: p_1
url: ws://one.test
api_key: APIone
api_secret: secretone
7 changes: 5 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"os"
"path"
"runtime"
"strings"
"time"

Expand Down Expand Up @@ -332,9 +333,11 @@ func LoadOrCreate() (*CLIConfig, error) {
return c, nil
} else if err != nil {
return nil, err
} else if s.Mode().Perm()&0077 != 0 {
} else if runtime.GOOS != "windows" && s.Mode().Perm()&0077 != 0 {
// because this file contains private keys, warn that
// only the owner should have permission to access it
// only the owner should have permission to access it. Go reports
// 0666 for every writable file on Windows (0444 if read-only), so
// the mode says nothing there.
util.Warnf("WARNING: config file %s should have permissions %o", configPath, 0600)
}

Expand Down
Loading