forked from microsoft/hcsshim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚨WIP: Populate new base layers with real but empty hives
Somewhere between Windows RS5 (Server LTSC 2019) and Windows 20H2, the HCS started trying to load one of the hives in the base layer when importing a layer that depends on it. The observed symptom is: > hcsshim::ImportLayer - failed failed in Win32: The configuration registry database is corrupt. (0x3f1) WIP because at some point since I had this working in 2021, the behaviour of `go mod vendor` changed and no longer includes the testdata/minimal file, so that probably needs to be replaced. Possibly, just with a HTTP pull from GitHub; the relevant file hasn't changed in 3 years. Signed-off-by: Paul "TBBle" Hampson <[email protected]>
- Loading branch information
Showing
66 changed files
with
13,660 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
//go:build generate_but_never_actually_compile | ||
|
||
// This exists to force the inclusion of the below package in | ||
// go.mod and hence the vendor directory, so that | ||
// golang.org/x/tools/go/packages.Load can read files from it. | ||
|
||
// However, if this import statement gets pulled into an actual | ||
// compile (i.e. by appearing in mkminimalhive_windows.go) then | ||
// it forces both CGO and installation of the libhive library | ||
// this package wraps. | ||
|
||
// Per https://github.com/golang/go/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module | ||
// this is the best option. | ||
|
||
package main | ||
|
||
import _ "github.com/gabriel-samfira/go-hivex" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
//go:build generate | ||
|
||
/* | ||
mkminimalhive_windows generates a minimal hive blob function | ||
so that we do not carry a runtime dependency on the hive source. | ||
The generated source contains a single function, minimalHiveContents, | ||
which returns a []byte of the desired data. | ||
Largely based on how mksyscall_windows works. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"encoding/base64" | ||
"errors" | ||
"flag" | ||
"fmt" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
|
||
"golang.org/x/tools/go/packages" | ||
) | ||
|
||
var ( | ||
filename = flag.String("output", "", "output file name (standard output if omitted)") | ||
) | ||
|
||
//readMinimalHiveContents finds the `minimal` hive binary from the package as there's no way to create this file | ||
// Originally from https://github.com/buildpacks/imgutil/blob/main/tools/bcdhive_generator/bcdhive_hivex.go | ||
func readMinimalHiveContents() ([]byte, error) { | ||
pkgs, err := packages.Load(&packages.Config{}, "github.com/gabriel-samfira/go-hivex") | ||
if err != nil { | ||
return nil, err | ||
} | ||
if len(pkgs) != 1 || len(pkgs[0].GoFiles) != 1 { | ||
return nil, errors.New("hivex module root not found") | ||
} | ||
hivexRootPath := filepath.Dir(pkgs[0].GoFiles[0]) | ||
minimalHivePath := filepath.Join(hivexRootPath, "testdata", "minimal") | ||
return os.ReadFile(minimalHivePath) | ||
} | ||
|
||
func usage() { | ||
fmt.Fprintf(os.Stderr, "usage: mkminimalhive_windows [flags] [path ...]\n") | ||
flag.PrintDefaults() | ||
os.Exit(1) | ||
} | ||
|
||
func main() { | ||
flag.Usage = usage | ||
flag.Parse() | ||
if len(flag.Args()) != 0 { | ||
fmt.Fprintf(os.Stderr, "unexpected filename arguments\n") | ||
usage() | ||
} | ||
|
||
hiveData, err := readMinimalHiveContents() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
hiveBase64 := base64.StdEncoding.EncodeToString(hiveData) | ||
|
||
source := []byte(`// Code generated by mkminimalhive_windows DO NOT EDIT. | ||
package wclayer | ||
import ( | ||
"encoding/base64" | ||
) | ||
const hiveBase64 = "` + hiveBase64 + `" | ||
func minimalHiveContents() ([]byte, error) { | ||
return base64.StdEncoding.DecodeString(hiveBase64) | ||
} | ||
`) | ||
|
||
if *filename == "" { | ||
_, err = os.Stdout.Write(source) | ||
} else { | ||
err = os.WriteFile(*filename, source, 0644) | ||
} | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.