Skip to content

Commit

Permalink
Merge pull request #2266 from afbjorklund/cidata-cacerts
Browse files Browse the repository at this point in the history
Fix cidata user-data ca_certs yaml content
  • Loading branch information
jandubois authored Apr 5, 2024
2 parents 9d31f2a + eea8427 commit f1096ae
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/cidata/cidata.TEMPLATE.d/user-data
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,15 @@ resolv_conf:
{{ with .CACerts }}
ca_certs:
remove_defaults: {{ .RemoveDefaults }}
{{- if .Trusted}}
trusted:
{{- range $cert := .Trusted }}
- |
{{- range $line := $cert.Lines }}
{{ $line }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}

{{- if .BootCmds }}
Expand Down
3 changes: 3 additions & 0 deletions pkg/cidata/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ func ValidateTemplateArgs(args TemplateArgs) error {
return fmt.Errorf("field mounts[%d] must be absolute, got %q", i, f)
}
}
if args.CACerts.RemoveDefaults == nil {
return errors.New("field CACerts.RemoveDefaults must be set")
}
return nil
}

Expand Down
11 changes: 11 additions & 0 deletions pkg/cidata/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"gotest.tools/v3/assert"
)

var defaultRemoveDefaults = false

func TestTemplate(t *testing.T) {
args := TemplateArgs{
Name: "default",
Expand All @@ -22,6 +24,10 @@ func TestTemplate(t *testing.T) {
{MountPoint: "/Users/dummy/lima"},
},
MountType: "reverse-sshfs",
CACerts: CACerts{
RemoveDefaults: &defaultRemoveDefaults,
Trusted: []Cert{},
},
}
layout, err := ExecuteTemplate(args)
assert.NilError(t, err)
Expand All @@ -33,6 +39,8 @@ func TestTemplate(t *testing.T) {
if f.Path == "user-data" {
// mounted later
assert.Assert(t, !strings.Contains(string(b), "mounts:"))
// ca_certs:
assert.Assert(t, !strings.Contains(string(b), "trusted:"))
}
}
}
Expand All @@ -51,6 +59,9 @@ func TestTemplate9p(t *testing.T) {
{Tag: "mount1", MountPoint: "/Users/dummy/lima", Type: "9p", Options: "rw,trans=virtio"},
},
MountType: "9p",
CACerts: CACerts{
RemoveDefaults: &defaultRemoveDefaults,
},
}
layout, err := ExecuteTemplate(args)
assert.NilError(t, err)
Expand Down

0 comments on commit f1096ae

Please sign in to comment.