gpt4 book ai didi

ssl - terraform kubernetes 提供程序 - tls secret 未正确创建

转载 作者:太空宇宙 更新时间:2023-11-03 13:49:08 25 4
gpt4 key购买 nike

  1. 我通过 terraform 创建了一个自签名的 tls 证书和私钥。这些文件称为 server.key 和 server.crt
  2. 我使用此命令使用此证书和私钥创建一个 kubernetes tls secret:
    kubectl create secret tls dpaas-secret -n dpaas-prod --key server.key --cert server.crt

  3. 这工作正常,nginx ingress ssl 终止工作,以及以下 kubectl 命令:kubectl get secret test-secret -o yaml -n dpaas-prod
    使用 tls.crt pem 数据和 tls.key pem 数据返回正确的输出(请参阅下面第 6 步中的正确输出)

  4. 由于我们使用 terraform,我尝试通过 terraform kubernetes 提供程序使用相同的 server.key 和 servert.crt 文件创建相同的 secret 。然而这一次,命令:
    kubectl get secret test-secret -o yaml -n dpaas-prod
    为 crt pem 和 key pem 返回了奇怪的输出(请参阅下面第 5 步中的输出)并且我的 nginx ingress 上的 ssl 终止不起作用。
    这就是我通过 terraform 创建 kubernetes secret 的方式:

      resource "kubernetes_secret" "this" {
metadata {
name = "dpaas-secret"
namespace = "dpaas-prod"
}

data = {
"tls.crt" = "${path.module}/certs/server.crt"
"tls.key" = "${path.module}/certs/server.key"
}

type = "kubernetes.io/tls"
}
  1. 第 4 步后的错误输出。注意 tls.crt 和 tls.key 的短值(通过 terraform 创建的 secret ):
    *apiVersion: v1
data:
tls.crt: bXktdGVzdHMvY2VydHMvc2VydmVyLmNydA==
tls.key: bXktdGVzdHMvY2VydHMvc2VydmVyLmtleQ==
`enter code here` kind: Secret
metadata:
creationTimestamp: "2019-12-17T16:18:22Z"
name: dpaas-secret
namespace: dpaas-prod
resourceVersion: "9879"
selfLink: /api/v1/namespaces/dpaas-prod/secrets/dpaas-secret
uid: d84db7f0-20e8-11ea-aa92-1269ad9fd693
type: kubernetes.io/tls*
  1. 按照第 2 步正确输出(通过 kubectl 命令创建的 secret )
*apiVersion: v1
data:
tls.crt: LS0tLS1CRUdJTiBDRVJUSUZJQ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05ZU3FvOU55MkZQNVBmQlplQgpWbzYvekhHR0dqVkFPQUhBczA5My8zZUZxSFRleWVCSzhQR
kJWMHh5em9ZZThxYUhBR1JxVnpjS240Zy9LVjhWClpjVGMwTm5aQzB5b09NZkhYUTVnQm1kWnpBVXBFOHlqZzhucGV0c0NnWUVBd0ZxU1ZxYytEUkhUdk4ranNiUmcKUG5DWG1mTHZ2RDlXWVRtYUc0cnNXaFk1cWUrQ0ZqRGpjOVRSQmsvMzdsVWZkVGVRVlY2Mi82L
3VVdVg2eGhRNwppeGtVWnB2Q3ZIVHhiY1hheUNRUFUvN0xrYWIzeC9hMUtvdWlVTHdhclQxdmE1OW1TNTF1SlkzSEJuK3RNOGZXCnNHZ0szMVluOThJVEp6T3pQa1UrdjRFQ2dZQUpRQkFCKzhocCtPbVBhbk10Yng5ZHMydzg0MWdtRlN3ZnBXcloKYWxCQ0RqbWRLS
mVSOGJxaUxDNWJpWWZiYm1YUEhRTDBCWGV0UlI0WmNGVE5JR2FRZCtCUU9iS0gzZmtZNnRyZgpEL2RLR1hUQVUycHdRNWFSRWRjSTFNV0drcmdTM0xWWHJmZnl3bHlmL2xFempMRFhDSloyTVhyalZTYWtVOHFwCk1lY3BHUUtCZ0c0ZjVobDRtL1EvaTNJdGZJbGw4W
DFRazFUSXVDK0JkL1NGM0xVVW5JUytyODA4dzVuaTNCUnEKNXgvQjFnRUhZbTNjSTROajR5ZzEvcE1CejhPMk1PeFhVbVNVZVh6dit1MG5oOFQxUE96eDJHOTNZaVlOL0cvNQpjMlBMSFMvTTlmVjhkTEVXL0hBVFM3K0hsMDFGQlVlREhrODQrVXlha2V2ZFU2djdVZ
2ErCi0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0tCg==
kind: Secret
metadata:
creationTimestamp: "2019-12-17T16:16:56Z"
name: dpaas-secret
namespace: dpaas-prod
resourceVersion: "9727"
selfLink: /api/v1/namespaces/dpaas-prod/secrets/dpaas-secret
uid: a5739134-20e8-11ea-a977-0a0ee9b505f9
type: kubernetes.io/tls*

问题:为什么在使用 terraform 添加 secret 时,kubernetes secret pem 数据变短(损坏?)?
我们使用 terraform 版本 0.12.8 和 kubernetes 1.13

为了重现这里是文件链接:

最佳答案

问题是您将证书文件的路径编码为 secret ,而不是文件的内容

如果您对示例中的 secret 字符串进行 base64 解码,您会发现情况就是这样:

$ echo -n bXktdGVzdHMvY2VydHMvc2VydmVyLmNydA== | base64 -d
my-tests/certs/server.crt
$ echo -n bXktdGVzdHMvY2VydHMvc2VydmVyLmtleQ== | base64 -d
my-tests/certs/server.key

所以,而不是这个:

data = {
"tls.crt" = "${path.module}/certs/server.crt"
"tls.key" = "${path.module}/certs/server.key"
}

这样做:

data = {
"tls.crt" = file("${path.module}/certs/server.crt")
"tls.key" = file("${path.module}/certs/server.key")
}

关于ssl - terraform kubernetes 提供程序 - tls secret 未正确创建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59378938/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com