Removed indicator for background LUKS validation (#28218)

#25700
This commit is contained in:
Dante Catalfamo 2025-04-16 12:25:41 -04:00 committed by GitHub
parent 3c86055139
commit f59713b7ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 12 additions and 173 deletions

View file

@ -0,0 +1 @@
- Changed LUKS escrow instrucitons

View file

@ -24,6 +24,10 @@ const CreateLinuxKeyModal = ({
In the pop-up, enter the passphrase used to encrypt your device during
setup.
</li>
<li>
Wait for Fleet to create a new key. This process may take up to 10
minutes.
</li>
<li>
Close this window and select <b>Refetch</b> on your <b>My device</b>{" "}
page. This shares the new key with your organization.

View file

@ -0,0 +1 @@
- Removed popup loading indicator for LUKS key escrow

View file

@ -23,9 +23,6 @@ type Dialog interface {
// ShowInfo displays a dialog that displays information. It returns an error if the dialog
// could not be displayed.
ShowInfo(opts InfoOptions) error
// Progress displays a dialog that shows progress. It waits until the
// context is cancelled.
ShowProgress(opts ProgressOptions) (cancelFunc func() error, err error)
}
// EntryOptions represents options for a dialog that accepts end user input.

View file

@ -50,23 +50,6 @@ func (k *KDialog) ShowEntry(opts dialog.EntryOptions) ([]byte, error) {
return output, nil
}
func (k *KDialog) ShowProgress(opts dialog.ProgressOptions) (func() error, error) {
args := []string{"--msgbox"}
if opts.Text != "" {
args = append(args, opts.Text)
}
if opts.Title != "" {
args = append(args, "--title", opts.Title)
}
cancel, err := k.cmdWithCancel(args...)
if err != nil {
return nil, err
}
return cancel, nil
}
func (k *KDialog) ShowInfo(opts dialog.InfoOptions) error {
args := []string{"--msgbox"}
if opts.Text != "" {

View file

@ -30,16 +30,6 @@ func (m *mockExecCmd) runWithOutput(timeout time.Duration, args ...string) ([]by
return m.output, m.exitCode, nil
}
func (m *mockExecCmd) runWithCancel(args ...string) (cancelFunc func() error, err error) {
m.capturedArgs = append(m.capturedArgs, args...)
if m.err != nil {
return nil, m.err
}
return nil, nil
}
func TestShowEntryArgs(t *testing.T) {
testCases := []struct {
name string
@ -164,32 +154,3 @@ func TestShowInfoError(t *testing.T) {
})
}
}
func TestShowProgressArgs(t *testing.T) {
testCases := []struct {
name string
opts dialog.ProgressOptions
expectedArgs []string
}{
{
name: "Basic Progress",
opts: dialog.ProgressOptions{
Title: "A Title",
Text: "Some text",
},
expectedArgs: []string{"--msgbox", "Some text", "--title", "A Title"},
},
}
for _, tt := range testCases {
t.Run(tt.name, func(t *testing.T) {
mock := &mockExecCmd{}
k := &KDialog{
cmdWithCancel: mock.runWithCancel,
}
_, err := k.ShowProgress(tt.opts)
assert.NoError(t, err)
assert.Equal(t, tt.expectedArgs, mock.capturedArgs)
})
}
}

View file

@ -33,7 +33,7 @@ const (
retryEntryDialogText = "Passphrase incorrect. Please try again."
infoTitle = "Disk encryption"
infoFailedText = "Failed to escrow key. Please try again later."
infoSuccessText = "Success! Now, return to your browser window and follow the instructions to verify disk encryption."
infoSuccessText = "Disk encryption key created! Now, return to your browser window and follow the instructions to verify."
timeoutMessage = "Please visit Fleet Desktop > My device and click Create key"
maxKeySlots = 8
userKeySlot = 0 // Key slot 0 is assumed to be the location of the user's passphrase
@ -145,21 +145,9 @@ func (lr *LuksRunner) getEscrowKey(ctx context.Context, devicePath string) ([]by
return nil, nil, nil
}
cancelProgress, err := lr.notifier.ShowProgress(dialog.ProgressOptions{
Title: infoTitle,
Text: "Validating passphrase...",
})
if err != nil {
log.Error().Err(err).Msg("failed to show progress dialog")
}
defer func() {
if err := cancelProgress(); err != nil {
log.Debug().Err(err).Msg("failed to cancel progress dialog")
}
}()
// Validate the passphrase
for {
log.Debug().Msg("Validating disk passphrase")
valid, err := lr.passphraseIsValid(ctx, device, devicePath, passphrase, userKeySlot)
if err != nil {
return nil, nil, fmt.Errorf("Failed validating passphrase: %w", err)
@ -181,45 +169,27 @@ func (lr *LuksRunner) getEscrowKey(ctx context.Context, devicePath string) ([]by
}
if err := cancelProgress(); err != nil {
log.Error().Err(err).Msg("failed to cancel progress dialog")
}
cancelProgress, err = lr.notifier.ShowProgress(dialog.ProgressOptions{
Title: infoTitle,
Text: "Escrowing key...",
})
if err != nil {
log.Error().Err(err).Msg("failed to show progress dialog")
}
defer func() {
if err := cancelProgress(); err != nil {
log.Error().Err(err).Msg("failed to cancel progress dialog")
}
}()
log.Debug().Msg("generating random disk encryption passphrase")
log.Debug().Msg("Generating random disk encryption passphrase")
escrowPassphrase, err := generateRandomPassphrase()
if err != nil {
return nil, nil, fmt.Errorf("Failed to generate random passphrase: %w", err)
}
log.Debug().Msg("Getting the next available keyslot")
keySlot, err := getNextAvailableKeySlot(ctx, devicePath)
if err != nil {
return nil, nil, fmt.Errorf("finding available keyslot: %w", err)
}
log.Debug().Msgf("found available keyslot: %d", keySlot)
log.Debug().Msgf("Found available keyslot: %d", keySlot)
userKey := encryption.NewKey(userKeySlot, passphrase)
escrowKey := encryption.NewKey(int(keySlot), escrowPassphrase) // #nosec G115
log.Debug().Msgf("adding new key to keyslot %d", keySlot)
if err := device.AddKey(ctx, devicePath, userKey, escrowKey); err != nil {
return nil, nil, fmt.Errorf("Failed to add key: %w", err)
}
log.Debug().Msg("validating newly inserted key")
log.Debug().Msg("Validating newly inserted key")
valid, err := lr.passphraseIsValid(ctx, device, devicePath, escrowPassphrase, keySlot)
if err != nil {
return nil, nil, fmt.Errorf("Error while validating escrow passphrase: %w", err)

View file

@ -85,34 +85,6 @@ func (z *Zenity) ShowInfo(opts dialog.InfoOptions) error {
return nil
}
// ShowProgress starts a Zenity pulsating progress dialog with the given options.
// It returns a cancel function that can be used to cancel the dialog.
func (z *Zenity) ShowProgress(opts dialog.ProgressOptions) (func() error, error) {
args := []string{"--progress"}
if opts.Title != "" {
args = append(args, fmt.Sprintf("--title=%s", opts.Title))
}
if opts.Text != "" {
args = append(args, fmt.Sprintf("--text=%s", opts.Text))
}
// --pulsate shows a pulsating progress bar
args = append(args, "--pulsate")
// --no-cancel disables the cancel button
args = append(args, "--no-cancel")
// --auto-close automatically closes the dialog when stdin is closed
args = append(args, "--auto-close")
cancel, err := z.cmdWithCancel(args...)
if err != nil {
return nil, fmt.Errorf("failed to start progress dialog: %w", err)
}
return cancel, nil
}
func execCmdWithOutput(args ...string) ([]byte, int, error) {
var opts []execuser.Option
for _, arg := range args {

View file

@ -27,12 +27,6 @@ func (m *mockExecCmd) runWithOutput(args ...string) ([]byte, int, error) {
return m.output, m.exitCode, nil
}
func (m *mockExecCmd) runWithStdin(args ...string) (func() error, error) {
m.capturedArgs = append(m.capturedArgs, args...)
return nil, nil
}
func TestShowEntryArgs(t *testing.T) {
testCases := []struct {
name string
@ -191,32 +185,3 @@ func TestShowInfoError(t *testing.T) {
})
}
}
func TestProgressArgs(t *testing.T) {
testCases := []struct {
name string
opts dialog.ProgressOptions
expectedArgs []string
}{
{
name: "Basic Entry",
opts: dialog.ProgressOptions{
Title: "A Title",
Text: "Some text",
},
expectedArgs: []string{"--progress", "--title=A Title", "--text=Some text", "--pulsate", "--no-cancel", "--auto-close"},
},
}
for _, tt := range testCases {
t.Run(tt.name, func(t *testing.T) {
mock := &mockExecCmd{}
z := &Zenity{
cmdWithCancel: mock.runWithStdin,
}
_, err := z.ShowProgress(tt.opts)
assert.NoError(t, err)
assert.Equal(t, tt.expectedArgs, mock.capturedArgs)
})
}
}

View file

@ -38,21 +38,6 @@ func main() {
panic(err)
}
cancelProgress, err := prompt.ShowProgress(dialog.ProgressOptions{
Title: "Zenity Test Progress Title",
Text: "Zenity Test Progress Text",
})
if err != nil {
fmt.Println("Err ShowProgress")
panic(err)
}
time.Sleep(2 * time.Second)
if err := cancelProgress(); err != nil {
fmt.Println("Err cancelProgress")
panic(err)
}
err = prompt.ShowInfo(dialog.InfoOptions{
Title: "Zenity Test Info Title",
Text: "Result: " + string(output),