hashicorp / vault

A tool for secrets management, encryption as a service, and privileged access management
https://www.vaultproject.io/
Other
30.04k stars 4.12k forks source link

PKI: Imported Issuer Clarity #26037

Open dannyleesmith opened 3 months ago

dannyleesmith commented 3 months ago

Is your feature request related to a problem? Please describe. I am working on a project to automate CA rotation in PKI mounts. When using the pki/intermediate/set-signed endpoint the response generally looks like this:

{
  "request_id": "235a392a-6aab-6ced-3c6e-ab0fb7dca760",
  "lease_id": "",
  "lease_duration": 0,
  "renewable": false,
  "data": {
    "existing_issuers": [
      "27dd1484-7695-a508-9bf5-0c44ef5037a0",
      "1fbb3cd9-122c-c775-4b9f-6687c67eb039"
    ],
    "existing_keys": null,
    "imported_issuers": [
      "a44facfa-5fd5-fd1f-5ac7-79348ef61ee4"
    ],
    "imported_keys": null,
    "mapping": {
      "1fbb3cd9-122c-c775-4b9f-6687c67eb039": "",
      "27dd1484-7695-a508-9bf5-0c44ef5037a0": "",
      "a44facfa-5fd5-fd1f-5ac7-79348ef61ee4": "9a5e7782-18f5-20ca-41fe-7469e062a602"
    }
  },
  "warnings": null
}

This output was for a newly signed certificate for an intermediate where the chain has not changed.

It is frustrating that of all the issuers returned (imported_issuers in this case was 1 in this case but would be more if it were the first time parent CA(s) were being imported) there is not a field to specify the one that is for the new intermediate. This is important because it is the one you might want to feed through to following commands to perform actions such as updating it to have a friendly name, make it the default issuer for a role, make it the default issuer for the mount, etc.

Describe the solution you'd like What would be ideal is that set-signed could determine the issuer reference of all the returned issuers so it could be fed through to the following commands. Alternatively, if there is some sort of consistency to the returned values (for example if imported_issuers or mapping can also be determined based on the input then this could be calculated.

For example, in testing it seems that the mapping field has the keys returned in the order that a bundle was imported. For example, if I had a root, 2nd tier intermediate, and third tier intermediate, and I specifically built the PEM bundle to be in that order, the final key was the correct reference. If this is the case then a documentation update to make this clear that the order is always consistent would allow for those writing automation to ensure they have a consistent approach to building chains. Particularly if they only needed to ensure the final certificate was the new certificate that had just been signed.

Describe alternatives you've considered An alternative was to take a read of all the existing keys before performing set-signed and then comparing that to a list after the fact. This worked most of the time but did not feel as consistent.

Explain any additional use-cases The use cases above I feel cover the problem well.

Additional context No other context comes to mind but happy to field questions and provide what I can.

stevendpclark commented 2 months ago

Hi @dannyleesmith,

Agreed, when importing multiple CAs through set-signed the response isn't the most helpful. Also the ordering within mapping field should not be relied upon, there are quite a few layers of code that might in the future tweak the output of that map.

A few questions to start a discussion around this:

dannyleesmith commented 2 months ago

Hi @stevendpclark,

Yes I had found the mapping field to be unreliable so went through additional testing and that then led me to an answer that speaks to your first question.

Thanks for looking into this one.