horten the unix socket path for shim

Use sha256 hash to shorten the unix socket path to satisfy the
length limitation of abstract socket path

This commit also backports the feature storing address path to
a file from v2 to keep compatibility

Fixes #3032

Signed-off-by: Eric Lin <linxiulei@gmail.com>
This commit is contained in:
Eric Lin
2019-02-22 15:56:08 +08:00
committed by leilei.lin
parent a15b6e2097
commit a631796fda
4 changed files with 112 additions and 3 deletions

View File

@@ -20,6 +20,8 @@ package shim
import (
"context"
"crypto/sha256"
"fmt"
"net"
"path/filepath"
"strings"
@@ -50,7 +52,8 @@ func SocketAddress(ctx context.Context, id string) (string, error) {
if err != nil {
return "", err
}
return filepath.Join(string(filepath.Separator), "containerd-shim", ns, id, "shim.sock"), nil
d := sha256.Sum256([]byte(filepath.Join(ns, id)))
return filepath.Join(string(filepath.Separator), "containerd-shim", fmt.Sprintf("%x.sock", d)), nil
}
// AnonDialer returns a dialer for an abstract socket