Skip to content

End-to-end integrity of crates in registries #4768

@withoutboats

Description

@withoutboats

I have been working on a proposal which would add a feature to cargo to make registries trust free - that is, to verify the integrity and authenticity of crates downloaded from a registry like crates.io even if crates.io were compromised.

I don't have an RFC yet, but I have a sketch & I thought I'd post it here. In brief, we automatically sign crates on publication and verify the signature on download.

First, we need a concept of a source of truth about user identities to cargo. For crates.io, the current source of truth is GitHub (crates.io does not manage its own authentication). Such a source of truth needs to have a feature which allows users to publish a public key that can be used to verify their signature. GitHub today allows users to publish GPG keys to verify their commits (though we don't need to actually use GPG, just format our public keys according to the OpenPGP spec - I wrote a crate to do this already for ed25519 keys).

We adjust the cargo login flow to generate a new key pair and publish the public key to GitHub - this happens entirely client side, crates.io never gains permission to publish GPG keys. The private key is saved in the user's .cargo directory, and used to sign crates published from this machine. Key revokation is done by deleting the key from GitHub.

In the registry, we additionally track the signature and the means to identify the public key (in this case, the info needed to request it from GitHub). When downloading crates, we verify the signature in the registry. We display to the user (published by GitHub user @withoutboats) or something similar, providing them the guarantee that this user did actually publish this data, and the data has not been modified since.

Critically, the registry plays no role in distributing public keys. Though I've so far discussed this in terms of distributing them through GitHub, the system can be flexible to allow additional sources of identity in the future, which would display different information.

Why not TUF?

  1. TUF was not designed with an external authority about identity in mind, and so it involves the registry managing the ultimate source of truth for identities (the master key). We already delegate responsibility for managing user identity to a third party (GitHub).
  2. TUF is opt-in, and has a high cost for opting in. Most users would probably not opt in.

In other words, adopting TUF would not provide much security for most users. All security would still depend on our security practices (in managing the master key), and only a small handful of crates would even see the gains.

The high opt-in cost has its own advantages: only users who are serious about key management would be likely to do it. However, users already have to trust the security practices of the authors of crates they depend on, and there's not really a way to avoid that.

Future extensions

Beyond the basic proposal I've sketched out, there are many ways the security of this system could be improved further:

  1. We could adopt threshold signatures from TUF for crates with multiple owners, providing a higher degree of security (this would require a significant UX revamp).
  2. We could adopt a trust-on-first-use system for ownership, to help catch e.g. withoutboots publishing a crate that actually belongs to withoutboats (there are some serious challenges I haven't worked out here about backwards compatibility and our github teams feature).
  3. We could add options to require signatures and refuse to build crates without them, influencing resolution.

cc @rust-lang/cargo.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-registriesArea: registriesA-securityArea: securityS-needs-rfcStatus: Needs an RFC to make progress.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions