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

feat: use trusted publishing to adapt UI #14657

Merged
merged 3 commits into from
Oct 10, 2023
Merged

Conversation

miketheman
Copy link
Member

@miketheman miketheman commented Sep 29, 2023

Projects using Trusted Publishing from GitHub have a strong attestation that the repo is the one they came from.

Using the metadata we have from the upload events, we can determine how the file got there, and bubble that up to the Release to control some aspects of the UI.
We could also display something in the Download Files if we wanted to.

Wrapping the sidebar statistics with the HTML <details> accomplishes preserving the sidebar metadata for projects, but making it more prominent for those using a Trusted Publishing workflow.

Refs: StarJacking
Addresses #8462 (partially) and probably replaces #10917

@miketheman miketheman added HTML requires change to HTML files admin Features needed for the Admin UI (people running the site) trusted-publishing labels Sep 29, 2023
@miketheman miketheman requested a review from a team as a code owner September 29, 2023 19:28
@miketheman
Copy link
Member Author

miketheman commented Sep 29, 2023

Looks a little something like this: Removed from PR scope.

Screen.Recording.2023-09-29.at.15.29.23.mov

A Release can be considered published via a trusted publisher if
**all** the Files in the release are published via a trusted publisher.
"""
files = self.files.all() # type: ignore[attr-defined]
Copy link
Member Author

Choose a reason for hiding this comment

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

Since self.files returns an AppenderQuery, it returns True until we resolve the query by fetching the rows. If there's a better way to do this, I'm all ears!

@di di self-requested a review October 1, 2023 17:12
@@ -603,6 +603,17 @@ def has_meta(self):
]
)

@property
def trusted_published(self) -> bool:
Copy link
Member Author

Choose a reason for hiding this comment

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

Thought: If this is too cumbersome a query pattern, we could explore creating a database trigger to update the Release's value on upload.

@miketheman miketheman requested a review from dstufft October 6, 2023 15:31
@@ -69,6 +70,7 @@ <h3 class="sidebar-section__title">{% trans %}Statistics{% endtrans %}</h3>
</li>
</ul>
</div>
{% if not release.trusted_published %}</details>{% endif %}
Copy link
Member

Choose a reason for hiding this comment

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

I think this is probably not worth doing this way, for a few reasons, and we should Do It Right™ instead.

As-is, we're not actually checking that the URL used for getting repo statistics is the same as the URL used for trusted publishing, so this can be subverted easily by using trusted publishing for something that is attempting to do "starjacking".

Additionally, it also doesn't indicate to the user or maintainer why sometimes statistics are hidden, and why sometimes they are not, which will make a more confusing UI.

I think we should remove this from the PR for now, with the plan to eventually replace it with a new statistics sidebar that does the following:

  • if trusted publishing from GitHub has been used for the release:
  • if trusted publishing was not used, and a GitHub URL was provided in the metadata (e.g., we would currently show statistics):
    • don't fetch the statistics
    • instead, include a message + provide a link that indicates that trusted publishing should be used to enable GitHub statistics

Copy link
Member Author

Choose a reason for hiding this comment

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

@di Thanks for the feedback!

I've gone ahead and removed this change from scope so we can ship the other enhancements in the meantime.

I'll move the rest of the notes to a new issue so we can discuss the stats sidebar.

@miketheman miketheman removed the HTML requires change to HTML files label Oct 10, 2023
@miketheman miketheman requested a review from di October 10, 2023 15:28
@miketheman miketheman merged commit 1801d36 into pypi:main Oct 10, 2023
@miketheman miketheman deleted the miketheman/tp branch October 10, 2023 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
admin Features needed for the Admin UI (people running the site) trusted-publishing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants