Skip to content

Make cpanm install more secure #40

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

Closed
wants to merge 3 commits into from
Closed

Conversation

zakame
Copy link
Member

@zakame zakame commented Aug 16, 2017

Use a local known-good fatpacked copy of cpanm and install it instead of
fetching it from GitHub.

Fixes #39.

zakame added 3 commits August 16, 2017 16:33
Have a known-good local fatpacked copy of cpanm from
https://github.com/miyagawa/cpanminus.  Pin at version 1.7043.
Instead of fetching cpanm from GitHub, copy our local fatpacked cpanm
into the context directory of each Perl image, so it can be installed
into /usr/local/bin.
Looks a bit ugly copying cpanm in so many times, but due to the way
Docker Hub works, it can't be helped...
@tianon
Copy link
Contributor

tianon commented Aug 16, 2017

Why not instead just replace master with a known-good commit or release tag?

@zakame
Copy link
Member Author

zakame commented Aug 16, 2017

That can work too, although if I read #39 correctly it was concern about the repo (or even github itself) being compromised at the time of image build. I'd go the commit/tag route myself if it were GPG-signed (or there's some other way to externally verify the authenticity; perhaps an alternate might be to fetch from CPAN instead of GitHub, via plain cpan.)

I'm not too keen on this PR itself since we make copies of cpanm, so alternatives are very much welcome!

@tianon
Copy link
Contributor

tianon commented Aug 16, 2017 via email

@zakame
Copy link
Member Author

zakame commented Aug 16, 2017

I checked CPAN, it provides a CHECKSUMS file per author that contains SHA256 for the dists, so e.g. for App-cpanminus-1.7043:

  'App-cpanminus-1.7043.tar.gz' => {
    'md5' => '067e668f287c27c96cd392cf39b7ea56',
    'md5-ungz' => '109cce105cb1eb3c4b66b348aefa25e1',
    'mtime' => '2017-04-03',
    'sha256' => '68a06f7da80882a95bc02c92c7ee305846fb6ab648cf83678ea945e44ad65c65',
    'sha256-ungz' => 'c70be8763f1322b6023435cade5bf22d26120165003f65ba089556c412cb1b89',
    'size' => 317984
  },

Normal cpan uses this for verification:

# cpan install App::cpanminus
cpan install App::cpanminus
Loading internal null logger. Install Log::Log4perl for logging messages
Fetching with HTTP::Tiny:
http://www.cpan.org/authors/01mailrc.txt.gz
Reading '/root/.cpan/sources/authors/01mailrc.txt.gz'
............................................................................DONE
Fetching with HTTP::Tiny:
http://www.cpan.org/modules/02packages.details.txt.gz
Reading '/root/.cpan/sources/modules/02packages.details.txt.gz'
  Database was generated on Wed, 16 Aug 2017 11:41:02 GMT
  HTTP::Date not available
............................................................................DONE
Fetching with HTTP::Tiny:
http://www.cpan.org/modules/03modlist.data.gz
Reading '/root/.cpan/sources/modules/03modlist.data.gz'
DONE
Writing /root/.cpan/Metadata
Running install for module 'App::cpanminus'
Fetching with HTTP::Tiny:
http://www.cpan.org/authors/id/M/MI/MIYAGAWA/App-cpanminus-1.7043.tar.gz
Fetching with HTTP::Tiny:
http://www.cpan.org/authors/id/M/MI/MIYAGAWA/CHECKSUMS
Checksum for /root/.cpan/sources/authors/id/M/MI/MIYAGAWA/App-cpanminus-1.7043.tar.gz ok
'YAML' not installed, will not store persistent state
Configuring M/MI/MIYAGAWA/App-cpanminus-1.7043.tar.gz with Makefile.PL
Checking if your kit is complete...
Looks good
Generating a Unix-style Makefile
Writing Makefile for App::cpanminus
Writing MYMETA.yml and MYMETA.json
  MIYAGAWA/App-cpanminus-1.7043.tar.gz
  /usr/local/bin/perl Makefile.PL -- OK
Running make for M/MI/MIYAGAWA/App-cpanminus-1.7043.tar.gz
cp lib/App/cpanminus.pm blib/lib/App/cpanminus.pm
cp lib/App/cpanminus/fatscript.pm blib/lib/App/cpanminus/fatscript.pm
cp bin/cpanm blib/script/cpanm
"/usr/local/bin/perl" -MExtUtils::MY -e 'MY->fixin(shift)' -- blib/script/cpanm
  MIYAGAWA/App-cpanminus-1.7043.tar.gz
  /usr/bin/make -- OK
Running make test
PERL_DL_NONLAZY=1 "/usr/local/bin/perl" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/happy_cpantesters.t .. 1/1 # App::cpanminus/1.7043
t/happy_cpantesters.t .. ok
All tests successful.
Files=1, Tests=1,  0 wallclock secs ( 0.02 usr  0.01 sys +  0.04 cusr  0.00 csys =  0.07 CPU)
Result: PASS
  MIYAGAWA/App-cpanminus-1.7043.tar.gz
  /usr/bin/make test -- OK
Running make install
Installing /usr/local/lib/perl5/site_perl/5.26.0/App/cpanminus.pm
Installing /usr/local/lib/perl5/site_perl/5.26.0/App/cpanminus/fatscript.pm
Installing /usr/local/bin/cpanm
Appending installation info to /usr/local/lib/perl5/5.26.0/x86_64-linux/perllocal.pod
  MIYAGAWA/App-cpanminus-1.7043.tar.gz
  /usr/bin/make install  -- OK

While it would seem we can certainly use cpan, I'll also try embedding SHA256 of cpanm@1.7043. Thanks!

@tianon
Copy link
Contributor

tianon commented Aug 16, 2017 via email

@zakame
Copy link
Member Author

zakame commented Aug 16, 2017

Yeah, it is a bit of a bother to checksum against the dist then unpack and install, but it is doable.

I'll whip up another PR. Thanks!

@zakame
Copy link
Member Author

zakame commented Aug 19, 2017

Now unneeded since #41 is merged. Thanks!

@zakame zakame closed this Aug 19, 2017
@zakame zakame deleted the secure-cpanminus branch August 19, 2017 11:26
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.

2 participants