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

rpk: replace usage of md5 with sha256 in generating filename backup hash #17568

Merged

Conversation

andrewhsu
Copy link
Member

@andrewhsu andrewhsu commented Apr 3, 2024

issue https://redpandadata.atlassian.net/browse/PESDLC-1040

when rpk does a backup on files that it modifies, e.g. /etc/default/grub files, the original file was copied to a new filename with a hash using md5, e.g. /etc/default/grub.vectorized.2c349a84043328ae3a9f2d021ff143c3.bk. Now they will use sha256 so the hash portion will likely look different, e.g.
/etc/default/grub.vectorized.9be9f2dfe19f13b03e09fcc75648d4ec.bk.

Backports Required

  • none - not a bug fix
  • none - this is a backport
  • none - issue does not exist in previous branches
  • none - papercut/not impactful enough to backport
  • v23.3.x
  • v23.2.x

Release Notes

Improvements

  • rpk: change hash for backup filenames to use sha256

No functionality change, just test refactor.
No functionality change, just test refactor.
No functionality change, just test refactor.
No functionality change, just test refactor.
No functionality change, just ensuring consistency in behaviour so a
static golden file can be used to validate.
No functionality change, just test refactor.
No functionality change, just test refactor.
No functionality change, just test refactor.
No functionality change, just test refactor.
No functionality change, just test refactor.
@andrewhsu andrewhsu force-pushed the PESDLC-1040-replace-filename-backup-hash branch from 68b4b4d to 7fdaad4 Compare April 3, 2024 14:40
@andrewhsu andrewhsu marked this pull request as ready for review April 3, 2024 14:44
@andrewhsu andrewhsu requested review from gousteris and removed request for a team April 3, 2024 14:45
@@ -83,28 +83,28 @@ func WriteBytes(fs afero.Fs, bs []byte, path string) (int, error) {
return len(bs), afero.WriteFile(fs, path, bs, 0o600)
}

func FileMd5(fs afero.Fs, filePath string) (string, error) {
Copy link
Member Author

Choose a reason for hiding this comment

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

this is the only golang exported function that changed name. changed from FileMd5 to FilenameHash. from search in redpanda-data org, doesn't look like it is used anywhere.

@andrewhsu
Copy link
Member Author

tests are passing. ready for review.

Copy link
Contributor

@twmb twmb left a comment

Choose a reason for hiding this comment

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

+1 for Go changes
(don't know what the grub stuff is)

@deniscoady
Copy link

Are there any concerns about upgrades with existing files on disk? Do existing backups need to be modified with the new hash?

@andrewhsu
Copy link
Member Author

(don't know what the grub stuff is)

@twmb i kept the test cases in grub_test.go logically the same to be conservative, but i had to refactor the test cases to use golden files in testdata dir so sha256sum calculation is easier. at runtime the grub stuff is called when tune command is used and certain conditions are met:

sudo rpk redpanda tune cpu --reboot-allowed

example output:

Disabling CPU C-States 
Backup of GRUB config created '/etc/default/grub.vectorized.0045f30dc1f17bb71be8f965442b1dc1.bk'
Disabling CPU P-States
Backup of GRUB config created '/etc/default/grub.vectorized.3bada2a45a2faa298ce368920ecadf47.bk'
Updating GRUB configuration
TUNER         APPLIED        ENABLED        SUPPORTED
cpu  true  true  true
IMPORTANT: Reboot system and run 'rpk redpanda tune cpu' again

@andrewhsu
Copy link
Member Author

Are there any concerns about upgrades with existing files on disk? Do existing backups need to be modified with the new hash?

@deniscoady i don't believe so. it seems rpk will create the backup files before it modifies the original, but i did not notice any rpk code that subsequently looks up the backup file to do anything (like "undo" operation). i think the backup file is just there for humans to undo if they want. @twmb correct me if i'm wrong here.

@vbotbuildovich
Copy link
Collaborator

@andrewhsu andrewhsu merged commit 5b58e73 into redpanda-data:dev Apr 3, 2024
23 checks passed
@andrewhsu andrewhsu deleted the PESDLC-1040-replace-filename-backup-hash branch April 3, 2024 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants