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

Fix handling of default values in subject #10

Merged
merged 1 commit into from
Nov 9, 2017
Merged

Fix handling of default values in subject #10

merged 1 commit into from
Nov 9, 2017

Conversation

SpencerBrown
Copy link
Contributor

@SpencerBrown SpencerBrown commented Nov 7, 2017

When creating a new certificate request or self-signed certificate, the subject map has a number of fields, all of which are optional. provider.go has a function nameFromResourceData that creates a pkix.Name struct from the data in the subject map.

That function tests for missing values by comparing with nil. This is incorrect, as missing string values come through as "" and missing list values come through as []. The result of this error is that the following HCL produces a certificate with the Subject Name C=, ST=, L=/postalCode=, O=MongoDB, OU=, CN=Example CA:

resource "tls_private_key" "ca" {
  algorithm = "RSA"
  rsa_bits = 2048
}
resource "tls_self_signed_cert" "ca" {
  is_ca_certificate = true
  key_algorithm = "RSA"
  allowed_uses = [
    "cert_signing",
    "ocsp_signing"
  ]
  private_key_pem = "${tls_private_key.ca.private_key_pem}"
  "subject" {
    organization = "MongoDB"
    common_name = "Example CA"
  }
  validity_period_hours = 8760
}

With this fix, the Subject Name is O=MongoDB, CN=Example CA as it should be.

@apparentlymart
Copy link
Member

Thanks for working on this, @SpencerBrown!

Looks good to me. Thanks for all of the thorough testing.

@apparentlymart apparentlymart merged commit d4c37ce into hashicorp:master Nov 9, 2017
nreisbeck pushed a commit to nreisbeck/tectonic-installer that referenced this pull request Jan 27, 2018
module/tls creates certificates with invalid distinguishedName
attributes for Subject and Issuer causing certificate validation issues.

Upstream Fix: terraform-provider-tls [coreos#10](hashicorp/terraform-provider-tls#10)
Fixes: coreos#2189

Verified Fix 2018-01-26
* Tectonic: 1.8.4-tectonic.2
* Terraform: v0.11.1
* Platforms: AWS, DigitalOcean

Thanks to @seslattery for helping debug, @SpencerBrown for the upstream
fix.
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants