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

Handle signed narinfo files #75

Closed
shlevy opened this issue Dec 14, 2012 · 11 comments
Closed

Handle signed narinfo files #75

shlevy opened this issue Dec 14, 2012 · 11 comments
Labels
feature Feature request or proposal

Comments

@shlevy
Copy link
Member

shlevy commented Dec 14, 2012

The binary cache substituter should be able to verify signed .narinfo files (and ensure that the downloaded .nar file matches the hash in the .narinfo file). This will help prevent MITM attacks and allow non-root users to use binary caches whose public keys have been trusted by root.

edolstra added a commit that referenced this issue Jan 8, 2014
NAR info files in binary caches can now have a cryptographic signature
that Nix will verify before using the corresponding NAR file.

To create a private/public key pair for signing and verifying a binary
cache, do:

  $ openssl genrsa -out ./cache-key.sec 2048
  $ openssl rsa -in ./cache-key.sec -pubout > ./cache-key.pub

You should also come up with a symbolic name for the key, such as
"cache.example.org-1".  This will be used by clients to look up the
public key.  (It's a good idea to number keys, in case you ever need
to revoke/replace one.)

To create a binary cache signed with the private key:

  $ nix-push --dest /path/to/binary-cache --key ./cache-key.sec --key-name cache.example.org-1

The public key (cache-key.pub) should be distributed to the clients.
They should have a nix.conf should contain something like:

  signed-binary-caches = *
  binary-cache-public-key-cache.example.org-1 = /path/to/cache-key.pub

If all works well, then if Nix fetches something from the signed
binary cache, you will see a message like:

  *** Downloading ‘http://cache.example.org/nar/7dppcj5sc1nda7l54rjc0g5l1hamj09j-subversion-1.7.11’ (signed by ‘cache.example.org-1’) to ‘/nix/store/7dppcj5sc1nda7l54rjc0g5l1hamj09j-subversion-1.7.11’...

On the other hand, if the signature is wrong, you get a message like

  NAR info file `http://cache.example.org/7dppcj5sc1nda7l54rjc0g5l1hamj09j.narinfo' has an invalid signature; ignoring

Signatures are implemented as a single line appended to the NAR info
file, which looks like this:

  Signature: 1;cache.example.org-1;HQ9Xzyanq9iV...muQ==

Thus the signature has 3 fields: a version (currently "1"), the ID of
key, and the base64-encoded signature of the SHA-256 hash of the
contents of the NAR info file up to but not including the Signature
line.

Issue #75.
@vcunat
Copy link
Member

vcunat commented Mar 15, 2014

What about starting to use this feature by default? Can Hydra produce signed caches?

@domenkozar
Copy link
Member

@edolstra this is fixed, right?

@wmertens
Copy link
Contributor

...and does Hydra have a key? Shouldn't we distribute that key with the default nix install?

@edolstra
Copy link
Member

Hydra does provide a signed binary cache, but I'm not sure we should include the key in Nix because we don't really want to encourage people using Hydra's binary cache instead of cache.nixos.org.

Cache.nixos.org is not currently signed, though.

@wmertens
Copy link
Contributor

Indeed. So what would it take to sign cache.nixos.org? I'm actually
surprised that the build products aren't the same? Are they not copies from
Hydra? I'm probably missing a piece in the Hydra->cache.nixos.org workflow.

On Thu Jan 22 2015 at 3:04:58 PM Eelco Dolstra [email protected]
wrote:

Hydra does provide a signed binary cache, but I'm not sure we should
include the key in Nix because we don't really want to encourage people
using Hydra's binary cache instead of cache.nixos.org.

Cache.nixos.org is not currently signed, though.


Reply to this email directly or view it on GitHub
#75 (comment).

@edolstra
Copy link
Member

Yes, they're copied from Hydra, but the signatures are not copied.

Signing cache.nixos.org wouldn't be hard but it would require signing all NARs that are already there (which is quite a lot).

@vcunat
Copy link
Member

vcunat commented Jan 22, 2015

Oh, I thought each NAR would have its own signature. Signatures should be small enough to afford that, well under a kilobyte IMHO.

@edolstra
Copy link
Member

@vcunat It's actually the .narinfo files tar contain a signature:

$ curl http://hydra.nixos.org/la5imi1602jxhpds9675n2n2d0683lbq.narinfo
StorePath: /nix/store/la5imi1602jxhpds9675n2n2d0683lbq-glibc-2.20
URL: nar/la5imi1602jxhpds9675n2n2d0683lbq-glibc-2.20
Compression: bzip2
NarHash: sha256:1s536x07qfv6xzby6vc46h0lw207kfmllsyswa9d38h4ix3l429h
NarSize: 32411536
References: la5imi1602jxhpds9675n2n2d0683lbq-glibc-2.20 qwwxgsg6l33lhx0v75mgmb077qggh8yl-linux-headers-3.12.32
Deriver: acim6v6lskfyjxjw0gg8dk7mh6vx76yj-glibc-2.20.drv
System: x86_64-linux
Signature: 1;hydra.nixos.org-1;pTmO8ckMiKCUcxMAS5Qdd8Vly9CBnEm3J6ie1sP3HvqmWoYA0znlSJDeU19WXuLk/h8X1nlVk4vhLdVxBmgepSMPJoqbjPuEZoE4GvKeB/ZIB+RkSDZLV1n+Wrn4KZ81XN/oRxho8Po+rbO2qijs4YZXuW4eZP4WKy67JH2/Uj81hez0Yq5HXppJkgGAUEEkBl4v/dq9mvd9s0pxWijm5gy+E4YOG5bayYoPegBGpcNRMOzYPHhe3I/hJKGw8vhSExtNzQiJ0Hc0LjRR3Pnwmaiy5QXF8dHBjmD+RHsEAE8sE8TUBzwFKrjqFlC7oZaT2Lm/fUr5sSR1oSHogB0qTw==

@vcunat
Copy link
Member

vcunat commented Jan 22, 2015

Why not start copying those *.narinfo with signatures just for NARs that are newly copied to the cache?

BTW, I wonder... cache.nixos.org has a different NarHash for this same narinfo. (There's a different compression, but docs say it's supposed to be hash of uncompressed NAR.) I guess it's some non-determinism/impurity, still even in glibc.

@edolstra
Copy link
Member

cache.nixos.org uses base-16 in the NarHash field rather than base-32, but the actual hash is the same.

@edolstra
Copy link
Member

edolstra commented Jun 4, 2015

All of cache.nixos.org is signed now.

@edolstra edolstra closed this as completed Jun 4, 2015
zolodev pushed a commit to zolodev/nix that referenced this issue Jan 1, 2024
Continuous Integration with GitHub Actions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Feature request or proposal
Projects
None yet
Development

No branches or pull requests

5 participants