Skip to content

Commit

Permalink
base/v0_6_exp: Validate merged/replaced Ingition Configs
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam0Brien committed Jul 27, 2023
1 parent 546d1ff commit 11a4472
Show file tree
Hide file tree
Showing 18 changed files with 1,089 additions and 51 deletions.
15 changes: 15 additions & 0 deletions base/v0_6_exp/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package v0_6_exp
import (
baseutil "github.com/coreos/butane/base/util"
"github.com/coreos/butane/config/common"
exp "github.com/coreos/ignition/v2/config/v3_5_experimental"

"github.com/coreos/ignition/v2/config/util"
"github.com/coreos/vcontext/path"
Expand All @@ -29,10 +30,24 @@ func (rs Resource) Validate(c path.ContextPath) (r report.Report) {
if rs.Local != nil {
sources++
field = "local"
rsLocalBytes := []byte(*rs.Local)
_, report, err := exp.ParseCompatibleVersion(rsLocalBytes)
if err != nil {
r.AddOnError(c.Append("ignition", "config", "merge", "local"), common.ErrTooManyResourceSources)
} else {
r.Merge(report)
}
}
if rs.Inline != nil {
sources++
field = "inline"
rsInlineBytes := []byte(*rs.Inline)
_, report, err := exp.ParseCompatibleVersion(rsInlineBytes)
if err == nil {
r.AddOnError(c.Append("ignition", "config", "merge", "inline"), common.ErrTooManyResourceSources)
} else {
r.Merge(report)
}
}
if rs.Source != nil {
sources++
Expand Down
1 change: 0 additions & 1 deletion config/common/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ var (
// high-level errors for fatal reports
ErrInvalidSourceConfig = errors.New("source config is invalid")
ErrInvalidGeneratedConfig = errors.New("config generated was invalid")
ErrInvalidFileExtension = errors.New("file type provided was invalid; use .ign for local/inline instead")

// deprecated variant/version
ErrRhcosVariantUnsupported = errors.New("rhcos variant has been removed; use openshift variant instead: https://coreos.github.io/butane/upgrading-openshift/")
Expand Down
13 changes: 0 additions & 13 deletions config/fcos/v1_6_exp/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
const rootDevice = "/dev/disk/by-id/coreos-boot-disk"

var allowedMountpoints = regexp.MustCompile(`^/(etc|var)(/|$)`)
var fileExt = regexp.MustCompile("^(.ign)$")

// We can't define a Validate function directly on Disk because that's defined in base,
// so we use a Validate function on the top-level Config instead.
Expand All @@ -46,18 +45,6 @@ func (conf Config) Validate(c path.ContextPath) (r report.Report) {
r.AddOnError(c.Append("storage", "filesystems", i, "path"), common.ErrMountPointForbidden)
}
}

if conf.Ignition.Config.Merge != nil {
for i, conf := range conf.Ignition.Config.Merge {
if conf.Inline != nil && !fileExt.MatchString(string(*conf.Inline)) {
r.AddOnError(c.Append("ignition", "config", "merge", i, "inline"), common.ErrInvalidFileExtension)
}

if conf.Local != nil && !fileExt.MatchString(string(*conf.Local)) {
r.AddOnError(c.Append("ignition", "config", "merge", i, "local"), common.ErrInvalidFileExtension)
}
}
}
return
}

Expand Down
35 changes: 0 additions & 35 deletions config/fcos/v1_6_exp/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,38 +479,3 @@ func TestValidateConfig(t *testing.T) {
})
}
}

func TestValidateFileExtension(t *testing.T) {
tests := []struct {
in Config
out error
errPath path.ContextPath
}{
{
in: Config{
Config: base.Config{
Ignition: base.Ignition{
Config: base.IgnitionConfig{
Merge: []base.Resource{
{
Inline: util.StrToPtr("config.bu"),
},
},
},
},
},
},
out: common.ErrInvalidFileExtension,
errPath: path.New("yaml", "ignition", "config", "merge", 0, "inline"),
},
}
for i, test := range tests {
t.Run(fmt.Sprintf("validate %d", i), func(t *testing.T) {
actual := test.in.Validate(path.New("yaml"))
baseutil.VerifyReport(t, test.in, actual)
expected := report.Report{}
expected.AddOnError(test.errPath, test.out)
assert.Equal(t, expected, actual, "invalid report")
})
}
}
3 changes: 1 addition & 2 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ key](https://getfedora.org/security/).
openshift 4.14.0-exp)_
- Require `storage.filesystems.path` to start with `/etc` or `/var` if
`with_mount_unit` is true _(fcos 1.6.0-exp, openshift 4.14.0-exp)_
- Require local/inline fields from Ignition.Config.Merge to have the .ign file
extension _(fcos 1.6.0-exp)_
- Validate merged/replaced ignition configs if they are local/inline _(fcos 1.6.0-exp)_

### Bug fixes

Expand Down
187 changes: 187 additions & 0 deletions vendor/github.com/coreos/ignition/v2/config/translate/translate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 73 additions & 0 deletions vendor/github.com/coreos/ignition/v2/config/v3_0/config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 11a4472

Please sign in to comment.