Skip to content

Surface crate security information in the UI #6397

Open
@LawnGnome

Description

@LawnGnome

Background

As part of the Rust Foundation's security initiative, we'd like to surface information related to crate security more prominently within crates.io. Our initial focus is on supply chain security, so surfacing information relevant to provenance is key, but we would also like to rapidly start surfacing information relevant to the security of individual crate versions as well.

Items below that are related to open questions are linked and italicised.

tl;dr executive summary

We would like to add a new tab to the crate1 page that surfaces security information relevant to the crate in an easy to digest form. In the initial version, this will include two things: the result of any checks run on the crate (the most recent version, in the case of the unversioned crate version), and — if present — the security policy in the SECURITY.md2 file in the repo.

The initial check that would be added is almost certainly a provenance check3, with other checks4 based on static analysis of the repository and code to be added in short order.

Pictures

These are static mockups for now, although I'm going to wire up a prototype PR Real Soon Now™5 to better explore this space.

(Obligatory disclaimer: I am not, nor do I pretend to be, a designer. I intend to iterate further on this; this is mostly just to show the shape of what I'm thinking, rather than the specifics of the design around typography, spacing, colours, etc.)

Crate nav bar

The styling is probably too dramatic, particularly in the failed check case, but you get the general idea. (And the "icons" are just Unicode right now, but would probably be replaced with a more appropriate SVG in due course.)

pass-bar
fail-bar

Security tab

I used ChatGPT to create a "plausible sounding security policy" for this screenshot. All errors are therefore… uh, someone else's. Promise.

(And, yes, the padding appears to be off just because of how Firefox chose to screenshot the relevant element.)

success-security
fail-security

Security policies

We would discover the security policy using the same general heuristics as GitHub uses, with one addition to handle repositories with multiple crates:

  1. Is there a SECURITY.md file at the same level as Cargo.toml?
  2. Is there a file at the repository root?
  3. Is there a file in docs (relative to the repository root)?
  4. Is there a file in .github (relative to the repository root)?

This will obviously require Cargo assistance for anything beyond the first point, since theose files may not be in the .crate tarball.

We may also want to add a new Cargo.toml field, similar to the existing readme field.

Checks

The idea here is much like general CI checks in GitHub, GitLab, or your favourite code host. Each check will represent a single pass/fail/skipped check for a specific crate version, with some level of content shown in the UI to indicate the result in more detail and contextualise what the check is actually showing.

As mentioned above, the initial check this would roll out with would be a provenance check for the source code in the crate tarball.

It is anticipated that the initial work here would only involve checks run on a global basis. These checks would be facilitated (and, initially, developed) by the Rust Foundation in conjunction with the crates.io team. Over time, I expect this would open up to allow other collaborators within the Rust ecosystem to propose and implement other checks that make sense within the ecosystem.

It is also possible in the future that these checks may feed into a quarantine system where crates that fail key, high fidelity security checks require human review before being published. That is not in the scope of this proposal, however.

An open question here is whether crate authors should be able to define their own, crate-specific checks.

Operation

Without going into great detail just yet on the schema or API calls, here's how I anticipate this would work:

  1. crates.io can be configured with a webhook6 that is invoked when a crate version is published.
  2. On publish, the webhook would be invoked with the crate version metadata and a URL including a one time shared secret that can be used to report check results back.
  3. Each check started would then:
    1. Report that it has started.
    2. Report success, failure, or skipped with a structured blob7 that also includes relevant data for the UI to display, describing the result and what the check actually checked.

Open questions

Should we allow crate authors to include their own checks?

As discussed in the checks section, an additional possibility here would be to allow crate authors to define crate-specific checks they want to run when their crate is published, and then surface those results alongside the security checks that are run over all published crates.

What does this tab look like?

"Security" would be the obvious label, but if we allow non-security checks as well, then either a more generic name or two tabs might make more sense.

How do we discover the security policy?

I think the heuristic in the security policies section is probably uncontroversial.

Whether we should add a new Cargo.toml field is a different question.8 Because this is a relatively new "standard" from GitHub, there isn't really the diversity of possible locations that there is with READMEs — we can reasonably assume the file will be called SECURITY.md, and that it will be in Markdown format. However, I do wonder if there are organisations that would prefer to link out to a single security policy, rather than adding it to each repository.

My gut feeling is that a new field may make sense, but only if it also allows for URLs to be specified, with some sort of handling in the crates.io UI to then provide a useful looking link (presumably augmented with Open Graph metadata where available). Whether this is better than simply having a SECURITY.md in the repository that points to the external policy is unclear to me.

We need you!

Nothing in here is set in stone, or closed to discussion. I genuinely want your feedback!

Ideally, I'd like to have feedback in within the next couple of weeks (so by early-to-mid May) — I intend to do some prototyping work in parallel with the feedback session to continue to explore this space, but obviously no concrete decisions will be made until after that. I'm also more focused on the admin console work in #6353, since that's a higher priority for me right now, so there isn't a tonne of urgency on this just at the moment.

Nevertheless, I would love to hear from you!

Footnotes

  1. For simplicity, I'm mostly talking in terms of crates in the UI, but I'm aware that this will also extend to crate version specific routes. Consider "crate" shorthand for both unless there's an explicit callout that something's different on a version route.

  2. This is a GitHub initiative, announced back in 2019, to make it easier for authors to provide security policies for their projects in a standard place.

  3. Or, put in plain English, does the content of the .crate file match what was tagged in the source repository?

  4. This is a significant focus area for @walterhpearce in the near term, so I would expect the initial batch of follow up checks would likely come from the Foundation.

  5. I'm also working on Prototype admin console #6353 simultaneously, and that's higher priority, so take this more as an expression of intention than a rock solid commitment.

  6. Initially, I expect this will invoke a service or lambda in Rust Foundation managed infrastructure than can then fan out to whatever checks are available.

  7. There's complexity that we definitely don't need to reproduce here, but a cut down version of the output field in GitHub check results is probably pretty close to what I'm thinking.

  8. My thanks to @epage for pointing this out.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancement ✨Category: Adding new behavior or a change to the way an existing feature works

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions