From 629bb21f12789284b14f3504a35086c1ac08afae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Cluseau?= Date: Tue, 10 Feb 2026 21:08:45 +0100 Subject: [PATCH] base64 k8s (yaml) decoder expects padding --- cmd/dkl-local-server/boot-iso.go | 2 +- cmd/dkl-local-server/bootv2.go | 17 +++++------------ cmd/dkl-local-server/render-context.go | 21 +++------------------ cmd/dkl-local-server/ws-host.go | 4 +--- 4 files changed, 10 insertions(+), 34 deletions(-) diff --git a/cmd/dkl-local-server/boot-iso.go b/cmd/dkl-local-server/boot-iso.go index f773b74..6011a46 100644 --- a/cmd/dkl-local-server/boot-iso.go +++ b/cmd/dkl-local-server/boot-iso.go @@ -51,7 +51,7 @@ func buildBootISO(out io.Writer, ctx *renderContext) (err error) { } // create a tag file - bootstrapBytes, _, err := ctx.BootstrapConfig() + bootstrapBytes, err := ctx.BootstrapConfig() if err != nil { return } diff --git a/cmd/dkl-local-server/bootv2.go b/cmd/dkl-local-server/bootv2.go index 38ce49d..1c58fc8 100644 --- a/cmd/dkl-local-server/bootv2.go +++ b/cmd/dkl-local-server/bootv2.go @@ -4,7 +4,6 @@ import ( "archive/tar" "bytes" "crypto" - "encoding/json" "fmt" "io" "log" @@ -12,26 +11,20 @@ import ( "os" "github.com/klauspost/compress/zstd" - yaml "gopkg.in/yaml.v2" "novit.tech/direktil/pkg/cpiocat" ) -func renderBootstrapConfig(w http.ResponseWriter, r *http.Request, ctx *renderContext, asJson bool) (err error) { +func renderBootstrapConfig(w http.ResponseWriter, ctx *renderContext) (err error) { log.Printf("sending bootstrap config for %q", ctx.Host.Name) - _, cfg, err := ctx.BootstrapConfig() + ba, err := ctx.BootstrapConfig() if err != nil { return err } - if asJson { - err = json.NewEncoder(w).Encode(cfg) - } else { - err = yaml.NewEncoder(w).Encode(cfg) - } - - return nil + _, err = w.Write(ba) + return } func buildInitrd(out io.Writer, ctx *renderContext) (err error) { @@ -72,7 +65,7 @@ func buildInitrd(out io.Writer, ctx *renderContext) (err error) { } // config - cfgBytes, _, err := ctx.BootstrapConfig() + cfgBytes, err := ctx.BootstrapConfig() if err != nil { return } diff --git a/cmd/dkl-local-server/render-context.go b/cmd/dkl-local-server/render-context.go index 552b0db..3c37b52 100644 --- a/cmd/dkl-local-server/render-context.go +++ b/cmd/dkl-local-server/render-context.go @@ -26,14 +26,10 @@ import ( "novit.tech/direktil/pkg/config" "novit.tech/direktil/pkg/localconfig" - - bsconfig "novit.tech/direktil/pkg/bootstrapconfig" ) var cmdlineParam = restful.QueryParameter("cmdline", "Linux kernel cmdline addition") -var b64 = base64.StdEncoding.WithPadding(base64.NoPadding) - type renderContext struct { Host *localconfig.Host SSLConfig *cfsslconfig.Config @@ -114,19 +110,8 @@ func (ctx *renderContext) Config() (ba []byte, cfg *config.Config, err error) { return } -func (ctx *renderContext) BootstrapConfig() (ba []byte, cfg *bsconfig.Config, err error) { - ba, err = ctx.render(ctx.Host.BootstrapConfig) - if err != nil { - return - } - - cfg = &bsconfig.Config{} - if err = yaml.Unmarshal(ba, cfg); err != nil { - log.Print("invalid bootstrap config yaml:\n", string(ba)) - return - } - - return +func (ctx *renderContext) BootstrapConfig() (ba []byte, err error) { + return ctx.render(ctx.Host.BootstrapConfig) } func (ctx *renderContext) render(templateText string) (ba []byte, err error) { @@ -190,7 +175,7 @@ func (ctx *renderContext) TemplateFuncs() map[string]any { for name, method := range map[string]any{ "base64": func(input string) string { - return b64.EncodeToString([]byte(input)) + return base64.StdEncoding.EncodeToString([]byte(input)) }, "host_ip": func() (s string) { diff --git a/cmd/dkl-local-server/ws-host.go b/cmd/dkl-local-server/ws-host.go index e6abe47..0f28680 100644 --- a/cmd/dkl-local-server/ws-host.go +++ b/cmd/dkl-local-server/ws-host.go @@ -211,9 +211,7 @@ func renderHost(w http.ResponseWriter, r *http.Request, what string, host *local // boot v2 case "bootstrap-config": - err = renderBootstrapConfig(w, r, ctx, false) - case "bootstrap-config.json": - err = renderBootstrapConfig(w, r, ctx, true) + err = renderBootstrapConfig(w, ctx) default: http.NotFound(w, r)