Skip to content

Update install for authenticated proxy #409

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
40 changes: 33 additions & 7 deletions bin/install
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,12 @@ begin
def usage
print <<EOF

install [--sanity-check] [--disable-imds-v1] [--proxy http://hostname:port] <package-type>
install [--sanity-check] [--disable-imds-v1] [--proxy http://hostname:port] [--user username] [--pass pasword] <package-type>
--sanity-check [optional]
--disable-imds-v1 [optional]
--proxy [optional]
--user [optional]
--pass [optional]
package-type: 'rpm', 'deb', or 'auto'

Installs fetches the latest package version of the specified type and
Expand All @@ -243,7 +245,8 @@ If --disable-imds-v1 is specified, the install script will not fallback to IMDS
IMDS v2 call is failed

To use a HTTP proxy, specify --proxy followed by the proxy server
defined by http://hostname:port
defined by http://hostname:port. If it is an authenticated proxy add the additional
--user and --pass options.

This install script needs Ruby versions 2.x or 3.x installed as a prerequisite.
Currently recommended Ruby versions are 2.0.0, 2.1.8, 2.2.4, 2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 3.1, and 3.2
Expand Down Expand Up @@ -290,7 +293,7 @@ EOF
end

def parse_args()
if (ARGV.length > 4)
if (ARGV.length > 7)
usage
@log.error('Too many arguments.')
exit(1)
Expand All @@ -304,6 +307,8 @@ EOF
@disable_imds_v1 = false
@reexeced = false
@http_proxy = nil
@proxy_user = nil
@proxy_pass = nil
@target_version_arg = nil

@args = Array.new(ARGV)
Expand All @@ -313,6 +318,8 @@ EOF
['--help', GetoptLong::NO_ARGUMENT],
['--re-execed', GetoptLong::NO_ARGUMENT],
['--proxy', GetoptLong::OPTIONAL_ARGUMENT],
['--user', GetoptLong::OPTIONAL_ARGUMENT],
['--pass', GetoptLong::OPTIONAL_ARGUMENT],
['-v', '--version', GetoptLong::OPTIONAL_ARGUMENT]
)
opts.each do |opt, args|
Expand All @@ -330,6 +337,14 @@ EOF
if (args != '')
@http_proxy = args
end
when '--user'
if (args != '')
@proxy_user = args
end
when '--pass'
if (args != '')
@proxy_pass = args
end
when '-v' || '--version'
@target_version_arg = args
end
Expand Down Expand Up @@ -439,8 +454,15 @@ EOF
retries ||= 0
exceptions = [OpenURI::HTTPError, OpenSSL::SSL::SSLError]
begin
uri.open(:ssl_verify_mode => OpenSSL::SSL::VERIFY_PEER, :redirect => true, :read_timeout => 120, :proxy => @http_proxy) do |s3|
package_file.write(s3.read)
if @proxy_user == nil
uri.open(:ssl_verify_mode => OpenSSL::SSL::VERIFY_PEER, :redirect => true, :read_timeout => 120, :proxy => @http_proxy) do |s3|
package_file.write(s3.read)
end
else
proxy_uri=URI.parse(@http_proxy)
uri.open(:ssl_verify_mode => OpenSSL::SSL::VERIFY_PEER, :redirect => true, :read_timeout => 120, :proxy_http_basic_authentication => [proxy_uri, @proxy_user, @proxy_pass]) do |s3|
package_file.write(s3.read)
end
end
rescue *exceptions => e
@log.warn("Could not find package to download at '#{uri.to_s}' - Retrying... Attempt: '#{retries.to_s}'")
Expand All @@ -465,8 +487,12 @@ EOF
exceptions = [OpenURI::HTTPError, OpenSSL::SSL::SSLError, Errno::ETIMEDOUT]
begin
require 'json'

version_string = uri.read(:ssl_verify_mode => OpenSSL::SSL::VERIFY_PEER, :redirect => true, :read_timeout => 120, :proxy => @http_proxy)
if @proxy_user == nil
version_string = uri.read(:ssl_verify_mode => OpenSSL::SSL::VERIFY_PEER, :redirect => true, :read_timeout => 120, :proxy => @http_proxy)
else
proxy_uri=URI.parse(@http_proxy)
version_string = uri.read(:ssl_verify_mode => OpenSSL::SSL::VERIFY_PEER, :redirect => true, :read_timeout => 120, :proxy_http_basic_authentication => [proxy_uri, @proxy_user, @proxy_pass])
end
JSON.parse(version_string)
rescue *exceptions => e
@log.warn("Could not find version file to download at '#{uri.to_s}' - Retrying... Attempt: '#{retries.to_s}'")
Expand Down