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

keymanager v1: fix payload retrieve for binary data #1505

Merged
merged 1 commit into from Mar 6, 2023

Conversation

kayrus
Copy link
Collaborator

@kayrus kayrus commented Mar 2, 2023

Fixes #1492

Now payload state is stored in base64 format in case when it's not the text. In these cases it's responsibility of end user to detect the encoding/content-type and call https://developer.hashicorp.com/terraform/language/functions/base64decode

Payloads with whitespaces and newlines are also supported now, e.g. passwords that have whitespace at the end.

@kayrus
Copy link
Collaborator Author

kayrus commented Mar 2, 2023

That's wired. My local tests:

checking payload: "p3\xb2q\x10E\x9e\x1e" vs "cDOycRBFnh4=" decoded("p3\xb2q\x10E\x9e\x1e")

differ from CI tests:

checking payload: "p3�q\x10E�\x1e" vs "cDOycRBFnh4=" decoded("p3\xb2q\x10E\x9e\x1e")

with extra debug added:

func resourceSecretV1PayloadBase64CustomizeDiff(diff *schema.ResourceDiff) error {
        encoding := diff.Get("payload_content_encoding").(string)
        if diff.Id() != "" && diff.HasChange("payload") && encoding == "base64" {
                o, n := diff.GetChange("payload")
                oldPayload := o.(string)
                newPayload := n.(string)

                v, err := base64.StdEncoding.DecodeString(newPayload)
                if err != nil {
                        return fmt.Errorf("The Payload is not in the defined base64 format: %s", err)
                }
                newPayloadDecoded := string(v)

                log.Printf("[DEBUG] checking payload: %q vs %q decoded(%q)", oldPayload, newPayload, newPayloadDecoded)
                if oldPayload == newPayloadDecoded {
                        log.Printf("[DEBUG] payload has not changed. clearing diff")
                        return diff.Clear("payload")
                }
        }

        return nil
}

@kayrus
Copy link
Collaborator Author

kayrus commented Mar 2, 2023

I decided to store binary data in base64 to avoid these issues.

@kayrus
Copy link
Collaborator Author

kayrus commented Mar 2, 2023

@ozerovandrei @nikParasyr please review
@lcurtis-datto can you test this PR in your environment?

@lcurtis-datto
Copy link

This works! Thanks a million for fixing this so quickly.

LGTM

@kayrus kayrus force-pushed the fix-barbican branch 3 times, most recently from 398714f to 6afb29d Compare March 3, 2023 20:10
Copy link
Member

@nikParasyr nikParasyr left a comment

Choose a reason for hiding this comment

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

LGTM. is it ready from your side @kayrus? Cause i saw some conversation going on on the related issue

@kayrus
Copy link
Collaborator Author

kayrus commented Mar 6, 2023

yes, it's ready.

@nikParasyr nikParasyr merged commit 5683dcc into terraform-provider-openstack:main Mar 6, 2023
@kayrus kayrus deleted the fix-barbican branch March 6, 2023 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants