Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for disabled_validations to the PKI CMPv2 config resource #2412

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ FEATURES:
* Add support for key_usage and serial_number to `vault_pki_secret_backend_intermediate_cert_request` ([#2404])(https://github.com/hashicorp/terraform-provider-vault/pull/2404)
* Add support for `skip_import_rotation` in `vault_database_secret_backend_static_role`. Requires Vault Enterprise 1.18.5+ ([#2386](https://github.com/hashicorp/terraform-provider-vault/pull/2386)).
* Add support for `not_after` in `vault_pki_secret_backend_cert`, `vault_pki_secret_backend_role`, `vault_pki_secret_backend_root_cert`, `vault_pki_secret_backend_root_sign_intermediate`, and `vault_pki_secret_backend_sign` ([#2385](https://github.com/hashicorp/terraform-provider-vault/pull/2385)).
* Add suppor for `disabled_validations` in `vault_pki_secret_backend_config_cmpv2` [#2412](https://github.com/hashicorp/terraform-provider-vault/pull/2412)

BUGS:

Expand Down
1 change: 1 addition & 0 deletions internal/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ const (
FieldAuthenticators = "authenticators"
FieldEnableSentinelParsing = "enable_sentinel_parsing"
FieldAuditFields = "audit_fields"
FieldDisabledValidations = "disabled_validations"
FieldLastUpdated = "last_updated"
FieldCustomEndpoint = "custom_endpoint"
FieldPrivateKeyID = "private_key_id"
Expand Down
10 changes: 10 additions & 0 deletions vault/data_source_pki_secret_backend_config_cmpv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ func pkiSecretBackendConfigCMPV2DataSource() *schema.Resource {
Type: schema.TypeString,
},
},
consts.FieldDisabledValidations: {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every other field seems to have a "computed" line - why not this one? How is this different than AuditFields in that sense? I'm also not really sure how optional works here? Most of these don't have that listed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The computed argument is mainly used when a value is returned from the server when no initial value from Terraform itself was provided. In this case since I believe the value returned will be an empty list it isn't required.

Optional only means the field does not need to be specified within the resource block

Type: schema.TypeList,
Required: false,
Optional: true,
Description: "A comma-separated list of validations not to perform on CMPv2 messages.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
consts.FieldLastUpdated: {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -108,6 +117,7 @@ func readCMPV2Config(ctx context.Context, d *schema.ResourceData, client *api.Cl
consts.FieldDefaultPathPolicy,
consts.FieldEnableSentinelParsing,
consts.FieldAuditFields,
consts.FieldDisabledValidations,
consts.FieldLastUpdated,
}

Expand Down
10 changes: 10 additions & 0 deletions vault/resource_pki_secret_backend_config_cmpv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ func pkiSecretBackendConfigCMPV2Resource() *schema.Resource {
Type: schema.TypeString,
},
},
consts.FieldDisabledValidations: {
Type: schema.TypeList,
Required: false,
Optional: true,
Description: "A comma-separated list of validations not to perform on CMPv2 messages.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
consts.FieldLastUpdated: {
Type: schema.TypeString,
Computed: true, // read-only property
Expand Down Expand Up @@ -99,6 +108,7 @@ func pkiSecretBackendConfigCMPV2Write(ctx context.Context, d *schema.ResourceDat
consts.FieldDefaultPathPolicy,
consts.FieldEnableSentinelParsing,
consts.FieldAuditFields,
consts.FieldDisabledValidations,
}

data := map[string]interface{}{}
Expand Down
12 changes: 9 additions & 3 deletions vault/resource_pki_secret_backend_config_cmpv2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ package vault

import (
"fmt"
"github.com/hashicorp/terraform-provider-vault/internal/provider"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"

"github.com/hashicorp/terraform-provider-vault/internal/consts"
"github.com/hashicorp/terraform-provider-vault/internal/provider"
"github.com/hashicorp/terraform-provider-vault/testutil"
)

Expand Down Expand Up @@ -88,7 +88,10 @@ func TestAccPKISecretBackendConfigCMPV2_AllFields(t *testing.T) {
resource.TestCheckResourceAttr(resourceBackend, consts.FieldAuthenticators+".0.cert.cert_role", "a-role"),
resource.TestCheckResourceAttr(resourceBackend, consts.FieldEnableSentinelParsing, "true"),
resource.TestCheckResourceAttr(resourceBackend, consts.FieldAuditFields+".#", "20"),
resource.TestCheckResourceAttrSet(dataName, consts.FieldLastUpdated),
resource.TestCheckResourceAttr(resourceBackend, consts.FieldDisabledValidations+".#", "2"),
resource.TestCheckResourceAttr(resourceBackend, consts.FieldDisabledValidations+".0", "DisableMatchingKeyIdValidation"),
resource.TestCheckResourceAttr(resourceBackend, consts.FieldDisabledValidations+".1", "DisableCertTimeValidation"),
resource.TestCheckResourceAttrSet(resourceBackend, consts.FieldLastUpdated),

// Validate that the data property can read back everything filled in
resource.TestCheckResourceAttr(dataName, consts.FieldBackend, backend),
Expand All @@ -98,9 +101,11 @@ func TestAccPKISecretBackendConfigCMPV2_AllFields(t *testing.T) {
resource.TestCheckResourceAttr(dataName, consts.FieldAuthenticators+".0.%", "1"),
resource.TestCheckResourceAttr(dataName, consts.FieldAuthenticators+".0.cert.%", "2"),
resource.TestCheckResourceAttr(dataName, consts.FieldAuthenticators+".0.cert.accessor", "test"),
resource.TestCheckResourceAttr(resourceBackend, consts.FieldAuthenticators+".0.cert.cert_role", "a-role"),
resource.TestCheckResourceAttr(dataName, consts.FieldAuthenticators+".0.cert.cert_role", "a-role"),
resource.TestCheckResourceAttr(dataName, consts.FieldEnableSentinelParsing, "true"),
resource.TestCheckResourceAttr(dataName, consts.FieldAuditFields+".#", "20"),
resource.TestCheckResourceAttr(dataName, consts.FieldDisabledValidations+".0", "DisableMatchingKeyIdValidation"),
resource.TestCheckResourceAttr(dataName, consts.FieldDisabledValidations+".1", "DisableCertTimeValidation"),
resource.TestCheckResourceAttrSet(dataName, consts.FieldLastUpdated),
),
},
Expand Down Expand Up @@ -145,6 +150,7 @@ resource "vault_pki_secret_backend_config_cmpv2" "test" {
"signature_bits", "exclude_cn_from_sans", "ou", "organization", "country",
"locality", "province", "street_address", "postal_code", "serial_number",
"use_pss", "key_type", "key_bits", "add_basic_constraints"]
disabled_validations = ["DisableMatchingKeyIdValidation", "DisableCertTimeValidation"]
}

data "vault_pki_secret_backend_config_cmpv2" "test" {
Expand Down
2 changes: 2 additions & 0 deletions website/docs/d/pki_secret_backend_config_cmpv2.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ The following arguments are supported:

* `audit_fields` - Fields parsed from the CSR that appear in the audit and can be used by sentinel policies.

* `disabled_validations` - A comma-separated list of validations not to perform on CMPv2 messages.

* `last_updated` - A read-only timestamp representing the last time the configuration was updated.

<a id="nestedatt--authenticators"></a>
Expand Down
5 changes: 4 additions & 1 deletion website/docs/r/pki_secret_backend_config_cmpv2.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ resource "vault_pki_secret_backend_config_cmpv2" "example" {
"signature_bits", "exclude_cn_from_sans", "ou", "organization", "country",
"locality", "province", "street_address", "postal_code", "serial_number",
"use_pss", "key_type", "key_bits", "add_basic_constraints"]
disabled_validations = ["DisableMatchingKeyIdValidation"]
}
```

Expand All @@ -72,8 +73,10 @@ The following arguments are supported:
* `enable_sentinel_parsing` - (Optional) If set, parse out fields from the provided CSR making them available for Sentinel policies.

* `enabled` - (Optional) Specifies whether CMPv2 is enabled.

* `audit_fields` - (Optional) Fields parsed from the CSR that appear in the audit and can be used by sentinel policies.

* `disabled_validations` - (Optional) A comma-separated list of validations not to perform on CMPv2 messages.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be nice to mention what the (current) supported options are.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the norm isn't to specify a list here as it can fall out of sync with the server side of things, especially across revisions.

Its the same reasoning the TFVP team have shied away from enforcing the valid values on the input schema as it causes end-user friction that we need to update and publish a new TFVP version every time something on the server changes


<a id="nestedatt--authenticators"></a>
### Nested Schema for `authenticators`
Expand Down
Loading