vvauth 2.6.0 → 2.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/publish-npm.yml +2 -4
- package/.github/workflows/test.yml +2 -1
- package/API_and_tests.md +107 -118
- package/README.md +57 -105
- package/SECURITY_AUDIT_COORDINATION.md +36 -0
- package/SECURITY_AUDIT_PROVENANCE.json +35 -0
- package/SECURITY_AUDIT_claude-opus-5-5.md +288 -0
- package/SECURITY_AUDIT_gpt-6.1-sol.md +323 -109
- package/cmd/vauth/main.go +10 -25
- package/cmd/vauth.js +12 -0
- package/gitlab.go +47 -0
- package/gitlab_test.go +116 -0
- package/go.mod +4 -3
- package/go.sum +6 -10
- package/index.js +63 -88
- package/package.json +6 -5
- package/rc.go +81 -193
- package/test/token-cache.js +122 -14
- package/vauth.go +32 -32
- package/vauth_test.go +76 -23
- package/SECURITY_AUDIT_fable-5.1.md +0 -88
package/vauth_test.go
CHANGED
|
@@ -195,7 +195,7 @@ type tokenCache struct {
|
|
|
195
195
|
}
|
|
196
196
|
|
|
197
197
|
func testCacheKey(v *Vauth) string {
|
|
198
|
-
key :=
|
|
198
|
+
key := strings.Trim(v.VAULT_ADDR(), "/")
|
|
199
199
|
body, err := json.Marshal(v.RC())
|
|
200
200
|
if err != nil {
|
|
201
201
|
panic(err)
|
|
@@ -204,10 +204,7 @@ func testCacheKey(v *Vauth) string {
|
|
|
204
204
|
if err != nil {
|
|
205
205
|
panic(err)
|
|
206
206
|
}
|
|
207
|
-
|
|
208
|
-
key += "," + auth
|
|
209
|
-
}
|
|
210
|
-
return sha256Hex(key + "}")
|
|
207
|
+
return sha256Hex(key + "/" + rc.AuthKey())
|
|
211
208
|
}
|
|
212
209
|
|
|
213
210
|
func cacheFile(v *Vauth) string { return filepath.Join(v.CacheDir, testCacheKey(v)+".creds") }
|
|
@@ -462,11 +459,11 @@ func TestCacheIsolation(t *testing.T) {
|
|
|
462
459
|
|
|
463
460
|
func TestTokenCacheKeyMatchesNode(t *testing.T) {
|
|
464
461
|
v := configuredClient(t, map[string]any{"vault_addr": "https://vault.example.test/", "ssh_auth": map[string]any{"role": "alice"}}, nil)
|
|
465
|
-
equal(t, testCacheKey(v), sha256Hex(`
|
|
462
|
+
equal(t, testCacheKey(v), sha256Hex(`https://vault.example.test/ssh/alice//`))
|
|
466
463
|
v = configuredClient(t, map[string]any{"vault_addr": "https://vault.example.test", "jwt_auth": map[string]any{"path": "jwt", "jwt": "x", "role": "r"}}, nil)
|
|
467
|
-
equal(t, testCacheKey(v), sha256Hex(`
|
|
464
|
+
equal(t, testCacheKey(v), sha256Hex(`https://vault.example.test//jwt/r/jwt/x`))
|
|
468
465
|
v = configuredClient(t, map[string]any{"vault_addr": "https://vault.example.test", "ssh_auth": map[string]any{"role": "$${env.USER}"}}, map[string]string{"USER": "bob"})
|
|
469
|
-
equal(t, testCacheKey(v), sha256Hex(`
|
|
466
|
+
equal(t, testCacheKey(v), sha256Hex(`https://vault.example.test/ssh/bob//`))
|
|
470
467
|
}
|
|
471
468
|
|
|
472
469
|
func TestRepeatedConnectReusesConnection(t *testing.T) {
|
|
@@ -703,14 +700,6 @@ func TestOneStatusPerConnection(t *testing.T) {
|
|
|
703
700
|
equal(t, stderr.String(), "")
|
|
704
701
|
}
|
|
705
702
|
|
|
706
|
-
func TestReplaceEnv(t *testing.T) {
|
|
707
|
-
dict := Lookup{"env": map[string]string{"USER": "alice"}, "profile": map[string]any{"TOKEN": "secret", "N": 3}}
|
|
708
|
-
equal(t, ReplaceEnv("$${env.USER}", dict), "alice")
|
|
709
|
-
equal(t, ReplaceEnv("x-$${profile.TOKEN}-$${profile.N}", dict), "x-secret-3")
|
|
710
|
-
equal(t, ReplaceEnv("$${profile.MISSING}", dict), "$${profile.MISSING}") // unresolved macros are kept, like nyks
|
|
711
|
-
equal(t, ReplaceEnv("plain", dict), "plain")
|
|
712
|
-
}
|
|
713
|
-
|
|
714
703
|
func sha256Hex(value string) string {
|
|
715
704
|
digest := sha256.Sum256([]byte(value))
|
|
716
705
|
return hex.EncodeToString(digest[:])
|
|
@@ -829,7 +818,7 @@ func TestNewConsumesCompleteRCSnapshot(t *testing.T) {
|
|
|
829
818
|
if err := os.Remove(os.Getenv("VAUTHRC")); err != nil {
|
|
830
819
|
t.Fatal(err)
|
|
831
820
|
}
|
|
832
|
-
config, err := configFromRC(v.RC(),
|
|
821
|
+
config, err := configFromRC(v.RC(), v.Environ)
|
|
833
822
|
if err != nil {
|
|
834
823
|
t.Fatal(err)
|
|
835
824
|
}
|
|
@@ -837,7 +826,7 @@ func TestNewConsumesCompleteRCSnapshot(t *testing.T) {
|
|
|
837
826
|
equal(t, value, "local-value")
|
|
838
827
|
}
|
|
839
828
|
|
|
840
|
-
func
|
|
829
|
+
func TestGitLabIsNotInferredDuringConstruction(t *testing.T) {
|
|
841
830
|
project := t.TempDir()
|
|
842
831
|
for _, args := range [][]string{{"init", "-q", project}, {"-C", project, "remote", "add", "origin", "git@git.example.test:Team/app.git"}} {
|
|
843
832
|
if out, err := exec.Command("git", args...).CombinedOutput(); err != nil {
|
|
@@ -857,12 +846,76 @@ func TestGitLabUsesWorkingProjectWithExternalRC(t *testing.T) {
|
|
|
857
846
|
}
|
|
858
847
|
})
|
|
859
848
|
for _, ci := range []string{"", "1"} {
|
|
860
|
-
v := configuredClient(t, map[string]any{"env": map[string]any{"gitlab": true, "map": map[string]any{"PROJECT": "$${env.CI_PROJECT_PATH}"}}}, map[string]string{"CI": ci, "CI_PROJECT_PATH": "pipeline/project"})
|
|
861
|
-
want := "
|
|
862
|
-
if ci != "" {
|
|
863
|
-
want = "pipeline/project"
|
|
864
|
-
}
|
|
849
|
+
v := configuredClient(t, map[string]any{"env": map[string]any{"gitlab": true, "map": map[string]any{"PROJECT": "$${env.CI_PROJECT_PATH}"}}}, map[string]string{"CI": ci, "CI_PROJECT_PATH": "pipeline/project", "CI_PROJECT_NAME": "project", "CI_PROJECT_NAMESPACE": "pipeline", "CI_PROJECT_PATH_SLUG": "pipeline-project"})
|
|
850
|
+
want := "pipeline/project"
|
|
865
851
|
value, _ := v.Config.Env.Map.Get("PROJECT")
|
|
866
852
|
equal(t, value, want)
|
|
867
853
|
}
|
|
868
854
|
}
|
|
855
|
+
|
|
856
|
+
func TestEnvMapScalarStringsPreserveRawRC(t *testing.T) {
|
|
857
|
+
values := map[string]any{"TEXT": "hello", "BOOL": true, "NUMBER": 42, "NULL": nil, "LARGE": 1e20, "SMALL": 1e-7, "ZERO": 0}
|
|
858
|
+
v := configuredClient(t, map[string]any{"env": map[string]any{"map": values}}, nil)
|
|
859
|
+
env, err := v.Env(false)
|
|
860
|
+
if err != nil {
|
|
861
|
+
t.Fatal(err)
|
|
862
|
+
}
|
|
863
|
+
for key, value := range map[string]string{"TEXT": "hello", "BOOL": "true", "NUMBER": "42", "NULL": "", "LARGE": "100000000000000000000", "SMALL": "1e-7", "ZERO": "0"} {
|
|
864
|
+
actual, ok := env.Get(key)
|
|
865
|
+
if !ok || actual != value {
|
|
866
|
+
t.Fatalf("%s: %q != %q", key, actual, value)
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
raw := v.RC()["env"].(map[string]any)["map"].(map[string]any)
|
|
870
|
+
equal(t, raw["BOOL"], true)
|
|
871
|
+
equal(t, raw["NUMBER"].(float64), float64(42))
|
|
872
|
+
if raw["NULL"] != nil {
|
|
873
|
+
t.Fatal("raw RC null changed")
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
func TestEnvMapRejectsObjectValuesAndMacros(t *testing.T) {
|
|
878
|
+
for _, value := range []any{map[string]any{"x": 1}, []any{"x"}, []any{"$${profile.SCALAR}"}} {
|
|
879
|
+
_, err := configFromRC(map[string]any{"env": map[string]any{"map": map[string]any{"VALUE": value}}}, nil)
|
|
880
|
+
if err == nil || !strings.Contains(err.Error(), "Invalid environment value 'VALUE' in env.map: expected a scalar") {
|
|
881
|
+
t.Fatalf("object accepted: %v", err)
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
f := newFixture(t, fixtureOptions{metadata: map[string]any{"SCALAR": 42, "BOOL": false, "NULL": nil, "OBJECT": map[string]any{"x": 1}, "ARRAY": []any{"x"}}})
|
|
885
|
+
v := f.client()
|
|
886
|
+
for _, value := range []string{"$${profile.OBJECT}", "$${profile.ARRAY}", "$${profile}"} {
|
|
887
|
+
v.Config.Env = &EnvConfig{}
|
|
888
|
+
v.Config.Env.Map.Set("VALUE", value)
|
|
889
|
+
if _, err := v.Env(false); err == nil || !strings.Contains(err.Error(), "Invalid environment value 'VALUE' in env.map: expected a scalar") {
|
|
890
|
+
t.Fatalf("object macro accepted: %v", err)
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
v.Config.Env = &EnvConfig{Git: true}
|
|
894
|
+
for key, macro := range map[string]string{"NUMBER": "$${profile.SCALAR}", "BOOL": "$${profile.BOOL}", "NULL": "$${profile.NULL}"} {
|
|
895
|
+
v.Config.Env.Map.Set(key, macro)
|
|
896
|
+
}
|
|
897
|
+
env, err := v.Env(false)
|
|
898
|
+
if err != nil {
|
|
899
|
+
t.Fatal(err)
|
|
900
|
+
}
|
|
901
|
+
for key, value := range map[string]string{"NUMBER": "42", "BOOL": "false", "NULL": "", "GIT_AUTHOR_EMAIL": "", "GIT_COMMITTER_EMAIL": ""} {
|
|
902
|
+
actual, ok := env.Get(key)
|
|
903
|
+
if !ok || actual != value {
|
|
904
|
+
t.Fatalf("%s: %q != %q", key, actual, value)
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
func TestConfigWalkPreservesKeysAndSnapshot(t *testing.T) {
|
|
910
|
+
raw := map[string]any{"env": map[string]any{"map": map[string]any{"$${env.KEY}": "$${env.VALUE}"}}}
|
|
911
|
+
config, err := configFromRC(raw, map[string]string{"KEY": "ACTUAL", "VALUE": "done"})
|
|
912
|
+
if err != nil {
|
|
913
|
+
t.Fatal(err)
|
|
914
|
+
}
|
|
915
|
+
value, ok := config.Env.Map.Get("$${env.KEY}")
|
|
916
|
+
if !ok {
|
|
917
|
+
t.Fatal("walker changed a mapping key")
|
|
918
|
+
}
|
|
919
|
+
equal(t, value, "done")
|
|
920
|
+
equal(t, raw["env"].(map[string]any)["map"].(map[string]any)["$${env.KEY}"], "$${env.VALUE}")
|
|
921
|
+
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
# vvauth: design review by Codex (Claude Fable 5.1)
|
|
2
|
-
|
|
3
|
-
Independent review of the design and of the Node and Go implementations of
|
|
4
|
-
[vvauth](README.md), scoring Coolness, Robustness and Safety out of 20. The
|
|
5
|
-
companion review is [SECURITY_AUDIT_gpt-6.1-sol.md](SECURITY_AUDIT_gpt-6.1-sol.md).
|
|
6
|
-
|
|
7
|
-
## The design, as read
|
|
8
|
-
|
|
9
|
-
`vauth` turns a `.vauthrc` (YAML with `$${env.X}`, `$${profile.X}`,
|
|
10
|
-
`$${secrets.X}` macros) into a Vault token and a resolved environment. Two
|
|
11
|
-
authentication flows: `jwt_auth` (CI) and `ssh_auth`, where the agent signs a
|
|
12
|
-
nonce fetched from `auth/<path>/nonce`, so the user's SSH key is the identity
|
|
13
|
-
and nothing else is stored. The token is cached in
|
|
14
|
-
`~/.vauth/tokens/<sha256(vault_addr, ssh_auth, jwt_auth)>.creds`, armored with
|
|
15
|
-
ssh-agent-crypt (key derived from an agent signature), reused while valid,
|
|
16
|
-
renewed in the last third of its lease, replaced when expired or rejected.
|
|
17
|
-
`env --source` prints `export K='v'` lines for the `venv` shell function;
|
|
18
|
-
`--ir://json` prints one JSON object for automation. Node and Go share the
|
|
19
|
-
contract byte for byte (cache key, armor, outputs) and are cross-tested.
|
|
20
|
-
|
|
21
|
-
## Strengths
|
|
22
|
-
|
|
23
|
-
- No long-lived secret on disk besides a Vault token that is itself encrypted
|
|
24
|
-
under the agent, with `0700`/`0600` modes, write-to-temp-then-rename, and a
|
|
25
|
-
cache that degrades to "not persisted" rather than "stored in clear".
|
|
26
|
-
- Correct lease handling: renewal only in the final third, `lookup-self` TTL
|
|
27
|
-
trusted over the local clock when the token is foreign, reauthentication only
|
|
28
|
-
on `400`/`403`, never on network failures (no accidental token storm).
|
|
29
|
-
- Secret values never reach stdout unescaped in `--source` mode
|
|
30
|
-
(`ShellEscape` single-quotes), `env.map` names are checked against
|
|
31
|
-
`^[A-Za-z_][A-Za-z0-9_]*$` before they reach `export`, and the shell echoes
|
|
32
|
-
`[redacted]`.
|
|
33
|
-
- The nonce is fetched fresh for every key tried; the agent only ever signs
|
|
34
|
-
server-provided data, no private key is handled by the tool.
|
|
35
|
-
- Two implementations with the same fake-Vault test matrix catch divergence;
|
|
36
|
-
the Go binary is static, signed, with `SHA256SUMS`; release runs the tests.
|
|
37
|
-
|
|
38
|
-
## Weaknesses and remedies
|
|
39
|
-
|
|
40
|
-
1. **`vault_addr` from the current directory redirects authentication.** A
|
|
41
|
-
hostile `.vauthrc` points to an attacker-controlled "Vault"; the tool then
|
|
42
|
-
fetches a nonce from it and has the agent sign it. The signature is over
|
|
43
|
-
attacker-chosen bytes (bounded to valid UTF-8 by the JSON transport, which
|
|
44
|
-
keeps it away from SSHSIG and SSH-userauth encodings, so no direct
|
|
45
|
-
cross-protocol reuse today), and the public key and role name are sent to
|
|
46
|
-
the attacker. *Remedy:* wrap the nonce in a vauth-specific preamble before
|
|
47
|
-
signing (as SSHSIG does), or require `https` plus a pinned allow-list of
|
|
48
|
-
Vault hosts in `~/.vauthrc`; at least surface the Vault address in the
|
|
49
|
-
`Vauth token:` status line on first contact. More generally, a
|
|
50
|
-
`./.vauthrc` from a cloned repository is trusted for everything; a cleaner
|
|
51
|
-
model would let it carry only the project part (`env.map`, `env.paths`,
|
|
52
|
-
`env.gitlab`) and keep `vault_addr`, `ssh_auth`, `jwt_auth` and
|
|
53
|
-
`ssh-agent-crypt` to `~/.vauthrc` or `VAUTHRC`.
|
|
54
|
-
2. **Whoever reaches the agent socket reads the token cache.** By design of
|
|
55
|
-
ssh-agent-crypt; nothing in vvauth adds a second factor. *Remedy:* document
|
|
56
|
-
it next to `token_cache` and recommend `ssh-add -c` on the cache key
|
|
57
|
-
(`SSH_AGENT_CRYPT_KEY` lets a dedicated, confirmed key be chosen).
|
|
58
|
-
3. **Macro expansion parity.** Go caps recursive expansion at 16 rounds; Node
|
|
59
|
-
(`nyks/string/replaceEnv`) recurses until the stack overflows on a
|
|
60
|
-
self-referencing value, and `$&`-style replacement patterns behave
|
|
61
|
-
differently. *Remedy:* port the bounded loop to Node or fix it upstream, and
|
|
62
|
-
add a cross-implementation fixture for pathological macros.
|
|
63
|
-
4. **Error swallowing.** `_read_token_cache` and the GitLab remote probe use
|
|
64
|
-
bare `catch(err) {}`; Go returns `nil` from `readTokenCache` for any cause.
|
|
65
|
-
A corrupt cache, a wrong key or a missing agent all look alike. *Remedy:* a
|
|
66
|
-
`--debug`-visible reason (the `vvauth:debug` logger exists in Node).
|
|
67
|
-
5. **HTTP hygiene.** Node uses `url.parse` (deprecated, lenient) and a 60 s
|
|
68
|
-
default timeout; Go uses `http.DefaultClient` with no timeout. Neither pins
|
|
69
|
-
or restricts TLS. *Remedy:* `url.URL`, an explicit `http.Client{Timeout}`,
|
|
70
|
-
and reject `http://` Vault addresses unless loopback.
|
|
71
|
-
6. **`install` rewrites `~/.bashrc` wholesale** (`0644`, trimmed, re-written),
|
|
72
|
-
and `FunctionExists` runs `bash -lc`, executing the user's whole login
|
|
73
|
-
profile. *Remedy:* append-only, and grep the file instead of spawning a
|
|
74
|
-
login shell.
|
|
75
|
-
7. **Release integrity.** `SHA256SUMS` is unsigned and the Linux binary is
|
|
76
|
-
unsigned; `release.yml` pulls `131/gh-actions@v1` by mutable tag. *Remedy:*
|
|
77
|
-
sign the checksum file (or publish build provenance) and pin the action by
|
|
78
|
-
commit.
|
|
79
|
-
|
|
80
|
-
## Scores
|
|
81
|
-
|
|
82
|
-
| Criterion | Score | Why |
|
|
83
|
-
| --- | ---: | --- |
|
|
84
|
-
| Coolness | 15/20 | One `.vauthrc`, one `venv`, and a Vault token appears from the SSH key you already carry, cached safely, identical from Node or a signed static binary. The macro language and the GitLab `CI_PROJECT_*` derivation make it a genuinely pleasant developer tool; what a repository's `./.vauthrc` may decide is the open question. |
|
|
85
|
-
| Robustness | 16/20 | Lease logic, cache isolation and Node/Go parity are tested and solid; a project `package.json` may pin the `vvauth` version it expects, in both runtimes. Loses on unbounded macro recursion in Node, swallowed errors and the absence of HTTP timeouts in Go. |
|
|
86
|
-
| Safety | 14/20 | Good secret handling: encrypted cache, escaped values, validated variable names, no clear-text fallbacks. Loses on the blanket trust in `./.vauthrc` (a cloned repository picks the Vault and gets a raw agent signature), on the agent-socket exposure of the cache, and on HTTP without timeouts or transport constraints. |
|
|
87
|
-
|
|
88
|
-
Codex (Claude Fable 5.1)
|