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

Revise LUKS API to expect key slot and salt when escrowing successfully #23952

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

iansltx
Copy link
Member

@iansltx iansltx commented Nov 19, 2024

#23584

Checklist for submitter

If some of the following don't apply, delete the relevant line.

  • Input data is properly validated, SELECT * is avoided, SQL injection is prevented (using placeholders for values in statements)
  • Added/updated tests
    - [ ] Manual QA for all new/changed functionality Will be tested E2E

Copy link

codecov bot commented Nov 19, 2024

Codecov Report

Attention: Patch coverage is 75.86207% with 7 lines in your changes missing coverage. Please review.

Project coverage is 63.19%. Comparing base (f390db7) to head (f4409ea).
Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
...41116233322_AddLuksDataToHostDiskEncryptionKeys.go 58.33% 4 Missing and 1 partial ⚠️
server/service/orbit.go 77.77% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #23952      +/-   ##
==========================================
+ Coverage   63.16%   63.19%   +0.03%     
==========================================
  Files        1561     1563       +2     
  Lines      148732   148840     +108     
  Branches     3788     3788              
==========================================
+ Hits        93945    94058     +113     
+ Misses      47365    47359       -6     
- Partials     7422     7423       +1     
Flag Coverage Δ
backend 64.04% <75.86%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

Copy link
Member

@lucasmrod lucasmrod left a comment

Choose a reason for hiding this comment

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

LGTM!

Left a few questions.


func Up_20241116233322(tx *sql.Tx) error {
_, err := tx.Exec(`ALTER TABLE host_disk_encryption_keys
ADD COLUMN base64_encrypted_salt VARCHAR(255) NOT NULL DEFAULT '' AFTER base64_encrypted,
Copy link
Member

Choose a reason for hiding this comment

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

[...] CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci

Copy link
Member Author

Choose a reason for hiding this comment

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

Touché. Fixing.

Copy link
Member Author

Choose a reason for hiding this comment

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

Of note, we could save storage here by keeping the charset as-is, because the column should never be joined or sorted, and since this is base64'd even ASCII would represent this fine. But might as well be consistent.


func Up_20241116233322(tx *sql.Tx) error {
_, err := tx.Exec(`ALTER TABLE host_disk_encryption_keys
ADD COLUMN base64_encrypted_salt VARCHAR(255) NOT NULL DEFAULT '' AFTER base64_encrypted,
Copy link
Member

Choose a reason for hiding this comment

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

What's the reason to use AFTER?

Copy link
Member Author

Choose a reason for hiding this comment

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

Slight cleanliness thing when I (or others) use the mysql command line. Figured I might as well put encrypted/encryption related columns visually next to each other.

func (svc *Service) validateAndEncrypt(ctx context.Context, passphrase string, slotKey string) (string, string, error) {
if passphrase == "" {
return "", "", badRequest("Blank passphrase provided")
func (svc *Service) validateAndEncrypt(ctx context.Context, passphrase string, salt string, keySlot *uint) (string, string, uint, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Nit, when having many same-typed return types, it's a good practice to use named returns:
(string, string, uint, error) -> (encryptedPassphrase string, encryptedSalt string, keySlot uint, err 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.

Thanks for the call-out. Will fix.

func (ds *Datastore) SaveLUKSData(ctx context.Context, hostID uint, encryptedBase64Passphrase string, encryptedBase64SlotKey string) error {
if encryptedBase64Passphrase == "" { // should have been caught at service level
return errors.New("blank encrypted passphrase")
func (ds *Datastore) SaveLUKSData(ctx context.Context, hostID uint, encryptedBase64Passphrase string, encryptedBase64Salt string, keySlot uint) error {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Should keySlot be *uint to map cleanly to the underlying NULLable type type.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope. Only reason key slot is nullable in the DB is we use this table for BitLocker/FileVault, which (from our perspective at least) have neither key slot nor salt. Per the Slack convo earlier today, we're guaranteed to get key slot if we have valid LUKS data, and this method is only called when we have valid LUKS data, so we can tighten the parameter type.

Likewise we're guaranteed to have passphrase and salt when persisting LUKS, but I can't enforce that easily in the type system, hence the runtime check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants