Skip to content
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

support ipxe scripts over data uris in ipxe script urls #194

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ require (
github.com/stretchr/testify v1.7.0
github.com/tinkerbell/tftp-go v0.0.0-20200825172122-d9200358b6cd
github.com/tinkerbell/tink v0.0.0-20201109122352-0e8e57332303
github.com/vincent-petithory/dataurl v0.0.0-20191104211930-d1553a71de50
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.21.0
go.opentelemetry.io/otel v1.0.0-RC2
go.opentelemetry.io/otel/trace v1.0.0-RC2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,8 @@ github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/vincent-petithory/dataurl v0.0.0-20191104211930-d1553a71de50 h1:uxE3GYdXIOfhMv3unJKETJEhw78gvzuQqRX/rVirc2A=
github.com/vincent-petithory/dataurl v0.0.0-20191104211930-d1553a71de50/go.mod h1:FHafX5vmDzyP+1CQATJn7WFKc9CvnvxyvZy6I1MrG/U=
github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
Expand Down
4 changes: 4 additions & 0 deletions installers/custom_ipxe/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/tinkerbell/boots/ipxe"
"github.com/tinkerbell/boots/job"
"github.com/tinkerbell/boots/packet"
"github.com/vincent-petithory/dataurl"
)

type Installer struct{}
Expand All @@ -29,6 +30,9 @@ func (i Installer) BootScript() job.BootScript {
}
} else if strings.HasPrefix(j.UserData(), "#!ipxe") {
cfg = &packet.InstallerData{Script: j.UserData()}
} else if dataURL, err := dataurl.DecodeString(j.IPXEScriptURL()); err == nil {
// I assume err is returned unless there is a real data URL, but we might need different logic to ensure the URL was actually a data URL and not just empty
cfg = &packet.InstallerData{Script: string(dataURL.Data)}
} else if j.IPXEScriptURL() != "" {
cfg = &packet.InstallerData{Chain: j.IPXEScriptURL()}
} else {
Expand Down
20 changes: 20 additions & 0 deletions installers/custom_ipxe/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,26 @@ func TestIpxeScript(t *testing.T) {
echo userdata script
`,
},
{
"installer: ipxe data url",
"custom_ipxe",
// base64 encoding reads: "echo my data uri script" (no newline)
&packet.InstallerData{Chain: "data:text/plain;charset=utf-8;base64,ZWNobyBteSBkYXRhIHVyaSBzY3JpcHQ="},
displague marked this conversation as resolved.
Show resolved Hide resolved
`#!ipxe


params
param body Device connected to DHCP system
param type provisioning.104.01
imgfetch ${tinkerbell}/phone-home##params
imgfree

set packet_facility test.facility
set packet_plan test.slug

echo my data uri script
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test fails, with this line being a chain-url line, referencing the unexpanded data uri.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you paste the test failure here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm rerunning the test to capture the log output.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--- FAIL: TestIpxeScript (0.00s)
    --- FAIL: TestIpxeScript/installer:_ipxe_data_url (0.00s)
        main_test.go:172:
            	Error Trace:	main_test.go:172
            	Error:      	Not equal:
            	            	expected: "#!ipxe\n\n\nparams\nparam body Device connected to DHCP system\nparam type provisioning.104.01\nimgfetch ${tinkerbell}/phone-home##params\nimgfree\n\nset packet_facility test.facility\nset packet_plan test.slug\n\necho my data uri script\n"
            	            	actual  : "#!ipxe\n\n\nparams\nparam body Device connected to DHCP system\nparam type provisioning.104.01\nimgfetch ${tinkerbell}/phone-home##params\nimgfree\n\nset packet_facility test.facility\nset packet_plan test.slug\nchain --autofree data:text/plain;charset=utf-8;base64,ZWNobyBteSBkYXRhIHVyaSBzY3JpcHQ=\n"

            	            	Diff:
            	            	--- Expected
            	            	+++ Actual
            	            	@@ -11,4 +11,3 @@
            	            	 set packet_plan test.slug
            	            	+chain --autofree data:text/plain;charset=utf-8;base64,ZWNobyBteSBkYXRhIHVyaSBzY3JpcHQ=

            	            	-echo my data uri script
            	            	-
            	Test:       	TestIpxeScript/installer:_ipxe_data_url
{"level":"error","ts":1637329705.027709,"caller":"custom_ipxe/main.go:54","msg":"validating ipxe config","service":"github.com/tinkerbell/boots","error":"ipxe config URL or Script must be defined"}
FAIL

`,
},
}

for _, tc := range testCases {
Expand Down
2 changes: 1 addition & 1 deletion rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ ipxe/ipxe/snp-hua.efi:
ipxe/ipxe/build/${ipxev}.tar.gz: ipxev.mk ## Download iPXE source tarball
mkdir -p $(@D)
curl -fL https://github.com/ipxe/ipxe/archive/${ipxev}.tar.gz > $@
echo "${ipxeh} $@" | sha512sum -c
echo "${ipxeh} $@" | shasum -a 512 -c

# given t=$(patsubst ipxe/ipxe/build/%,%,$@)
# and $@=ipxe/ipxe/build/*/*
Expand Down