Skip to content

Fix cidata user-data ca_certs yaml content #2266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading