You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Consider updating SHA checks to new SHA files #6495
This approach could significantly simplify the workflow for building .NET images. I always delete the SHA checking lines when I update these Dockerfiles. I am sure others do the same. It would be nice to not need to do so.
Those were just the first three (and only) examples I checked. Yes, all different. I suspect if we did a more comprehensive survey that we'd see similar diversity. I think any option is good as long as we have a good way of describing what to do. I'm happy to see that we're progressing on this.
What is the goal with making this change? By having the SHA value hardcoded in the Dockerfile, it guarantees the integrity of the downloaded file as originally intended from the release. By downloading the SHA as its own file, it opens you up to security issues:
If an attacker made their way into the storage account, they could modify the installer file as well as its corresponding SHA file so that they are in sync. The Dockerfile build would think everything is fine.
A MITM attack could intercept the downloading of both files to deliver a malicious installer file along with a tampered SHA file.
Both of these scenarios are mitigated by having a hardcoded SHA value in the Dockerfile.
/cc @blowdart on the security questions. I believe Rich has brought this up with him before. Some thoughts I had:
If an attacker made their way into the storage account...
This should be prevented by WORM policies in our storage accounts.
A MITM attack could intercept the downloading of both files to deliver a malicious installer file along with a tampered SHA file.
Are MITM attacks a significant concern since we are using HTTPS?
Here are some of the pros for this approach:
.NET version is controllable entirely by Dockerfile build arguments. Someone could take our Dockerfiles and build images for any .NET version without changing the Dockerfiles.
manifest.versions.json can be greatly simplified since it no longer needs to contain checksums.
update-dependencies tooling can be greatly simplified since it no longer needs to fetch/calculate checksums.
Dockerfiles have much smaller diffs when changing .NET versions. In the best-case scenario, .NET updates only require updating the default ARG value in the Dockerfiles.
Overall, I think it would be a big cost savings for maintaining this repo.
So yes, HTTPS is the mitigation for MITM. You should consider enabling OCSP/CRL checking by default, which is off by default in HttpClient et al as it can introduce failures if you can't reach the revocation servers. You could add an optional parameter to disable the online checks for those weird environments where this might happen.
I have no real opinion versus hardcoded/downloadable. I leave that as PG rather than a security decision on whether the pros outweigh the cons
(And go enable WORM on the storage account if it's not already)
My take is that hard coding SHAs makes the Dockerfiles unusable for others and makes them less secure as a result. I also don't think of it as an industry best practice. Everyone else does what Logan (and I) is proposing to do. As Logan is suggesting, we're taking on significant cost and complexity for this extra validation.
For example, if we ever get to a a model where we have a dotnet install command, it will do this same thing.
Activity
lbussell commentedon Jun 19, 2025
Amazing!!
So in combination with Refactor how version numbers are specified after the introduction of installer stages (dotnet/dotnet-docker#6266), our new Dockerfile could look something like this:
However, the content of the .sha512 file is:
It is missing the file to check. I would expect it to be something like the following, which is what you get when you actually run
sha512sum.This means we can't actually use the sha512sum command as intended. We'll instead have to do something ugly like:
Note that there is precedent for formatting .sha* files this way. See Chisel's .sha384 files for example: https://github.com/canonical/chisel/releases/tag/v1.1.0
If this is really the first time that these files have been made public, we should really do this the right way.
richlander commentedon Jun 19, 2025
Here are some examples:
.sha256to the URLs)lbussell commentedon Jun 19, 2025
I looked at the formats for those. They're all different.
20a06e644b0d9bd2fbdbfd52d42540bdde820ea7df86e92e533c073da0cdd43c *./rustup-initIt strikes me that we may be able to use the
--ignore-missingargument to use the combined checksum file for .NET 8/9. I'll work on a POC for that!richlander commentedon Jun 19, 2025
Those were just the first three (and only) examples I checked. Yes, all different. I suspect if we did a more comprehensive survey that we'd see similar diversity. I think any option is good as long as we have a good way of describing what to do. I'm happy to see that we're progressing on this.
lbussell commentedon Jun 19, 2025
The following works:
RUN dotnet_filename=dotnet-runtime-${DOTNET_VERSION}-linux-x64.tar.gz \ && curl --fail --show-error --location --remote-name https://builds.dotnet.microsoft.com/dotnet/Runtime/${DOTNET_VERSION}/${dotnet_filename} \ && curl --fail --show-error --location --remote-name https://builds.dotnet.microsoft.com/dotnet/checksums/${DOTNET_VERSION}-sha.txt \ && sha512sum --ignore-missing --check ${DOTNET_VERSION}-sha.txtrichlander commentedon Jun 19, 2025
That looks pretty solid to me. Nice!
mthalman commentedon Jun 19, 2025
What is the goal with making this change? By having the SHA value hardcoded in the Dockerfile, it guarantees the integrity of the downloaded file as originally intended from the release. By downloading the SHA as its own file, it opens you up to security issues:
Both of these scenarios are mitigated by having a hardcoded SHA value in the Dockerfile.
lbussell commentedon Jun 19, 2025
/cc @blowdart on the security questions. I believe Rich has brought this up with him before. Some thoughts I had:
This should be prevented by WORM policies in our storage accounts.
Are MITM attacks a significant concern since we are using HTTPS?
Here are some of the pros for this approach:
manifest.versions.jsoncan be greatly simplified since it no longer needs to contain checksums.Overall, I think it would be a big cost savings for maintaining this repo.
blowdart commentedon Jun 19, 2025
So yes, HTTPS is the mitigation for MITM. You should consider enabling OCSP/CRL checking by default, which is off by default in HttpClient et al as it can introduce failures if you can't reach the revocation servers. You could add an optional parameter to disable the online checks for those weird environments where this might happen.
I have no real opinion versus hardcoded/downloadable. I leave that as PG rather than a security decision on whether the pros outweigh the cons
(And go enable WORM on the storage account if it's not already)
richlander commentedon Jun 19, 2025
My take is that hard coding SHAs makes the Dockerfiles unusable for others and makes them less secure as a result. I also don't think of it as an industry best practice. Everyone else does what Logan (and I) is proposing to do. As Logan is suggesting, we're taking on significant cost and complexity for this extra validation.
For example, if we ever get to a a model where we have a
dotnet installcommand, it will do this same thing.lbussell commentedon Jun 19, 2025
+1, when prototyping with the current Dockerfiles the first thing I do is remove the sha checking commands, since it is so inflexible.
richlander commentedon Jun 27, 2025
We should do a writeup on this once we're done, both to explain/describe the change and to encourage DIY users to adopt it (and why).
lbussell commentedon Jul 15, 2025
As of Preview 6, .NET 10 Dockerfiles use the new format:
dotnet-docker/src/runtime/10.0/noble/amd64/Dockerfile
Lines 6 to 11 in 631a4e6
Fixed with #6521