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

Spaces in record names cause plugin crash #210

Open
1 task done
codello opened this issue May 18, 2022 · 0 comments
Open
1 task done

Spaces in record names cause plugin crash #210

codello opened this issue May 18, 2022 · 0 comments
Labels

Comments

@codello
Copy link

codello commented May 18, 2022

Terraform CLI and Provider Versions

Terraform v1.1.9
on darwin_amd64
+ provider registry.terraform.io/hashicorp/dns v3.2.3

Terraform Configuration

terraform {
  required_version = ">= 1.1.9"

  required_providers {
    dns = {
      source  = "hashicorp/dns"
      version = "3.2.3"
    }
  }
}

variable "zone" {
  type = string
  default = "<zone>"
}

variable "ttl" {
  type = number
  default = 60
}

provider "dns" {
  update {
    server = "<server>"
    gssapi {
      realm    = "<REALM>"
      username = "<username>"
      password = "<password>"
    }
  }
}

# This causes a crash
resource "dns_txt_record_set" "test1" {
  zone = var.zone
  name = "This is a test"
  txt = ["Hello World"]
  ttl = var.ttl
}

# This causes a crash
resource "dns_ptr_record" "test2" {
  zone = var.zone
  name = "test._dns-sd._udp"
  ptr = "Hello World.${var.zone}"
  ttl = var.ttl
}

# This correctly applies but falsely causes errors on subsequent runs
resource "dns_ptr_record" "test3" {
  zone = var.zone
  name = "test._dns-sd._udp"
  ptr = "Hello\\ World.${var.zone}"
  ttl = var.ttl
}

Expected Behavior

I expect the DNS provider to automatically escape special characters in record names and in all places that reference record names. I expect the provided example configuration to be applied successfully.

Actual Behavior

Terraform crashes during the apply command.

Steps to Reproduce

  1. In the provided configuration substitute appropriate values for <zone>, <server>, <REALM>, <username>, and <password>. I suspect that the issue also occurs when using keys for authentication, but I did not test that.
  2. Run terraform apply
  3. The plan succeeds. Type yes and hit enter
  4. Terraform crashes while trying to apply the configuration

How much impact is this issue causing?

Medium

Logs

https://gist.github.com/codello/6a2137e7bb0f5af522d7962d448840da

Additional Information

This issue has two variants:

  1. Unescaped spaces in record names (or record values referencing record names) cause a plugin crash
  2. Escaped spaces in PTR values falsely cause errors

The logs for the first case are in spaces-in-record-names.log in the gist linked above. A successful workaround for this case is to manually escape the record names. Using name = "This\\ is\\ a\\ test" yields the expected result. The same workaround can be used for SRV targets. I have not tested the other record types.

The logs for the second case are in spaces-in-ptr.log in the gist linked above. This case occurs if the PTR value is escaped using the workaround mentioned above. In this case the record is successfully created. However the value of the created record is seen by terraform only up to the first space, so on every subsequent run an update is planned. However since trimming the PTR value like this makes it a non fully qualified domain the plugin raises an error. I have not yet found a workaround for this.

Code of Conduct

  • I agree to follow this project's Code of Conduct
@codello codello added the bug label May 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant