Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update authentication handling #13540

Merged
merged 5 commits into from
Nov 12, 2024
Merged
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
3 changes: 2 additions & 1 deletion lib/vagrant/util/curl_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class CurlHelper
SILENCED_HOSTS = [
"vagrantcloud-files-production.s3-accelerate.amazonaws.com".freeze,
"vagrantcloud.com".freeze,
"vagrantup.com".freeze
"vagrantup.com".freeze,
"cloud.hashicorp.com".freeze,
].freeze

def self.capture_output_proc(logger, ui, source=nil)
Expand Down
6 changes: 0 additions & 6 deletions lib/vagrant/util/downloader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ class Downloader
# Vagrant/1.7.4 (+https://www.vagrantup.com; ruby2.1.0)
USER_AGENT = "Vagrant/#{VERSION} (+https://www.vagrantup.com; #{RUBY_ENGINE}#{RUBY_VERSION}) #{ENV['VAGRANT_USER_AGENT_PROVISIONAL_STRING']}".strip.freeze

# Hosts that do not require notification on redirect
SILENCED_HOSTS = [
"vagrantcloud.com".freeze,
"vagrantup.com".freeze
].freeze

attr_accessor :source
attr_reader :destination
attr_accessor :headers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
Vagrant.require "uri"
Vagrant.require "vagrant/util/credential_scrubber"

require_relative "./add_authentication"

require Vagrant.source_root.join("plugins/commands/cloud/client/client")
require_relative "./add_authentication"

# Similar to AddAuthentication this middleware will add authentication for interacting
# with Vagrant cloud. It does this by adding Authentication headers to a
Expand Down Expand Up @@ -54,6 +53,8 @@ def call(env)
else
env[:downloader].headers << "Authorization: Bearer #{token}"
end
else
@logger.debug("Not adding authentication header, host mismatch #{target_url.host} != #{server_uri.host}")
end

env[:downloader]
Expand Down
18 changes: 13 additions & 5 deletions plugins/commands/cloud/client/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ def self.reset!
def initialize(env)
@logger = Log4r::Logger.new("vagrant::cloud::client")
@env = env
@client = VagrantCloud::Client.new(
access_token: token,
url_base: api_server_url
)
if !defined?(@@client)
@@client = VagrantCloud::Client.new(
access_token: token,
url_base: api_server_url
)
end
@client = @@client
end

# Removes the token, effectively logging the user out.
Expand All @@ -54,7 +57,8 @@ def clear_token
#
# @return [Boolean]
def logged_in?
return false if !client.access_token
return false if !client&.access_token

Vagrant::Util::CredentialScrubber.sensitive(client.access_token)

with_error_handling do
Expand Down Expand Up @@ -128,6 +132,10 @@ def store_token(token)
#
# @return [String]
def token
# If the client is defined, use the client for the access token
# to allow proper token generation if required
return client.access_token if client && !client.access_token.nil?

if present?(ENV["VAGRANT_CLOUD_TOKEN"]) && token_path.exist?
# Only show warning if it has not been previously shown
if !defined?(@@double_token_warning)
Expand Down
4 changes: 2 additions & 2 deletions vagrant.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Gem::Specification.new do |s|
s.add_dependency "rexml", "~> 3.2"
s.add_dependency "rgl", "~> 0.5.10"
s.add_dependency "rubyzip", "~> 2.3.2"
s.add_dependency "vagrant_cloud", "~> 3.1.1"
s.add_dependency "vagrant_cloud", "~> 3.1.2"
s.add_dependency "wdm", "~> 0.1.1"
s.add_dependency "winrm", ">= 2.3.9", "< 3.0"
s.add_dependency "winrm-elevated", ">= 1.2.3", "< 2.0"
Expand All @@ -56,7 +56,7 @@ Gem::Specification.new do |s|
s.add_development_dependency "rspec", "~> 3.11"
s.add_development_dependency "rspec-its", "~> 1.3.0"
s.add_development_dependency "fake_ftp", "~> 0.3.0"
s.add_development_dependency "webrick", "~> 1.7.0"
s.add_development_dependency "webrick", "~> 1.7"

# The following block of code determines the files that should be included
# in the gem. It does this by reading all the files in the directory where
Expand Down