vaultez-cli 0.2.2 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 14c54ce2993304e11bb04d4295bdc8fbab8596f7387db6fa4639c1e32dd40e7c
4
- data.tar.gz: ec8e484b39065e1a3221c60bc3d5acf431c51f8daeb77c03658cbc439f5b73b7
3
+ metadata.gz: 78043da2b439dff80b3ed04f33ee62a77936276e5bd60935be94d2eca29592f0
4
+ data.tar.gz: aa76a4503506bd47d5e5b8a582725fbcee604bfdd0b23976e868e13bb7af2240
5
5
  SHA512:
6
- metadata.gz: 13ba71b6797e10a7cb46d15b9b61e76b18817d1de62c541eadfc44a994172bf2c21df2f526e9b7b2b0f0bbb6464402caf4a0562ca51aa62d20ebcbc698913007
7
- data.tar.gz: 9bc5011daa631088362b7bfb6b3153f87eec3471ef568d477b8dde69572690620b67257c819f3a3b9e98e57351637f0200e43c6e0dc3d62f2ad68ac20bc272f6
6
+ metadata.gz: 1214dc2431ac95bac73be69ce5ed35a6bb1f854ebbdede1e011954bf6161e3031ef1a628f810ff531284fb228808a86f4d8a33df8bfab776c6d756d87c3dec5f
7
+ data.tar.gz: 1c9dcf449a65eeba1412ecae189f4d00cbae4cfe98437c7ed649a559b0868ad4f17e09090d92b6483a4d62c35154918dc738ae0695f4db8465cb251b1b62c8c9
data/lib/vaultez/cli.rb CHANGED
@@ -12,14 +12,6 @@ module Vaultez
12
12
 
13
13
  map %w[--version -v] => :__version
14
14
 
15
- class_option :token, type: :string, banner: "TOKEN",
16
- desc: "Use a project token instead of the saved session"
17
-
18
- def initialize(*args)
19
- super
20
- ENV["VAULTEZ_TOKEN"] = options[:token] if options[:token]
21
- end
22
-
23
15
  desc "login", "Authenticate with email, password, and 2FA code"
24
16
  long_desc <<~DESC, wrap: false
25
17
  Authenticate with your Vaultez account. You will be prompted for your
@@ -55,14 +47,17 @@ module Vaultez
55
47
  vaultez fetch --company="Acme" --project="Backend"
56
48
  vaultez fetch --company="Acme" --project="Backend" --secret="DATABASE_URL"
57
49
 
58
- PROJECT TOKEN (VAULTEZ_TOKEN env var or --token flag):
50
+ PROJECT TOKEN (VAULTEZ_TOKEN env var):
59
51
  When a project token is active, it already knows which project to use.
60
52
  No --project flag is needed.
61
53
 
62
54
  VAULTEZ_TOKEN=vz_... vaultez fetch
63
- vaultez fetch --token=vz_... --secret="DATABASE_URL"
55
+ VAULTEZ_TOKEN=vz_... vaultez fetch --secret="DATABASE_URL"
64
56
 
65
57
  Project tokens can be created in the Tokens tab of your project settings.
58
+ Always pass the token via the VAULTEZ_TOKEN environment variable, never
59
+ as a command-line flag — CLI arguments are visible to other local users
60
+ via `ps` and get saved in shell history.
66
61
  DESC
67
62
  option :companies, type: :boolean, desc: "List all your companies"
68
63
  option :company, type: :string, desc: "Company name"
@@ -103,15 +98,14 @@ module Vaultez
103
98
  puts " help Show help for any command"
104
99
  puts
105
100
  puts "Options:"
106
- puts " --token Use a project token instead of the saved session"
107
101
  puts " --version Show the installed CLI version"
108
102
  puts
109
103
  puts "Examples:"
110
104
  puts " vaultez login"
111
105
  puts " vaultez fetch --project=\"Backend\""
112
106
  puts " vaultez fetch --project=\"Backend\" --secret=\"DATABASE_URL\""
113
- puts " vaultez fetch --token=\"vz_...\""
114
- puts " vaultez fetch --token=\"vz_...\" --secret=\"DATABASE_URL\""
107
+ puts " VAULTEZ_TOKEN=\"vz_...\" vaultez fetch"
108
+ puts " VAULTEZ_TOKEN=\"vz_...\" vaultez fetch --secret=\"DATABASE_URL\""
115
109
  end
116
110
  end
117
111
  end
@@ -4,6 +4,14 @@ require "uri"
4
4
 
5
5
  module Vaultez
6
6
  class Client
7
+ # A legitimate response (companies/projects/secrets, all short strings)
8
+ # is a handful of KB at most. This bounds how much of a compromised or
9
+ # malicious response - a compromised API backend, a MITM'd/redirected
10
+ # api_url, or a compromised account crafting an oversized payload - this
11
+ # process will hold in memory, independent of any size limit a caller
12
+ # (e.g. the oma-vaultez plugin) enforces on this CLI's own stdout.
13
+ MAX_RESPONSE_BYTES = 4 * 1024 * 1024
14
+
7
15
  def initialize
8
16
  @api_url = Vaultez::Config.api_url
9
17
  @token = Vaultez::Config.token
@@ -68,7 +76,9 @@ module Vaultez
68
76
  req.body = body.to_json if body
69
77
 
70
78
  begin
71
- response = http.request(req)
79
+ response = fetch_bounded(http, req)
80
+ rescue Vaultez::Error
81
+ raise
72
82
  rescue StandardError => error
73
83
  raise Vaultez::ApiError, "Could not reach the Vaultez API: #{error.message}"
74
84
  end
@@ -76,6 +86,27 @@ module Vaultez
76
86
  parse_response(response)
77
87
  end
78
88
 
89
+ # Reads the response body incrementally instead of Net::HTTP's default
90
+ # #request behavior, which fully buffers the entire body in memory
91
+ # before returning with no size limit at all. Aborts (closing the
92
+ # connection) the moment the body crosses MAX_RESPONSE_BYTES, rather
93
+ # than finishing the download and only noticing afterward.
94
+ def fetch_bounded(http, req)
95
+ response = nil
96
+ body = +""
97
+ http.request(req) do |res|
98
+ response = res
99
+ res.read_body do |chunk|
100
+ body << chunk
101
+ if body.bytesize > MAX_RESPONSE_BYTES
102
+ raise Vaultez::ApiError, "Vaultez API response exceeded the maximum allowed size"
103
+ end
104
+ end
105
+ end
106
+ response.body = body
107
+ response
108
+ end
109
+
79
110
  def build_request(method, uri)
80
111
  case method
81
112
  when :get then Net::HTTP::Get.new(uri)
@@ -41,12 +41,30 @@ module Vaultez
41
41
 
42
42
  def self.read
43
43
  return {} unless File.exist?(CONFIG_PATH)
44
+ tighten_permissions
44
45
  YAML.safe_load(File.read(CONFIG_PATH)) || {}
45
46
  end
46
47
 
47
48
  def self.write(data)
48
- FileUtils.mkdir_p(File.dirname(CONFIG_PATH))
49
- File.write(CONFIG_PATH, data.to_yaml)
49
+ dir = File.dirname(CONFIG_PATH)
50
+ FileUtils.mkdir_p(dir, mode: 0o700)
51
+ # The mode argument to mkdir_p/File.open only applies at creation time,
52
+ # so explicitly chmod too - this also retroactively tightens a config
53
+ # directory/file that was created before this fix, which would
54
+ # otherwise stay world-readable forever (0644/0755 by default umask).
55
+ File.chmod(0o700, dir)
56
+ File.open(CONFIG_PATH, File::CREAT | File::TRUNC | File::WRONLY, 0o600) do |f|
57
+ f.write(data.to_yaml)
58
+ end
59
+ File.chmod(0o600, CONFIG_PATH)
60
+ end
61
+
62
+ def self.tighten_permissions
63
+ dir = File.dirname(CONFIG_PATH)
64
+ File.chmod(0o700, dir) if File.directory?(dir) && (File.stat(dir).mode & 0o777) != 0o700
65
+ File.chmod(0o600, CONFIG_PATH) if (File.stat(CONFIG_PATH).mode & 0o777) != 0o600
66
+ rescue StandardError
67
+ nil # best-effort; never block a read over a permissions fix
50
68
  end
51
69
  end
52
70
  end
@@ -1,3 +1,3 @@
1
1
  module Vaultez
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vaultez-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nur Ketene
@@ -58,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
58
  - !ruby/object:Gem::Version
59
59
  version: '0'
60
60
  requirements: []
61
- rubygems_version: 3.6.9
61
+ rubygems_version: 4.0.16
62
62
  specification_version: 4
63
63
  summary: CLI tool for Vaultez — manage your secrets from the terminal
64
64
  test_files: []