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

Add checksums (SHA256) to GitHub releases for all files #29656

Closed
o-l-a-v opened this issue Aug 6, 2024 · 15 comments
Closed

Add checksums (SHA256) to GitHub releases for all files #29656

o-l-a-v opened this issue Aug 6, 2024 · 15 comments
Assignees
Labels
Azure CLI Team The command of the issue is owned by Azure CLI team customer-reported Issues that are reported by GitHub users external to the Azure organization. feature-request
Milestone

Comments

@o-l-a-v
Copy link

o-l-a-v commented Aug 6, 2024

Related command

Add checksums (SHA256) to releases for all files, be it files hosted on GitHub (MSI, source code), and files from azcliprod.blob.core.windows.net (ZIP, MSI etc.).

Is your feature request related to a problem? Please describe.

Describe the solution you'd like

Add a list to GitHub releases with SHA256, like Beaver Notes does:

Describe alternatives you've considered

None.

Additional context

None.

@microsoft-github-policy-service microsoft-github-policy-service bot added the customer-reported Issues that are reported by GitHub users external to the Azure organization. label Aug 6, 2024
@yonzhan
Copy link
Collaborator

yonzhan commented Aug 6, 2024

Thank you for opening this issue, we will look into it.

@yonzhan yonzhan added feature-request Azure CLI Team The command of the issue is owned by Azure CLI team labels Aug 6, 2024
@yonzhan yonzhan added this to the Backlog milestone Aug 6, 2024
@jiasli
Copy link
Member

jiasli commented Aug 7, 2024

Hi @o-l-a-v, I noticed https://github.com/Beaver-Notes/Beaver-Notes/releases/tag/3.5.0 puts SHA256s in the release description:

image

https://github.com/PowerShell/PowerShell/releases/tag/v7.4.4 uses a different format:

image

How does Scoop extract this information from plaintext?

@o-l-a-v
Copy link
Author

o-l-a-v commented Aug 7, 2024

I have a PR on Beaver Notes for Scoop that shows the info Scoop needs to fetch the SHA256 checksums:

Here's the manifest for pwsh, looks like it fetches SHA256 info from release info too:

Here's info on the Scoop app manifest:

Here's Scoop main manifest repos, see if you can find more examples there:


Edit: And I believe the logic for getting new versions is found inside here:

Which calls Invoke-AutoUpdate from here:

@jiasli
Copy link
Member

jiasli commented Aug 7, 2024

Thanks @o-l-a-v, but I think you misunderstand my question.

In other words, how is 6461dd3fda39fc65e30c7642f863b9e1dabe32885043094e1d8a79dffcef1dcb extracted from https://github.com/PowerShell/PowerShell/releases/tag/v7.4.4 to https://github.com/ScoopInstaller/Main/blob/75c4fa28f734a4849633a8bd920013bf7d93911a/bucket/pwsh.json#L16 ? Is this a manual process? Or is there a standard format? I would like to know which format you want us to use to provide the SHA256s.

BTW, I noticed Scoop computes the SHA256 of https://azcliprod.blob.core.windows.net/zip/azure-cli-2.63.0-x64.zip by itself: https://github.com/ScoopInstaller/Main/blob/75c4fa28f734a4849633a8bd920013bf7d93911a/bucket/azure-cli.json#L13

@o-l-a-v
Copy link
Author

o-l-a-v commented Aug 7, 2024

As the feature request states: Scoop can calculate SHA256 by downloading the artifact. But if checksum is already made available and Scoop is told were to look, it does not have to 1) download the artifact and 2) calculate hash.

Scoop has logic to autoupdate manifests. If we add hash ("autoupdate":{"hash": {}}) property to the manifest JSON, Scoop will try to find the checksums depending on the logic. So for Beaver-Notes https://github.com/ScoopInstaller/Extras/pull/13661/files:

{
    ...
    "autoupdate": {
        "architecture": {
            "64bit": {
                "url": "https://github.com/Beaver-Notes/Beaver-Notes/releases/download/$version/Beaver-notes.$version.portable.exe#/dl.7z"
            },
            "arm64": {
                "url": "https://github.com/Beaver-Notes/Beaver-Notes/releases/download/$version/Beaver-notes.$version.portable.arm64.exe#/dl.7z"
            }
        },
        "hash": {
            "url": "https://github.com/Beaver-Notes/Beaver-Notes/releases/tag/$version",
            "regex": "$sha256.*?$basename"
        }
    }
}

And for pwsh https://github.com/ScoopInstaller/Main/blob/master/bucket/pwsh.json:

{
    ...
    "autoupdate": {
        "architecture": {
            "64bit": {
                "url": "https://github.com/PowerShell/PowerShell/releases/download/v$version/PowerShell-$version-win-x64.zip"
            },
            "32bit": {
                "url": "https://github.com/PowerShell/PowerShell/releases/download/v$version/PowerShell-$version-win-x86.zip"
            },
            "arm64": {
                "url": "https://github.com/PowerShell/PowerShell/releases/download/v$version/PowerShell-$version-win-arm64.zip"
            }
        },
        "hash": {
            "url": "$baseurl/hashes.sha256"
        }
    }
}

@o-l-a-v
Copy link
Author

o-l-a-v commented Aug 7, 2024

There are som find_hash_in_x functions inside here:

You could probably also just add checksum files to the GitHub release instead of adding it as plain text, if you prefer that.

@jiasli
Copy link
Member

jiasli commented Aug 8, 2024

Thank you for the detailed explanation. find_hash_in_textfile looks a little bit fragile. I think creating a hashes.sha256 with sha256sum --binary * is a more formal and reliable implementation. We will consider this as a feature request.

BTW, we can reuse the code from https://github.com/PowerShell/PowerShell/blob/a1774fd9332925f7635e0832b64b2d158e3a3745/.pipelines/templates/release-githubtasks.yml#L88-L104

@jiasli
Copy link
Member

jiasli commented Dec 26, 2024

I noticed today that Python provides very convenient functions to compute file hashes:

https://docs.python.org/3/library/hashlib.html#file-hashing

import io, hashlib, hmac
with open(hashlib.__file__, "rb") as f:
    digest = hashlib.file_digest(f, "sha256")

digest.hexdigest()  

@jiasli
Copy link
Member

jiasli commented Dec 26, 2024

Our release pipeline is on Linux, so the below command will do the job:

sha256sum --binary azure-cli* > hashes.sha256

hashes.sha256 will look like

723cf2ac1d252ee086841dece0fff10538e15926d2c7ed1085d02c0f82b7393e *azure-cli-2.67.0-x64.msi
b8b31530939d8016ff23da4d2196a4286e9db6477117733c770b805b6fa64162 *azure-cli-2.67.0-x64.zip
c4cdd13157968052bc2ffeecb4459d466de95d4b9ab8194963ab601d9f613c44 *azure-cli-2.67.0.msi

* indicates binary mode.

According to https://manpages.ubuntu.com/manpages/noble/man1/sha256sum.1.html

Note: There is no difference between binary mode and text mode on GNU systems.

But it is still better to specify --binary to align with hashes.sha256 from https://github.com/PowerShell/PowerShell/releases

@jiasli
Copy link
Member

jiasli commented Dec 26, 2024

@o-l-a-v, we have updated the latest release (2.67.0) to include SHA256 hashes for the release artifacts in the release description: https://github.com/Azure/azure-cli/releases/tag/azure-cli-2.67.0

This is only experimental, so please let us know if this suits your needs. If you want us to change its format, feel free to let us know. 😊

Also, do you want us to publish a hashes.sha256 file? If so, any preference on the file name?

@o-l-a-v
Copy link
Author

o-l-a-v commented Dec 26, 2024

Nice! That should make it easy for both humans and automation like Scoop to find the checksums.

I think I prefer one <filename.ext>.sha256 file per artifact, but one file for all hashes like PowerShell do works too:

@jiasli
Copy link
Member

jiasli commented Dec 27, 2024

I am glad it works for you. 😊

Actually, I noticed https://github.com/Beaver-Notes/Beaver-Notes/releases doesn't have a dedicated file for hashes.

Image

Does putting hashes only in release description work for you? Or is it still necessary for us to release dedicated hash file(s)?

Also, there doesn't seem to be an industry standard on what should be inside that file.

@o-l-a-v
Copy link
Author

o-l-a-v commented Dec 27, 2024

Hashes in description only works.

If creating checksum file(s) it'd be great it they work with sha256sum:

sha256sum --check --ignore-missing checksums.sha256

Would be great if Microsoft had a standard across projects which can be managed by package managers, like Azure CLI, Bicep, PowerShell etc. Or if the GitHub releases API added checksum to each artifact.


Edit: Example on how to mimic SHA256SUM on Windows with PowerShell:

# Assets
$FilePath = [string] 'C:\Users\olavb\Desktop\azure-cli-2.67.0-x64.zip'
$OutputFilePath = [string] $FilePath + '.sha256'

# Using PowerShell native
<#
    Examples where it's used:
    * <https://github.com/pbek/QOwnNotes/blob/main/build-systems/github/windows/build-zip.ps1>
#>
Out-File -Encoding 'utf8' -Force -FilePath $OutputFilePath -InputObject (
    [string]::Concat(
        (Get-FileHash -Path $FilePath -Algorithm 'SHA256').'Hash',
        ' *',
        $([System.IO.FileInfo]($FilePath)).'Name'
    )
)

@jiasli
Copy link
Member

jiasli commented Dec 30, 2024

@o-l-a-v, thanks for the additional information. As I mentioned in #29656 (comment), our pipeline is on a Linux agent, so a single sha256sum --binary azure-cli* > hashes.sha256 command will do the job.

There is even no convention on the hash file name: hashes.sha256 vs checksums.sha256. Also, as PowerShell does, if we add hashes.sha256, the hashes.sha256 needs its own hash (https://github.com/PowerShell/PowerShell/releases/tag/v7.4.6). I prefer not to complicate things too much.

As "Hashes in description only works", I will keep it this way. If a dedicated hash file is needed someday, please don't hesitate to create a new issue.

@jiasli jiasli closed this as completed Dec 30, 2024
@o-l-a-v
Copy link
Author

o-l-a-v commented Dec 30, 2024

Perfect, thanks @jiasli. 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Azure CLI Team The command of the issue is owned by Azure CLI team customer-reported Issues that are reported by GitHub users external to the Azure organization. feature-request
Projects
None yet
Development

No branches or pull requests

4 participants