【问题标题】:BigTable Emulator cbt gives error on creating table "transport: authentication handshake failed: tls: first record does not look like a TLS handshake"BigTable Emulator cbt 在创建表时出错“传输:身份验证握手失败:tls:第一条记录看起来不像 TLS 握手”
【发布时间】:2020-09-18 12:59:52
【问题描述】:

我正在使用“cbt”云 BigTable CLI 工具。 在 .cbtrc 文件中设置变量后:附加图片

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

当我运行命令时: cbt createtable my-table

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

【问题讨论】:

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


【解决方案1】:

.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 环境变量,但这在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机器上,没有设置正确的环境,我得到同样的错误,但设置正确的环境后它可以工作:

$ 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 变量。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-06
    • 1970-01-01
    • 1970-01-01
    • 2019-06-07
    • 2020-09-06
    • 1970-01-01
    • 2019-12-16
    • 2015-01-04
    相关资源
    最近更新 更多