Skip to content
Open
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

BUG FIXES

- `Client#with_token` now sends the given token from API objects (`#logical`, `#auth`, ...) that the original client had already used. Before, the copy reused them, and their requests went out with the original client's token.

## v0.20.1 (March 31, 2026)

BUG FIXES
Expand Down
8 changes: 8 additions & 0 deletions lib/vault/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ def initialize(options = {})
@nhp = nil
end

# The API objects (#logical, #auth, ...) are memoized with a reference to
# the client that built them. A copy must build its own, or a request
# through the copy would use the original client's token.
def initialize_copy(other)
super
@logical = @auth = @auth_token = @auth_tls = @approle = @sys = @transform = nil
end

def pool
@lock.synchronize do
return @nhp if @nhp
Expand Down
12 changes: 12 additions & 0 deletions spec/unit/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ module Vault
end
expect(client.token).to eq("abcd-1234")
end

it "sends the new token from an API the original client already used" do
client = described_class.new(address: "http://vault.test", token: "abcd-1234")
stub_request(:get, "http://vault.test/v1/secret/foo")
.to_return(body: '{"data":{}}', headers: { "Content-Type" => "application/json" })
client.logical.read("secret/foo")

client.with_token("defg-5678") { |c| c.logical.read("secret/foo") }

expect(a_request(:get, "http://vault.test/v1/secret/foo")
.with(headers: { "X-Vault-Token" => "defg-5678" })).to have_been_made.once
end
end

describe "#get" do
Expand Down