如何在 GCP Keychain 中存储 CloudSQL 客户端 SSL 证书

How to store a CloudSQL client SSL certificate in GCP Keychain

我不确定在 Google 云密钥链中存储 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

结果是这些错误

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

另请检查您的密钥是否为 supported

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

算法 rsa-decrypt-oaep-3072-sha256 与要导入的实际密钥的长度不匹配。因此,在命令“gcloud kms keys versions import.

中将其替换为算法 rsa-decrypt-oaep-2048-sha256

示例: gcloud kms 密钥版本导入 --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 键名

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

openssl pkey -in <~/client-key.pem> -outform DER -out <~/client-key.der>