This repository has been archived by the owner on Jan 3, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Vault Identity Tokens to authenticate to the monolith (#247)
* Switched Token Generation to Vault's identity tokens * Run rubocop * remove test rote * remove typo * refactored to fit new standard * fix rubocop
- Loading branch information
1 parent
405ce56
commit eced6e0
Showing
6 changed files
with
76 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
class WcaApi | ||
# TODO: switch this to Vault identity tokens https://developer.hashicorp.com/vault/docs/secrets/identity/identity-token | ||
def self.get_wca_token(audience) | ||
iat = Time.now.to_i | ||
jti_raw = [JwtOptions.secret, iat].join(':').to_s | ||
jti = Digest::MD5.hexdigest(jti_raw) | ||
payload = { data: { service_id: "registration.worldcubeassociation.org" }, aud: audience, exp: Time.now.to_i + JwtOptions.expiry, sub: "registration.worldcubeassociation.org", iat: iat, jti: jti } | ||
JWT.encode payload, JwtOptions.secret, JwtOptions.algorithm | ||
WCA_API_HEADER = 'X-WCA-Service-Token' | ||
# Uses Vault ID Tokens: see https://developer.hashicorp.com/vault/docs/secrets/identity/identity-token | ||
def self.get_wca_token | ||
Vault.with_retries(Vault::HTTPConnectionError) do | ||
data = Vault.logical.read("identity/oidc/token/#{@vault_application}") | ||
if data.present? | ||
data.data[:data][:token] | ||
else # TODO: should we hard error out here? | ||
puts "Tried to get identity token, but got error" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters