File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -210,6 +210,27 @@ func TestConfig(t *testing.T) {
210210` ,
211211 fail : false ,
212212 },
213+ // expected failure: Env is invalid
214+ {
215+ config : `
216+ {
217+ "architecture": "amd64",
218+ "os": "linux",
219+ "config": {
220+ "Env": [
221+ "foo"
222+ ]
223+ },
224+ "rootfs": {
225+ "diff_ids": [
226+ "sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef"
227+ ],
228+ "type": "layers"
229+ }
230+ }
231+ ` ,
232+ fail : true ,
233+ },
213234 } {
214235 r := strings .NewReader (tt .config )
215236 err := schema .ValidatorMediaTypeImageConfig .Validate (r )
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ import (
2020 "fmt"
2121 "io"
2222 "io/ioutil"
23+ "regexp"
2324
2425 digest "github.com/opencontainers/go-digest"
2526 "github.com/opencontainers/image-spec/specs-go/v1"
@@ -138,7 +139,7 @@ func validateDescriptor(r io.Reader) error {
138139 }
139140
140141 err = header .Digest .Validate ()
141- if err == digest .ErrDigestUnsupported {
142+ if err == digest .ErrDigestUnsupported {
142143 // we ignore unsupported algorithms
143144 fmt .Printf ("warning: unsupported digest: %q: %v\n " , header .Digest , err )
144145 return nil
@@ -184,6 +185,13 @@ func validateConfig(r io.Reader) error {
184185
185186 checkPlatform (header .OS , header .Architecture )
186187
188+ envRegexp := regexp .MustCompile (`^[^=]+=.*$` )
189+ for _ , e := range header .Config .Env {
190+ if ! envRegexp .MatchString (e ) {
191+ return errors .Errorf ("unexpected env: %q" , e )
192+ }
193+ }
194+
187195 return nil
188196}
189197
You can’t perform that action at this time.
0 commit comments