magodo / terraform-provider-restful

Terraform provider to manage RESTful resources
https://registry.terraform.io/providers/magodo/restful
Mozilla Public License 2.0
15 stars 5 forks source link

Create resources with secret attributed injected from HSM [input attributes] #52

Open LaurentLesle opened 1 year ago

LaurentLesle commented 1 year ago

Customers have some regulated use cases and cannot include in configuration files (tfvars) or non HSM storage some secret attributes. However those attributes may be required to create or update a resource.

This issue is the opposite of #51 (Store sensitive attributes as HSM secret value [output attributes]) and propose a way to retrieve sensitive data from external HSM and inject them into the payload.

Some API calls are returning sensitive information (passwords, authorisation keys, crypto objects...) that should not be persisted in the tfstate as defined in #51 . The same requirement applies to this feature.

Design goals:

Implementation directions:

This issue describes the desired state of that feature. In this scenario the Authorization Key is not stored in a variable but retrieved from the HSM and injected by the provider into the payload request of the PUT or POST method

With this approach secure attributes are kept into the HSM and only injected at PUT or POST execution. Their value is never stored into the tfstate.

resource "restful_resource" "resource" {
  path = format("...")
  create_method = "PUT"
  body = jsonencode({
    name = "name"
  })

 hsm_input_attrs = {

  authorizationKey = {
     provider = azure.keyvault
     definition = {
       endpoint = "resource id of the keyvault secret"
       // HSM security context can inherit from the provider context or provide a specific block in the provider to set the HSM security context.
     }
      // secret value to retrieve from the HSM
     secret_name = "authorization-key"
      // JSON path where the value must be included
     path = "body.authorization_key"
   }

}

After apply execution it is expected that the output attribute will have "body.authorization_key" removed from the json.

 output = {
   // api response json with hsm_input_attrs removed
  }
image