BigTable Emulator cbt在创建表时出现错误“传输:身份验证握手失败:tls:第一条记录看起来不像TLS握手”

时间:2020-09-18 12:59:52

标签: google-cloud-platform google-cloud-bigtable

我正在使用“ cbt” Cloud BigTable CLI工具。 在.cbtrc文件中设置变量后:附加图像 enter image description here

BigTable模拟器正在运行: btemulator.exe --host = localhost --port = 8086 [bigtable] Cloud Bigtable模拟器运行在127.0.0.1:8086

当我运行命令时: cbt createtable我的表

我遇到错误: 正在创建表:rpc错误:代码=不可用desc =连接错误:desc =“传输:身份验证握手失败:tls:第一条记录看起来不像TLS握手”

1 个答案:

答案 0 :(得分:0)

.rc文件是UNIX系统的标准,但对于Windows没有那么多。

在这种情况下,我们可以检查cbt命令的代码以检查其如何找到.cbtrc文件,它是in this piece of code

// Filename returns the filename consulted for standard configuration.
func Filename() string {
    // TODO(dsymonds): Might need tweaking for Windows.
    return filepath.Join(os.Getenv("HOME"), ".cbtrc")
}

代码获取HOME env变量,但这在Windows中不可用(this superuser question中的某些详细信息)。 windows equivalent%HOMEPATH%。代码上甚至还有一个TODO,以使其在Windows中更好地工作。

这意味着cbt命令没有找到配置文件,因此没有应用它。

您可以在计算机中设置HOME env变量,也可以直接在命令中传递命令标志:

cbt -project fake-project -instance fake-instance -admin-endpoint localhost:8086 -data-endpoint localhost:8086 -creds C:\path\to\your\creds -auth-token <TOKEN> createtable my-table

此外,您必须为cbt设置正确的环境变量,以了解它正在模拟器上运行。这意味着设置BIGTABLE_EMULATOR_HOST环境变量。

在linux机器上,没有设置正确的env,我会得到相同的错误,但是在设置正确的env之后它可以工作:

$ cbt -project test -instance test -admin-endpoint localhost:8086 -data-endpoint localhost:8086 createtable test
2020/10/13 08:23:13 Creating table: rpc error: code = Unavailable desc = connection error: desc = "transport: authentication handshake failed: tls: first record does not look like a TLS handshake"

$ $(gcloud beta emulators bigtable env-init)

$ cbt -project test -instance test -admin-endpoint localhost:8086 -data-endpoint localhost:8086 createtable test

$ cbt -project test -instance test -admin-endpoint localhost:8086 -data-endpoint localhost:8086 ls
test

cbt代码中,我们还可以看到,如果设置了该环境变量,它将使调用不安全,但是如果未设置,它将尝试使调用变得安全,从而导致TLS错误(本地仿真器未设置安全端点。

这可以在this piece of code中看到:

// DefaultClientOptions returns the default client options to use for the
// client's gRPC connection.
func DefaultClientOptions(endpoint, scope, userAgent string) ([]option.ClientOption, error) {
    var o []option.ClientOption
    // Check the environment variables for the bigtable emulator.
    // Dial it directly and don't pass any credentials.
    if addr := os.Getenv("BIGTABLE_EMULATOR_HOST"); addr != "" {
        conn, err := grpc.Dial(addr, grpc.WithInsecure())
        if err != nil {
            return nil, fmt.Errorf("emulator grpc.Dial: %v", err)
        }
        o = []option.ClientOption{option.WithGRPCConn(conn)}
    } else {
        o = []option.ClientOption{
            option.WithEndpoint(endpoint),
            option.WithScopes(scope),
            option.WithUserAgent(userAgent),
        }
    }
    return o, nil
}

总结:请确保您设置了正确的环境变量,以使cbt正常工作。对于您看到的特定错误,可能是缺少BIGTABLE_EMULATOR_HOST变量。