diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a5b2192..0570ff4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,7 +1,9 @@ name: Release # Builds plugctl for each platform and publishes a GitHub release with the archives, plus the -# container image ghcr.io/zompinc/plugctl built from the Linux binaries. +# container image ghcr.io/zompinc/plugctl built from the Linux binaries. Both carry build +# provenance: `gh attestation verify -R zompinc/plugctl` (or oci://) checks that +# this workflow built them, and from which commit. # # - Run it from the Actions tab (workflow_dispatch) on master: it tags the commit with the # version Nerdbank.GitVersioning calculates and publishes. @@ -71,6 +73,9 @@ jobs: # Hosted runners: this repository is public. runs-on: ${{ matrix.os }} + env: + # Whether the signing secrets are available, without putting them in every step's env. + CAN_SIGN: ${{ secrets.AZURE_SIGNER_CLIENT_SECRET != '' }} steps: - uses: actions/checkout@v4 @@ -98,6 +103,34 @@ jobs: cargo build --release --locked --target ${{ matrix.target }} fi + # Authenticode-signs plugctl.exe with Zomp's Azure Trusted Signing account, so SmartScreen + # and Smart App Control see a known publisher. sign-universal is Zomp's own signer + # (github.com/zompinc/sign-universal). The secrets are organization secrets, which pull + # requests from forks do not get, so those build unsigned. + - name: Sign + if: ${{ runner.os == 'Windows' && !env.ACT && env.CAN_SIGN == 'true' }} + shell: pwsh + # sign-universal reads these, as DefaultAzureCredential does. + env: + AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} + AZURE_CLIENT_ID: ${{ secrets.AZURE_SIGNER_CLIENT_ID }} + AZURE_CLIENT_SECRET: ${{ secrets.AZURE_SIGNER_CLIENT_SECRET }} + run: | + dotnet tool install SignUniversal.Cli --version 1.0.39 --tool-path "$env:RUNNER_TEMP/sign" + $su = "$env:RUNNER_TEMP/sign/sign-universal" + $exe = "target/${{ matrix.target }}/release/plugctl.exe" + & $su sign $exe ` + --trusted-signing-endpoint "${{ secrets.TRUSTED_SIGNING_ENDPOINT }}" ` + --trusted-signing-account "${{ secrets.TRUSTED_SIGNING_ACCOUNT }}" ` + --trusted-signing-certificate-profile "${{ secrets.TRUSTED_SIGNING_CERTIFICATE_PROFILE }}" + if ($LASTEXITCODE) { exit $LASTEXITCODE } + & $su verify $exe + if ($LASTEXITCODE) { exit $LASTEXITCODE } + # verify leaves trust to Windows; this asks Windows whether it trusts the chain. + $sig = Get-AuthenticodeSignature $exe + "$($sig.Status): $($sig.SignerCertificate.Subject)" + if ($sig.Status -ne 'Valid') { exit 1 } + - name: Package shell: bash run: | @@ -124,6 +157,9 @@ jobs: permissions: contents: read packages: write + # For the provenance attestation: a GitHub OIDC token to sign it, and the right to store it. + id-token: write + attestations: write steps: - uses: actions/checkout@v4 - uses: actions/download-artifact@v4 @@ -161,6 +197,7 @@ jobs: username: ${{ github.actor }} password: ${{ github.token }} - uses: docker/build-push-action@v6 + id: push with: context: . platforms: linux/amd64,linux/arm64 @@ -173,6 +210,12 @@ jobs: org.opencontainers.image.version=${{ needs.version.outputs.version }} org.opencontainers.image.licenses=MIT org.opencontainers.image.description=Switch or power-cycle smart plugs by MAC + - uses: actions/attest-build-provenance@v4 + if: ${{ github.event_name != 'pull_request' }} + with: + subject-name: ghcr.io/${{ github.repository }} + subject-digest: ${{ steps.push.outputs.digest }} + push-to-registry: true publish: needs: [version, build, image] @@ -180,12 +223,18 @@ jobs: runs-on: ubuntu-latest permissions: contents: write + id-token: write + attestations: write steps: - uses: actions/download-artifact@v4 with: path: dist merge-multiple: true + - uses: actions/attest-build-provenance@v4 + with: + subject-path: dist/* + - name: Publish env: GH_TOKEN: ${{ github.token }} diff --git a/README.md b/README.md index a0438f0..b20d996 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,15 @@ TP-Link Kasa plugs come first, including firmware that only accepts KLAP (the en Download the archive for your platform from [Releases](https://github.com/zompinc/plugctl/releases) and put `plugctl` (or `plugctl.exe`) on your `PATH`. There are static Linux builds for x86_64 and aarch64 (which also run on aarch64 OpenWrt routers), Windows x86_64, and macOS on Apple silicon and Intel. `SHA256SUMS` lists each archive's checksum. +Each archive and image carries a build provenance attestation, which shows that this repository's release workflow built it and from which commit: + +```sh +gh attestation verify plugctl--.tar.gz -R zompinc/plugctl +gh attestation verify oci://ghcr.io/zompinc/plugctl: -R zompinc/plugctl +``` + +The Windows binary is Authenticode-signed by Zomp Inc.; the macOS binaries are not signed yet. On macOS, a binary downloaded with a browser needs `xattr -d com.apple.quarantine plugctl` before it runs. + ### Container Each release is also an image for linux/amd64 and linux/arm64, `ghcr.io/zompinc/plugctl:` (`latest` follows stable releases only). It keeps the config and the off-time log in `/config`, and takes the login from the environment, since there is no keyring in a container: