Skip to content

WIP: Prepare for the deployment onto Sonatype Nexus - #187

Merged
cpovirk merged 3 commits into
mainfrom
deploy-with-gpg
Jul 9, 2021
Merged

cpovirk merged 3 commits into
mainfrom
deploy-with-gpg

Conversation

@KengoTODA

Copy link
Copy Markdown
Collaborator
  1. sign files to meet a requirement from Sonatype
  2. deploy to Sonatype Nexus and close its staging repository automatic by io.github.gradle-nexus.publish-plugin

@KengoTODA KengoTODA self-assigned this Jun 9, 2021
@google-cla google-cla Bot added the cla: yes See https://cla.developers.google.com/ label Jun 9, 2021
@KengoTODA

Copy link
Copy Markdown
Collaborator Author

@cpovirk Are you familiar with GitHub Secrets?
I want to ask you or other admin of this GitHub repo, to:

  1. Generate pgp keys with passphrase,
  2. Export ascii-armored key by gpg --armor --export-secret-keys <EMAIL>,
  3. Set exported key to PGP_ARMORED_PRIVATE_KEY GitHub Secrets variable,
  4. Set passphrase to PGP_PASS_PHREASE GitHub Secrets variable, and
  5. Rerun the build in this PR

If everything works well, we'll see that the artifact is signed with gpg automatically.

Note that this PR contains nothing that enables deployment to Sonatype Nexus at this moment.
To enable it, we need to run the publish task in the build.

@cpovirk

cpovirk commented Jun 11, 2021

Copy link
Copy Markdown
Collaborator

Thanks! I didn't get a chance to do that today, but I will get to it next week.

@cpovirk

cpovirk commented Jun 22, 2021

Copy link
Copy Markdown
Collaborator

I'm sorry for not getting to this last week. I finally looked at it earlier today.

While I haven't found a direct statement from our security people about this, I have read enough that I'm nervous about uploading the PGP key because of the possibility of a GitHub compromise or other incident. Is it possible to skip signing for snapshot releases? If Sonatype requires signing even for snapshot releases, we could skip snapshots entirely: Our annotations change infrequently, so we can afford to manually push new releases after any major change. And for the final release, I assume we can run the build manually and enter the passphrase when required?

@cpovirk

cpovirk commented Jun 22, 2021

Copy link
Copy Markdown
Collaborator

(It looks like the build script already skips signing if the key is unavailable, so maybe all we'd need is a way to prompt for the passphrase during a release to Central?)

@KengoTODA

Copy link
Copy Markdown
Collaborator Author

Is it possible to skip signing for snapshot releases?

I think it's not possible.

I've checked several snapshots at https://s01.oss.sonatype.org/content/repositories/snapshots/ and found that they has .asc file in their release. It means that other OSSRH users sign their artifacts before they deploy SNAPSHOT version.

@KengoTODA

Copy link
Copy Markdown
Collaborator Author

(It looks like the build script already skips signing if the key is unavailable, so maybe all we'd need is a way to prompt for the passphrase during a release to Central?)

No.

What we need to release to Central (via Sonatype Nexus) is just Sonatype user name and password.
But even though the passphrase is needless at that timing, the artifact needs to be signed before the release process.
So we surely need passphrase to make a release.

So if we don't want to upload the GPG key to GitHub Secrets, we need to handle release procedure manually in your local.

I personally don't prefer this way, because it limits who can release and maintain the project. SpotBugs team forked FindBugs because the owner was inactive even though he kept release privilege to himself. And each OSS project has a risk to be so.

Of course I can understand your security concerns. Recently we had a case that leaked env var at Codecov, actually.
So if we use the manual way, I suggest you to find another and let them to have a release privilege.

@cpovirk

cpovirk commented Jul 2, 2021

Copy link
Copy Markdown
Collaborator

Sorry for dropping this again.

I had forgotten about the history of FindBugs :( We definitely do not want to repeat that.

While I remain nervous about uploading GPG keys, given my lack of security knowledge, I do want to make sure that multiple people can publish. If worst comes to worst, I'd expect that the various people who have write access to this repo can prove ownership to Sonatype through the usual process of pushing files to the repo. But there is no reason to wait for a problem to arise. I had requested a couple other owners when I filed the Sonatype ticket, but it's not clear to me that Sonatype gave permissions to anyone but me. I will post on the ticket to see if they will grant more permissions there or if we need to file new tickets.

In the meantime, this PR looks good to me. I think we could merge it as it is, and that would unblock manual deployment. If we're leaving out the GPG keys, then we could even simplify the PR slightly by omitting the build.yml setup for secrets.

@cpovirk

cpovirk commented Jul 2, 2021 •

Copy link
Copy Markdown
Collaborator

Some notes, which we should eventually turn into documentation for the release process:

The ultimate command line [edit: after setting the version number in a detached head to be tagged later, ideally in a fresh clone of the repo] is something like this [edit: after #860 changes from the plugin we used for 1.0.0 to the one we used for 1.0.1!]:

JAVA_HOME=$HOME/jdk-21.0.2 ./gradlew clean publishMavenPublicationToMavenCentralRepository -Psigning.secretKeyRingFile=$HOME/.gnupg/secring.gpg -PpgpPassword="$(passphrase)" -PprivateKey="$(gpg --armor --export-secret-keys --passphrase="$(passphrase)" --batch --pinentry-mode=loopback ABCDEF12)"

[edit: For the 1.0.1 release, I had also included -PmavenCentralUsername="$(username)" -PmavenCentralPassword="$(password)". It's likely that this would have been unnecessary after the updated $HOME/.gradle/gradle.properties setup discussed below.]

[edit: JAVA_HOME should be unnecessary after #818 unless your default JDK is so old/new that our current version of Gradle doesn't support it. I successfully omitted it for 1.0.1.]

[edit: Once upon a time, we needed --no-configuration-cache. That is being solved by #860.]

In that command, ABCDEF12 is your "public key ID" from these Gradle release docs.

Those instructions also include an --export-secret-keys setup step. It looks like I had done that already, presumably for Guava. (Or I once used an old enough version of GPG that I didn't need to do that step?)

Another setup step: Create $HOME/.gradle/gradle.properties (with permissions so that no one else can read it) with your Sonatype credentials [edit: This is probably an alternative to having some configuration in build.gradle or a similar "Gradle file", perhaps username+password nested under nexusPublishing > repositories > sonatype at one point, and this is separate from some other plugin that uses maven somewhere in there.]:

mavenCentralUsername=<username from https://central.sonatype.org/publish/generate-portal-token/, *not* the one you use to log in>
mavenCentralPassword=<likewise from https://central.sonatype.org/publish/generate-portal-token/, *not* the one you use to log in>

# NOT ANYMORE:
#sonatypeUsername=cpovirk
#sonatypePassword=...

Note that the command above deploys to and closes the staging repository, but it does not perform a release to Maven Central. If we want, we should be able to perform the release by changing [edit: the command somehow or other]. Naturally, I haven't wanted to try that yet :)

To examine the staging repository, you can [edit: log into https://central.sonatype.com/ and go to "Publish" (near the top right) and then "Deployments."] Again, there should be no need to look here if we [edit: someday, maybe!] have Gradle release the artifacts for us. But it is good to know about for testing [edit: and for the release process as it stands today]. Plus, if there are errors (you know, hypothetically :)), those errors appear on that site under the Activity tab for a repository. [edit: Or I assume that they show up there somewhere now; the system has changed since I had problems with the 1.0.0 release, and 1.0.1 didn't hit any problems during this step.]

General documentation for the Gradle plugin we're using is available at https://github.com/gradle-nexus/publish-plugin https://vanniktech.github.io/gradle-maven-publish-plugin/

Other notes:

If you get something wrong with the signing -P flags, you'll either get a build failure (usually) or a silently un-signed artifact. To see if the artifact was signed, you can look at whether the build created any build/libs/*.asc files. (Of course, make sure that you're not looking at .asc files from a previous build. This is one of the reasons I suggest clean in the command line.) If you get silently un-signed artifacts, the "close" step of the staging deployment should cause the build to fail, too, if you're running the command above (or any other command that performs the deployment step).

Finally, the command above passes your PGP passphrase twice as command-line arguments. I've set mine up so that the passphrase comes from a script, which can be as simple as echo thepassphrase or as complicated as prompting the user for the passphrase. Note that this still means that the passphrase is at least temporarily visible to essentially anyone on your machine and anyone who can see the data you get from ps. So this is not a good idea for shared machines. The only security I'm getting out of it relative hardcoding the passphrase in the command line is (a) that I can't accidentally copy and paste the passphrase here and (b) that I don't end up with the passphrase in my Bash history, from which it might appear when others are looking over my shoulder in the future.

[edit: We should also update documentation for each new release and of course publish release notes from a tag we push. Some of us might also want to quickly adopt the new version in our libraries/tools, perhaps following on testing that we conducted beforehand.]

[edit: A release is probably also not a bad time to update the copies of our annotations in our jdk repo.]

@cpovirk

cpovirk commented Jul 2, 2021

Copy link
Copy Markdown
Collaborator

OK, Sonatype said there was some kind of bug that prevented others from being given permissions initially. They've now added the other people, whom I roped in from other projects where we already shared permissions. We could use some non-Google members if you (Kengo) or others are interested.

we'll handle release procedure manually, so
no need to handle GPG in the workflow
@KengoTODA

Copy link
Copy Markdown
Collaborator Author

OK, thanks. I've removed GPG related process from the workflow :)

We could use some non-Google members if you (Kengo) or others are interested.

At this moment I don't need the permission to deploy :) Thanks for your consideration!

@cpovirk

cpovirk commented Jul 9, 2021

Copy link
Copy Markdown
Collaborator

Thanks. I see that this PR is still marked as a draft, but it sounds to me like it's ready, so I'm going to merge it. If I'm wrong about that, do let me know, and we can revert it or fix forward as needed.

@cpovirk
cpovirk marked this pull request as ready for review July 9, 2021 19:34
@cpovirk
cpovirk merged commit f1d885a into main Jul 9, 2021
@KengoTODA
KengoTODA deleted the deploy-with-gpg branch July 13, 2021 02:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes See https://cla.developers.google.com/

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants