使用terraform oci提供程序的私钥进行openssl检查失败



我在azure管道代理中运行terraform plan时遇到错误(使用terraform oci提供程序(。

Error: can not create client, bad configuration: did not find a proper configuration for private key
│ 
│   with provider["registry.terraform.io/hashicorp/oci"],
│   on provider.tf line 4, in provider "oci":
│    4: provider "oci" {

这是供应商。tf:

## Provider file
## Define the provider
provider "oci" {
tenancy_ocid     = var.tenancy_ocid
user_ocid        = var.user_ocid
fingerprint      = var.fingerprint
private_key_path = var.private_key_path
region           = var.region
}

所有变量值都是使用类似$TF_VAR_private_key_path的环境变量传递的。私钥文件被添加到管道库安全文件中,并在管道运行任务时下载到代理。

因此,请检查该文件是否存在于代理中,并且它在那里。尝试使用cat命令打印.pem文件。输出看起来不错。

然后我尝试用openssl命令检查.pem文件,它返回错误:

$ openssl rsa -in $TF_VAR_private_key_path -check
unable to load Private Key
139790939505984:error:0D07209B:asn1 encoding routines:ASN1_get_object:too long:../crypto/asn1/asn1_lib.c:91:
139790939505984:error:0D068066:asn1 encoding routines:asn1_check_tlen:bad object header:../crypto/asn1/tasn_dec.c:1137:
139790939505984:error:0D07803A:asn1 encoding routines:asn1_item_embed_d2i:nested asn1 error:../crypto/asn1/tasn_dec.c:309:Type=RSAPrivateKey
139790939505984:error:04093004:rsa routines:old_rsa_priv_decode:RSA lib:../crypto/rsa/rsa_ameth.c:133:
139790939505984:error:0D07209B:asn1 encoding routines:ASN1_get_object:too long:../crypto/asn1/asn1_lib.c:91:
139790939505984:error:0D068066:asn1 encoding routines:asn1_check_tlen:bad object header:../crypto/asn1/tasn_dec.c:1137:
139790939505984:error:0D07803A:asn1 encoding routines:asn1_item_embed_d2i:nested asn1 error:../crypto/asn1/tasn_dec.c:309:Type=PKCS8_PRIV_KEY_INFO
139790939505984:error:0907B00D:PEM routines:PEM_read_bio_PrivateKey:ASN1 lib:../crypto/pem/pem_pkey.c:88:

有人能帮助理解openssl的实际问题吗?

注意:

当通过存储库文件而不是安全文件直接在目录中提供api_key文件时,就不会出现这样的错误。可能是安全文件为私钥文件添加了额外的编码??

错误已修复。我比较了这两个api文件的内容——一个是从安全文件($TF_VAR_private_key_path(下载到管道代理的,另一个是作为文件添加到存储库(/home/vsts/work/1/s/terraform/api_keys/oci_api_key.pem(的。

cat $TF_VAR_private_key_path
cat /home/vsts/work/1/s/terraform/api_keys/oci_api_key.pem
openssl rsa -in $TF_VAR_private_key_path -check
openssl rsa -in /home/vsts/work/1/s/terraform/api_keys/oci_api_key.pem -check

问题是我添加到azure pipeline库的安全文件的api密钥文件中缺少了一些行。将正确的api密钥文件上传到安全文件后,一切都很好!

这个博客说明了这个错误的一些原因。

如果您收到诸如provider.oci: can not create client, bad configuration: did not find a proper configuration for private key之类的错误消息,您可能错过了以下内容之一:

  • 未在配置中指定private_key或private_key_path
  • 指定不是私钥文件的有效路径的private_key_path
  • 未为加密的私钥指定private_key_password
  • 为加密的私钥指定不正确的private_key_password
  • 设置API密钥不正确

最新更新