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 d8b6402
Show file tree
Hide file tree
Showing 16 changed files with 1,088 additions and 48 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
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")
})
}
}
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 d8b6402

Please sign in to comment.