如何在 GCP 钥匙串中存储 CloudSQL 客户端 SSL 证书

问题描述

我不确定在 Google Cloud 密钥链中存储 Cloudsql ssl 证书时使用哪些选项,我的导入作业失败。哪些是客户端 SSL 证书的正确加密选项?

    # Get the private  key
    gcloud sql ssl client-certs create devDb-prv-key ~/client-key.pem --instance=devDb

    # Store the private key in the KeyChain
    gcloud kms import-jobs create postges-prv-key-import \
        --location $GPC_REGION \
        --keyring $KMS_RING \
        --import-method rsa-oaep-3072-sha1-aes-256 \
        --protection-level software

    # Create an empty version first
    gcloud kms keys create private-postgres-ssl-key \
        --location $GPC_REGION  \
        --keyring $KMS_RING \
        --purpose asymmetric-encryption \
        --default-algorithm=rsa-decrypt-oaep-3072-sha256 \
        --skip-initial-version-creation

    # Now you can import the file 
    gcloud kms keys versions import \
        --import-job postges-prv-key-import \
        --location $GPC_REGION \
        --keyring $KMS_RING \
        --key private-postgres-ssl-key \
        --algorithm rsa-decrypt-oaep-3072-sha256 \
        --target-key-file ~/client-key.pem

结果就是这些错误

enter image description here

enter image description here

解决方法

我在我的环境中对此进行了测试,并且能够成功导入密钥。找到随附的屏幕截图。

算法 rsa-decrypt-oaep-3072-sha256 与要导入的实际密钥长度不匹配。因此,在命令“gcloud kms keys versions import”中将其替换为算法 rsa-decrypt-oaep-2048-sha256。

示例: gcloud kms 密钥版本 import --import-job job-name --location us-central1 --keyring key-ring-name -- key key-name --algorithm rsa-decrypt-oaep-2048-sha256 --target-key-file client-key.der

使用下面的命令列出密钥版本及其状态。

gcloud kms 密钥版本列表 --keyring key-ring-name --location us-central1 --key key-name

注意: 将私钥转换为 der 格式并使用该文件导入密钥。要将文件转换为 der 格式,您还可以使用以下命令。

openssl pkey -in -outform DER -out

key import failed

key import successful

,

您应该查看官方 documentation 以在 CloudSQL 中管理您的密钥。

还要检查您的密钥是否为 supported