Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
FC: Fix error of overlong firecracker API unix socket
Browse files Browse the repository at this point in the history
When sandbox id is too long, it will incur error of overlong firecracker
API unix socket.
In Linux, sun_path could maximumly contains 108 bytes in size.
http://man7.org/linux/man-pages/man7/unix.7.html
So here we try to truncate FC id to only keep the size of UUID(128bit).

Fixes: #2504

Signed-off-by: Penny Zheng <[email protected]>
  • Loading branch information
Pennyzct committed Mar 23, 2020
1 parent c3bafd5 commit 44e2349
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
15 changes: 14 additions & 1 deletion virtcontainers/fc.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,19 @@ func (fc *firecracker) trace(name string) (opentracing.Span, context.Context) {
return span, ctx
}

//At some cases, when sandbox id is too long, it will incur error of overlong
//firecracker API unix socket(fc.socketPath).
//In Linux, sun_path could maximumly contains 108 bytes in size.
//(http://man7.org/linux/man-pages/man7/unix.7.html)
func (fc *firecracker) truncateID(id string) string {
if len(id) > 32 {
//truncate the id to only leave the size of UUID(128bit).
return id[:32]
}

return id
}

// For firecracker this call only sets the internal structure up.
// The sandbox will be created and started through startSandbox().
func (fc *firecracker) createSandbox(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig, stateful bool) error {
Expand All @@ -190,7 +203,7 @@ func (fc *firecracker) createSandbox(ctx context.Context, id string, networkNS N

//TODO: check validity of the hypervisor config provided
//https://github.com/kata-containers/runtime/issues/1065
fc.id = id
fc.id = fc.truncateID(id)
fc.state.set(notReady)
fc.config = *hypervisorConfig
fc.stateful = stateful
Expand Down
16 changes: 16 additions & 0 deletions virtcontainers/fc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,19 @@ func TestFCGenerateSocket(t *testing.T) {
assert.NotEmpty(hvsock.UdsPath)
assert.NotZero(hvsock.Port)
}

func TestFCTruncateID(t *testing.T) {
assert := assert.New(t)

fc := firecracker{}

testLongID := "3ef98eb7c6416be11e0accfed2f4e6560e07f8e33fa8d31922fd4d61747d7ead"
expectedID := "3ef98eb7c6416be11e0accfed2f4e656"
id := fc.truncateID(testLongID)
assert.Equal(expectedID, id)

testShortID := "3ef98eb7c6416be11"
expectedID = "3ef98eb7c6416be11"
id = fc.truncateID(testShortID)
assert.Equal(expectedID, id)
}

0 comments on commit 44e2349

Please sign in to comment.