Skip to content

Commit 5360bb6

Browse files
committed
Add gcp authentication support
1 parent 4780e89 commit 5360bb6

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

lib/vault/api/auth.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,29 @@ def aws_ec2(role, pkcs7, nonce = nil)
186186
return secret
187187
end
188188

189+
# Authenticate via the GCP authentication method. If authentication is
190+
# successful, the resulting token will be stored on the client and used
191+
# for future requests.
192+
#
193+
# @example
194+
# Vault.auth.gcp("read-only", "jwt", "gcp") #=> #<Vault::Secret lease_id="">
195+
#
196+
# @param [String] role
197+
# @param [String] jwt
198+
# jwt returned by the instance identity metadata
199+
# @param [String] path optional
200+
# the path were the gcp auth backend is mounted
201+
#
202+
# @return [Secret]
203+
def gcp(role, jwt, path = 'gcp')
204+
payload = { role: role, jwt: jwt }
205+
# Set a custom nonce if client is providing one
206+
json = client.post("/v1/auth/#{CGI.escape(path)}/login", JSON.fast_generate(payload))
207+
secret = Secret.decode(json)
208+
client.token = secret.auth.client_token
209+
return secret
210+
end
211+
189212
# Authenticate via a TLS authentication method. If authentication is
190213
# successful, the resulting token will be stored on the client and used
191214
# for future requests.

0 commit comments

Comments
 (0)