Skip to content

Commit 2f97c62

Browse files
authored
Filesystemlayout createoptions can be specified invalid (#478)
1 parent d61abc7 commit 2f97c62

File tree

4 files changed

+227
-124
lines changed

4 files changed

+227
-124
lines changed

cmd/metal-api/internal/metal/filesystem.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package metal
22

33
import (
4+
"errors"
45
"fmt"
56
"path"
67
"sort"
@@ -249,6 +250,10 @@ func (f FilesystemLayout) Validate() error {
249250
if !ok {
250251
return fmt.Errorf("filesystem:%s format:%s is not supported", *fs.Path, fs.Format)
251252
}
253+
err := validateCreateOptions(fs.CreateOptions)
254+
if err != nil {
255+
return err
256+
}
252257
}
253258

254259
// validate constraints
@@ -260,6 +265,19 @@ func (f FilesystemLayout) Validate() error {
260265
return nil
261266
}
262267

268+
func validateCreateOptions(opts []string) error {
269+
var errs []error
270+
for _, opt := range opts {
271+
if len(strings.Fields(opt)) > 1 {
272+
errs = append(errs, fmt.Errorf("the given createoption:%q contains whitespace and must be split into separate options", opt))
273+
}
274+
}
275+
if len(errs) > 0 {
276+
return errors.Join(errs...)
277+
}
278+
return nil
279+
}
280+
263281
func (c *FilesystemLayoutConstraints) validate() error {
264282
// no pure wildcard in images
265283
for os, vc := range c.Images {

cmd/metal-api/internal/metal/filesystem_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,48 @@ func TestFilesystemLayout_Validate(t *testing.T) {
640640
},
641641
wantErr: false,
642642
},
643+
{
644+
id: "fsl-19",
645+
name: "invalid createoptions",
646+
fields: fields{
647+
Filesystems: []Filesystem{
648+
{
649+
Path: strPtr("/boot/efi"),
650+
Device: "/dev/sda1",
651+
Format: VFAT,
652+
CreateOptions: []string{
653+
"-F 32",
654+
},
655+
},
656+
},
657+
Disks: []Disk{
658+
{Device: "/dev/sda1"},
659+
},
660+
},
661+
wantErr: true,
662+
errString: "the given createoption:\"-F 32\" contains whitespace and must be split into separate options",
663+
},
664+
{
665+
id: "fsl-20",
666+
name: "valid createoptions",
667+
fields: fields{
668+
Filesystems: []Filesystem{
669+
{
670+
Path: strPtr("/boot/efi"),
671+
Device: "/dev/sda1",
672+
Format: VFAT,
673+
CreateOptions: []string{
674+
"-F",
675+
"32",
676+
},
677+
},
678+
},
679+
Disks: []Disk{
680+
{Device: "/dev/sda1"},
681+
},
682+
},
683+
wantErr: false,
684+
},
643685
}
644686
for _, tt := range tests {
645687
tt := tt

go.mod

Lines changed: 52 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,28 @@ require (
1010
github.com/emicklei/go-restful-openapi/v2 v2.9.1
1111
github.com/emicklei/go-restful/v3 v3.11.0
1212
github.com/go-openapi/spec v0.20.9
13-
github.com/google/go-cmp v0.5.9
14-
github.com/google/uuid v1.3.1
13+
github.com/google/go-cmp v0.6.0
14+
github.com/google/uuid v1.4.0
1515
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
1616
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
1717
github.com/juanfont/headscale v0.22.3
1818
github.com/looplab/fsm v0.3.0
1919
github.com/metal-stack/go-ipam v1.8.5
20-
github.com/metal-stack/masterdata-api v0.10.0
21-
github.com/metal-stack/metal-lib v0.13.5
20+
github.com/metal-stack/masterdata-api v0.10.1
21+
github.com/metal-stack/metal-lib v0.13.6
2222
github.com/metal-stack/security v0.6.7
2323
github.com/metal-stack/v v1.0.3
2424
github.com/nsqio/go-nsq v1.1.0
25-
github.com/prometheus/client_golang v1.16.0
26-
github.com/spf13/cobra v1.7.0
27-
github.com/spf13/viper v1.16.0
25+
github.com/prometheus/client_golang v1.17.0
26+
github.com/spf13/cobra v1.8.0
27+
github.com/spf13/viper v1.17.0
2828
github.com/stretchr/testify v1.8.4
29-
github.com/testcontainers/testcontainers-go v0.23.0
29+
github.com/testcontainers/testcontainers-go v0.26.0
3030
github.com/undefinedlabs/go-mpatch v1.0.7
31-
go.uber.org/zap v1.25.0
32-
golang.org/x/crypto v0.12.0
33-
golang.org/x/sync v0.3.0
34-
google.golang.org/grpc v1.57.0
31+
go.uber.org/zap v1.26.0
32+
golang.org/x/crypto v0.15.0
33+
golang.org/x/sync v0.5.0
34+
google.golang.org/grpc v1.59.0
3535
google.golang.org/protobuf v1.31.0
3636
gopkg.in/rethinkdb/rethinkdb-go.v6 v6.2.2
3737
)
@@ -45,35 +45,38 @@ replace (
4545
)
4646

4747
require (
48-
connectrpc.com/connect v1.11.1 // indirect
48+
connectrpc.com/connect v1.12.0 // indirect
4949
dario.cat/mergo v1.0.0 // indirect
5050
filippo.io/edwards25519 v1.0.0 // indirect
5151
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
5252
github.com/Microsoft/go-winio v0.6.1 // indirect
53+
github.com/Microsoft/hcsshim v0.11.4 // indirect
5354
github.com/akutz/memconn v0.1.0 // indirect
5455
github.com/alexbrainman/sspi v0.0.0-20210105120005-909beea2cc74 // indirect
5556
github.com/andybalholm/brotli v1.0.5 // indirect
5657
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
5758
github.com/avast/retry-go v3.0.0+incompatible // indirect
58-
github.com/benbjohnson/clock v1.3.5 // indirect
5959
github.com/beorn7/perks v1.0.1 // indirect
6060
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
6161
github.com/cespare/xxhash/v2 v2.2.0 // indirect
62-
github.com/containerd/containerd v1.7.3 // indirect
63-
github.com/coreos/go-oidc/v3 v3.6.0 // indirect
62+
github.com/containerd/containerd v1.7.9 // indirect
63+
github.com/containerd/log v0.1.0 // indirect
64+
github.com/coreos/go-oidc/v3 v3.7.0 // indirect
6465
github.com/cpuguy83/dockercfg v0.3.1 // indirect
65-
github.com/davecgh/go-spew v1.1.1 // indirect
66+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
6667
github.com/deckarep/golang-set/v2 v2.3.1 // indirect
6768
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
68-
github.com/docker/distribution v2.8.2+incompatible // indirect
69-
github.com/docker/docker v24.0.5+incompatible // indirect
69+
github.com/distribution/reference v0.5.0 // indirect
70+
github.com/docker/distribution v2.8.3+incompatible // indirect
71+
github.com/docker/docker v24.0.7+incompatible // indirect
7072
github.com/docker/go-connections v0.4.0 // indirect
7173
github.com/docker/go-units v0.5.0 // indirect
7274
github.com/fsnotify/fsnotify v1.6.0 // indirect
7375
github.com/fxamacker/cbor/v2 v2.4.0 // indirect
7476
github.com/glebarez/go-sqlite v1.20.3 // indirect
7577
github.com/glebarez/sqlite v1.7.0 // indirect
7678
github.com/go-jose/go-jose/v3 v3.0.0 // indirect
79+
github.com/go-ole/go-ole v1.2.6 // indirect
7780
github.com/go-openapi/errors v0.20.4 // indirect
7881
github.com/go-openapi/jsonpointer v0.20.0 // indirect
7982
github.com/go-openapi/jsonreference v0.20.2 // indirect
@@ -105,7 +108,7 @@ require (
105108
github.com/josharian/native v1.1.1-0.20230202152459-5c7d0dd6ab86 // indirect
106109
github.com/jsimonetti/rtnetlink v1.3.4 // indirect
107110
github.com/json-iterator/go v1.1.12 // indirect
108-
github.com/klauspost/compress v1.16.7 // indirect
111+
github.com/klauspost/compress v1.17.0 // indirect
109112
github.com/leodido/go-urn v1.2.4 // indirect
110113
github.com/lestrrat-go/backoff/v2 v2.0.8 // indirect
111114
github.com/lestrrat-go/blackmagic v1.0.1 // indirect
@@ -114,69 +117,78 @@ require (
114117
github.com/lestrrat-go/jwx v1.2.26 // indirect
115118
github.com/lestrrat-go/option v1.0.1 // indirect
116119
github.com/lib/pq v1.10.9 // indirect
120+
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
117121
github.com/magiconair/properties v1.8.7 // indirect
118122
github.com/mailru/easyjson v0.7.7 // indirect
119123
github.com/mattn/go-colorable v0.1.13 // indirect
120124
github.com/mattn/go-isatty v0.0.19 // indirect
121125
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
122126
github.com/mdlayher/netlink v1.7.2 // indirect
123127
github.com/mdlayher/socket v0.4.1 // indirect
124-
github.com/meilisearch/meilisearch-go v0.25.0 // indirect
128+
github.com/meilisearch/meilisearch-go v0.26.0 // indirect
125129
github.com/mitchellh/go-ps v1.0.0 // indirect
126130
github.com/mitchellh/mapstructure v1.5.0 // indirect
127-
github.com/moby/patternmatcher v0.5.0 // indirect
131+
github.com/moby/patternmatcher v0.6.0 // indirect
128132
github.com/moby/sys/sequential v0.5.0 // indirect
129133
github.com/moby/term v0.5.0 // indirect
130134
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
131135
github.com/modern-go/reflect2 v1.0.2 // indirect
132136
github.com/morikuni/aec v1.0.0 // indirect
133137
github.com/oklog/ulid v1.3.1 // indirect
134138
github.com/opencontainers/go-digest v1.0.0 // indirect
135-
github.com/opencontainers/image-spec v1.1.0-rc4 // indirect
139+
github.com/opencontainers/image-spec v1.1.0-rc5 // indirect
136140
github.com/opencontainers/runc v1.1.9 // indirect
137141
github.com/opentracing/opentracing-go v1.2.0 // indirect
138142
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
139-
github.com/pelletier/go-toml/v2 v2.0.9 // indirect
143+
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
140144
github.com/philip-bui/grpc-zerolog v1.0.1 // indirect
141145
github.com/pkg/errors v0.9.1 // indirect
142-
github.com/pmezard/go-difflib v1.0.0 // indirect
143-
github.com/prometheus/client_model v0.4.0 // indirect
146+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
147+
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
148+
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect
144149
github.com/prometheus/common v0.44.0 // indirect
145150
github.com/prometheus/procfs v0.11.1 // indirect
146151
github.com/puzpuzpuz/xsync/v2 v2.4.1 // indirect
147152
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
148153
github.com/rs/zerolog v1.30.0 // indirect
154+
github.com/sagikazarmark/locafero v0.3.0 // indirect
155+
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
149156
github.com/samber/lo v1.38.1 // indirect
157+
github.com/shirou/gopsutil/v3 v3.23.9 // indirect
158+
github.com/shoenig/go-m1cpu v0.1.6 // indirect
150159
github.com/sirupsen/logrus v1.9.3 // indirect
151-
github.com/spf13/afero v1.9.5 // indirect
160+
github.com/sourcegraph/conc v0.3.0 // indirect
161+
github.com/spf13/afero v1.10.0 // indirect
152162
github.com/spf13/cast v1.5.1 // indirect
153-
github.com/spf13/jwalterweatherman v1.1.0 // indirect
154163
github.com/spf13/pflag v1.0.5 // indirect
155164
github.com/stretchr/objx v0.5.1 // indirect
156165
github.com/subosito/gotenv v1.6.0 // indirect
157166
github.com/tailscale/hujson v0.0.0-20221223112325-20486734a56a // indirect
167+
github.com/tklauser/go-sysconf v0.3.12 // indirect
168+
github.com/tklauser/numcpus v0.6.1 // indirect
158169
github.com/valyala/bytebufferpool v1.0.0 // indirect
159170
github.com/valyala/fasthttp v1.48.0 // indirect
160171
github.com/x448/float16 v0.8.4 // indirect
172+
github.com/yusufpapurcu/wmi v1.2.3 // indirect
161173
go.mongodb.org/mongo-driver v1.12.1 // indirect
162174
go.uber.org/multierr v1.11.0 // indirect
163175
go4.org/intern v0.0.0-20230205224052-192e9f60865c // indirect
164176
go4.org/mem v0.0.0-20220726221520-4f986261bf13 // indirect
165177
go4.org/netipx v0.0.0-20230728180743-ad4cb58a6516 // indirect
166178
go4.org/unsafe/assume-no-moving-gc v0.0.0-20230525183740-e7c30c78aeb2 // indirect
167-
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63
168-
golang.org/x/mod v0.12.0 // indirect
169-
golang.org/x/net v0.14.0 // indirect
170-
golang.org/x/oauth2 v0.11.0 // indirect
171-
golang.org/x/sys v0.11.0 // indirect
172-
golang.org/x/text v0.12.0 // indirect
173-
golang.org/x/time v0.3.0 // indirect; indirecct
174-
golang.org/x/tools v0.12.1-0.20230815132531-74c255bcf846 // indirect
179+
golang.org/x/exp v0.0.0-20230905200255-921286631fa9
180+
golang.org/x/mod v0.14.0 // indirect
181+
golang.org/x/net v0.18.0 // indirect
182+
golang.org/x/oauth2 v0.14.0 // indirect
183+
golang.org/x/sys v0.14.0 // indirect
184+
golang.org/x/text v0.14.0 // indirect
185+
golang.org/x/time v0.4.0 // indirect; indirecct
186+
golang.org/x/tools v0.15.0 // indirect
175187
golang.zx2c4.com/wireguard/windows v0.5.3 // indirect
176-
google.golang.org/appengine v1.6.7 // indirect
177-
google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5 // indirect
178-
google.golang.org/genproto/googleapis/api v0.0.0-20230726155614-23370e0ffb3e // indirect
179-
google.golang.org/genproto/googleapis/rpc v0.0.0-20230815205213-6bfd019c3878 // indirect
188+
google.golang.org/appengine v1.6.8 // indirect
189+
google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17 // indirect
190+
google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17 // indirect
191+
google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 // indirect
180192
gopkg.in/cenkalti/backoff.v2 v2.2.1 // indirect
181193
gopkg.in/inf.v0 v0.9.1 // indirect
182194
gopkg.in/ini.v1 v1.67.0 // indirect

0 commit comments

Comments
 (0)