From f03d4574bca26bca3875cccee1f0385fe07b78cd Mon Sep 17 00:00:00 2001 From: schmidtw Date: Thu, 7 Mar 2024 17:21:49 -0800 Subject: [PATCH] Convert the inline PEM into the expected bytes. --- cmd/xmidt-agent/instructions.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/cmd/xmidt-agent/instructions.go b/cmd/xmidt-agent/instructions.go index 6ebc58a..5647b31 100644 --- a/cmd/xmidt-agent/instructions.go +++ b/cmd/xmidt-agent/instructions.go @@ -4,7 +4,9 @@ package main import ( + "encoding/pem" "os" + "strings" "github.com/xmidt-org/xmidt-agent/internal/jwtxt" "github.com/xmidt-org/xmidt-agent/internal/jwtxt/event" @@ -55,8 +57,19 @@ func provideInstructions(in instructionsIn) (*jwtxt.Instructions, error) { if len(in.Service.JwtTxtRedirector.PEMs) > 0 { pems := make([][]byte, 0, len(in.Service.JwtTxtRedirector.PEMs)) - for _, pem := range in.Service.JwtTxtRedirector.PEMs { - pems = append(pems, []byte(pem)) + for _, item := range in.Service.JwtTxtRedirector.PEMs { + block, rest := pem.Decode([]byte(item)) + + if block == nil || strings.TrimSpace(string(rest)) != "" { + return nil, jwtxt.ErrInvalidInput + } + + buf := pem.EncodeToMemory(block) + if buf == nil { + return nil, jwtxt.ErrInvalidInput + } + + pems = append(pems, buf) } opts = append(opts, jwtxt.WithPEMs(pems...)) }