vaultkit 1.2.1 → 1.3.0
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.
- checksums.yaml +4 -4
- data/README.md +71 -53
- data/lib/vkit/cli/api/client.rb +26 -8
- data/lib/vkit/cli/base_cli.rb +8 -1
- data/lib/vkit/cli/commands/agent_tokens_create_command.rb +12 -0
- data/lib/vkit/cli/commands/agent_tokens_list_command.rb +2 -0
- data/lib/vkit/cli/commands/agent_tokens_revoke_command.rb +6 -2
- data/lib/vkit/cli/commands/approval_command.rb +1 -1
- data/lib/vkit/cli/commands/grant_revoke_command.rb +5 -1
- data/lib/vkit/cli/commands/request_command.rb +16 -3
- data/lib/vkit/core/credential_store.rb +52 -45
- data/lib/vkit/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 17014258d6102f66c5d3479d541fbc2540f5f4b988c87c46c0bf8a7d17340043
|
|
4
|
+
data.tar.gz: 83c4694cc2efd7bc579c2fbc29bf2f556fd22539ffae1a23f52ce741b55f126e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 452fad9cc3ed91570302342f4e319c26cf62c3446bb008f225719f01487731de5f953046ce67b8dbe0b33e6cad6406fa36d1b6e35cb1092a12bb7826e8999fa0
|
|
7
|
+
data.tar.gz: c6ec74cacd3cc839ff3160413c86513f5f3a0d8a036f6a6bb938bfc56bc473215583dd9e63414c05c83710ba1c2d6d9a8c70dccd57fde6760e9f125058f6d34e
|
data/README.md
CHANGED
|
@@ -43,7 +43,6 @@ The VaultKit CLI provides command-line access to VaultKit for:
|
|
|
43
43
|
| **Datasource Admin** | Register and manage database connections (admin only) |
|
|
44
44
|
| **Schema Discovery** | Scan datasources and detect schema drift |
|
|
45
45
|
| **Policy Deployment** | Build, validate, and deploy policy bundles |
|
|
46
|
-
| **Audit Queries** | Search and export audit logs |
|
|
47
46
|
|
|
48
47
|
### Mental Model
|
|
49
48
|
|
|
@@ -200,6 +199,14 @@ Clear stored credentials and end session.
|
|
|
200
199
|
vkit logout
|
|
201
200
|
```
|
|
202
201
|
|
|
202
|
+
### Where the login is saved
|
|
203
|
+
|
|
204
|
+
`vkit login` saves the endpoint and token in the macOS Keychain, or in the Secret
|
|
205
|
+
Service keyring (GNOME Keyring, KWallet) on Linux when `secret-tool` is installed.
|
|
206
|
+
Elsewhere, including Windows, or when saving to the keychain fails (for example, over
|
|
207
|
+
SSH with no unlocked keyring), it saves them to `~/.vkit/credentials.json`, readable
|
|
208
|
+
only by you, and says so. Login tokens expire after an hour.
|
|
209
|
+
|
|
203
210
|
### Credentials from the environment
|
|
204
211
|
|
|
205
212
|
`vkit` normally uses the login saved by `vkit login`, in your OS keychain or
|
|
@@ -258,13 +265,17 @@ vkit request --aql '{
|
|
|
258
265
|
}'
|
|
259
266
|
|
|
260
267
|
# Output:
|
|
261
|
-
#
|
|
262
|
-
# Grant
|
|
263
|
-
#
|
|
264
|
-
#
|
|
268
|
+
# ✅ ACCESS GRANTED
|
|
269
|
+
# Grant Ref: g_public_reports_3f9a
|
|
270
|
+
# Request ID: 8d1c0a2e-… (look it up under Activity in the console)
|
|
271
|
+
# Expires: 2024-01-15 18:00:00 UTC
|
|
272
|
+
# Masked Fields: none
|
|
273
|
+
#
|
|
274
|
+
# To execute and retrieve the data, run:
|
|
275
|
+
# vkit fetch --grant g_public_reports_3f9a
|
|
265
276
|
|
|
266
277
|
# 2. Fetch data
|
|
267
|
-
vkit fetch --grant
|
|
278
|
+
vkit fetch --grant g_public_reports_3f9a --format table
|
|
268
279
|
```
|
|
269
280
|
|
|
270
281
|
### Workflow 2: Approval Required
|
|
@@ -278,17 +289,17 @@ vkit request --aql '{
|
|
|
278
289
|
}'
|
|
279
290
|
|
|
280
291
|
# Output:
|
|
281
|
-
# ⏳
|
|
282
|
-
# Request ID:
|
|
283
|
-
# Approver: finance_manager
|
|
292
|
+
# ⏳ QUEUED for approval
|
|
293
|
+
# Request ID: 3b7e19c4-… (look it up under Activity in the console)
|
|
294
|
+
# Approver roles: finance_manager
|
|
284
295
|
# Reason: Financial data requires manager approval
|
|
285
|
-
#
|
|
296
|
+
#
|
|
297
|
+
# Once it's approved, run the same request again to get the data.
|
|
286
298
|
|
|
287
299
|
# 2. Check status
|
|
288
300
|
vkit requests list --state pending
|
|
289
301
|
|
|
290
|
-
# 3. After approval,
|
|
291
|
-
vkit fetch --grant gr_approved_abc123
|
|
302
|
+
# 3. After approval, run the same request again; it returns the rows
|
|
292
303
|
```
|
|
293
304
|
|
|
294
305
|
### Workflow 3: Denied Access
|
|
@@ -301,11 +312,9 @@ vkit request --aql '{
|
|
|
301
312
|
}'
|
|
302
313
|
|
|
303
314
|
# Output:
|
|
304
|
-
# ❌
|
|
315
|
+
# ❌ DENIED
|
|
305
316
|
# Reason: Direct payment card data access forbidden
|
|
306
|
-
#
|
|
307
|
-
# Alternative: Use tokenized_card_id field instead
|
|
308
|
-
# Audit ID: audit_20240115_denied_123
|
|
317
|
+
# Request ID: 7f29e0aa-… (look it up under Activity in the console)
|
|
309
318
|
```
|
|
310
319
|
|
|
311
320
|
---
|
|
@@ -861,60 +870,71 @@ vkit policy show <POLICY_ID>
|
|
|
861
870
|
|
|
862
871
|
---
|
|
863
872
|
|
|
864
|
-
###
|
|
873
|
+
### Agent Token Commands (Admin Only)
|
|
865
874
|
|
|
866
|
-
|
|
875
|
+
Agents (an MCP server, a scheduled job, a coding assistant) authenticate with
|
|
876
|
+
an agent token instead of a login. An agent is every token with the same
|
|
877
|
+
`--name`; the console's Agents page groups them that way.
|
|
867
878
|
|
|
868
|
-
|
|
879
|
+
#### `vkit agents tokens create`
|
|
869
880
|
|
|
870
881
|
```bash
|
|
871
|
-
vkit
|
|
882
|
+
vkit agents tokens create --name NAME [OPTIONS]
|
|
872
883
|
```
|
|
873
884
|
|
|
874
885
|
**Options:**
|
|
875
|
-
- `--
|
|
876
|
-
- `--
|
|
877
|
-
- `--
|
|
878
|
-
- `--
|
|
879
|
-
- `--
|
|
880
|
-
|
|
886
|
+
- `--name` — The agent's name (e.g. `incident-bot`); tokens with the same name are one agent
|
|
887
|
+
- `--label` — What this token is for, shown next to it in the console (e.g. `"PagerDuty runner"`)
|
|
888
|
+
- `--for` — Email of the person the agent acts for. Their Activity shows the agent's requests, so a member can follow what an agent does on their behalf. Must be an active member of your organization. Without it the agent acts for no one, and only admins see its requests.
|
|
889
|
+
- `--expires-in` — Lifetime: `1h`, `24h`, `30d` (default: no expiry)
|
|
890
|
+
- `--role`, `--clearance`, `--region`, `--tenant` — What policies see for this token
|
|
891
|
+
|
|
892
|
+
The token is printed once; store it straight away. The console never shows it.
|
|
881
893
|
|
|
882
|
-
**Examples:**
|
|
883
894
|
```bash
|
|
884
|
-
|
|
885
|
-
|
|
895
|
+
vkit agents tokens create --name incident-bot --label "PagerDuty runner" \
|
|
896
|
+
--for sam@acme.test --expires-in 30d
|
|
897
|
+
```
|
|
886
898
|
|
|
887
|
-
|
|
888
|
-
|
|
899
|
+
`--for` names who the agent acts for. It's separate from who created the
|
|
900
|
+
token (you), which the console shows as "Created by".
|
|
889
901
|
|
|
890
|
-
|
|
891
|
-
vkit audit query --dataset customers --action granted
|
|
902
|
+
#### `vkit agents tokens list`
|
|
892
903
|
|
|
893
|
-
|
|
894
|
-
vkit
|
|
904
|
+
```bash
|
|
905
|
+
vkit agents tokens list [--agent NAME] [--format table|json]
|
|
895
906
|
```
|
|
896
907
|
|
|
897
|
-
#### `vkit
|
|
898
|
-
|
|
899
|
-
Export audit logs for compliance reporting.
|
|
908
|
+
#### `vkit agents tokens revoke`
|
|
900
909
|
|
|
901
910
|
```bash
|
|
902
|
-
vkit
|
|
911
|
+
vkit agents tokens revoke --token PREFIX_OR_ID --reason "Leaked in CI logs"
|
|
903
912
|
```
|
|
904
913
|
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
914
|
+
`--reason` is required and recorded in the audit log. The token stops working
|
|
915
|
+
at once: its live grants are revoked, and a request already in flight with it
|
|
916
|
+
gets no rows.
|
|
917
|
+
|
|
918
|
+
`--for` needs a control plane with the console's Agents page; an older one
|
|
919
|
+
ignores it, and the token acts for no one. That control plane also refuses a
|
|
920
|
+
revoke without a reason, so older CLI versions can't revoke against it.
|
|
921
|
+
|
|
922
|
+
### Audit Log
|
|
923
|
+
|
|
924
|
+
There's no `vkit audit` command. Every request, decision and revoke is in the
|
|
925
|
+
audit log; read it in the console:
|
|
926
|
+
|
|
927
|
+
- **Activity** lists every request: who asked, what was decided and why, and
|
|
928
|
+
what ran. Filter by decision, agent, person, dataset or time, and open one
|
|
929
|
+
by the request ID that `vkit request` prints.
|
|
930
|
+
- **Export CSV** on the Activity page downloads the filtered view.
|
|
931
|
+
- A refused request, for example one made with a revoked agent token, prints
|
|
932
|
+
its code and request ID too:
|
|
910
933
|
|
|
911
|
-
**Example:**
|
|
912
934
|
```bash
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
--format csv \
|
|
917
|
-
--output compliance_reports/january_2024.csv
|
|
935
|
+
# API 401: Agent token vkit_agent_f5f5d9 was revoked at 2026-11-04T19:55:11Z: Leaked in CI logs
|
|
936
|
+
# Code: token_revoked
|
|
937
|
+
# Request ID: 7973fcba-… (look it up under Activity in the console)
|
|
918
938
|
```
|
|
919
939
|
|
|
920
940
|
---
|
|
@@ -1074,9 +1094,7 @@ docker compose up
|
|
|
1074
1094
|
|
|
1075
1095
|
**Problem:**
|
|
1076
1096
|
```
|
|
1077
|
-
|
|
1078
|
-
Grant ID: gr_abc123xyz
|
|
1079
|
-
Expired at: 2024-01-15 12:00:00 UTC
|
|
1097
|
+
API 403: Grant expired
|
|
1080
1098
|
```
|
|
1081
1099
|
|
|
1082
1100
|
**Solutions:**
|
data/lib/vkit/cli/api/client.rb
CHANGED
|
@@ -83,7 +83,7 @@ module Vkit
|
|
|
83
83
|
|
|
84
84
|
when 403
|
|
85
85
|
if body.is_a?(Hash) && body.key?("error")
|
|
86
|
-
raise APIError.
|
|
86
|
+
raise APIError.from_body(code, body)
|
|
87
87
|
else
|
|
88
88
|
# Valid domain response (e.g. policy denied)
|
|
89
89
|
body
|
|
@@ -93,21 +93,39 @@ module Vkit
|
|
|
93
93
|
# Queued for approval
|
|
94
94
|
body
|
|
95
95
|
|
|
96
|
-
when 422
|
|
97
|
-
raise APIError.new(code, body["error"] || body)
|
|
98
|
-
|
|
99
96
|
else
|
|
100
|
-
raise APIError.
|
|
97
|
+
raise APIError.from_body(code, body)
|
|
101
98
|
end
|
|
102
99
|
end
|
|
103
100
|
end
|
|
104
101
|
|
|
102
|
+
# The control plane's { error, code, request_id }. code says why in a
|
|
103
|
+
# word (token_revoked, token_expired), and request_id finds the request
|
|
104
|
+
# on the console's Activity page.
|
|
105
105
|
class APIError < StandardError
|
|
106
|
-
attr_reader :status
|
|
106
|
+
attr_reader :status, :error, :code, :request_id
|
|
107
|
+
|
|
108
|
+
def self.from_body(status, body)
|
|
109
|
+
return new(status, body) unless body.is_a?(Hash)
|
|
110
|
+
|
|
111
|
+
new(status, body["error"] || body, code: body["code"], request_id: body["request_id"])
|
|
112
|
+
end
|
|
107
113
|
|
|
108
|
-
def initialize(status,
|
|
114
|
+
def initialize(status, error, code: nil, request_id: nil)
|
|
109
115
|
@status = status
|
|
110
|
-
|
|
116
|
+
@error = error
|
|
117
|
+
@code = code
|
|
118
|
+
@request_id = request_id
|
|
119
|
+
super(describe)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
private
|
|
123
|
+
|
|
124
|
+
def describe
|
|
125
|
+
lines = ["API #{status}: #{error}"]
|
|
126
|
+
lines << "Code: #{code}" if code
|
|
127
|
+
lines << "Request ID: #{request_id} (look it up under Activity in the console)" if request_id
|
|
128
|
+
lines.join("\n")
|
|
111
129
|
end
|
|
112
130
|
end
|
|
113
131
|
end
|
data/lib/vkit/cli/base_cli.rb
CHANGED
|
@@ -115,7 +115,7 @@ module Vkit
|
|
|
115
115
|
|
|
116
116
|
desc "grant:revoke", "Revoke a grant"
|
|
117
117
|
option :grant, type: :string, required: true
|
|
118
|
-
option :reason, type: :string
|
|
118
|
+
option :reason, type: :string, required: true, desc: "Why it's revoked; recorded in the audit log"
|
|
119
119
|
option :force, type: :boolean, default: false
|
|
120
120
|
define_method("grant:revoke") do
|
|
121
121
|
Commands::GrantRevokeCommand.new.call(
|
|
@@ -335,9 +335,14 @@ module Vkit
|
|
|
335
335
|
option :tenant, type: :string, desc: "Tenant this token acts for on tenant-scoped datasets"
|
|
336
336
|
option :clearance, type: :string, desc: "Clearance policies see: low, medium or high"
|
|
337
337
|
option :region, type: :string, desc: "Region policies see: EU, US, CA or APAC"
|
|
338
|
+
option :label, type: :string, desc: "What this token is for, shown in the console (e.g. \"PagerDuty runner\")"
|
|
339
|
+
option :for, type: :string, banner: "EMAIL",
|
|
340
|
+
desc: "Email of the person the agent acts for; they see its requests in Activity"
|
|
338
341
|
def create
|
|
339
342
|
Commands::AgentTokensCreateCommand.new.call(
|
|
340
343
|
name: options[:name],
|
|
344
|
+
label: options[:label],
|
|
345
|
+
for: options[:for],
|
|
341
346
|
expires_in: options[:expires_in],
|
|
342
347
|
role: options[:role],
|
|
343
348
|
tenant: options[:tenant],
|
|
@@ -349,10 +354,12 @@ module Vkit
|
|
|
349
354
|
# agents tokens revoke
|
|
350
355
|
desc "revoke", "Revoke an agent token"
|
|
351
356
|
option :token, required: true, desc: "Token ID or prefix"
|
|
357
|
+
option :reason, type: :string, required: true, desc: "Why it's revoked; recorded in the audit log"
|
|
352
358
|
option :force, type: :boolean, default: false, desc: "Skip confirmation"
|
|
353
359
|
def revoke
|
|
354
360
|
Commands::AgentTokensRevokeCommand.new.call(
|
|
355
361
|
token: options[:token],
|
|
362
|
+
reason: options[:reason],
|
|
356
363
|
force: options[:force]
|
|
357
364
|
)
|
|
358
365
|
end
|
|
@@ -25,6 +25,8 @@ module Vkit
|
|
|
25
25
|
puts
|
|
26
26
|
|
|
27
27
|
puts "🧠 Name: #{token["name"]}"
|
|
28
|
+
puts "📝 Label: #{token["label"]}" if token["label"]
|
|
29
|
+
puts "👤 Acts for: #{acts_for(token)}"
|
|
28
30
|
puts "🎭 Role: #{token["role"]}"
|
|
29
31
|
puts "🏢 Tenant: #{token["tenant"]}" if token["tenant"]
|
|
30
32
|
puts "🛡 Clearance: #{token["clearance"]}" if token["clearance"]
|
|
@@ -49,6 +51,9 @@ module Vkit
|
|
|
49
51
|
def build_body(options)
|
|
50
52
|
body = {
|
|
51
53
|
name: options.fetch(:name),
|
|
54
|
+
label: options[:label],
|
|
55
|
+
# Resolved to a member of your organization by the control plane.
|
|
56
|
+
user_email: options[:for],
|
|
52
57
|
role: options[:role],
|
|
53
58
|
tenant: options[:tenant],
|
|
54
59
|
clearance: options[:clearance],
|
|
@@ -62,6 +67,13 @@ module Vkit
|
|
|
62
67
|
body
|
|
63
68
|
end
|
|
64
69
|
|
|
70
|
+
def acts_for(token)
|
|
71
|
+
person = token["acts_for"]
|
|
72
|
+
return "no one (its requests show only to admins)" unless person
|
|
73
|
+
|
|
74
|
+
person["name"] == person["email"] ? person["email"] : "#{person["name"]} <#{person["email"]}>"
|
|
75
|
+
end
|
|
76
|
+
|
|
65
77
|
def parse_expires_in(value)
|
|
66
78
|
number = value.to_i
|
|
67
79
|
|
|
@@ -42,6 +42,8 @@ module Vkit
|
|
|
42
42
|
"ID" => t["id"],
|
|
43
43
|
"Agent" => t["name"],
|
|
44
44
|
"Prefix" => t["prefix"],
|
|
45
|
+
"Label" => t["label"] || "-",
|
|
46
|
+
"Acts For" => t.dig("acts_for", "email") || "-",
|
|
45
47
|
"Expires At" => t["expires_at"] || "never",
|
|
46
48
|
"Revoked At" => t["revoked_at"] || "-",
|
|
47
49
|
"Created At" => t["created_at"]
|
|
@@ -8,6 +8,9 @@ module Vkit
|
|
|
8
8
|
class AgentTokensRevokeCommand < BaseCommand
|
|
9
9
|
def call(options)
|
|
10
10
|
token_ref = options.fetch(:token)
|
|
11
|
+
reason = options[:reason].to_s.strip
|
|
12
|
+
# The control plane refuses a revoke without one.
|
|
13
|
+
raise "A reason is required (--reason)" if reason.empty?
|
|
11
14
|
|
|
12
15
|
with_auth do
|
|
13
16
|
user = credential_store.user
|
|
@@ -21,7 +24,7 @@ module Vkit
|
|
|
21
24
|
|
|
22
25
|
authenticated_client.post(
|
|
23
26
|
"/api/v1/orgs/#{org}/agent_tokens/#{token["id"]}/revoke",
|
|
24
|
-
body: {}
|
|
27
|
+
body: { reason: reason }
|
|
25
28
|
)
|
|
26
29
|
|
|
27
30
|
puts "🛑 AGENT TOKEN REVOKED"
|
|
@@ -29,8 +32,9 @@ module Vkit
|
|
|
29
32
|
puts "🧠 Name: #{token["name"]}"
|
|
30
33
|
puts "🏷 Prefix: #{token["prefix"]}"
|
|
31
34
|
puts "🆔 ID: #{token["id"]}"
|
|
35
|
+
puts "📝 Reason: #{reason}"
|
|
32
36
|
puts
|
|
33
|
-
puts "✅ The token is no longer valid."
|
|
37
|
+
puts "✅ The token is no longer valid, and its grants are revoked."
|
|
34
38
|
end
|
|
35
39
|
end
|
|
36
40
|
|
|
@@ -61,7 +61,7 @@ module Vkit
|
|
|
61
61
|
puts " The grant is issued once every role has approved."
|
|
62
62
|
else
|
|
63
63
|
puts "✅ Approved request #{id}"
|
|
64
|
-
puts " → Grant Ref: #{res["grant_ref"]
|
|
64
|
+
puts " → Grant Ref: #{res["grant_ref"]}"
|
|
65
65
|
puts " → Expires: #{res["expires_at"]}"
|
|
66
66
|
end
|
|
67
67
|
end
|
|
@@ -5,6 +5,10 @@ module Vkit
|
|
|
5
5
|
module Commands
|
|
6
6
|
class GrantRevokeCommand < BaseCommand
|
|
7
7
|
def call(grant_ref:, reason:, force:)
|
|
8
|
+
reason = reason.to_s.strip
|
|
9
|
+
# The control plane refuses a revoke without one.
|
|
10
|
+
raise "A reason is required (--reason)" if reason.empty?
|
|
11
|
+
|
|
8
12
|
with_auth do
|
|
9
13
|
user = credential_store.user
|
|
10
14
|
org = user["organization_slug"]
|
|
@@ -14,7 +18,7 @@ module Vkit
|
|
|
14
18
|
unless force
|
|
15
19
|
puts "⚠️ You are about to revoke grant: #{grant_ref}"
|
|
16
20
|
puts " Organization: #{org}"
|
|
17
|
-
puts " Reason: #{reason
|
|
21
|
+
puts " Reason: #{reason}"
|
|
18
22
|
print "Continue? (y/N): "
|
|
19
23
|
answer = STDIN.gets.strip
|
|
20
24
|
return puts("Aborted.") unless answer.downcase == "y"
|
|
@@ -43,9 +43,17 @@ module Vkit
|
|
|
43
43
|
|
|
44
44
|
private
|
|
45
45
|
|
|
46
|
+
# Every response names its request; the console's Activity page
|
|
47
|
+
# finds it by this id.
|
|
48
|
+
def print_request_id(result)
|
|
49
|
+
return if result["request_id"].to_s.empty?
|
|
50
|
+
|
|
51
|
+
puts "Request ID: #{result["request_id"]} (look it up under Activity in the console)"
|
|
52
|
+
end
|
|
53
|
+
|
|
46
54
|
def print_queued(result)
|
|
47
55
|
puts "⏳ QUEUED for approval"
|
|
48
|
-
|
|
56
|
+
print_request_id(result)
|
|
49
57
|
|
|
50
58
|
roles = ApprovalRoles.required_roles(result)
|
|
51
59
|
puts "Approver roles: #{roles.join(', ')}" if roles.any?
|
|
@@ -67,6 +75,7 @@ module Vkit
|
|
|
67
75
|
when "denied"
|
|
68
76
|
puts "❌ DENIED"
|
|
69
77
|
puts "Reason: #{result["reason"]}"
|
|
78
|
+
print_request_id(result)
|
|
70
79
|
exit 2
|
|
71
80
|
|
|
72
81
|
# The control plane answers "pending_approval"; "queued" is what
|
|
@@ -79,7 +88,8 @@ module Vkit
|
|
|
79
88
|
expires_at = Time.parse(result["expires_at"]).getlocal
|
|
80
89
|
|
|
81
90
|
puts "✅ ACCESS GRANTED"
|
|
82
|
-
puts "Grant
|
|
91
|
+
puts "Grant Ref: #{result["grant_ref"]}"
|
|
92
|
+
print_request_id(result)
|
|
83
93
|
puts "Expires: #{expires_at.strftime("%Y-%m-%d %H:%M:%S %Z")}"
|
|
84
94
|
|
|
85
95
|
if (mask = result["masked_fields"]) && mask.any?
|
|
@@ -90,7 +100,7 @@ module Vkit
|
|
|
90
100
|
|
|
91
101
|
puts
|
|
92
102
|
puts "To execute and retrieve the data, run:"
|
|
93
|
-
puts " vkit fetch --grant #{result["grant_ref"]
|
|
103
|
+
puts " vkit fetch --grant #{result["grant_ref"]}"
|
|
94
104
|
exit 0
|
|
95
105
|
|
|
96
106
|
when "ok"
|
|
@@ -102,6 +112,8 @@ module Vkit
|
|
|
102
112
|
end
|
|
103
113
|
|
|
104
114
|
puts "✅ OK — #{rows.size} rows"
|
|
115
|
+
puts "Grant Ref: #{result["grant_ref"]} (reused)" if result["grant_ref"]
|
|
116
|
+
print_request_id(result)
|
|
105
117
|
|
|
106
118
|
if meta.any?
|
|
107
119
|
puts "ℹ️ Query Metadata:"
|
|
@@ -116,6 +128,7 @@ module Vkit
|
|
|
116
128
|
else
|
|
117
129
|
puts "❓ Unexpected response:"
|
|
118
130
|
puts result.inspect
|
|
131
|
+
print_request_id(result) if result.is_a?(Hash)
|
|
119
132
|
exit 1
|
|
120
133
|
end
|
|
121
134
|
end
|
|
@@ -15,6 +15,8 @@ module Vkit
|
|
|
15
15
|
class CredentialStore
|
|
16
16
|
SERVICE = "vkit"
|
|
17
17
|
ACCOUNT = "credentials"
|
|
18
|
+
# security -i reads lines of about 4 KB; a login is well under that.
|
|
19
|
+
MAC_KEYCHAIN_MAX_HEX = 3_900
|
|
18
20
|
|
|
19
21
|
@override_noticed = false
|
|
20
22
|
|
|
@@ -34,15 +36,7 @@ module Vkit
|
|
|
34
36
|
"user" => user
|
|
35
37
|
}
|
|
36
38
|
|
|
37
|
-
|
|
38
|
-
when mac?
|
|
39
|
-
mac_keychain_store(payload)
|
|
40
|
-
when linux? && secret_tool_available?
|
|
41
|
-
linux_secret_service_store(payload)
|
|
42
|
-
else
|
|
43
|
-
file_store(payload)
|
|
44
|
-
end
|
|
45
|
-
|
|
39
|
+
store(payload)
|
|
46
40
|
true
|
|
47
41
|
end
|
|
48
42
|
|
|
@@ -56,16 +50,8 @@ module Vkit
|
|
|
56
50
|
return unless payload
|
|
57
51
|
|
|
58
52
|
payload["user"] = user
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
when mac?
|
|
62
|
-
mac_keychain_store(payload)
|
|
63
|
-
when linux? && secret_tool_available?
|
|
64
|
-
linux_secret_service_store(payload)
|
|
65
|
-
else
|
|
66
|
-
file_store(payload)
|
|
67
|
-
end
|
|
68
|
-
end
|
|
53
|
+
store(payload)
|
|
54
|
+
end
|
|
69
55
|
|
|
70
56
|
def endpoint
|
|
71
57
|
load_payload&.dig("endpoint")
|
|
@@ -110,9 +96,8 @@ module Vkit
|
|
|
110
96
|
mac_keychain_delete
|
|
111
97
|
when linux? && secret_tool_available?
|
|
112
98
|
linux_secret_service_delete
|
|
113
|
-
else
|
|
114
|
-
file_delete
|
|
115
99
|
end
|
|
100
|
+
file_delete
|
|
116
101
|
end
|
|
117
102
|
|
|
118
103
|
def clear_token!
|
|
@@ -120,15 +105,7 @@ module Vkit
|
|
|
120
105
|
return unless payload
|
|
121
106
|
|
|
122
107
|
payload.delete("token")
|
|
123
|
-
|
|
124
|
-
case
|
|
125
|
-
when mac?
|
|
126
|
-
mac_keychain_store(payload)
|
|
127
|
-
when linux? && secret_tool_available?
|
|
128
|
-
linux_secret_service_store(payload)
|
|
129
|
-
else
|
|
130
|
-
file_store(payload)
|
|
131
|
-
end
|
|
108
|
+
store(payload)
|
|
132
109
|
end
|
|
133
110
|
|
|
134
111
|
# endpoint and token only; the user is looked up separately (#user),
|
|
@@ -137,15 +114,40 @@ module Vkit
|
|
|
137
114
|
env_override || stored_payload
|
|
138
115
|
end
|
|
139
116
|
|
|
117
|
+
# The keychain first, then the file, which also holds the login when
|
|
118
|
+
# saving to the keychain failed.
|
|
140
119
|
def stored_payload
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
120
|
+
keychain =
|
|
121
|
+
case
|
|
122
|
+
when mac?
|
|
123
|
+
mac_keychain_load
|
|
124
|
+
when linux? && secret_tool_available?
|
|
125
|
+
linux_secret_service_load
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
keychain || file_load
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# Saves to the OS keychain when there is one. If that fails (no
|
|
132
|
+
# unlocked keyring over SSH, a locked login keychain), saves to
|
|
133
|
+
# ~/.vkit instead and says so, rather than reporting a login that
|
|
134
|
+
# wasn't kept.
|
|
135
|
+
def store(payload)
|
|
136
|
+
saved =
|
|
137
|
+
case
|
|
138
|
+
when mac?
|
|
139
|
+
mac_keychain_store(payload)
|
|
140
|
+
when linux? && secret_tool_available?
|
|
141
|
+
linux_secret_service_store(payload)
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
if saved
|
|
145
|
+
file_delete
|
|
146
|
+
return
|
|
148
147
|
end
|
|
148
|
+
|
|
149
|
+
warn "vkit: couldn't save to the system keychain; saved to #{@fallback_path} instead." unless saved.nil?
|
|
150
|
+
file_store(payload)
|
|
149
151
|
end
|
|
150
152
|
|
|
151
153
|
def override_user(override)
|
|
@@ -171,15 +173,19 @@ module Vkit
|
|
|
171
173
|
system("which secret-tool > /dev/null 2>&1")
|
|
172
174
|
end
|
|
173
175
|
|
|
176
|
+
# `security -i` reads the command from stdin, so the token never
|
|
177
|
+
# appears in the process list, as it would with `-w` on the command
|
|
178
|
+
# line. The data goes in hex (-X) to avoid quoting.
|
|
174
179
|
def mac_keychain_store(payload)
|
|
180
|
+
hex = payload.to_json.unpack1("H*")
|
|
181
|
+
return false if hex.bytesize > MAC_KEYCHAIN_MAX_HEX
|
|
182
|
+
|
|
175
183
|
mac_keychain_delete
|
|
176
|
-
|
|
177
|
-
"security", "
|
|
178
|
-
"-a
|
|
179
|
-
"-s", SERVICE,
|
|
180
|
-
"-w", payload.to_json,
|
|
181
|
-
"-U"
|
|
184
|
+
_stdout, _stderr, status = Open3.capture3(
|
|
185
|
+
"security", "-i",
|
|
186
|
+
stdin_data: "add-generic-password -a #{ACCOUNT} -s #{SERVICE} -U -X #{hex}\n"
|
|
182
187
|
)
|
|
188
|
+
status.success?
|
|
183
189
|
end
|
|
184
190
|
|
|
185
191
|
def mac_keychain_load
|
|
@@ -208,7 +214,7 @@ module Vkit
|
|
|
208
214
|
end
|
|
209
215
|
|
|
210
216
|
def linux_secret_service_store(payload)
|
|
211
|
-
Open3.capture3(
|
|
217
|
+
_stdout, _stderr, status = Open3.capture3(
|
|
212
218
|
"secret-tool",
|
|
213
219
|
"store",
|
|
214
220
|
"--label=VaultKit Credentials",
|
|
@@ -216,6 +222,7 @@ module Vkit
|
|
|
216
222
|
"account", ACCOUNT,
|
|
217
223
|
stdin_data: payload.to_json
|
|
218
224
|
)
|
|
225
|
+
status.success?
|
|
219
226
|
end
|
|
220
227
|
|
|
221
228
|
def linux_secret_service_load
|
|
@@ -234,7 +241,7 @@ module Vkit
|
|
|
234
241
|
end
|
|
235
242
|
|
|
236
243
|
def linux_secret_service_delete
|
|
237
|
-
|
|
244
|
+
system("secret-tool", "clear", "service", SERVICE, "account", ACCOUNT, out: File::NULL, err: File::NULL)
|
|
238
245
|
end
|
|
239
246
|
|
|
240
247
|
def file_store(payload)
|
data/lib/vkit/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: vaultkit
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nnamdi Ogundu
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-11-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: thor
|