-
Notifications
You must be signed in to change notification settings - Fork 2
Update output format and do a build check #30
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,17 +10,71 @@ import ( | |
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
| "sync" | ||
|
|
||
| "github.com/Microsoft/hcsshim/pkg/cimfs" | ||
| cimimport "github.com/Microsoft/hcsshim/pkg/ociwclayer/cim" | ||
| log "github.com/sirupsen/logrus" | ||
| "golang.org/x/sys/windows" | ||
| ) | ||
|
|
||
| type ParentLayers []*cimfs.BlockCIM | ||
|
|
||
| var ( | ||
| checkWindowsVersionOnce sync.Once | ||
| windowsVersionError error | ||
| ) | ||
|
|
||
| // checkWindowsVersion verifies that we're running on Windows Server 2025 (build 26100) or newer. | ||
| // CIM file generation on older versions will not produce deterministic hashes. | ||
| // Returns an error if the version requirement is not met, unless debug mode is enabled. | ||
| func checkWindowsVersion() error { | ||
| checkWindowsVersionOnce.Do(func() { | ||
| ver := windows.RtlGetVersion() | ||
| if ver == nil { | ||
| windowsVersionError = fmt.Errorf("failed to get Windows version information") | ||
| return | ||
| } | ||
|
|
||
| build := ver.BuildNumber | ||
| // Windows Server 2025 is build 26100 | ||
| // Deterministic CIM file generation requires WS2025+ | ||
| if build < 26100 { | ||
| if debugSkipVersionCheck { | ||
| // Debug mode: warn but allow execution | ||
| log.WithFields(log.Fields{ | ||
| "current_build": build, | ||
| "required_build": 26100, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need the more than this. 26100 => Windows 2025. There is a version number of WS2025 (today's one) that we require. Note that my Windows 11 25H2 is 26200.7985 and it is not suitable. I guess you need to check xxxxx.yyyy where xxxxx == 26100 and yyyy >= today's build. |
||
| "debug_mode": true, | ||
| }).Warn("DEBUG MODE: Running on pre-WS2025. Hashes may not be deterministic. This is for development/testing only.") | ||
| windowsVersionError = nil | ||
| } else { | ||
| // Production mode: fail with error | ||
| windowsVersionError = fmt.Errorf( | ||
| "Windows Server 2025 (build 26100) or newer is required for deterministic Windows container hashes. "+ | ||
| "Current build: %d. Windows platform processing cannot continue on this version.", | ||
| build, | ||
| ) | ||
| log.WithFields(log.Fields{ | ||
| "current_build": build, | ||
| "required_build": 26100, | ||
| }).Error("Insufficient Windows version for deterministic CIM generation") | ||
| } | ||
| } else { | ||
| log.WithField("build", build).Debug("Windows version check passed") | ||
| } | ||
| }) | ||
| return windowsVersionError | ||
| } | ||
|
|
||
| func tarToCim(tarReader io.Reader, parentLayers ParentLayers, out string, layerName string) (string, ParentLayers, error) { | ||
| log.Trace("tarToCim called") | ||
|
|
||
| // Check Windows version for deterministic hash support | ||
| if err := checkWindowsVersion(); err != nil { | ||
| return "", parentLayers, err | ||
| } | ||
|
|
||
| // If no out path is given, use a temp directory | ||
| var err error | ||
| if out == "" { | ||
|
|
@@ -70,6 +124,11 @@ func tarToCim(tarReader io.Reader, parentLayers ParentLayers, out string, layerN | |
| func generateMergedCim(parentLayers ParentLayers, out string, mergedName string) (string, error) { | ||
| log.Trace("generateMergedCim called") | ||
|
|
||
| // Check Windows version for deterministic hash support | ||
| if err := checkWindowsVersion(); err != nil { | ||
| return "", err | ||
| } | ||
|
|
||
| if mergedName == "" { | ||
| mergedName = "merged" | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,24 +12,28 @@ import ( | |
| ) | ||
|
|
||
| const ( | ||
| usernameFlag = "username" | ||
| passwordFlag = "password" | ||
| platformFlag = "platform" | ||
| inputFlag = "input" | ||
| outputFlag = "output" | ||
| typeFlag = "type" | ||
| verboseFlag = "verbose" | ||
| traceFlag = "trace" | ||
| profilerFlag = "profiler" // enable profiling | ||
| outputDirFlag = "out-dir" | ||
| dockerFlag = "docker" | ||
| bufferedReaderFlag = "buffered-reader" | ||
| tarballFlag = "tarball" | ||
| hashDeviceVhdFlag = "hash-dev-vhd" | ||
| dataVhdFlag = "data-vhd" | ||
| maxVHDSize = dmverity.RecommendedVHDSizeGB | ||
| usernameFlag = "username" | ||
| passwordFlag = "password" | ||
| platformFlag = "platform" | ||
| inputFlag = "input" | ||
| outputFlag = "output" | ||
| typeFlag = "type" | ||
| verboseFlag = "verbose" | ||
| traceFlag = "trace" | ||
| profilerFlag = "profiler" // enable profiling | ||
| outputDirFlag = "out-dir" | ||
| dockerFlag = "docker" | ||
| bufferedReaderFlag = "buffered-reader" | ||
| tarballFlag = "tarball" | ||
| hashDeviceVhdFlag = "hash-dev-vhd" | ||
| dataVhdFlag = "data-vhd" | ||
| debugSkipVersionFlag = "debug-skip-version-check" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not entirely debug. We'll need it when using base2-hyp. Can I suggest "ignore-windows-version". There might also be a check in the hcsshim code BTW. |
||
| maxVHDSize = dmverity.RecommendedVHDSizeGB | ||
| ) | ||
|
|
||
| // Global variable to control Windows version check strictness | ||
| var debugSkipVersionCheck bool = false | ||
|
|
||
| func init() { | ||
| log.SetFormatter(&log.TextFormatter{ | ||
| DisableTimestamp: false, | ||
|
|
@@ -82,6 +86,10 @@ func main() { | |
| Name: profilerFlag, | ||
| Usage: "Optional: profile and put the results in this file", | ||
| }, | ||
| cli.BoolFlag{ | ||
| Name: debugSkipVersionFlag, | ||
| Usage: "Optional: DEBUG ONLY - skip Windows version check (allows running on pre-WS2025 with warnings)", | ||
| }, | ||
| } | ||
|
|
||
| if err := app.Run(os.Args); err != nil { | ||
|
|
@@ -128,6 +136,7 @@ var createVHDCommand = cli.Command{ | |
| Action: func(ctx *cli.Context) error { | ||
| setupProfiler(ctx) | ||
| setLoggingLevel(ctx) | ||
| setDebugSkipVersionCheck(ctx) | ||
| log.Trace("createVHDCommand called") | ||
|
|
||
| imageName, outDir, platform, verityHashDev, verityData, imageFetcher, imageParser, manifestParser, err := parseCreateVhdArgs(ctx) | ||
|
|
@@ -165,13 +174,15 @@ var rootHashVHDCommand = cli.Command{ | |
| Action: func(ctx *cli.Context) error { | ||
| setupProfiler(ctx) | ||
| setLoggingLevel(ctx) | ||
| setDebugSkipVersionCheck(ctx) | ||
| log.Trace("rootHashVHDCommand called") | ||
|
|
||
| imageFetcher, imageParser, manifestParser, layerParser, mergedHashGenerator, err := parseRoothashArgs(ctx) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| err = roothash(imageFetcher, imageParser, manifestParser, layerParser, mergedHashGenerator) | ||
| platform := ctx.String(platformFlag) | ||
| err = roothash(imageFetcher, imageParser, manifestParser, layerParser, mergedHashGenerator, platform) | ||
| stopProfiler(ctx) | ||
| return err | ||
| }, | ||
|
|
@@ -195,6 +206,7 @@ var hashLayerCommand = cli.Command{ | |
| Action: func(ctx *cli.Context) error { | ||
| setupProfiler(ctx) | ||
| setLoggingLevel(ctx) | ||
| setDebugSkipVersionCheck(ctx) | ||
| log.Trace("hashLayerCommand called") | ||
|
|
||
| tarPath, platform, err := parseHashLayerArgs(ctx) | ||
|
|
@@ -233,6 +245,7 @@ var tar2hashedCommand = cli.Command{ | |
| Action: func(ctx *cli.Context) error { | ||
| setupProfiler(ctx) | ||
| setLoggingLevel(ctx) | ||
| setDebugSkipVersionCheck(ctx) | ||
| log.Trace("tar2hashedCommand called") | ||
|
|
||
| srcTarPath := ctx.String(inputFlag) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to specify the particular minimum WS2025