base64 k8s (yaml) decoder expects padding

This commit is contained in:
Mikaël Cluseau
2026-02-10 21:08:45 +01:00
parent 6d9499ebb1
commit 629bb21f12
4 changed files with 10 additions and 34 deletions

View File

@ -51,7 +51,7 @@ func buildBootISO(out io.Writer, ctx *renderContext) (err error) {
} }
// create a tag file // create a tag file
bootstrapBytes, _, err := ctx.BootstrapConfig() bootstrapBytes, err := ctx.BootstrapConfig()
if err != nil { if err != nil {
return return
} }

View File

@ -4,7 +4,6 @@ import (
"archive/tar" "archive/tar"
"bytes" "bytes"
"crypto" "crypto"
"encoding/json"
"fmt" "fmt"
"io" "io"
"log" "log"
@ -12,26 +11,20 @@ import (
"os" "os"
"github.com/klauspost/compress/zstd" "github.com/klauspost/compress/zstd"
yaml "gopkg.in/yaml.v2"
"novit.tech/direktil/pkg/cpiocat" "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) log.Printf("sending bootstrap config for %q", ctx.Host.Name)
_, cfg, err := ctx.BootstrapConfig() ba, err := ctx.BootstrapConfig()
if err != nil { if err != nil {
return err return err
} }
if asJson { _, err = w.Write(ba)
err = json.NewEncoder(w).Encode(cfg) return
} else {
err = yaml.NewEncoder(w).Encode(cfg)
}
return nil
} }
func buildInitrd(out io.Writer, ctx *renderContext) (err error) { func buildInitrd(out io.Writer, ctx *renderContext) (err error) {
@ -72,7 +65,7 @@ func buildInitrd(out io.Writer, ctx *renderContext) (err error) {
} }
// config // config
cfgBytes, _, err := ctx.BootstrapConfig() cfgBytes, err := ctx.BootstrapConfig()
if err != nil { if err != nil {
return return
} }

View File

@ -26,14 +26,10 @@ import (
"novit.tech/direktil/pkg/config" "novit.tech/direktil/pkg/config"
"novit.tech/direktil/pkg/localconfig" "novit.tech/direktil/pkg/localconfig"
bsconfig "novit.tech/direktil/pkg/bootstrapconfig"
) )
var cmdlineParam = restful.QueryParameter("cmdline", "Linux kernel cmdline addition") var cmdlineParam = restful.QueryParameter("cmdline", "Linux kernel cmdline addition")
var b64 = base64.StdEncoding.WithPadding(base64.NoPadding)
type renderContext struct { type renderContext struct {
Host *localconfig.Host Host *localconfig.Host
SSLConfig *cfsslconfig.Config SSLConfig *cfsslconfig.Config
@ -114,19 +110,8 @@ func (ctx *renderContext) Config() (ba []byte, cfg *config.Config, err error) {
return return
} }
func (ctx *renderContext) BootstrapConfig() (ba []byte, cfg *bsconfig.Config, err error) { func (ctx *renderContext) BootstrapConfig() (ba []byte, err error) {
ba, err = ctx.render(ctx.Host.BootstrapConfig) return 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) render(templateText string) (ba []byte, err error) { 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{ for name, method := range map[string]any{
"base64": func(input string) string { "base64": func(input string) string {
return b64.EncodeToString([]byte(input)) return base64.StdEncoding.EncodeToString([]byte(input))
}, },
"host_ip": func() (s string) { "host_ip": func() (s string) {

View File

@ -211,9 +211,7 @@ func renderHost(w http.ResponseWriter, r *http.Request, what string, host *local
// boot v2 // boot v2
case "bootstrap-config": case "bootstrap-config":
err = renderBootstrapConfig(w, r, ctx, false) err = renderBootstrapConfig(w, ctx)
case "bootstrap-config.json":
err = renderBootstrapConfig(w, r, ctx, true)
default: default:
http.NotFound(w, r) http.NotFound(w, r)