(#4913) apt_key now does not always send auth basic
authorStefan Andres <s.andres@syseleven.de>
Mon, 15 May 2017 08:21:50 +0000 (10:21 +0200)
committerStefan Andres <s.andres@syseleven.de>
Mon, 15 May 2017 08:21:50 +0000 (10:21 +0200)
Prior to this commit, apt_key always sent auth basic header when source
came from http(s). This might fail for some webservers (e.g. Amazon S3)
when empty auth basic is sent.

Now apt_key only sends the auth basic header when userinfo can
be parsed from the URL.

lib/puppet/provider/apt_key/apt_key.rb

index d7e85dafaf5a1e6ab762153f137394a49cc52d47..668fd0f18d2ee35c0addb98e1bd365956d7f2a11 100644 (file)
@@ -127,9 +127,15 @@ Puppet::Type.type(:apt_key).provide(:apt_key) do
       f
     else
       begin
-        user_pass = parsedValue.userinfo.nil? ? nil : parsedValue.userinfo.split(':')
-        parsedValue.userinfo = ''
-        key = open(parsedValue, :http_basic_authentication => user_pass).read
+        # Only send basic auth if URL contains userinfo
+        # Some webservers (e.g. Amazon S3) return code 400 if empty basic auth is sent
+        if parsedValue.userinfo.nil?
+          key = parsedValue.read
+        else
+          user_pass = parsedValue.userinfo.split(':')
+          parsedValue.userinfo = ''
+          key = open(parsedValue, :http_basic_authentication => user_pass).read
+        end
       rescue OpenURI::HTTPError, Net::FTPPermError => e
         fail("#{e.message} for #{resource[:source]}")
       rescue SocketError