14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/legion/crypt/vault_kerberos_auth.rb', line 14
def self.login(spnego_token:, auth_path: DEFAULT_AUTH_PATH)
raise AuthError, 'Vault is not connected' unless vault_connected?
log.info "[crypt:vault_kerberos] login requested auth_path=#{auth_path}"
response = ::Vault.logical.write(auth_path, authorization: "Negotiate #{spnego_token}")
raise AuthError, 'Vault Kerberos auth returned no auth data' unless response&.auth
{
token: response.auth.client_token,
lease_duration: response.auth.lease_duration,
renewable: response.auth.renewable?,
policies: response.auth.policies,
metadata: response.auth.metadata
}
rescue ::Vault::HTTPClientError => e
handle_exception(e, level: :warn, operation: 'crypt.vault_kerberos_auth.login', auth_path: auth_path)
raise AuthError, "Vault Kerberos auth failed: #{e.message}"
rescue StandardError => e
handle_exception(e, level: :error, operation: 'crypt.vault_kerberos_auth.login', auth_path: auth_path)
raise
end
|