diff --git a/internal/setup/setup.go b/internal/setup/setup.go index 133989ee..6dde7e6f 100644 --- a/internal/setup/setup.go +++ b/internal/setup/setup.go @@ -319,7 +319,7 @@ func readSlices(release *Release, baseDir, dirName string) error { type yamlRelease struct { Format string `yaml:"format"` - Archives map[string]yamlArchive `yaml:"archives` + Archives map[string]yamlArchive `yaml:"archives"` PublicKeys map[string]yamlPublicKey `yaml:"public-keys"` } @@ -411,7 +411,7 @@ func parseRelease(baseDir, filePath string, data []byte) (*Release, error) { yamlVar := yamlRelease{} dec := yaml.NewDecoder(bytes.NewBuffer(data)) - dec.KnownFields(true) + dec.KnownFields(false) err := dec.Decode(&yamlVar) if err != nil { return nil, fmt.Errorf("%s: cannot parse release definition: %v", fileName, err) @@ -490,7 +490,7 @@ func parsePackage(baseDir, pkgName, pkgPath string, data []byte) (*Package, erro yamlPkg := yamlPackage{} dec := yaml.NewDecoder(bytes.NewBuffer(data)) - dec.KnownFields(true) + dec.KnownFields(false) err := dec.Decode(&yamlPkg) if err != nil { return nil, fmt.Errorf("cannot parse package %q slice definitions: %v", pkgName, err) diff --git a/internal/setup/setup_test.go b/internal/setup/setup_test.go index 4e5fc108..72bd6aa9 100644 --- a/internal/setup/setup_test.go +++ b/internal/setup/setup_test.go @@ -817,6 +817,64 @@ var setupTests = []setupTest{{ }, }, }, +}, { + summary: "Extra fields in YAML are ignored (necessary for forward compatibility)", + input: map[string]string{ + "chisel.yaml": ` + format: chisel-v1 + archives: + ubuntu: + version: 22.04 + components: [main, other] + suites: [jammy, jammy-security] + public-keys: [test-key] + madeUpKey1: whatever + madeUpKey2: whatever + public-keys: + test-key: + id: ` + testKey.ID + ` + armor: |` + "\n" + testutil.PrefixEachLine(testKey.ArmoredPublicKey, "\t\t\t\t\t\t") + ` + madeUpKey6: whatever + `, + "slices/mydir/mypkg.yaml": ` + package: mypkg + madeUpKey3: whatever + slices: + myslice: + madeUpKey4: whatever + contents: + /path: {madeUpKey5: whatever} + `, + }, + release: &setup.Release{ + DefaultArchive: "ubuntu", + + Archives: map[string]*setup.Archive{ + "ubuntu": { + Name: "ubuntu", + Version: "22.04", + Suites: []string{"jammy", "jammy-security"}, + Components: []string{"main", "other"}, + PublicKeys: []*packet.PublicKey{testKey.PublicKey}, + }, + }, + Packages: map[string]*setup.Package{ + "mypkg": { + Archive: "ubuntu", + Name: "mypkg", + Path: "slices/mydir/mypkg.yaml", + Slices: map[string]*setup.Slice{ + "myslice": { + Package: "mypkg", + Name: "myslice", + Contents: map[string]setup.PathInfo{ + "/path": {Kind: "copy"}, + }, + }, + }, + }, + }, + }, }, { summary: "Archives with public keys", input: map[string]string{