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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

(PUP-6114) Adds new HTTP headers for checksum validation. #5707

Closed

Conversation

petems
Copy link
Contributor

@petems petems commented Mar 13, 2017

  • This is primarily for the support of the artifactory HTTP headers for
    checksum validation. However, other headers could be configured in
    defaults for other providers

Resurrecting #4828, looking to implement the ideas from @MikaelSmith's previous comment:

These [artifactory headers] are non-standard, and could potentially be used for a different purpose on other websites. As such, I'm not comfortable hard-coding these headers as fallbacks.

However, this could be done as settings that can be configured in puppet.conf. See https://github.com/puppetlabs/puppet/blob/master/lib/puppet/defaults.rb#L825-L839 for an example of a setting that takes an array. My suggestion would be to introduce 3 settings - one each for custom md5, sha1, and sha256 headers - that can be an array of possible headers. Then #initialize would iterate through them to look for a valid checksum.

Might need some help on the defaults bit 馃槃

* This is primarily for the support of the artifactory HTTP headers for 
checksum validation. However, other headers could be configured in 
defaults for other providers
@puppetcla
Copy link

CLA signed by all contributors.

@@ -20,7 +20,21 @@ def initialize(http_response, path = '/dev/null')
checksum = checksum.unpack("m0").first.unpack("H*").first
@checksums[:md5] = "{md5}#{checksum}"
end
# Add support for artifactory headers.
# This adds support for all three algorithms, sha256, sha1, and md5.
if checksum = http_response['X-Checksum-Md5']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does artifactory require this specific header format? I'd be slightly more warm and fuzzy if we didn't have to insert a different header for every checksum type we support.

Also, I'm curious; what exactly are you doing with artifactory interfacing with the Puppet http file metadata endpoint?

Copy link
Contributor

@Iristyle Iristyle Mar 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't seen the X-Checksum-MD5 header before - usually I've seen this done via ETag header, but I don't think the HTTP spec says that ETag must be MD5, hence the need for an X style extension here it looks like.

I think these are mutually exclusive though, correct? We can only serve one... which defaults to MD5 / is optionally configurable as SHA2 instead - see https://github.com/puppetlabs/puppet/blob/master/lib/puppet/defaults.rb#L867-L887

This code doesn't quite look right to me...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why doesn't it look right? The file resource type can specify which checksum to use. However, this metadata endpoint has no knowledge of what's expected from the file type, so just appends everything.

@mafgh
Copy link

mafgh commented Mar 20, 2017

Regarding

However, this could be done as settings that can be configured in puppet.conf.

Something along those lines?

default.rb:

  define_settings(:agent,                                  
    :checksum_header_md5 => { 
        :default => [ 'X-Checksum-Md5' ],
        :type    => :array,    
        :desc    => 'fixme',
    },
    :checksum_header_sha256 => {
        :default => [ 'X-Checksum-Sha256' ],   
        :type    => :array,                                                        
        :desc    => 'fixme',                                                       
    },                                      

http_metadata.rb:

  Puppet.settings[:checksum_header_md5].each do |header|                         
     if checksum = http_response[header]
       Puppet.debug {"Using md5 header '#{header}'"} 
       @checksums[:md5] = "{md5}#{checksum}"
       break
     end
   end 
   
   Puppet.settings[:checksum_header_sha256].each do |header|
     if checksum = http_response[header]
       Puppet.debug {"Using sha256 header '#{header}'"}
       @checksums[:sha256] = "{sha256}#{checksum}"
       break
     end
   end 

@MikaelSmith
Copy link
Contributor

MikaelSmith commented Mar 20, 2017

Yes, that would work. I don't think it's a very good idea though, since it would apply to all HTTP requests (and different sites could use different headers). I guess an alternative would be to have a new parameter for the file type that lets you set that for a particular resource.

Update: On thinking about this more, my original settings description does seem to make some sense. And @mafgh's description looks about right.

@joshcooper joshcooper added Agent and removed Agent labels Mar 21, 2017
@mafgh
Copy link

mafgh commented May 17, 2017

@petems do you still need help with the "defaults bit"?

@petems
Copy link
Contributor Author

petems commented May 17, 2017

To be honest I don't have the bandwidth to complete this right now 馃槩

I'll close for now, if anyone wants to pick it up, possibly at #puppethack, then go for it! 馃槃

@petems petems closed this May 17, 2017
@tek0011
Copy link

tek0011 commented Aug 6, 2018

Would love to see this implemented. Multiple vendors of our use artifactory for shares, chocolatey, builds, etc. We recently ran into a big headache where we realized files were not md5 checking, using artifactory and its X-CheckSum-xxx. As a side note, it also seems that mtime is also way off on numerous files vs. the artifactory (remote) mtime. Without this update, I will have to move all file resources that use artifactory, to a file uri. Which means having to move these to more of a file share type system.

joshcooper added a commit to joshcooper/puppet that referenced this pull request Jun 16, 2020
Artifactory generates X-Checksum-{Md5,Sha1,Sha256} headers, so parse them from
the HTTP response, if present, when determining the remote checksum.

There is a draft RFC for Want-Digest and Digest headers, but it's not
finalized yet: https://tools.ietf.org/html/draft-ietf-httpbis-digest-headers

This commit also sets the header fields on the response instead of stubbing
methods.

This is based on PR puppetlabs#5707 from

    Author: Dylan Cochran <heliocentric@gmail.com>
    Commit: Peter Souter <peter.souter+GIT@puppet.com>
joshcooper added a commit to joshcooper/puppet that referenced this pull request Jun 17, 2020
Artifactory generates X-Checksum-{Md5,Sha1,Sha256} headers, so parse them from
the HTTP response to determine the remote checksum. Note we parse all of the
checksum headers, but use the first header based on the order given in the
`collect` method.

This commit is taken from PR puppetlabs#5707.

There is a draft RFC for Want-Digest and Digest headers, but it's not finalized
yet: https://tools.ietf.org/html/draft-ietf-httpbis-digest-headers. At some
point, we'll probably want to support that.

Co-Author: Dylan Cochran <heliocentric@gmail.com>
joshcooper added a commit to joshcooper/puppet that referenced this pull request Jun 17, 2020
Artifactory generates X-Checksum-{Md5,Sha1,Sha256} headers, so parse them from
the HTTP response to determine the remote checksum. Note we parse all of the
checksum headers, but use the first header based on the order given in the
`collect` method.

This commit is taken from PR puppetlabs#5707.

There is a draft RFC for Want-Digest and Digest headers, but it's not finalized
yet: https://tools.ietf.org/html/draft-ietf-httpbis-digest-headers. At some
point, we'll probably want to support that.

Co-Author: Dylan Cochran <heliocentric@gmail.com>
joshcooper added a commit to joshcooper/puppet that referenced this pull request Jun 18, 2020
Artifactory generates X-Checksum-{Md5,Sha1,Sha256} headers, so parse them from
the HTTP response to determine the remote checksum. Note we parse all of the
checksum headers, but use the first header based on the order given in the
`collect` method.

This commit is taken from PR puppetlabs#5707.

There is a draft RFC for Want-Digest and Digest headers, but it's not finalized
yet: https://tools.ietf.org/html/draft-ietf-httpbis-digest-headers. At some
point, we'll probably want to support that.

Co-Author: Dylan Cochran <heliocentric@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants