vvauth 2.7.0 → 2.7.2
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/release.yml +5 -0
- package/.github/workflows/test.yml +7 -0
- package/API_and_tests.md +11 -0
- package/README.md +5 -0
- package/cmd/vauth/main.go +9 -1
- package/cmd/vauth/main_test.go +35 -0
- package/cmd/vauth.js +14 -1
- package/go.mod +1 -1
- package/package.json +2 -2
- package/test/env-source.js +166 -0
|
@@ -18,6 +18,11 @@ jobs:
|
|
|
18
18
|
- uses: actions/setup-go@v5
|
|
19
19
|
with:
|
|
20
20
|
go-version-file: go.mod
|
|
21
|
+
- uses: actions/setup-node@v4
|
|
22
|
+
with:
|
|
23
|
+
node-version: '24.x'
|
|
24
|
+
# Go's interop tests execute the Node SDK as well.
|
|
25
|
+
- run: npm install
|
|
21
26
|
- run: go vet ./... && go test ./...
|
|
22
27
|
- uses: actions/checkout@v4
|
|
23
28
|
with:
|
|
@@ -31,6 +31,13 @@ jobs:
|
|
|
31
31
|
- uses: actions/setup-go@v5
|
|
32
32
|
with:
|
|
33
33
|
go-version-file: go.mod
|
|
34
|
+
- uses: actions/setup-node@v4
|
|
35
|
+
if: runner.os == 'Linux'
|
|
36
|
+
with:
|
|
37
|
+
node-version: '24.x'
|
|
38
|
+
# Go's interop tests execute the Node SDK as well.
|
|
39
|
+
- run: npm install
|
|
40
|
+
if: runner.os == 'Linux'
|
|
34
41
|
- run: gofmt -l . && test -z "$(gofmt -l .)"
|
|
35
42
|
shell: bash
|
|
36
43
|
- run: go vet ./...
|
package/API_and_tests.md
CHANGED
|
@@ -16,6 +16,11 @@ venv --gitlab
|
|
|
16
16
|
`env --ir://json` writes one JSON object to stdout, with diagnostics on stderr.
|
|
17
17
|
JSON key order and final whitespace are not significant. `venv` sources
|
|
18
18
|
`vauth env --source "$@"`; renewal forces authentication.
|
|
19
|
+
On ordinary configuration/authentication/profile/macro errors, `env --source`
|
|
20
|
+
writes exactly `return 1\n` to stdout, preserves diagnostics on stderr and exits
|
|
21
|
+
nonzero. Sourcing that output returns 1 without exiting the caller or publishing
|
|
22
|
+
partial exports. Successful output and non-source error output are unchanged;
|
|
23
|
+
this does not cover crashes or a missing executable.
|
|
19
24
|
|
|
20
25
|
## Node CLI — cnyks
|
|
21
26
|
|
|
@@ -119,6 +124,12 @@ go test -race ./...
|
|
|
119
124
|
GOOS=windows GOARCH=amd64 go build ./cmd/vauth
|
|
120
125
|
```
|
|
121
126
|
|
|
127
|
+
`test/env-source.js` checks exact failure stdout, nonzero CLI status, Bash
|
|
128
|
+
process-substitution sourcing and continued execution, plus successful exports,
|
|
129
|
+
renewal flags and non-source failures. It uses temporary homes/configurations
|
|
130
|
+
and a loopback Vault. `cmd/vauth/main_test.go` builds the native Go CLI and runs
|
|
131
|
+
the same checks against that executable (requires Node and Bash).
|
|
132
|
+
|
|
122
133
|
Tests use disposable SSH keys/agents, temporary configuration and loopback
|
|
123
134
|
Vault fixtures; they do not require real credentials. Differential checks cover
|
|
124
135
|
profile/KV operations, renewal, trust refusal, local secrets, configuration,
|
package/README.md
CHANGED
|
@@ -30,6 +30,11 @@ venv --renew
|
|
|
30
30
|
function venv() { source <(/usr/bin/env vauth env --source "$@"); }
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
+
For ordinary configuration, authentication, profile or macro failures,
|
|
34
|
+
`env --source` writes only `return 1` to stdout and exits nonzero; diagnostics
|
|
35
|
+
remain on stderr. `venv` therefore returns 1 without closing the calling shell
|
|
36
|
+
or applying partial exports. This is a CLI error protocol, not crash handling.
|
|
37
|
+
|
|
33
38
|
`source ~/.bashrc` loads it in the current shell. `--renew` forces fresh
|
|
34
39
|
authentication. For a machine-readable result:
|
|
35
40
|
|
package/cmd/vauth/main.go
CHANGED
|
@@ -95,7 +95,7 @@ func main() {
|
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
func run(argv []string) error {
|
|
98
|
+
func run(argv []string) (err error) {
|
|
99
99
|
args, dict := parseArgs(argv)
|
|
100
100
|
if len(args) > 1 && args[0] == "env" && args[1] == "gitlab" {
|
|
101
101
|
args = []string{"gitlab"}
|
|
@@ -111,6 +111,14 @@ func run(argv []string) error {
|
|
|
111
111
|
os.Exit(1)
|
|
112
112
|
}
|
|
113
113
|
command, args := args[0], args[1:]
|
|
114
|
+
if command == "env" && truthy(param(args, dict, 0, "source")) {
|
|
115
|
+
defer func() {
|
|
116
|
+
if err != nil {
|
|
117
|
+
// Fail the sourced helper, not the shell that called it.
|
|
118
|
+
fmt.Fprintln(os.Stdout, "return 1")
|
|
119
|
+
}
|
|
120
|
+
}()
|
|
121
|
+
}
|
|
114
122
|
_, jsonOutput := dict["ir://json"]
|
|
115
123
|
if command == "version" || command == "--version" {
|
|
116
124
|
fmt.Println(strings.TrimPrefix(buildVersion(), "v"))
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
package main
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"os"
|
|
5
|
+
"os/exec"
|
|
6
|
+
"path/filepath"
|
|
7
|
+
"testing"
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
func TestEnvSource(t *testing.T) {
|
|
11
|
+
if _, err := exec.LookPath("node"); err != nil {
|
|
12
|
+
t.Skip("shared CLI checks require Node")
|
|
13
|
+
}
|
|
14
|
+
if _, err := exec.LookPath("bash"); err != nil {
|
|
15
|
+
t.Skip("source checks require Bash")
|
|
16
|
+
}
|
|
17
|
+
root, err := filepath.Abs("../..")
|
|
18
|
+
if err != nil {
|
|
19
|
+
t.Fatal(err)
|
|
20
|
+
}
|
|
21
|
+
binary := filepath.Join(t.TempDir(), "vauth")
|
|
22
|
+
build := exec.Command("go", "build", "-o", binary, "./cmd/vauth")
|
|
23
|
+
build.Dir = root
|
|
24
|
+
if output, err := build.CombinedOutput(); err != nil {
|
|
25
|
+
t.Fatalf("build CLI: %v\n%s", err, output)
|
|
26
|
+
}
|
|
27
|
+
checks := exec.Command("node", "--test", "test/env-source.js")
|
|
28
|
+
checks.Dir = root
|
|
29
|
+
checks.Env = append(os.Environ(), "VAUTH_TEST_BINARY="+binary)
|
|
30
|
+
output, err := checks.CombinedOutput()
|
|
31
|
+
t.Logf("%s", output)
|
|
32
|
+
if err != nil {
|
|
33
|
+
t.Fatal(err)
|
|
34
|
+
}
|
|
35
|
+
}
|
package/cmd/vauth.js
CHANGED
|
@@ -9,4 +9,17 @@ const options = command ? [`--ir://run=${command}`] : [];
|
|
|
9
9
|
if(command === 'env' && !dict['ir://json'])
|
|
10
10
|
options.push('--ir://raw');
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
if(command === 'env' && dict.source) {
|
|
13
|
+
(async () => {
|
|
14
|
+
try {
|
|
15
|
+
await new Vvauth().Env(dict.source, dict.renew, dict.gitlab);
|
|
16
|
+
} catch(err) {
|
|
17
|
+
// Fail the sourced helper, not the shell that called it.
|
|
18
|
+
process.stdout.write('return 1\n');
|
|
19
|
+
console.error(err, err && err.stack || '');
|
|
20
|
+
process.exitCode = 1;
|
|
21
|
+
}
|
|
22
|
+
})();
|
|
23
|
+
} else {
|
|
24
|
+
cnyks(Vvauth, 'vauth', options);
|
|
25
|
+
}
|
package/go.mod
CHANGED
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vvauth",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.2",
|
|
4
4
|
"description": "Vault Auth helper",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
7
7
|
"vauth": "./cmd/vauth.js"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
|
-
"test": "node --test test/token-cache.js test/delegate.js",
|
|
10
|
+
"test": "node --test test/token-cache.js test/delegate.js test/env-source.js",
|
|
11
11
|
"eslint": "eslint ."
|
|
12
12
|
},
|
|
13
13
|
"author": "",
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const assert = require('node:assert/strict');
|
|
4
|
+
const {test} = require('node:test');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const os = require('os');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const http = require('http');
|
|
9
|
+
const {execFile} = require('child_process');
|
|
10
|
+
const {promisify} = require('util');
|
|
11
|
+
const exec = promisify(execFile);
|
|
12
|
+
const binary = process.env.VAUTH_TEST_BINARY;
|
|
13
|
+
const command = binary ? [binary] : [process.execPath, path.resolve(__dirname, '../cmd/vauth.js')];
|
|
14
|
+
|
|
15
|
+
async function fixture(t, rc, handler) {
|
|
16
|
+
const home = fs.mkdtempSync(path.join(os.tmpdir(), 'vvauth-source-'));
|
|
17
|
+
t.after(() => fs.rmSync(home, {recursive : true, force : true}));
|
|
18
|
+
const file = path.join(home, '.vauthrc');
|
|
19
|
+
const bin = path.join(home, 'bin');
|
|
20
|
+
fs.mkdirSync(bin);
|
|
21
|
+
fs.symlinkSync(binary || command[1], path.join(bin, 'vauth'));
|
|
22
|
+
// Only synthetic credentials/configuration reach either CLI, never the user's environment.
|
|
23
|
+
const env = {PATH : `${bin}:${process.env.PATH}`, HOME : home, USERPROFILE : home, VAUTHRC : file};
|
|
24
|
+
if(handler) {
|
|
25
|
+
const server = http.createServer(handler);
|
|
26
|
+
await new Promise(resolve => server.listen(0, '127.0.0.1', resolve));
|
|
27
|
+
t.after(() => new Promise(resolve => server.close(resolve)));
|
|
28
|
+
env.VAULT_ADDR = `http://127.0.0.1:${server.address().port}`;
|
|
29
|
+
rc.vault_addr = env.VAULT_ADDR;
|
|
30
|
+
rc.token_cache = false;
|
|
31
|
+
}
|
|
32
|
+
fs.writeFileSync(file, typeof rc === 'string' ? rc : JSON.stringify(rc));
|
|
33
|
+
const run = async (program, args) => {
|
|
34
|
+
try {
|
|
35
|
+
return {...await exec(program, args, {cwd : home, env}), code : 0};
|
|
36
|
+
} catch(err) {
|
|
37
|
+
return err;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
return {
|
|
41
|
+
env,
|
|
42
|
+
cli : (...args) => run(command[0], [...command.slice(1), ...args]),
|
|
43
|
+
shell : (script, ...args) => run('bash', ['--noprofile', '--norc', '-c', script, '_', ...args]),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const failureShell = `
|
|
48
|
+
function venv() { source <(/usr/bin/env vauth env --source "$@"); }
|
|
49
|
+
OK=caller
|
|
50
|
+
unset BAD
|
|
51
|
+
initial_token=\${VAULT_TOKEN-unset}
|
|
52
|
+
venv
|
|
53
|
+
status=$?
|
|
54
|
+
if [ "\${VAULT_TOKEN-unset}" = "$initial_token" ]; then token=unchanged; else token=changed; fi
|
|
55
|
+
printf '%s|continued|%s|%s|%s\\n' "$status" "$OK" "\${BAD-unset}" "$token"
|
|
56
|
+
`;
|
|
57
|
+
const map = {OK : 'synthetic-secret', BAD : '$${delegate.unknown}'};
|
|
58
|
+
const cases = [
|
|
59
|
+
['malformed configuration', 'env: [\n', /parse|YAML|flow|end/i],
|
|
60
|
+
['invalid delegation configuration', {delegate : {}, env : {map}}, /Invalid Vault delegation/],
|
|
61
|
+
['invalid variable name', {env : {map : {OK : 'synthetic-secret', 'BAD-NAME' : 'value'}}}, /Invalid environment variable name/],
|
|
62
|
+
['invalid map value', {env : {map : {OK : 'synthetic-secret', BAD : {nested : true}}}}, /Invalid environment value/],
|
|
63
|
+
['unknown macro', {env : {map}}, /Unknown Vault delegation/],
|
|
64
|
+
['missing GitLab prerequisite', {env : {gitlab : true, map}}, /Missing CI_PROJECT/],
|
|
65
|
+
['missing local secret file', {'ssh-agent-crypt' : {path : 'missing-synthetic-file'}, env : {map}}, /no such file|ENOENT/i],
|
|
66
|
+
['authentication denied', {jwt_auth : {role : 'synthetic-role', jwt : 'synthetic-jwt'}, env : {map}}, /403/,
|
|
67
|
+
(req, res) => { res.writeHead(403); res.end('{"errors":["synthetic-denied"]}'); }],
|
|
68
|
+
['profile denied', {env : {map}}, /403/, (req, res) => {
|
|
69
|
+
if(req.url.endsWith('/auth/token/lookup-self')) {
|
|
70
|
+
res.end(JSON.stringify({data : {entity_id : 'synthetic-entity', ttl : 3600}}));
|
|
71
|
+
} else {
|
|
72
|
+
res.writeHead(403); res.end('{"errors":["synthetic-denied"]}');
|
|
73
|
+
}
|
|
74
|
+
}],
|
|
75
|
+
['secret path denied', {env : {paths : ['synthetic-path'], map}}, /403/, (req, res) => {
|
|
76
|
+
if(req.url.endsWith('/auth/token/lookup-self')) {
|
|
77
|
+
res.end(JSON.stringify({data : {entity_id : 'synthetic-entity', ttl : 3600}}));
|
|
78
|
+
} else if(req.url.includes('/identity/entity/id/')) {
|
|
79
|
+
res.end('{"data":{"metadata":{}}}');
|
|
80
|
+
} else {
|
|
81
|
+
res.writeHead(403); res.end('{"errors":["synthetic-denied"]}');
|
|
82
|
+
}
|
|
83
|
+
}],
|
|
84
|
+
];
|
|
85
|
+
|
|
86
|
+
for(const [name, rc, diagnostic, handler] of cases) {
|
|
87
|
+
test(`${binary ? 'Go' : 'Node'} env --source: ${name}`, async t => {
|
|
88
|
+
const f = await fixture(t, rc, handler);
|
|
89
|
+
if(['profile denied', 'secret path denied'].includes(name))
|
|
90
|
+
f.env.VAULT_TOKEN = 'synthetic-parent';
|
|
91
|
+
const result = await f.cli('env', '--source');
|
|
92
|
+
assert.equal(result.code, 1);
|
|
93
|
+
assert.equal(result.stdout, 'return 1\n');
|
|
94
|
+
assert.match(result.stderr, diagnostic);
|
|
95
|
+
assert.ok(!result.stderr.includes('synthetic-secret'));
|
|
96
|
+
assert.ok(!result.stderr.includes('synthetic-parent'));
|
|
97
|
+
const shell = await f.shell(failureShell);
|
|
98
|
+
assert.equal(shell.code, 0);
|
|
99
|
+
assert.equal(shell.stdout, '1|continued|caller|unset|unchanged\n');
|
|
100
|
+
assert.match(shell.stderr, diagnostic);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
test('non-source failures keep stdout empty', async t => {
|
|
105
|
+
const f = await fixture(t, {env : {map}});
|
|
106
|
+
for(const args of [['env', '--ir://json'], ['env', '--source=0', '--ir://json']]) {
|
|
107
|
+
const result = await f.cli(...args);
|
|
108
|
+
assert.equal(result.code, 1);
|
|
109
|
+
assert.equal(result.stdout, '');
|
|
110
|
+
assert.match(result.stderr, /Unknown Vault delegation/);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test('successful exports, JSON and source flags are unchanged', async t => {
|
|
115
|
+
const values = {OK : "spaces ' quotes\nnew line", COUNT : 42, FLAG : false, EMPTY : null};
|
|
116
|
+
const f = await fixture(t, {env : {map : values}});
|
|
117
|
+
const exports = {
|
|
118
|
+
OK : `export OK='spaces '"'"' quotes\nnew line'\necho export OK="[redacted]" >&2\n`,
|
|
119
|
+
COUNT : `export COUNT='42'\necho export COUNT="[redacted]" >&2\n`,
|
|
120
|
+
FLAG : `export FLAG='false'\necho export FLAG="[redacted]" >&2\n`,
|
|
121
|
+
EMPTY : `export EMPTY=''\necho export EMPTY="[redacted]" >&2\n`,
|
|
122
|
+
};
|
|
123
|
+
// Go's configuration clone already sorts map keys; Node retains insertion order.
|
|
124
|
+
const keys = binary ? Object.keys(values).sort() : Object.keys(values);
|
|
125
|
+
const expected = keys.map(key => exports[key]).join('');
|
|
126
|
+
for(const flags of [['--source'], ['--source', '--renew'], ['--source', '--renew=0'],
|
|
127
|
+
['--source', '--ir://json'], ['--source=1']]) {
|
|
128
|
+
const result = await f.cli('env', ...flags);
|
|
129
|
+
assert.equal(result.code, 0);
|
|
130
|
+
assert.equal(result.stdout, expected);
|
|
131
|
+
}
|
|
132
|
+
const json = await f.cli('env', '--ir://json');
|
|
133
|
+
assert.equal(json.code, 0);
|
|
134
|
+
assert.deepEqual(JSON.parse(json.stdout), {...values, COUNT : '42', FLAG : 'false', EMPTY : ''});
|
|
135
|
+
const shell = await f.shell(`
|
|
136
|
+
function venv() { source <(/usr/bin/env vauth env --source "$@"); }
|
|
137
|
+
venv "$@"
|
|
138
|
+
status=$?
|
|
139
|
+
printf '%s|continued|%s|%s|%s|%s\\n' "$status" "$OK" "$COUNT" "$FLAG" "$EMPTY"
|
|
140
|
+
`, '--renew=0');
|
|
141
|
+
assert.equal(shell.code, 0);
|
|
142
|
+
assert.equal(shell.stdout, `0|continued|${values.OK}|42|false|\n`);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test('renew flag still forces login instead of the inherited token', async t => {
|
|
146
|
+
let logins = 0;
|
|
147
|
+
const f = await fixture(t, {jwt_auth : {role : 'synthetic-role', jwt : 'synthetic-jwt'}}, (req, res) => {
|
|
148
|
+
if(req.url.endsWith('/auth/jwt/login')) {
|
|
149
|
+
logins++;
|
|
150
|
+
res.end('{"auth":{"client_token":"synthetic-issued","lease_duration":3600,"renewable":false}}');
|
|
151
|
+
} else if(req.url.endsWith('/auth/token/lookup-self')) {
|
|
152
|
+
res.end('{"data":{"entity_id":"synthetic-entity","ttl":3600}}');
|
|
153
|
+
} else {
|
|
154
|
+
res.end('{"data":{"metadata":{}}}');
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
f.env.VAULT_TOKEN = 'synthetic-parent';
|
|
158
|
+
const reused = await f.cli('env', '--source', '--renew=0');
|
|
159
|
+
assert.equal(reused.code, 0);
|
|
160
|
+
assert.match(reused.stdout, /export VAULT_TOKEN='synthetic-parent'/);
|
|
161
|
+
assert.equal(logins, 0);
|
|
162
|
+
const renewed = await f.cli('env', '--source', '--renew');
|
|
163
|
+
assert.equal(renewed.code, 0);
|
|
164
|
+
assert.match(renewed.stdout, /export VAULT_TOKEN='synthetic-issued'/);
|
|
165
|
+
assert.equal(logins, 1);
|
|
166
|
+
});
|