oracle / terraform-provider-oci

Terraform Oracle Cloud Infrastructure provider
https://www.terraform.io/docs/providers/oci/
Mozilla Public License 2.0
751 stars 672 forks source link

terraform doesn't support PKCS#8 format API Keys #2127

Open luckeyca opened 3 months ago

luckeyca commented 3 months ago

Community Note

Terraform Version and Provider Version

Terraform v1.5.4 on linux_amd64

Affected Resource(s)

affected_resources = terraform

Terraform Configuration Files

N/A

Expected Behavior

As per issue: https://github.com/oracle/oci-go-sdk/issues/242, terraform should support both PKCS#1 and PKCS#8 API key formats.

Actual Behavior

It doesn't support PKCS#8 format. If the API key is generated using openssl version 3 with the newer header, terraform plan/apply will fail with error: Error: can not create client, bad configuration: did not find a proper configuration for private key. newer header format: -----BEGIN ENCRYPTED PRIVATE KEY-----

Once created key with PKCS#1 format using openssl version 1 with the older header, terraform plan/apply works fine. older header format:

-----BEGIN RSA PRIVATE KEY----- Proc-Type: 4,ENCRYPTED DEK-Info: AES-256-CBC,

Steps to Reproduce

  1. openssl genrsa -out ./ociprivatekeyfile -aes256 2048
  2. openssl rsa -pubout -in ./ociprivatekeyfile -out ./ociprivatekeyfile_public.pem
  3. upload the public key generated from step 2 to oci console under the terraform user id.
  4. update ~/.oci/config file with the necessary information
  5. run terraform plan to create a simple compartment

if the commands 1&2 were done using openssl version 1, terraform plan will succeed, if using openssl version 3, terraform plan will fail.

Important Factoids

References

tf-oci-pub commented 3 months ago

Thank you for reporting the issue. We observed the affected resources are not provided in the description or it's incorrect. We request you to add it in issue description as mentioned in below format. Example: affected_resources = oci_core_instance , oci_core_instances

If it's not related to any particular resource then mention affected resource as terraform. Example: affected_resources = terraform

As this works through automation, request you to follow exact syntax.

luckeyca commented 3 months ago

Hi, updated "affected_resources" as instructed. Please let me know if you need more details.

luckeyca commented 3 months ago

Hi, Please make sure developers tested the following two situations using ENCRYPTED keys, NOT keys without password

  1. Deleting the ~/.oci/config file and only left the environment variables as below.

export TF_VAR_fingerprint= export TF_VAR_user_oci= export TF_VAR_tenancy_ocid= export TF_VAR_region= export TF_VAR_private_key_password= export TF_VAR_private_key_path=

  1. unset all the TFVAR environment variables and only use ~/.oci/config
luckeyca commented 3 months ago

We DO NOT set these settings in the provider block given it's static, but only use ~/.oci/config and TFVAR environment variables. DO need BOTH ~/.oci/config AND TFVAR environment variables work independently for different use cases.