From a92e599c87da22fa17b2b19e9b7d0148b151a6cf Mon Sep 17 00:00:00 2001 From: ymmt Date: Fri, 21 Dec 2018 10:17:55 +0900 Subject: [PATCH 1/2] Update ignition to 0.30 and conform to spec version v2.3.0. https://coreos.com/ignition/docs/latest/configuration-v2_3.html --- go.mod | 2 +- ignition.go | 2 +- .../ignition/config/shared/errors/errors.go | 6 + .../ignition/config/util/parsingErrors.go | 2 +- .../coreos/ignition/config/v2_0/append.go | 73 ---- .../coreos/ignition/config/v2_1/append.go | 72 ---- .../coreos/ignition/config/v2_1/types/url.go | 9 +- .../coreos/ignition/config/v2_2/append.go | 76 ---- .../coreos/ignition/config/v2_2/types/url.go | 9 +- .../coreos/ignition/config/v2_3/cloudinit.go | 53 +++ .../coreos/ignition/config/v2_3/config.go | 70 ++++ .../coreos/ignition/config/v2_3/translate.go | 380 ++++++++++++++++++ .../{v2_3_experimental => v2_3}/types/ca.go | 0 .../ignition/config/v2_3/types/config.go | 91 +++++ .../types/directory.go | 0 .../{v2_3_experimental => v2_3}/types/disk.go | 20 + .../{v2_3_experimental => v2_3}/types/file.go | 0 .../types/filesystem.go | 0 .../types/ignition.go | 0 .../{v2_3_experimental => v2_3}/types/mode.go | 0 .../{v2_3_experimental => v2_3}/types/node.go | 0 .../types/partition.go | 26 +- .../types/passwd.go | 0 .../{v2_3_experimental => v2_3}/types/path.go | 0 .../{v2_3_experimental => v2_3}/types/raid.go | 0 .../types/schema.go | 2 + .../{v2_3_experimental => v2_3}/types/unit.go | 0 .../{v2_3_experimental => v2_3}/types/url.go | 9 +- .../types/verification.go | 0 .../link.go => v2_4_experimental/types/ca.go} | 18 +- .../types/config.go | 2 +- .../types/directory.go} | 22 +- .../config/v2_4_experimental/types/disk.go | 164 ++++++++ .../config/v2_4_experimental/types/file.go | 71 ++++ .../v2_4_experimental/types/filesystem.go | 146 +++++++ .../v2_4_experimental/types/ignition.go | 52 +++ .../types/mode.go} | 17 +- .../config/v2_4_experimental/types/node.go | 73 ++++ .../v2_4_experimental/types/partition.go | 112 ++++++ .../config/v2_4_experimental/types/passwd.go | 67 +++ .../config/v2_4_experimental/types/path.go | 28 ++ .../config/v2_4_experimental/types/raid.go | 57 +++ .../config/v2_4_experimental/types/schema.go | 250 ++++++++++++ .../config/v2_4_experimental/types/unit.go | 131 ++++++ .../config/v2_4_experimental/types/url.go | 53 +++ .../v2_4_experimental/types/verification.go | 77 ++++ vendor/modules.txt | 16 +- 47 files changed, 1989 insertions(+), 269 deletions(-) delete mode 100644 vendor/github.com/coreos/ignition/config/v2_0/append.go delete mode 100644 vendor/github.com/coreos/ignition/config/v2_1/append.go delete mode 100644 vendor/github.com/coreos/ignition/config/v2_2/append.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_3/cloudinit.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_3/config.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_3/translate.go rename vendor/github.com/coreos/ignition/config/{v2_3_experimental => v2_3}/types/ca.go (100%) create mode 100644 vendor/github.com/coreos/ignition/config/v2_3/types/config.go rename vendor/github.com/coreos/ignition/config/{v2_3_experimental => v2_3}/types/directory.go (100%) rename vendor/github.com/coreos/ignition/config/{v2_3_experimental => v2_3}/types/disk.go (90%) rename vendor/github.com/coreos/ignition/config/{v2_3_experimental => v2_3}/types/file.go (100%) rename vendor/github.com/coreos/ignition/config/{v2_3_experimental => v2_3}/types/filesystem.go (100%) rename vendor/github.com/coreos/ignition/config/{v2_3_experimental => v2_3}/types/ignition.go (100%) rename vendor/github.com/coreos/ignition/config/{v2_3_experimental => v2_3}/types/mode.go (100%) rename vendor/github.com/coreos/ignition/config/{v2_3_experimental => v2_3}/types/node.go (100%) rename vendor/github.com/coreos/ignition/config/{v2_3_experimental => v2_3}/types/partition.go (77%) rename vendor/github.com/coreos/ignition/config/{v2_3_experimental => v2_3}/types/passwd.go (100%) rename vendor/github.com/coreos/ignition/config/{v2_3_experimental => v2_3}/types/path.go (100%) rename vendor/github.com/coreos/ignition/config/{v2_3_experimental => v2_3}/types/raid.go (100%) rename vendor/github.com/coreos/ignition/config/{v2_3_experimental => v2_3}/types/schema.go (98%) rename vendor/github.com/coreos/ignition/config/{v2_3_experimental => v2_3}/types/unit.go (100%) rename vendor/github.com/coreos/ignition/config/{v2_3_experimental => v2_3}/types/url.go (84%) rename vendor/github.com/coreos/ignition/config/{v2_3_experimental => v2_3}/types/verification.go (100%) rename vendor/github.com/coreos/ignition/config/{v2_2/types/link.go => v2_4_experimental/types/ca.go} (70%) rename vendor/github.com/coreos/ignition/config/{v2_3_experimental => v2_4_experimental}/types/config.go (99%) rename vendor/github.com/coreos/ignition/config/{v2_1/types/link.go => v2_4_experimental/types/directory.go} (66%) create mode 100644 vendor/github.com/coreos/ignition/config/v2_4_experimental/types/disk.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_4_experimental/types/file.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_4_experimental/types/filesystem.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_4_experimental/types/ignition.go rename vendor/github.com/coreos/ignition/config/{v2_3_experimental/types/link.go => v2_4_experimental/types/mode.go} (67%) create mode 100644 vendor/github.com/coreos/ignition/config/v2_4_experimental/types/node.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_4_experimental/types/partition.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_4_experimental/types/passwd.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_4_experimental/types/path.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_4_experimental/types/raid.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_4_experimental/types/schema.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_4_experimental/types/unit.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_4_experimental/types/url.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_4_experimental/types/verification.go diff --git a/go.mod b/go.mod index 0734e5cd..f932c9a3 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 // indirect github.com/coreos/etcd v3.3.10+incompatible github.com/coreos/go-systemd v0.0.0-20181031085051-9002847aa142 // indirect - github.com/coreos/ignition v0.28.0 + github.com/coreos/ignition v0.30.0 github.com/cybozu-go/etcdutil v1.3.1 github.com/cybozu-go/log v1.5.0 github.com/cybozu-go/netutil v1.2.0 diff --git a/ignition.go b/ignition.go index f075cbe1..71189193 100644 --- a/ignition.go +++ b/ignition.go @@ -8,7 +8,7 @@ import ( "net/url" "text/template" - ignition "github.com/coreos/ignition/config/v2_2" + ignition "github.com/coreos/ignition/config/v2_3" "github.com/vincent-petithory/dataurl" yaml "gopkg.in/yaml.v2" ) diff --git a/vendor/github.com/coreos/ignition/config/shared/errors/errors.go b/vendor/github.com/coreos/ignition/config/shared/errors/errors.go index 9700b058..81e85762 100644 --- a/vendor/github.com/coreos/ignition/config/shared/errors/errors.go +++ b/vendor/github.com/coreos/ignition/config/shared/errors/errors.go @@ -64,6 +64,9 @@ var ( ErrUnrecognizedRaidLevel = errors.New("unrecognized raid level") ErrShouldNotExistWithOthers = errors.New("shouldExist specified false with other options also specified") ErrZeroesWithShouldNotExist = errors.New("shouldExist is false for a partition and other partition(s) has start or size 0") + ErrPartitionsUnitsMismatch = errors.New("cannot mix MBs and sectors within a disk") + ErrSizeDeprecated = errors.New("size is deprecated; use sizeMB instead") + ErrStartDeprecated = errors.New("start is deprecated; use startMB instead") // Passwd section errors ErrPasswdCreateDeprecated = errors.New("the create object has been deprecated in favor of user-level options") @@ -91,6 +94,9 @@ var ( ErrHashWrongSize = errors.New("incorrect size for hash sum") ErrHashUnrecognized = errors.New("unrecognized hash function") ErrEngineConfiguration = errors.New("engine incorrectly configured") + + // AWS S3 specific errors + ErrInvalidS3ObjectVersionId = errors.New("invalid S3 object VersionId") ) // NewNoInstallSectionError produces an error indicating the given unit, named diff --git a/vendor/github.com/coreos/ignition/config/util/parsingErrors.go b/vendor/github.com/coreos/ignition/config/util/parsingErrors.go index 6b6b114d..aee77826 100644 --- a/vendor/github.com/coreos/ignition/config/util/parsingErrors.go +++ b/vendor/github.com/coreos/ignition/config/util/parsingErrors.go @@ -19,7 +19,7 @@ import ( "errors" configErrors "github.com/coreos/ignition/config/shared/errors" - "github.com/coreos/ignition/config/v2_3_experimental/types" + "github.com/coreos/ignition/config/v2_4_experimental/types" "github.com/coreos/ignition/config/validate/report" json "github.com/ajeddeloh/go-json" diff --git a/vendor/github.com/coreos/ignition/config/v2_0/append.go b/vendor/github.com/coreos/ignition/config/v2_0/append.go deleted file mode 100644 index cee6bc41..00000000 --- a/vendor/github.com/coreos/ignition/config/v2_0/append.go +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2016 CoreOS, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2_0 - -import ( - "reflect" - - "github.com/coreos/ignition/config/v2_0/types" -) - -// Append appends newConfig to oldConfig and returns the result. Appending one -// config to another is accomplished by iterating over every field in the -// config structure, appending slices, recursively appending structs, and -// overwriting old values with new values for all other types. -func Append(oldConfig, newConfig types.Config) types.Config { - vOld := reflect.ValueOf(oldConfig) - vNew := reflect.ValueOf(newConfig) - - vResult := appendStruct(vOld, vNew) - - return vResult.Interface().(types.Config) -} - -// appendStruct is an internal helper function to AppendConfig. Given two values -// of structures (assumed to be the same type), recursively iterate over every -// field in the struct, appending slices, recursively appending structs, and -// overwriting old values with the new for all other types. Individual fields -// are able to override their merge strategy using the "merge" tag. Accepted -// values are "new" or "old": "new" uses the new value, "old" uses the old -// value. These are currently only used for "ignition.config" and -// "ignition.version". -func appendStruct(vOld, vNew reflect.Value) reflect.Value { - tOld := vOld.Type() - vRes := reflect.New(tOld) - - for i := 0; i < tOld.NumField(); i++ { - vfOld := vOld.Field(i) - vfNew := vNew.Field(i) - vfRes := vRes.Elem().Field(i) - - switch tOld.Field(i).Tag.Get("merge") { - case "old": - vfRes.Set(vfOld) - continue - case "new": - vfRes.Set(vfNew) - continue - } - - switch vfOld.Type().Kind() { - case reflect.Struct: - vfRes.Set(appendStruct(vfOld, vfNew)) - case reflect.Slice: - vfRes.Set(reflect.AppendSlice(vfOld, vfNew)) - default: - vfRes.Set(vfNew) - } - } - - return vRes.Elem() -} diff --git a/vendor/github.com/coreos/ignition/config/v2_1/append.go b/vendor/github.com/coreos/ignition/config/v2_1/append.go deleted file mode 100644 index b1517b73..00000000 --- a/vendor/github.com/coreos/ignition/config/v2_1/append.go +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright 2016 CoreOS, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2_1 - -import ( - "reflect" - - "github.com/coreos/ignition/config/v2_1/types" -) - -// Append appends newConfig to oldConfig and returns the result. Appending one -// config to another is accomplished by iterating over every field in the -// config structure, appending slices, recursively appending structs, and -// overwriting old values with new values for all other types. -func Append(oldConfig, newConfig types.Config) types.Config { - vOld := reflect.ValueOf(oldConfig) - vNew := reflect.ValueOf(newConfig) - - vResult := appendStruct(vOld, vNew) - - return vResult.Interface().(types.Config) -} - -// appendStruct is an internal helper function to AppendConfig. Given two values -// of structures (assumed to be the same type), recursively iterate over every -// field in the struct, appending slices, recursively appending structs, and -// overwriting old values with the new for all other types. Some individual -// struct fields have alternate merge strategies, determined by the field name. -// Currently these fields are "ignition.version", which uses the old value, and -// "ignition.config" which uses the new value. -func appendStruct(vOld, vNew reflect.Value) reflect.Value { - tOld := vOld.Type() - vRes := reflect.New(tOld) - - for i := 0; i < tOld.NumField(); i++ { - vfOld := vOld.Field(i) - vfNew := vNew.Field(i) - vfRes := vRes.Elem().Field(i) - - switch tOld.Field(i).Name { - case "Version": - vfRes.Set(vfOld) - continue - case "Config": - vfRes.Set(vfNew) - continue - } - - switch vfOld.Type().Kind() { - case reflect.Struct: - vfRes.Set(appendStruct(vfOld, vfNew)) - case reflect.Slice: - vfRes.Set(reflect.AppendSlice(vfOld, vfNew)) - default: - vfRes.Set(vfNew) - } - } - - return vRes.Elem() -} diff --git a/vendor/github.com/coreos/ignition/config/v2_1/types/url.go b/vendor/github.com/coreos/ignition/config/v2_1/types/url.go index 0fdc4a17..648328ac 100644 --- a/vendor/github.com/coreos/ignition/config/v2_1/types/url.go +++ b/vendor/github.com/coreos/ignition/config/v2_1/types/url.go @@ -32,7 +32,14 @@ func validateURL(s string) error { } switch u.Scheme { - case "http", "https", "oem", "tftp", "s3": + case "http", "https", "oem", "tftp": + return nil + case "s3": + if v, ok := u.Query()["versionId"]; ok { + if len(v) == 0 || v[0] == "" { + return errors.ErrInvalidS3ObjectVersionId + } + } return nil case "data": if _, err := dataurl.DecodeString(s); err != nil { diff --git a/vendor/github.com/coreos/ignition/config/v2_2/append.go b/vendor/github.com/coreos/ignition/config/v2_2/append.go deleted file mode 100644 index cf28f409..00000000 --- a/vendor/github.com/coreos/ignition/config/v2_2/append.go +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright 2016 CoreOS, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2_2 - -import ( - "reflect" - - "github.com/coreos/ignition/config/v2_2/types" -) - -// Append appends newConfig to oldConfig and returns the result. Appending one -// config to another is accomplished by iterating over every field in the -// config structure, appending slices, recursively appending structs, and -// overwriting old values with new values for all other types. -func Append(oldConfig, newConfig types.Config) types.Config { - vOld := reflect.ValueOf(oldConfig) - vNew := reflect.ValueOf(newConfig) - - vResult := appendStruct(vOld, vNew) - - return vResult.Interface().(types.Config) -} - -// appendStruct is an internal helper function to AppendConfig. Given two values -// of structures (assumed to be the same type), recursively iterate over every -// field in the struct, appending slices, recursively appending structs, and -// overwriting old values with the new for all other types. Some individual -// struct fields have alternate merge strategies, determined by the field name. -// Currently these fields are "ignition.version", which uses the old value, and -// "ignition.config" which uses the new value. -func appendStruct(vOld, vNew reflect.Value) reflect.Value { - tOld := vOld.Type() - vRes := reflect.New(tOld) - - for i := 0; i < tOld.NumField(); i++ { - vfOld := vOld.Field(i) - vfNew := vNew.Field(i) - vfRes := vRes.Elem().Field(i) - - switch tOld.Field(i).Name { - case "Version": - vfRes.Set(vfOld) - continue - case "Config": - vfRes.Set(vfNew) - continue - } - - switch vfOld.Type().Kind() { - case reflect.Struct: - vfRes.Set(appendStruct(vfOld, vfNew)) - case reflect.Slice: - vfRes.Set(reflect.AppendSlice(vfOld, vfNew)) - default: - if vfNew.Kind() == reflect.Ptr && vfNew.IsNil() { - vfRes.Set(vfOld) - } else { - vfRes.Set(vfNew) - } - } - } - - return vRes.Elem() -} diff --git a/vendor/github.com/coreos/ignition/config/v2_2/types/url.go b/vendor/github.com/coreos/ignition/config/v2_2/types/url.go index 2e90ff6d..11148fc0 100644 --- a/vendor/github.com/coreos/ignition/config/v2_2/types/url.go +++ b/vendor/github.com/coreos/ignition/config/v2_2/types/url.go @@ -33,7 +33,14 @@ func validateURL(s string) error { } switch u.Scheme { - case "http", "https", "oem", "tftp", "s3": + case "http", "https", "oem", "tftp": + return nil + case "s3": + if v, ok := u.Query()["versionId"]; ok { + if len(v) == 0 || v[0] == "" { + return errors.ErrInvalidS3ObjectVersionId + } + } return nil case "data": if _, err := dataurl.DecodeString(s); err != nil { diff --git a/vendor/github.com/coreos/ignition/config/v2_3/cloudinit.go b/vendor/github.com/coreos/ignition/config/v2_3/cloudinit.go new file mode 100644 index 00000000..3b83fbd9 --- /dev/null +++ b/vendor/github.com/coreos/ignition/config/v2_3/cloudinit.go @@ -0,0 +1,53 @@ +// Copyright 2015 CoreOS, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// These functions are copied from github.com/coreos/coreos-cloudinit/config. + +package v2_3 + +import ( + "bytes" + "compress/gzip" + "io/ioutil" + "strings" + "unicode" +) + +func isCloudConfig(userdata []byte) bool { + header := strings.SplitN(string(decompressIfGzipped(userdata)), "\n", 2)[0] + + // Trim trailing whitespaces + header = strings.TrimRightFunc(header, unicode.IsSpace) + + return (header == "#cloud-config") +} + +func isScript(userdata []byte) bool { + header := strings.SplitN(string(decompressIfGzipped(userdata)), "\n", 2)[0] + return strings.HasPrefix(header, "#!") +} + +func decompressIfGzipped(data []byte) []byte { + if reader, err := gzip.NewReader(bytes.NewReader(data)); err == nil { + uncompressedData, err := ioutil.ReadAll(reader) + reader.Close() + if err == nil { + return uncompressedData + } else { + return data + } + } else { + return data + } +} diff --git a/vendor/github.com/coreos/ignition/config/v2_3/config.go b/vendor/github.com/coreos/ignition/config/v2_3/config.go new file mode 100644 index 00000000..ebe884c3 --- /dev/null +++ b/vendor/github.com/coreos/ignition/config/v2_3/config.go @@ -0,0 +1,70 @@ +// Copyright 2015 CoreOS, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package v2_3 + +import ( + "github.com/coreos/ignition/config/shared/errors" + "github.com/coreos/ignition/config/v2_2" + "github.com/coreos/ignition/config/v2_3/types" + "github.com/coreos/ignition/config/validate" + "github.com/coreos/ignition/config/validate/report" + + json "github.com/ajeddeloh/go-json" + "github.com/coreos/go-semver/semver" +) + +// Parse parses the raw config into a types.Config struct and generates a report of any +// errors, warnings, info, and deprecations it encountered +func Parse(rawConfig []byte) (types.Config, report.Report, error) { + if isEmpty(rawConfig) { + return types.Config{}, report.Report{}, errors.ErrEmpty + } else if isCloudConfig(rawConfig) { + return types.Config{}, report.Report{}, errors.ErrCloudConfig + } else if isScript(rawConfig) { + return types.Config{}, report.Report{}, errors.ErrScript + } + + var err error + var config types.Config + + err = json.Unmarshal(rawConfig, &config) + + version, semverErr := semver.NewVersion(config.Ignition.Version) + + if err != nil || semverErr != nil || version.LessThan(types.MaxVersion) { + // We can fail unmarshaling if it's an older config. Attempt to parse + // it as such. + config, rpt, err := v2_2.Parse(rawConfig) + if err != nil { + return types.Config{}, rpt, err + } + return Translate(config), rpt, err + } + + if *version != types.MaxVersion { + return types.Config{}, report.Report{}, errors.ErrUnknownVersion + } + + rpt := validate.ValidateConfig(rawConfig, config) + if rpt.IsFatal() { + return types.Config{}, rpt, errors.ErrInvalid + } + + return config, rpt, nil +} + +func isEmpty(userdata []byte) bool { + return len(userdata) == 0 +} diff --git a/vendor/github.com/coreos/ignition/config/v2_3/translate.go b/vendor/github.com/coreos/ignition/config/v2_3/translate.go new file mode 100644 index 00000000..c1a9b2b1 --- /dev/null +++ b/vendor/github.com/coreos/ignition/config/v2_3/translate.go @@ -0,0 +1,380 @@ +// Copyright 2018 CoreOS, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package v2_3 + +import ( + "github.com/coreos/ignition/config/util" + v2_2 "github.com/coreos/ignition/config/v2_2/types" + "github.com/coreos/ignition/config/v2_3/types" +) + +func Translate(old v2_2.Config) types.Config { + translateConfigReference := func(old *v2_2.ConfigReference) *types.ConfigReference { + if old == nil { + return nil + } + return &types.ConfigReference{ + Source: old.Source, + Verification: types.Verification{ + Hash: old.Verification.Hash, + }, + } + } + translateConfigReferenceSlice := func(old []v2_2.ConfigReference) []types.ConfigReference { + var res []types.ConfigReference + for _, c := range old { + res = append(res, *translateConfigReference(&c)) + } + return res + } + translateCertificateAuthoritySlice := func(old []v2_2.CaReference) []types.CaReference { + var res []types.CaReference + for _, x := range old { + res = append(res, types.CaReference{ + Source: x.Source, + Verification: types.Verification{ + Hash: x.Verification.Hash, + }, + }) + } + return res + } + translateNetworkdDropinSlice := func(old []v2_2.NetworkdDropin) []types.NetworkdDropin { + var res []types.NetworkdDropin + for _, x := range old { + res = append(res, types.NetworkdDropin{ + Contents: x.Contents, + Name: x.Name, + }) + } + return res + } + translateNetworkdUnitSlice := func(old []v2_2.Networkdunit) []types.Networkdunit { + var res []types.Networkdunit + for _, u := range old { + res = append(res, types.Networkdunit{ + Contents: u.Contents, + Name: u.Name, + Dropins: translateNetworkdDropinSlice(u.Dropins), + }) + } + return res + } + translatePasswdGroupSlice := func(old []v2_2.PasswdGroup) []types.PasswdGroup { + var res []types.PasswdGroup + for _, g := range old { + res = append(res, types.PasswdGroup{ + Gid: g.Gid, + Name: g.Name, + PasswordHash: g.PasswordHash, + System: g.System, + }) + } + return res + } + translatePasswdUsercreateGroupSlice := func(old []v2_2.UsercreateGroup) []types.UsercreateGroup { + var res []types.UsercreateGroup + for _, g := range old { + res = append(res, types.UsercreateGroup(g)) + } + return res + } + translatePasswdUsercreate := func(old *v2_2.Usercreate) *types.Usercreate { + if old == nil { + return nil + } + return &types.Usercreate{ + Gecos: old.Gecos, + Groups: translatePasswdUsercreateGroupSlice(old.Groups), + HomeDir: old.HomeDir, + NoCreateHome: old.NoCreateHome, + NoLogInit: old.NoLogInit, + NoUserGroup: old.NoUserGroup, + PrimaryGroup: old.PrimaryGroup, + Shell: old.Shell, + System: old.System, + UID: old.UID, + } + } + translatePasswdUserGroupSlice := func(old []v2_2.Group) []types.Group { + var res []types.Group + for _, g := range old { + res = append(res, types.Group(g)) + } + return res + } + translatePasswdSSHAuthorizedKeySlice := func(old []v2_2.SSHAuthorizedKey) []types.SSHAuthorizedKey { + res := make([]types.SSHAuthorizedKey, len(old)) + for i, k := range old { + res[i] = types.SSHAuthorizedKey(k) + } + return res + } + translatePasswdUserSlice := func(old []v2_2.PasswdUser) []types.PasswdUser { + var res []types.PasswdUser + for _, u := range old { + res = append(res, types.PasswdUser{ + Create: translatePasswdUsercreate(u.Create), + Gecos: u.Gecos, + Groups: translatePasswdUserGroupSlice(u.Groups), + HomeDir: u.HomeDir, + Name: u.Name, + NoCreateHome: u.NoCreateHome, + NoLogInit: u.NoLogInit, + NoUserGroup: u.NoUserGroup, + PasswordHash: u.PasswordHash, + PrimaryGroup: u.PrimaryGroup, + SSHAuthorizedKeys: translatePasswdSSHAuthorizedKeySlice(u.SSHAuthorizedKeys), + Shell: u.Shell, + System: u.System, + UID: u.UID, + }) + } + return res + } + translateNodeGroup := func(old *v2_2.NodeGroup) *types.NodeGroup { + if old == nil { + return nil + } + return &types.NodeGroup{ + ID: old.ID, + Name: old.Name, + } + } + translateNodeUser := func(old *v2_2.NodeUser) *types.NodeUser { + if old == nil { + return nil + } + return &types.NodeUser{ + ID: old.ID, + Name: old.Name, + } + } + translateNode := func(old v2_2.Node) types.Node { + return types.Node{ + Filesystem: old.Filesystem, + Group: translateNodeGroup(old.Group), + Path: old.Path, + User: translateNodeUser(old.User), + Overwrite: old.Overwrite, + } + } + translateDirectorySlice := func(old []v2_2.Directory) []types.Directory { + var res []types.Directory + for _, x := range old { + res = append(res, types.Directory{ + Node: translateNode(x.Node), + DirectoryEmbedded1: types.DirectoryEmbedded1{ + Mode: x.DirectoryEmbedded1.Mode, + }, + }) + } + return res + } + translatePartitionSlice := func(old []v2_2.Partition) []types.Partition { + var res []types.Partition + for _, x := range old { + res = append(res, types.Partition{ + GUID: x.GUID, + Label: util.StrToPtrStrict(x.Label), + Number: x.Number, + Size: util.IntToPtr(x.Size), + Start: util.IntToPtr(x.Start), + TypeGUID: x.TypeGUID, + }) + } + return res + } + translateDiskSlice := func(old []v2_2.Disk) []types.Disk { + var res []types.Disk + for _, x := range old { + res = append(res, types.Disk{ + Device: x.Device, + Partitions: translatePartitionSlice(x.Partitions), + WipeTable: x.WipeTable, + }) + } + return res + } + translateFileSlice := func(old []v2_2.File) []types.File { + var res []types.File + for _, x := range old { + res = append(res, types.File{ + Node: translateNode(x.Node), + FileEmbedded1: types.FileEmbedded1{ + Contents: types.FileContents{ + Compression: x.Contents.Compression, + Source: x.Contents.Source, + Verification: types.Verification{ + Hash: x.Contents.Verification.Hash, + }, + }, + Mode: x.Mode, + Append: x.Append, + }, + }) + } + return res + } + translateMountCreateOptionSlice := func(old []v2_2.CreateOption) []types.CreateOption { + var res []types.CreateOption + for _, x := range old { + res = append(res, types.CreateOption(x)) + } + return res + } + translateMountCreate := func(old *v2_2.Create) *types.Create { + if old == nil { + return nil + } + return &types.Create{ + Force: old.Force, + Options: translateMountCreateOptionSlice(old.Options), + } + } + translateMountOptionSlice := func(old []v2_2.MountOption) []types.MountOption { + var res []types.MountOption + for _, x := range old { + res = append(res, types.MountOption(x)) + } + return res + } + translateMount := func(old *v2_2.Mount) *types.Mount { + if old == nil { + return nil + } + return &types.Mount{ + Create: translateMountCreate(old.Create), + Device: old.Device, + Format: old.Format, + Label: old.Label, + Options: translateMountOptionSlice(old.Options), + UUID: old.UUID, + WipeFilesystem: old.WipeFilesystem, + } + } + translateFilesystemSlice := func(old []v2_2.Filesystem) []types.Filesystem { + var res []types.Filesystem + for _, x := range old { + res = append(res, types.Filesystem{ + Mount: translateMount(x.Mount), + Name: x.Name, + Path: x.Path, + }) + } + return res + } + translateLinkSlice := func(old []v2_2.Link) []types.Link { + var res []types.Link + for _, x := range old { + res = append(res, types.Link{ + Node: translateNode(x.Node), + LinkEmbedded1: types.LinkEmbedded1{ + Hard: x.Hard, + Target: x.Target, + }, + }) + } + return res + } + translateDeviceSlice := func(old []v2_2.Device) []types.Device { + var res []types.Device + for _, x := range old { + res = append(res, types.Device(x)) + } + return res + } + translateRaidOptionSlice := func(old []v2_2.RaidOption) []types.RaidOption { + var res []types.RaidOption + for _, x := range old { + res = append(res, types.RaidOption(x)) + } + return res + } + translateRaidSlice := func(old []v2_2.Raid) []types.Raid { + var res []types.Raid + for _, x := range old { + res = append(res, types.Raid{ + Devices: translateDeviceSlice(x.Devices), + Level: x.Level, + Name: x.Name, + Spares: x.Spares, + Options: translateRaidOptionSlice(x.Options), + }) + } + return res + } + translateSystemdDropinSlice := func(old []v2_2.SystemdDropin) []types.SystemdDropin { + var res []types.SystemdDropin + for _, x := range old { + res = append(res, types.SystemdDropin{ + Contents: x.Contents, + Name: x.Name, + }) + } + return res + } + translateSystemdUnitSlice := func(old []v2_2.Unit) []types.Unit { + var res []types.Unit + for _, x := range old { + res = append(res, types.Unit{ + Contents: x.Contents, + Dropins: translateSystemdDropinSlice(x.Dropins), + Enable: x.Enable, + Enabled: x.Enabled, + Mask: x.Mask, + Name: x.Name, + }) + } + return res + } + config := types.Config{ + Ignition: types.Ignition{ + Version: types.MaxVersion.String(), + Timeouts: types.Timeouts{ + HTTPResponseHeaders: old.Ignition.Timeouts.HTTPResponseHeaders, + HTTPTotal: old.Ignition.Timeouts.HTTPTotal, + }, + Config: types.IgnitionConfig{ + Replace: translateConfigReference(old.Ignition.Config.Replace), + Append: translateConfigReferenceSlice(old.Ignition.Config.Append), + }, + Security: types.Security{ + TLS: types.TLS{ + CertificateAuthorities: translateCertificateAuthoritySlice(old.Ignition.Security.TLS.CertificateAuthorities), + }, + }, + }, + Networkd: types.Networkd{ + Units: translateNetworkdUnitSlice(old.Networkd.Units), + }, + Passwd: types.Passwd{ + Groups: translatePasswdGroupSlice(old.Passwd.Groups), + Users: translatePasswdUserSlice(old.Passwd.Users), + }, + Storage: types.Storage{ + Directories: translateDirectorySlice(old.Storage.Directories), + Disks: translateDiskSlice(old.Storage.Disks), + Files: translateFileSlice(old.Storage.Files), + Filesystems: translateFilesystemSlice(old.Storage.Filesystems), + Links: translateLinkSlice(old.Storage.Links), + Raid: translateRaidSlice(old.Storage.Raid), + }, + Systemd: types.Systemd{ + Units: translateSystemdUnitSlice(old.Systemd.Units), + }, + } + return config +} diff --git a/vendor/github.com/coreos/ignition/config/v2_3_experimental/types/ca.go b/vendor/github.com/coreos/ignition/config/v2_3/types/ca.go similarity index 100% rename from vendor/github.com/coreos/ignition/config/v2_3_experimental/types/ca.go rename to vendor/github.com/coreos/ignition/config/v2_3/types/ca.go diff --git a/vendor/github.com/coreos/ignition/config/v2_3/types/config.go b/vendor/github.com/coreos/ignition/config/v2_3/types/config.go new file mode 100644 index 00000000..1e1668d8 --- /dev/null +++ b/vendor/github.com/coreos/ignition/config/v2_3/types/config.go @@ -0,0 +1,91 @@ +// Copyright 2015 CoreOS, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package types + +import ( + "fmt" + + "github.com/coreos/go-semver/semver" + + "github.com/coreos/ignition/config/validate/report" +) + +var ( + MaxVersion = semver.Version{ + Major: 2, + Minor: 3, + } +) + +func (c Config) Validate() report.Report { + r := report.Report{} + rules := []rule{ + checkFilesFilesystems, + checkDuplicateFilesystems, + } + + for _, rule := range rules { + rule(c, &r) + } + return r +} + +type rule func(cfg Config, report *report.Report) + +func checkNodeFilesystems(node Node, filesystems map[string]struct{}, nodeType string) report.Report { + r := report.Report{} + if node.Filesystem == "" { + // Filesystem was not specified. This is an error, but its handled in types.File's Validate, not here + return r + } + _, ok := filesystems[node.Filesystem] + if !ok { + r.Add(report.Entry{ + Kind: report.EntryWarning, + Message: fmt.Sprintf("%v %q references nonexistent filesystem %q. (This is ok if it is defined in a referenced config)", + nodeType, node.Path, node.Filesystem), + }) + } + return r +} + +func checkFilesFilesystems(cfg Config, r *report.Report) { + filesystems := map[string]struct{}{"root": {}} + for _, filesystem := range cfg.Storage.Filesystems { + filesystems[filesystem.Name] = struct{}{} + } + for _, file := range cfg.Storage.Files { + r.Merge(checkNodeFilesystems(file.Node, filesystems, "File")) + } + for _, link := range cfg.Storage.Links { + r.Merge(checkNodeFilesystems(link.Node, filesystems, "Link")) + } + for _, dir := range cfg.Storage.Directories { + r.Merge(checkNodeFilesystems(dir.Node, filesystems, "Directory")) + } +} + +func checkDuplicateFilesystems(cfg Config, r *report.Report) { + filesystems := map[string]struct{}{"root": {}} + for _, filesystem := range cfg.Storage.Filesystems { + if _, ok := filesystems[filesystem.Name]; ok { + r.Add(report.Entry{ + Kind: report.EntryWarning, + Message: fmt.Sprintf("Filesystem %q shadows exising filesystem definition", filesystem.Name), + }) + } + filesystems[filesystem.Name] = struct{}{} + } +} diff --git a/vendor/github.com/coreos/ignition/config/v2_3_experimental/types/directory.go b/vendor/github.com/coreos/ignition/config/v2_3/types/directory.go similarity index 100% rename from vendor/github.com/coreos/ignition/config/v2_3_experimental/types/directory.go rename to vendor/github.com/coreos/ignition/config/v2_3/types/directory.go diff --git a/vendor/github.com/coreos/ignition/config/v2_3_experimental/types/disk.go b/vendor/github.com/coreos/ignition/config/v2_3/types/disk.go similarity index 90% rename from vendor/github.com/coreos/ignition/config/v2_3_experimental/types/disk.go rename to vendor/github.com/coreos/ignition/config/v2_3/types/disk.go index ebffc2cd..1430b0fd 100644 --- a/vendor/github.com/coreos/ignition/config/v2_3_experimental/types/disk.go +++ b/vendor/github.com/coreos/ignition/config/v2_3/types/disk.go @@ -59,6 +59,12 @@ func (n Disk) ValidatePartitions() report.Report { Kind: report.EntryError, }) } + if n.partitionsUnitsMismatch() { + r.Add(report.Entry{ + Message: errors.ErrPartitionsUnitsMismatch.Error(), + Kind: report.EntryError, + }) + } // Disks which have no errors at this point will likely succeed in sgdisk return r } @@ -142,3 +148,17 @@ func (n Disk) partitionsMixZeroesAndNonexistence() bool { } return hasZero && hasShouldNotExist } + +func (n Disk) partitionsUnitsMismatch() bool { + partsInMb := false + partsNotInMb := false + for _, p := range n.Partitions { + if p.Size != nil || p.Start != nil { + partsNotInMb = true + } + if p.SizeMiB != nil || p.StartMiB != nil { + partsInMb = true + } + } + return partsInMb && partsNotInMb +} diff --git a/vendor/github.com/coreos/ignition/config/v2_3_experimental/types/file.go b/vendor/github.com/coreos/ignition/config/v2_3/types/file.go similarity index 100% rename from vendor/github.com/coreos/ignition/config/v2_3_experimental/types/file.go rename to vendor/github.com/coreos/ignition/config/v2_3/types/file.go diff --git a/vendor/github.com/coreos/ignition/config/v2_3_experimental/types/filesystem.go b/vendor/github.com/coreos/ignition/config/v2_3/types/filesystem.go similarity index 100% rename from vendor/github.com/coreos/ignition/config/v2_3_experimental/types/filesystem.go rename to vendor/github.com/coreos/ignition/config/v2_3/types/filesystem.go diff --git a/vendor/github.com/coreos/ignition/config/v2_3_experimental/types/ignition.go b/vendor/github.com/coreos/ignition/config/v2_3/types/ignition.go similarity index 100% rename from vendor/github.com/coreos/ignition/config/v2_3_experimental/types/ignition.go rename to vendor/github.com/coreos/ignition/config/v2_3/types/ignition.go diff --git a/vendor/github.com/coreos/ignition/config/v2_3_experimental/types/mode.go b/vendor/github.com/coreos/ignition/config/v2_3/types/mode.go similarity index 100% rename from vendor/github.com/coreos/ignition/config/v2_3_experimental/types/mode.go rename to vendor/github.com/coreos/ignition/config/v2_3/types/mode.go diff --git a/vendor/github.com/coreos/ignition/config/v2_3_experimental/types/node.go b/vendor/github.com/coreos/ignition/config/v2_3/types/node.go similarity index 100% rename from vendor/github.com/coreos/ignition/config/v2_3_experimental/types/node.go rename to vendor/github.com/coreos/ignition/config/v2_3/types/node.go diff --git a/vendor/github.com/coreos/ignition/config/v2_3_experimental/types/partition.go b/vendor/github.com/coreos/ignition/config/v2_3/types/partition.go similarity index 77% rename from vendor/github.com/coreos/ignition/config/v2_3_experimental/types/partition.go rename to vendor/github.com/coreos/ignition/config/v2_3/types/partition.go index 4e962b63..dbe38adc 100644 --- a/vendor/github.com/coreos/ignition/config/v2_3_experimental/types/partition.go +++ b/vendor/github.com/coreos/ignition/config/v2_3/types/partition.go @@ -28,9 +28,33 @@ const ( ) func (p Partition) Validate() report.Report { + r := report.Report{} + if (p.Start != nil || p.Size != nil) && (p.StartMiB != nil || p.SizeMiB != nil) { + r.Add(report.Entry{ + Message: errors.ErrPartitionsUnitsMismatch.Error(), + Kind: report.EntryError, + }) + } if p.ShouldExist != nil && !*p.ShouldExist && (p.Label != nil || p.TypeGUID != "" || p.GUID != "" || p.Start != nil || p.Size != nil) { - return report.ReportFromError(errors.ErrShouldNotExistWithOthers, report.EntryError) + r.Add(report.Entry{ + Message: errors.ErrShouldNotExistWithOthers.Error(), + Kind: report.EntryError, + }) + } + return r +} + +func (p Partition) ValidateSize() report.Report { + if p.Size != nil { + return report.ReportFromError(errors.ErrSizeDeprecated, report.EntryDeprecated) + } + return report.Report{} +} + +func (p Partition) ValidateStart() report.Report { + if p.Start != nil { + return report.ReportFromError(errors.ErrStartDeprecated, report.EntryDeprecated) } return report.Report{} } diff --git a/vendor/github.com/coreos/ignition/config/v2_3_experimental/types/passwd.go b/vendor/github.com/coreos/ignition/config/v2_3/types/passwd.go similarity index 100% rename from vendor/github.com/coreos/ignition/config/v2_3_experimental/types/passwd.go rename to vendor/github.com/coreos/ignition/config/v2_3/types/passwd.go diff --git a/vendor/github.com/coreos/ignition/config/v2_3_experimental/types/path.go b/vendor/github.com/coreos/ignition/config/v2_3/types/path.go similarity index 100% rename from vendor/github.com/coreos/ignition/config/v2_3_experimental/types/path.go rename to vendor/github.com/coreos/ignition/config/v2_3/types/path.go diff --git a/vendor/github.com/coreos/ignition/config/v2_3_experimental/types/raid.go b/vendor/github.com/coreos/ignition/config/v2_3/types/raid.go similarity index 100% rename from vendor/github.com/coreos/ignition/config/v2_3_experimental/types/raid.go rename to vendor/github.com/coreos/ignition/config/v2_3/types/raid.go diff --git a/vendor/github.com/coreos/ignition/config/v2_3_experimental/types/schema.go b/vendor/github.com/coreos/ignition/config/v2_3/types/schema.go similarity index 98% rename from vendor/github.com/coreos/ignition/config/v2_3_experimental/types/schema.go rename to vendor/github.com/coreos/ignition/config/v2_3/types/schema.go index 8d0da1dd..5f91b71e 100644 --- a/vendor/github.com/coreos/ignition/config/v2_3_experimental/types/schema.go +++ b/vendor/github.com/coreos/ignition/config/v2_3/types/schema.go @@ -142,7 +142,9 @@ type Partition struct { Number int `json:"number,omitempty"` ShouldExist *bool `json:"shouldExist,omitempty"` Size *int `json:"size,omitempty"` + SizeMiB *int `json:"sizeMiB,omitempty"` Start *int `json:"start,omitempty"` + StartMiB *int `json:"startMiB,omitempty"` TypeGUID string `json:"typeGuid,omitempty"` WipePartitionEntry bool `json:"wipePartitionEntry,omitempty"` } diff --git a/vendor/github.com/coreos/ignition/config/v2_3_experimental/types/unit.go b/vendor/github.com/coreos/ignition/config/v2_3/types/unit.go similarity index 100% rename from vendor/github.com/coreos/ignition/config/v2_3_experimental/types/unit.go rename to vendor/github.com/coreos/ignition/config/v2_3/types/unit.go diff --git a/vendor/github.com/coreos/ignition/config/v2_3_experimental/types/url.go b/vendor/github.com/coreos/ignition/config/v2_3/types/url.go similarity index 84% rename from vendor/github.com/coreos/ignition/config/v2_3_experimental/types/url.go rename to vendor/github.com/coreos/ignition/config/v2_3/types/url.go index 2e90ff6d..11148fc0 100644 --- a/vendor/github.com/coreos/ignition/config/v2_3_experimental/types/url.go +++ b/vendor/github.com/coreos/ignition/config/v2_3/types/url.go @@ -33,7 +33,14 @@ func validateURL(s string) error { } switch u.Scheme { - case "http", "https", "oem", "tftp", "s3": + case "http", "https", "oem", "tftp": + return nil + case "s3": + if v, ok := u.Query()["versionId"]; ok { + if len(v) == 0 || v[0] == "" { + return errors.ErrInvalidS3ObjectVersionId + } + } return nil case "data": if _, err := dataurl.DecodeString(s); err != nil { diff --git a/vendor/github.com/coreos/ignition/config/v2_3_experimental/types/verification.go b/vendor/github.com/coreos/ignition/config/v2_3/types/verification.go similarity index 100% rename from vendor/github.com/coreos/ignition/config/v2_3_experimental/types/verification.go rename to vendor/github.com/coreos/ignition/config/v2_3/types/verification.go diff --git a/vendor/github.com/coreos/ignition/config/v2_2/types/link.go b/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/ca.go similarity index 70% rename from vendor/github.com/coreos/ignition/config/v2_2/types/link.go rename to vendor/github.com/coreos/ignition/config/v2_4_experimental/types/ca.go index f0284425..7440e1e2 100644 --- a/vendor/github.com/coreos/ignition/config/v2_2/types/link.go +++ b/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/ca.go @@ -1,4 +1,4 @@ -// Copyright 2017 CoreOS, Inc. +// Copyright 2018 CoreOS, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -18,16 +18,10 @@ import ( "github.com/coreos/ignition/config/validate/report" ) -func (s LinkEmbedded1) ValidateTarget() report.Report { - r := report.Report{} - if !s.Hard { - err := validatePath(s.Target) - if err != nil { - r.Add(report.Entry{ - Message: err.Error(), - Kind: report.EntryError, - }) - } +func (c CaReference) ValidateSource() report.Report { + err := validateURL(c.Source) + if err != nil { + return report.ReportFromError(err, report.EntryError) } - return r + return report.Report{} } diff --git a/vendor/github.com/coreos/ignition/config/v2_3_experimental/types/config.go b/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/config.go similarity index 99% rename from vendor/github.com/coreos/ignition/config/v2_3_experimental/types/config.go rename to vendor/github.com/coreos/ignition/config/v2_4_experimental/types/config.go index cfef0ed9..e3a05e80 100644 --- a/vendor/github.com/coreos/ignition/config/v2_3_experimental/types/config.go +++ b/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/config.go @@ -25,7 +25,7 @@ import ( var ( MaxVersion = semver.Version{ Major: 2, - Minor: 3, + Minor: 4, PreRelease: "experimental", } ) diff --git a/vendor/github.com/coreos/ignition/config/v2_1/types/link.go b/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/directory.go similarity index 66% rename from vendor/github.com/coreos/ignition/config/v2_1/types/link.go rename to vendor/github.com/coreos/ignition/config/v2_4_experimental/types/directory.go index f0284425..9fdc732a 100644 --- a/vendor/github.com/coreos/ignition/config/v2_1/types/link.go +++ b/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/directory.go @@ -15,19 +15,23 @@ package types import ( + "github.com/coreos/ignition/config/shared/errors" "github.com/coreos/ignition/config/validate/report" ) -func (s LinkEmbedded1) ValidateTarget() report.Report { +func (d Directory) ValidateMode() report.Report { r := report.Report{} - if !s.Hard { - err := validatePath(s.Target) - if err != nil { - r.Add(report.Entry{ - Message: err.Error(), - Kind: report.EntryError, - }) - } + if err := validateMode(d.Mode); err != nil { + r.Add(report.Entry{ + Message: err.Error(), + Kind: report.EntryError, + }) + } + if d.Mode == nil { + r.Add(report.Entry{ + Message: errors.ErrPermissionsUnset.Error(), + Kind: report.EntryWarning, + }) } return r } diff --git a/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/disk.go b/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/disk.go new file mode 100644 index 00000000..1430b0fd --- /dev/null +++ b/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/disk.go @@ -0,0 +1,164 @@ +// Copyright 2016 CoreOS, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package types + +import ( + "github.com/coreos/ignition/config/shared/errors" + "github.com/coreos/ignition/config/validate/report" +) + +func (n Disk) Validate() report.Report { + return report.Report{} +} + +func (n Disk) ValidateDevice() report.Report { + if len(n.Device) == 0 { + return report.ReportFromError(errors.ErrDiskDeviceRequired, report.EntryError) + } + if err := validatePath(string(n.Device)); err != nil { + return report.ReportFromError(err, report.EntryError) + } + return report.Report{} +} + +func (n Disk) ValidatePartitions() report.Report { + r := report.Report{} + if n.partitionNumbersCollide() { + r.Add(report.Entry{ + Message: errors.ErrPartitionNumbersCollide.Error(), + Kind: report.EntryError, + }) + } + if n.partitionsOverlap() { + r.Add(report.Entry{ + Message: errors.ErrPartitionsOverlap.Error(), + Kind: report.EntryError, + }) + } + if n.partitionsMisaligned() { + r.Add(report.Entry{ + Message: errors.ErrPartitionsMisaligned.Error(), + Kind: report.EntryError, + }) + } + if n.partitionsMixZeroesAndNonexistence() { + r.Add(report.Entry{ + Message: errors.ErrZeroesWithShouldNotExist.Error(), + Kind: report.EntryError, + }) + } + if n.partitionsUnitsMismatch() { + r.Add(report.Entry{ + Message: errors.ErrPartitionsUnitsMismatch.Error(), + Kind: report.EntryError, + }) + } + // Disks which have no errors at this point will likely succeed in sgdisk + return r +} + +// partitionNumbersCollide returns true if partition numbers in n.Partitions are not unique. +func (n Disk) partitionNumbersCollide() bool { + m := map[int][]Partition{} + for _, p := range n.Partitions { + if p.Number != 0 { + // a number of 0 means next available number, multiple devices can specify this + m[p.Number] = append(m[p.Number], p) + } + } + for _, n := range m { + if len(n) > 1 { + // TODO(vc): return information describing the collision for logging + return true + } + } + return false +} + +// end returns the last sector of a partition. Only used by partitionsOverlap. Requires non-nil Start and Size. +func (p Partition) end() int { + if *p.Size == 0 { + // a size of 0 means "fill available", just return the start as the end for those. + return *p.Start + } + return *p.Start + *p.Size - 1 +} + +// partitionsOverlap returns true if any explicitly dimensioned partitions overlap +func (n Disk) partitionsOverlap() bool { + for _, p := range n.Partitions { + // Starts of 0 are placed by sgdisk into the "largest available block" at that time. + // We aren't going to check those for overlap since we don't have the disk geometry. + if p.Start == nil || p.Size == nil || *p.Start == 0 { + continue + } + + for _, o := range n.Partitions { + if o.Start == nil || o.Size == nil || p == o || *o.Start == 0 { + continue + } + + // is p.Start within o? + if *p.Start >= *o.Start && *p.Start <= o.end() { + return true + } + + // is p.end() within o? + if p.end() >= *o.Start && p.end() <= o.end() { + return true + } + + // do p.Start and p.end() straddle o? + if *p.Start < *o.Start && p.end() > o.end() { + return true + } + } + } + return false +} + +// partitionsMisaligned returns true if any of the partitions don't start on a 2048-sector (1MiB) boundary. +func (n Disk) partitionsMisaligned() bool { + for _, p := range n.Partitions { + if p.Start != nil && ((*p.Start & (2048 - 1)) != 0) { + return true + } + } + return false +} + +func (n Disk) partitionsMixZeroesAndNonexistence() bool { + hasZero := false + hasShouldNotExist := false + for _, p := range n.Partitions { + hasShouldNotExist = hasShouldNotExist || (p.ShouldExist != nil && !*p.ShouldExist) + hasZero = hasZero || (p.Number == 0) + } + return hasZero && hasShouldNotExist +} + +func (n Disk) partitionsUnitsMismatch() bool { + partsInMb := false + partsNotInMb := false + for _, p := range n.Partitions { + if p.Size != nil || p.Start != nil { + partsNotInMb = true + } + if p.SizeMiB != nil || p.StartMiB != nil { + partsInMb = true + } + } + return partsInMb && partsNotInMb +} diff --git a/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/file.go b/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/file.go new file mode 100644 index 00000000..1897dc42 --- /dev/null +++ b/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/file.go @@ -0,0 +1,71 @@ +// Copyright 2016 CoreOS, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package types + +import ( + "fmt" + + "github.com/coreos/ignition/config/shared/errors" + "github.com/coreos/ignition/config/validate/report" +) + +func (f File) Validate() report.Report { + if f.Overwrite != nil && *f.Overwrite && f.Append { + return report.ReportFromError(errors.ErrAppendAndOverwrite, report.EntryError) + } + return report.Report{} +} + +func (f File) ValidateMode() report.Report { + r := report.Report{} + if err := validateMode(f.Mode); err != nil { + r.Add(report.Entry{ + Message: err.Error(), + Kind: report.EntryError, + }) + } + if f.Mode == nil { + r.Add(report.Entry{ + Message: errors.ErrPermissionsUnset.Error(), + Kind: report.EntryWarning, + }) + } + return r +} + +func (fc FileContents) ValidateCompression() report.Report { + r := report.Report{} + switch fc.Compression { + case "", "gzip": + default: + r.Add(report.Entry{ + Message: errors.ErrCompressionInvalid.Error(), + Kind: report.EntryError, + }) + } + return r +} + +func (fc FileContents) ValidateSource() report.Report { + r := report.Report{} + err := validateURL(fc.Source) + if err != nil { + r.Add(report.Entry{ + Message: fmt.Sprintf("invalid url %q: %v", fc.Source, err), + Kind: report.EntryError, + }) + } + return r +} diff --git a/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/filesystem.go b/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/filesystem.go new file mode 100644 index 00000000..2e847da6 --- /dev/null +++ b/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/filesystem.go @@ -0,0 +1,146 @@ +// Copyright 2016 CoreOS, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package types + +import ( + "fmt" + + "github.com/coreos/ignition/config/shared/errors" + "github.com/coreos/ignition/config/validate/report" +) + +func (f Filesystem) Validate() report.Report { + r := report.Report{} + if f.Mount == nil && f.Path == nil { + r.Add(report.Entry{ + Message: errors.ErrFilesystemNoMountPath.Error(), + Kind: report.EntryError, + }) + } + if f.Mount != nil { + if f.Path != nil { + r.Add(report.Entry{ + Message: errors.ErrFilesystemMountAndPath.Error(), + Kind: report.EntryError, + }) + } + if f.Mount.Create != nil { + if f.Mount.WipeFilesystem { + r.Add(report.Entry{ + Message: errors.ErrUsedCreateAndWipeFilesystem.Error(), + Kind: report.EntryError, + }) + } + if len(f.Mount.Options) > 0 { + r.Add(report.Entry{ + Message: errors.ErrUsedCreateAndMountOpts.Error(), + Kind: report.EntryError, + }) + } + r.Add(report.Entry{ + Message: errors.ErrWarningCreateDeprecated.Error(), + Kind: report.EntryWarning, + }) + } + } + return r +} + +func (f Filesystem) ValidatePath() report.Report { + r := report.Report{} + if f.Path != nil && validatePath(*f.Path) != nil { + r.Add(report.Entry{ + Message: fmt.Sprintf("filesystem %q: path not absolute", f.Name), + Kind: report.EntryError, + }) + } + return r +} + +func (m Mount) Validate() report.Report { + r := report.Report{} + switch m.Format { + case "ext4", "btrfs", "xfs", "swap", "vfat": + default: + r.Add(report.Entry{ + Message: errors.ErrFilesystemInvalidFormat.Error(), + Kind: report.EntryError, + }) + } + return r +} + +func (m Mount) ValidateDevice() report.Report { + r := report.Report{} + if err := validatePath(m.Device); err != nil { + r.Add(report.Entry{ + Message: err.Error(), + Kind: report.EntryError, + }) + } + return r +} + +func (m Mount) ValidateLabel() report.Report { + r := report.Report{} + if m.Label == nil { + return r + } + switch m.Format { + case "ext4": + if len(*m.Label) > 16 { + // source: man mkfs.ext4 + r.Add(report.Entry{ + Message: errors.ErrExt4LabelTooLong.Error(), + Kind: report.EntryError, + }) + } + case "btrfs": + if len(*m.Label) > 256 { + // source: man mkfs.btrfs + r.Add(report.Entry{ + Message: errors.ErrBtrfsLabelTooLong.Error(), + Kind: report.EntryError, + }) + } + case "xfs": + if len(*m.Label) > 12 { + // source: man mkfs.xfs + r.Add(report.Entry{ + Message: errors.ErrXfsLabelTooLong.Error(), + Kind: report.EntryError, + }) + } + case "swap": + // mkswap's man page does not state a limit on label size, but through + // experimentation it appears that mkswap will truncate long labels to + // 15 characters, so let's enforce that. + if len(*m.Label) > 15 { + r.Add(report.Entry{ + Message: errors.ErrSwapLabelTooLong.Error(), + Kind: report.EntryError, + }) + } + case "vfat": + if len(*m.Label) > 11 { + // source: man mkfs.fat + r.Add(report.Entry{ + Message: errors.ErrVfatLabelTooLong.Error(), + Kind: report.EntryError, + }) + } + } + return r +} diff --git a/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/ignition.go b/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/ignition.go new file mode 100644 index 00000000..bddf4958 --- /dev/null +++ b/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/ignition.go @@ -0,0 +1,52 @@ +// Copyright 2015 CoreOS, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package types + +import ( + "github.com/coreos/go-semver/semver" + + "github.com/coreos/ignition/config/shared/errors" + "github.com/coreos/ignition/config/validate/report" +) + +func (c ConfigReference) ValidateSource() report.Report { + r := report.Report{} + err := validateURL(c.Source) + if err != nil { + r.Add(report.Entry{ + Message: err.Error(), + Kind: report.EntryError, + }) + } + return r +} + +func (v Ignition) Semver() (*semver.Version, error) { + return semver.NewVersion(v.Version) +} + +func (v Ignition) Validate() report.Report { + tv, err := v.Semver() + if err != nil { + return report.ReportFromError(errors.ErrInvalidVersion, report.EntryError) + } + if MaxVersion.Major > tv.Major { + return report.ReportFromError(errors.ErrOldVersion, report.EntryError) + } + if MaxVersion.LessThan(*tv) { + return report.ReportFromError(errors.ErrNewVersion, report.EntryError) + } + return report.Report{} +} diff --git a/vendor/github.com/coreos/ignition/config/v2_3_experimental/types/link.go b/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/mode.go similarity index 67% rename from vendor/github.com/coreos/ignition/config/v2_3_experimental/types/link.go rename to vendor/github.com/coreos/ignition/config/v2_4_experimental/types/mode.go index f0284425..d06045d6 100644 --- a/vendor/github.com/coreos/ignition/config/v2_3_experimental/types/link.go +++ b/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/mode.go @@ -15,19 +15,12 @@ package types import ( - "github.com/coreos/ignition/config/validate/report" + "github.com/coreos/ignition/config/shared/errors" ) -func (s LinkEmbedded1) ValidateTarget() report.Report { - r := report.Report{} - if !s.Hard { - err := validatePath(s.Target) - if err != nil { - r.Add(report.Entry{ - Message: err.Error(), - Kind: report.EntryError, - }) - } +func validateMode(m *int) error { + if m != nil && (*m < 0 || *m > 07777) { + return errors.ErrFileIllegalMode } - return r + return nil } diff --git a/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/node.go b/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/node.go new file mode 100644 index 00000000..50badfdf --- /dev/null +++ b/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/node.go @@ -0,0 +1,73 @@ +// Copyright 2016 CoreOS, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package types + +import ( + "path/filepath" + + "github.com/coreos/ignition/config/shared/errors" + "github.com/coreos/ignition/config/validate/report" +) + +func (n Node) ValidateFilesystem() report.Report { + r := report.Report{} + if n.Filesystem == "" { + r.Add(report.Entry{ + Message: errors.ErrNoFilesystem.Error(), + Kind: report.EntryError, + }) + } + return r +} + +func (n Node) ValidatePath() report.Report { + r := report.Report{} + if err := validatePath(n.Path); err != nil { + r.Add(report.Entry{ + Message: err.Error(), + Kind: report.EntryError, + }) + } + return r +} + +func (n Node) Depth() int { + count := 0 + for p := filepath.Clean(string(n.Path)); p != "/"; count++ { + p = filepath.Dir(p) + } + return count +} + +func (nu NodeUser) Validate() report.Report { + r := report.Report{} + if nu.ID != nil && nu.Name != "" { + r.Add(report.Entry{ + Message: errors.ErrBothIDAndNameSet.Error(), + Kind: report.EntryError, + }) + } + return r +} +func (ng NodeGroup) Validate() report.Report { + r := report.Report{} + if ng.ID != nil && ng.Name != "" { + r.Add(report.Entry{ + Message: errors.ErrBothIDAndNameSet.Error(), + Kind: report.EntryError, + }) + } + return r +} diff --git a/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/partition.go b/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/partition.go new file mode 100644 index 00000000..dbe38adc --- /dev/null +++ b/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/partition.go @@ -0,0 +1,112 @@ +// Copyright 2016 CoreOS, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package types + +import ( + "fmt" + "regexp" + "strings" + + "github.com/coreos/ignition/config/shared/errors" + "github.com/coreos/ignition/config/validate/report" +) + +const ( + guidRegexStr = "^(|[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12})$" +) + +func (p Partition) Validate() report.Report { + r := report.Report{} + if (p.Start != nil || p.Size != nil) && (p.StartMiB != nil || p.SizeMiB != nil) { + r.Add(report.Entry{ + Message: errors.ErrPartitionsUnitsMismatch.Error(), + Kind: report.EntryError, + }) + } + if p.ShouldExist != nil && !*p.ShouldExist && + (p.Label != nil || p.TypeGUID != "" || p.GUID != "" || p.Start != nil || p.Size != nil) { + r.Add(report.Entry{ + Message: errors.ErrShouldNotExistWithOthers.Error(), + Kind: report.EntryError, + }) + } + return r +} + +func (p Partition) ValidateSize() report.Report { + if p.Size != nil { + return report.ReportFromError(errors.ErrSizeDeprecated, report.EntryDeprecated) + } + return report.Report{} +} + +func (p Partition) ValidateStart() report.Report { + if p.Start != nil { + return report.ReportFromError(errors.ErrStartDeprecated, report.EntryDeprecated) + } + return report.Report{} +} + +func (p Partition) ValidateLabel() report.Report { + r := report.Report{} + if p.Label == nil { + return r + } + // http://en.wikipedia.org/wiki/GUID_Partition_Table#Partition_entries: + // 56 (0x38) 72 bytes Partition name (36 UTF-16LE code units) + + // XXX(vc): note GPT calls it a name, we're using label for consistency + // with udev naming /dev/disk/by-partlabel/*. + if len(*p.Label) > 36 { + r.Add(report.Entry{ + Message: errors.ErrLabelTooLong.Error(), + Kind: report.EntryError, + }) + } + + // sgdisk uses colons for delimitting compound arguments and does not allow escaping them. + if strings.Contains(*p.Label, ":") { + r.Add(report.Entry{ + Message: errors.ErrLabelContainsColon.Error(), + Kind: report.EntryWarning, + }) + } + return r +} + +func (p Partition) ValidateTypeGUID() report.Report { + return validateGUID(p.TypeGUID) +} + +func (p Partition) ValidateGUID() report.Report { + return validateGUID(p.GUID) +} + +func validateGUID(guid string) report.Report { + r := report.Report{} + ok, err := regexp.MatchString(guidRegexStr, guid) + if err != nil { + r.Add(report.Entry{ + Message: fmt.Sprintf("error matching guid regexp: %v", err), + Kind: report.EntryError, + }) + } else if !ok { + r.Add(report.Entry{ + Message: errors.ErrDoesntMatchGUIDRegex.Error(), + Kind: report.EntryError, + }) + } + return r +} diff --git a/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/passwd.go b/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/passwd.go new file mode 100644 index 00000000..10508c56 --- /dev/null +++ b/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/passwd.go @@ -0,0 +1,67 @@ +// Copyright 2017 CoreOS, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package types + +import ( + "github.com/coreos/ignition/config/shared/errors" + "github.com/coreos/ignition/config/validate/report" +) + +func (p PasswdUser) Validate() report.Report { + r := report.Report{} + if p.Create != nil { + r.Add(report.Entry{ + Message: errors.ErrPasswdCreateDeprecated.Error(), + Kind: report.EntryWarning, + }) + addErr := func(err error) { + r.Add(report.Entry{ + Message: err.Error(), + Kind: report.EntryError, + }) + } + if p.Gecos != "" { + addErr(errors.ErrPasswdCreateAndGecos) + } + if len(p.Groups) > 0 { + addErr(errors.ErrPasswdCreateAndGroups) + } + if p.HomeDir != "" { + addErr(errors.ErrPasswdCreateAndHomeDir) + } + if p.NoCreateHome { + addErr(errors.ErrPasswdCreateAndNoCreateHome) + } + if p.NoLogInit { + addErr(errors.ErrPasswdCreateAndNoLogInit) + } + if p.NoUserGroup { + addErr(errors.ErrPasswdCreateAndNoUserGroup) + } + if p.PrimaryGroup != "" { + addErr(errors.ErrPasswdCreateAndPrimaryGroup) + } + if p.Shell != "" { + addErr(errors.ErrPasswdCreateAndShell) + } + if p.System { + addErr(errors.ErrPasswdCreateAndSystem) + } + if p.UID != nil { + addErr(errors.ErrPasswdCreateAndUID) + } + } + return r +} diff --git a/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/path.go b/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/path.go new file mode 100644 index 00000000..780607c3 --- /dev/null +++ b/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/path.go @@ -0,0 +1,28 @@ +// Copyright 2016 CoreOS, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package types + +import ( + "path" + + "github.com/coreos/ignition/config/shared/errors" +) + +func validatePath(p string) error { + if !path.IsAbs(p) { + return errors.ErrPathRelative + } + return nil +} diff --git a/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/raid.go b/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/raid.go new file mode 100644 index 00000000..3aceaa9f --- /dev/null +++ b/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/raid.go @@ -0,0 +1,57 @@ +// Copyright 2016 CoreOS, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package types + +import ( + "github.com/coreos/ignition/config/shared/errors" + "github.com/coreos/ignition/config/validate/report" +) + +func (n Raid) ValidateLevel() report.Report { + r := report.Report{} + switch n.Level { + case "linear", "raid0", "0", "stripe": + if n.Spares != 0 { + r.Add(report.Entry{ + Message: errors.ErrSparesUnsupportedForLevel.Error(), + Kind: report.EntryError, + }) + } + case "raid1", "1", "mirror": + case "raid4", "4": + case "raid5", "5": + case "raid6", "6": + case "raid10", "10": + default: + r.Add(report.Entry{ + Message: errors.ErrUnrecognizedRaidLevel.Error(), + Kind: report.EntryError, + }) + } + return r +} + +func (n Raid) ValidateDevices() report.Report { + r := report.Report{} + for _, d := range n.Devices { + if err := validatePath(string(d)); err != nil { + r.Add(report.Entry{ + Message: errors.ErrPathRelative.Error(), + Kind: report.EntryError, + }) + } + } + return r +} diff --git a/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/schema.go b/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/schema.go new file mode 100644 index 00000000..5f91b71e --- /dev/null +++ b/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/schema.go @@ -0,0 +1,250 @@ +package types + +// generated by "schematyper --package=types schema/ignition.json -o internal/config/types/schema.go --root-type=Config" -- DO NOT EDIT + +type CaReference struct { + Source string `json:"source"` + Verification Verification `json:"verification,omitempty"` +} + +type Config struct { + Ignition Ignition `json:"ignition"` + Networkd Networkd `json:"networkd,omitempty"` + Passwd Passwd `json:"passwd,omitempty"` + Storage Storage `json:"storage,omitempty"` + Systemd Systemd `json:"systemd,omitempty"` +} + +type ConfigReference struct { + Source string `json:"source"` + Verification Verification `json:"verification,omitempty"` +} + +type Create struct { + Force bool `json:"force,omitempty"` + Options []CreateOption `json:"options,omitempty"` +} + +type CreateOption string + +type Device string + +type Directory struct { + Node + DirectoryEmbedded1 +} + +type DirectoryEmbedded1 struct { + Mode *int `json:"mode,omitempty"` +} + +type Disk struct { + Device string `json:"device"` + Partitions []Partition `json:"partitions,omitempty"` + WipeTable bool `json:"wipeTable,omitempty"` +} + +type File struct { + Node + FileEmbedded1 +} + +type FileContents struct { + Compression string `json:"compression,omitempty"` + Source string `json:"source,omitempty"` + Verification Verification `json:"verification,omitempty"` +} + +type FileEmbedded1 struct { + Append bool `json:"append,omitempty"` + Contents FileContents `json:"contents,omitempty"` + Mode *int `json:"mode,omitempty"` +} + +type Filesystem struct { + Mount *Mount `json:"mount,omitempty"` + Name string `json:"name,omitempty"` + Path *string `json:"path,omitempty"` +} + +type Group string + +type Ignition struct { + Config IgnitionConfig `json:"config,omitempty"` + Security Security `json:"security,omitempty"` + Timeouts Timeouts `json:"timeouts,omitempty"` + Version string `json:"version,omitempty"` +} + +type IgnitionConfig struct { + Append []ConfigReference `json:"append,omitempty"` + Replace *ConfigReference `json:"replace,omitempty"` +} + +type Link struct { + Node + LinkEmbedded1 +} + +type LinkEmbedded1 struct { + Hard bool `json:"hard,omitempty"` + Target string `json:"target"` +} + +type Mount struct { + Create *Create `json:"create,omitempty"` + Device string `json:"device"` + Format string `json:"format"` + Label *string `json:"label,omitempty"` + Options []MountOption `json:"options,omitempty"` + UUID *string `json:"uuid,omitempty"` + WipeFilesystem bool `json:"wipeFilesystem,omitempty"` +} + +type MountOption string + +type Networkd struct { + Units []Networkdunit `json:"units,omitempty"` +} + +type NetworkdDropin struct { + Contents string `json:"contents,omitempty"` + Name string `json:"name"` +} + +type Networkdunit struct { + Contents string `json:"contents,omitempty"` + Dropins []NetworkdDropin `json:"dropins,omitempty"` + Name string `json:"name"` +} + +type Node struct { + Filesystem string `json:"filesystem"` + Group *NodeGroup `json:"group,omitempty"` + Overwrite *bool `json:"overwrite,omitempty"` + Path string `json:"path"` + User *NodeUser `json:"user,omitempty"` +} + +type NodeGroup struct { + ID *int `json:"id,omitempty"` + Name string `json:"name,omitempty"` +} + +type NodeUser struct { + ID *int `json:"id,omitempty"` + Name string `json:"name,omitempty"` +} + +type Partition struct { + GUID string `json:"guid,omitempty"` + Label *string `json:"label,omitempty"` + Number int `json:"number,omitempty"` + ShouldExist *bool `json:"shouldExist,omitempty"` + Size *int `json:"size,omitempty"` + SizeMiB *int `json:"sizeMiB,omitempty"` + Start *int `json:"start,omitempty"` + StartMiB *int `json:"startMiB,omitempty"` + TypeGUID string `json:"typeGuid,omitempty"` + WipePartitionEntry bool `json:"wipePartitionEntry,omitempty"` +} + +type Passwd struct { + Groups []PasswdGroup `json:"groups,omitempty"` + Users []PasswdUser `json:"users,omitempty"` +} + +type PasswdGroup struct { + Gid *int `json:"gid,omitempty"` + Name string `json:"name"` + PasswordHash string `json:"passwordHash,omitempty"` + System bool `json:"system,omitempty"` +} + +type PasswdUser struct { + Create *Usercreate `json:"create,omitempty"` + Gecos string `json:"gecos,omitempty"` + Groups []Group `json:"groups,omitempty"` + HomeDir string `json:"homeDir,omitempty"` + Name string `json:"name"` + NoCreateHome bool `json:"noCreateHome,omitempty"` + NoLogInit bool `json:"noLogInit,omitempty"` + NoUserGroup bool `json:"noUserGroup,omitempty"` + PasswordHash *string `json:"passwordHash,omitempty"` + PrimaryGroup string `json:"primaryGroup,omitempty"` + SSHAuthorizedKeys []SSHAuthorizedKey `json:"sshAuthorizedKeys,omitempty"` + Shell string `json:"shell,omitempty"` + System bool `json:"system,omitempty"` + UID *int `json:"uid,omitempty"` +} + +type Raid struct { + Devices []Device `json:"devices"` + Level string `json:"level"` + Name string `json:"name"` + Options []RaidOption `json:"options,omitempty"` + Spares int `json:"spares,omitempty"` +} + +type RaidOption string + +type SSHAuthorizedKey string + +type Security struct { + TLS `json:"tls,omitempty"` +} + +type Storage struct { + Directories []Directory `json:"directories,omitempty"` + Disks []Disk `json:"disks,omitempty"` + Files []File `json:"files,omitempty"` + Filesystems []Filesystem `json:"filesystems,omitempty"` + Links []Link `json:"links,omitempty"` + Raid []Raid `json:"raid,omitempty"` +} + +type Systemd struct { + Units []Unit `json:"units,omitempty"` +} + +type SystemdDropin struct { + Contents string `json:"contents,omitempty"` + Name string `json:"name"` +} + +type TLS struct { + CertificateAuthorities []CaReference `json:"certificateAuthorities,omitempty"` +} + +type Timeouts struct { + HTTPResponseHeaders *int `json:"httpResponseHeaders,omitempty"` + HTTPTotal *int `json:"httpTotal,omitempty"` +} + +type Unit struct { + Contents string `json:"contents,omitempty"` + Dropins []SystemdDropin `json:"dropins,omitempty"` + Enable bool `json:"enable,omitempty"` + Enabled *bool `json:"enabled,omitempty"` + Mask bool `json:"mask,omitempty"` + Name string `json:"name"` +} + +type Usercreate struct { + Gecos string `json:"gecos,omitempty"` + Groups []UsercreateGroup `json:"groups,omitempty"` + HomeDir string `json:"homeDir,omitempty"` + NoCreateHome bool `json:"noCreateHome,omitempty"` + NoLogInit bool `json:"noLogInit,omitempty"` + NoUserGroup bool `json:"noUserGroup,omitempty"` + PrimaryGroup string `json:"primaryGroup,omitempty"` + Shell string `json:"shell,omitempty"` + System bool `json:"system,omitempty"` + UID *int `json:"uid,omitempty"` +} + +type UsercreateGroup string + +type Verification struct { + Hash *string `json:"hash,omitempty"` +} diff --git a/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/unit.go b/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/unit.go new file mode 100644 index 00000000..70fe1179 --- /dev/null +++ b/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/unit.go @@ -0,0 +1,131 @@ +// Copyright 2016 CoreOS, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package types + +import ( + "fmt" + "path" + "strings" + + "github.com/coreos/go-systemd/unit" + + "github.com/coreos/ignition/config/shared/errors" + "github.com/coreos/ignition/config/shared/validations" + "github.com/coreos/ignition/config/validate/report" +) + +func (u Unit) ValidateContents() report.Report { + r := report.Report{} + opts, err := validateUnitContent(u.Contents) + if err != nil { + r.Add(report.Entry{ + Message: err.Error(), + Kind: report.EntryError, + }) + } + + isEnabled := u.Enable || (u.Enabled != nil && *u.Enabled) + r.Merge(validations.ValidateInstallSection(u.Name, isEnabled, u.Contents == "", opts)) + + return r +} + +func (u Unit) ValidateName() report.Report { + r := report.Report{} + switch path.Ext(u.Name) { + case ".service", ".socket", ".device", ".mount", ".automount", ".swap", ".target", ".path", ".timer", ".snapshot", ".slice", ".scope": + default: + r.Add(report.Entry{ + Message: errors.ErrInvalidSystemdExt.Error(), + Kind: report.EntryError, + }) + } + return r +} + +func (d SystemdDropin) Validate() report.Report { + r := report.Report{} + + if _, err := validateUnitContent(d.Contents); err != nil { + r.Add(report.Entry{ + Message: err.Error(), + Kind: report.EntryError, + }) + } + + switch path.Ext(d.Name) { + case ".conf": + default: + r.Add(report.Entry{ + Message: errors.ErrInvalidSystemdDropinExt.Error(), + Kind: report.EntryError, + }) + } + + return r +} + +func (u Networkdunit) Validate() report.Report { + r := report.Report{} + + if _, err := validateUnitContent(u.Contents); err != nil { + r.Add(report.Entry{ + Message: err.Error(), + Kind: report.EntryError, + }) + } + + switch path.Ext(u.Name) { + case ".link", ".netdev", ".network": + default: + r.Add(report.Entry{ + Message: errors.ErrInvalidNetworkdExt.Error(), + Kind: report.EntryError, + }) + } + + return r +} + +func (d NetworkdDropin) Validate() report.Report { + r := report.Report{} + + if _, err := validateUnitContent(d.Contents); err != nil { + r.Add(report.Entry{ + Message: err.Error(), + Kind: report.EntryError, + }) + } + + switch path.Ext(d.Name) { + case ".conf": + default: + r.Add(report.Entry{ + Message: errors.ErrInvalidNetworkdDropinExt.Error(), + Kind: report.EntryError, + }) + } + + return r +} + +func validateUnitContent(content string) ([]*unit.UnitOption, error) { + c := strings.NewReader(content) + opts, err := unit.Deserialize(c) + if err != nil { + return nil, fmt.Errorf("invalid unit content: %s", err) + } + return opts, nil +} diff --git a/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/url.go b/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/url.go new file mode 100644 index 00000000..11148fc0 --- /dev/null +++ b/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/url.go @@ -0,0 +1,53 @@ +// Copyright 2016 CoreOS, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package types + +import ( + "net/url" + + "github.com/vincent-petithory/dataurl" + + "github.com/coreos/ignition/config/shared/errors" +) + +func validateURL(s string) error { + // Empty url is valid, indicates an empty file + if s == "" { + return nil + } + u, err := url.Parse(s) + if err != nil { + return errors.ErrInvalidUrl + } + + switch u.Scheme { + case "http", "https", "oem", "tftp": + return nil + case "s3": + if v, ok := u.Query()["versionId"]; ok { + if len(v) == 0 || v[0] == "" { + return errors.ErrInvalidS3ObjectVersionId + } + } + return nil + case "data": + if _, err := dataurl.DecodeString(s); err != nil { + return err + } + return nil + default: + return errors.ErrInvalidScheme + } +} diff --git a/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/verification.go b/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/verification.go new file mode 100644 index 00000000..51e7d155 --- /dev/null +++ b/vendor/github.com/coreos/ignition/config/v2_4_experimental/types/verification.go @@ -0,0 +1,77 @@ +// Copyright 2016 CoreOS, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package types + +import ( + "crypto" + "encoding/hex" + "strings" + + "github.com/coreos/ignition/config/shared/errors" + "github.com/coreos/ignition/config/validate/report" +) + +// HashParts will return the sum and function (in that order) of the hash stored +// in this Verification, or an error if there is an issue during parsing. +func (v Verification) HashParts() (string, string, error) { + if v.Hash == nil { + // The hash can be nil + return "", "", nil + } + parts := strings.SplitN(*v.Hash, "-", 2) + if len(parts) != 2 { + return "", "", errors.ErrHashMalformed + } + + return parts[0], parts[1], nil +} + +func (v Verification) Validate() report.Report { + r := report.Report{} + + if v.Hash == nil { + // The hash can be nil + return r + } + + function, sum, err := v.HashParts() + if err != nil { + r.Add(report.Entry{ + Message: err.Error(), + Kind: report.EntryError, + }) + return r + } + var hash crypto.Hash + switch function { + case "sha512": + hash = crypto.SHA512 + default: + r.Add(report.Entry{ + Message: errors.ErrHashUnrecognized.Error(), + Kind: report.EntryError, + }) + return r + } + + if len(sum) != hex.EncodedLen(hash.Size()) { + r.Add(report.Entry{ + Message: errors.ErrHashWrongSize.Error(), + Kind: report.EntryError, + }) + } + + return r +} diff --git a/vendor/modules.txt b/vendor/modules.txt index a404de40..8bd2fa31 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -20,21 +20,23 @@ github.com/coreos/etcd/pkg/types github.com/coreos/go-semver/semver # github.com/coreos/go-systemd v0.0.0-20181031085051-9002847aa142 github.com/coreos/go-systemd/unit -# github.com/coreos/ignition v0.28.0 -github.com/coreos/ignition/config/v2_2 +# github.com/coreos/ignition v0.30.0 +github.com/coreos/ignition/config/v2_3 github.com/coreos/ignition/config/shared/errors github.com/coreos/ignition/config/util -github.com/coreos/ignition/config/v2_1 -github.com/coreos/ignition/config/v2_1/types +github.com/coreos/ignition/config/v2_2 github.com/coreos/ignition/config/v2_2/types +github.com/coreos/ignition/config/v2_3/types github.com/coreos/ignition/config/validate github.com/coreos/ignition/config/validate/report -github.com/coreos/ignition/config/v2_3_experimental/types -github.com/coreos/ignition/config/v2_0 -github.com/coreos/ignition/config/v2_0/types +github.com/coreos/ignition/config/v2_4_experimental/types +github.com/coreos/ignition/config/v2_1 +github.com/coreos/ignition/config/v2_1/types github.com/coreos/ignition/config/shared/validations github.com/coreos/ignition/config/validate/astjson github.com/coreos/ignition/config/validate/astnode +github.com/coreos/ignition/config/v2_0 +github.com/coreos/ignition/config/v2_0/types github.com/coreos/ignition/config/v1 github.com/coreos/ignition/config/v1/types # github.com/cybozu-go/etcdutil v1.3.1 From 6ea3630b874696ebf2f69d2e3391ae902d7f31dd Mon Sep 17 00:00:00 2001 From: ymmt Date: Fri, 21 Dec 2018 10:22:43 +0900 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a825b384..f1c25ca1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,10 +5,13 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Changed +* Update github.com/coreos/ignition to v0.30.0 and spec version v2.3.0 (#127). + ## [0.30] - 2018-12-06 ### Added -* [client] aliases to type in `sabakan` package. +* client: aliases to type in `sabakan` package. ## [0.29] - 2018-11-29