Add --verify/--no-verify to swiftly init - #577
Conversation
etcwilde
left a comment
There was a problem hiding this comment.
Thanks for looking into this. I'm not sure how much that test is verifying beyond that ArgumentParser is working, but I can't come up with a better test since it doesn't look like we have a test for this in the install tests either.
|
Thanks for the review, and that is a fair reading of the test. You are right that it is mostly exercising ArgumentParser. The narrow thing it does pin is the bit the bug was about: the gpg prerequisite check tells users to run What it does not cover is the part I would actually want covered, that |
|
Flagging the The job does not fail an assertion, the test binary dies with The other platforms on this same commit are green:
A change to an ArgumentParser flag declaration would not be platform specific, and it would not segfault a test binary after the parse test has already passed. The crash frames are in I have left it alone rather than pushing at it. Happy to re-run if that helps, or to dig further if this is not a known flake on that image. |
|
Yeah, there's a bug in Foundation that can sometimes cause issues in process launches. From what I remember, that's in the test harness itself and not in the Swiftly binary. Swiftly generally uses swift-subprocess. |
|
That is good to know, thanks. The harness rather than the binary also fits what the log shows, the crash frames are in Leaving it alone then. Nothing outstanding from my side on this one. |
|
@cmcgee1024, do you know if there is a way to observe whether a toolchain was verified or not? I'm looking at install, and it looks like the only thing is whether it failed to verify and then the install command fails. Trying to find a better way to verify that the flag is having the intended behavior. |
|
@etcwilde there are two observables already in the tree, and neither needs a production change. The direct one is console output. // Sources/LinuxPlatform/Linux.swift:485
await ctx.message("Verifying toolchain signature...")
The stronger one is the network. Verification makes two HTTP calls through // importGpgKeys
try await ctx.httpClient.getGpgKeys().download(to: tmpFile)
// verifyToolchainSignature
try await ctx.httpClient.getSwiftToolchainFileSignature(toolchainFile).download(to: sigFile)The mock already routes on The negative direction is the better assertion of the two. It is deterministic and needs no gpg on the runner, whereas the positive direction actually shells out to gpg with To set expectations honestly: I read these paths rather than ran them. |
|
@etcwilde your read on this was right, and I can now back it with the actual stack rather than the log tail. The job logs are reachable through It is a hard crash, not a test failure: Top of the crashing thread: So it is Nothing outstanding from me on this one. |
When gpg is missing, the Linux prerequisite check tells the user to pass --no-verify, but swiftly init never accepted that flag and rejected it as an unknown option. Init now takes the same --verify/--no-verify flag that install takes and passes it through to the toolchain installation, so the advice in the error message works. Fixes swiftlang#576
85d8916 to
d2d8365
Compare
|
I rebased this onto My reasoning was that the red here was a stale 05 August run and that That is worse for you, not better, and I should have checked the run attempt before pushing. The branch is otherwise unchanged, still the same three files and the same diff, now zero commits behind For reference the old failure was a SIGSEGV in the toolchain install tests, |
|
Overall, this looks good. There are a few more things to consider. The verify/no-verify currently relate to Swift toolchains, not swiftly itself. That's why it wasn't added to the global options, and used everywhere because the distinction can be important. Swift toolchains don't generally recommend changes and even provide commands that run as root, so installing a malicious one might only infect your user account, but not affect the entire machine. swiftly on the other hand has that potential and in the future it might even make changes to your system in order to streamline the workflow even more. The side effect is that the authorship of swiftly becomes more important than the toolchains themselves, so skipping that step has a more grave impact. This option should reflect that instead of being folded into the toolchain's option, and give a deeper sense of importance. Also, if we're skipping swiftly verification, then should this option also apply to self-update? Maybe as a user you might consider installing gpg onto your system since it's very commonly found in various Linux package managers and gain a much higher level of confidence of both swiftly and the toolchains that they are official and coming from swift.org? swiftly could do better to handle swiftly init more gracefully if it's not present. |
On Linux, when gpg is not installed, the prerequisite check tells the user "To skip signature verification, specify the --no-verify flag", but
swiftly initnever declared that flag, so passing it failed with "Unknown option '--no-verify'". This adds the same--verify/--no-verifyflag thatinstallandupdatealready have toinit, and threads it into the toolchain installation that init performs, so the advice in the error message now works. The confirmation prompt also stops promising to import swift.org GnuPG keys when verification is turned off, and the generated CLI reference was regenerated with the plugin. Verified with a new case in InitTests that parses--no-verify, which fails on main and passes here, plus the existing InitTests suite.Fixes #576