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

Potential data loss when using multiline fields #136

Open
bloudraak opened this issue Jan 14, 2024 · 2 comments
Open

Potential data loss when using multiline fields #136

bloudraak opened this issue Jan 14, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@bloudraak
Copy link

Your environment

Terraform Provider Version:
1.4.0

Connect Server Version:
N/A

CLI Version:
2.24.0

OS:
macOS Sonoma 14.2.1 (23C71)

Terraform Version:
Terraform v1.5.7
on darwin_arm64

1Password Application:
1Password for Mac 8.10.23 (81023003)

What happened?

When an item is created using Terraform, and a field has a multiline text 1\n2\n3\n4, the behavior differs from doing the same via the UI. Subsequent edits result in data loss (the newlines are removed).

What did you expect to happen?

I'd expect that Items created via Terraform will be identical to equivalent items created using the 1Password application.

Steps to reproduce

Create an item using 1Password

Create a new item Item 1 in a vault, "San Jose," using 1Password with a field that contains the following value. New lines are significant.

```
 1
 2
 3
 4
```

It should look something like this:

image

Create a Terraform module

Create a service token and update the following code snippet. We'll assume you saved it as main.tf in an empty directory

terraform {
  required_version = ">= 1.5"

  required_providers {
    onepassword = {
      source = "1Password/onepassword"
      version = ">= 1, < 2"
    }
  }
}

provider "onepassword" {
  service_account_token = "<service-token>"
}
data "onepassword_vault" "vault" {
  name = "San Jose"
}

data "onepassword_item" "item" {
  vault = data.onepassword_vault.vault.uuid
  title = "Item 1"
}

resource "local_file" "item" {
  filename = "${path.module}/item1.json"
  content  = jsonencode(data.onepassword_item.item)
}

resource "onepassword_item" "item" {
  vault = data.onepassword_vault.vault.uuid
  title = "Item 2"
  section {
    label = "Section 1"
    field {
      label = "text"
      value = "1\n2\n3\n4"
    }
  }
}

resource "local_file" "item2" {
  filename = "${path.module}/item2.json"
  content  = jsonencode(onepassword_item.item)
}

Execute the following commands:

terraform init
terraform apply

Open Item 1 in 1Password

image

Notice the text that were added is formatted with new lines.

Open Item 2 in 1Password

image

Note that the text is presented differently than in 1Password. If you copy and paste it, the newlines are still preserved.

Edit Item 2 in 1Password

image

Note how it seems the formatting is lost. Try to add a new line with the value 5. Notice that you can't (at least with 1Password I'm using). Also adding 5 removes all the newlines that previously existed, impacting formatting, and thus any application that may require strict formatting (for example, licenses, or encoded files)

Edit Item 1 in 1Password

Notice that Item 1 which was created using the 1Password application, preserves the formatting of the text that was edited, and adding a new line with 5 works as expected.

image

Notes & Logs

Ideally we could attach files to the item, but the Terraform provider doesn't support creating or reading them, so that's not an option. A feature #132 was requested to support it since the underlying APIs support the ability. In the meantime, using fields to store multiline text allows us to get around that problem.

When the items were dumped as JSON (see the Terraform snippet above), the formatting of the two fields look identical. It's unclear whether the defect is in the Terraform provider, 1Password infrastructure, or the 1Password application. However, I can reproduce it within my environment at will.

It's also important to note that typically these kinds of fields have their own lifecycle outside of the item in 1Password. A feature #133 was requested.

@bloudraak bloudraak added the bug Something isn't working label Jan 14, 2024
@volodymyrZotov
Copy link
Collaborator

@bloudraak Thanks for such a detailed explanation! Stay tuned for the future release where we'll address this!

Meanwhile, if you want to help and have time, you're welcome to contribute and create a PR with the fix! 😃
Here are our CONTRIBUTING.md instructions.

@volodymyrZotov
Copy link
Collaborator

Investigated this, and can say that this is not a provider issue, but something that should be solved on the 1Password side. What happens currently is, that 1Password Client Apps (for MacOS for example) support multiline fields, but Connect or CLI doesn't. I'll raise it within the team to plan the work on that.

Meanwhile, I keep this issue open and let you know what would be the next 1Password Connect and CLI versions that support the multiline fields. As soon as they are released you'll be able to use them with the current provider version to make the provider to support multi lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants