Skip to content

Newline trim fix - #4

Merged
guggero merged 7 commits into
lightninglabs:mainfrom
guggero:newline-trim-fix
Mar 22, 2022
Merged

guggero merged 7 commits into
lightninglabs:mainfrom
guggero:newline-trim-fix

Conversation

@guggero

@guggero guggero commented Mar 18, 2022

Copy link
Copy Markdown
Contributor

This PR fixes an issue where trailing newline characters (0x0d and 0x0a) were trimmed from macaroon files.

@guggero
guggero requested a review from bhandras March 18, 2022 12:15

@bhandras bhandras left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM 👍

@Roasbeef Roasbeef left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Easy fix, only comment is to extract the routine to add a basic test case to make sure we don't regress to what incident that happened on prod after deployment.

Comment thread cmd_gen_password.go
}
}

fmt.Printf("%s\n", passwordString)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is just a defense in depth fix, and the seeds actually weren't affected by this issue right? Or I guess maybe eventually a deployed seed would, as it's a random event that the characters line up

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Just to be a bit more consistent. A tool that is sensitive to newline characters in certain things should also be careful about not writing them by default. Also, we have comments like "lndinit doesn't add newlines itself" in some places. So I think this is just best practice.

Comment thread k8s.go
// Remove any newlines at the end of the file. We won't ever write a
// newline ourselves but maybe the file was provisioned by another
// process or user.
content := stripNewline(string(secret.Data[opts.SecretKeyName]))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

One way we can programmatically confirm/harden the fix would be to extra this routine into a simple function and add a test (based on a similar instance as we saw in prod) to make sure future changes here don't regress.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I did some refactoring and added unit tests. Hope that's what you had in mind.

guggero added 4 commits March 21, 2022 21:43
To avoid a newline being added to any password or seed secret created
with lndinit, we shouldn't print one to the console.
@guggero
guggero requested a review from Roasbeef March 21, 2022 20:44

@Roasbeef Roasbeef left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM 🦜

Comment thread k8s_test.go Resolved
@guggero
guggero merged commit 31c4dc4 into lightninglabs:main Mar 22, 2022
@guggero
guggero deleted the newline-trim-fix branch March 22, 2022 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants