Fleetd bitlocker management - #14022
Conversation
Codecov ReportPatch coverage has no change and project coverage change:
Additional details and impacted files@@ Coverage Diff @@
## feat-bitlocker #14022 +/- ##
==================================================
- Coverage 58.82% 58.73% -0.10%
==================================================
Files 903 903
Lines 74510 74565 +55
Branches 2100 2100
==================================================
- Hits 43831 43793 -38
- Misses 27188 27282 +94
+ Partials 3491 3490 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry. |
|
|
||
| err = w.EncryptionResult.SetOrUpdateDiskEncryptionKey(payload) | ||
| if err != nil { | ||
| log.Error().Err(err).Msgf("failed to get send encryption result to Fleet Server - Error %v", err) |
There was a problem hiding this comment.
| log.Error().Err(err).Msgf("failed to get send encryption result to Fleet Server - Error %v", err) | |
| log.Error().Err(err).Msg("failed to get send encryption result to Fleet Server") |
| return | ||
| } | ||
|
|
||
| // Performing Bitlocker encryption operation against C: volum |
| payload := fleet.OrbitHostDiskEncryptionKeyPayload{ | ||
| EncryptionKey: []byte(recoveryKey), | ||
| ClientError: err.Error(), | ||
| } | ||
|
|
There was a problem hiding this comment.
two notes:
if err != nilwe're early returning, so we will never report the errorif err == nil, isn't this going to panic? I think we probably need to add the error to the payload inside theifthat's right above
There was a problem hiding this comment.
Those are great points. I've fixed them on the code
#2 would have crashed during the E2E testing! I missed this scenario on the mocked-up version of bitlocker.EncryptVolume().
| // executions of the windows MDM enrollment attempt. | ||
| Frequency time.Duration | ||
| // HostUUID is the current host's UUID. | ||
| HostUUID string |
There was a problem hiding this comment.
Looks like the host uuid is not needed after all?
There was a problem hiding this comment.
yes, not needed. Just removed it from the type
| verb, path := "POST", "/api/fleet/orbit/disk_encryption_key" | ||
|
|
||
| var resp orbitPostDiskEncryptionKeyResponse | ||
| if err := oc.authenticatedRequest(verb, path, &diskEncryptionStatus, &resp); err != nil { |
There was a problem hiding this comment.
This won't work because diskEncryptionStatus var is not a struct type that can receive the orbit node key. You need to transfer your fleet.OrbitHostDiskEncryptionKeyPayload struct to the proper request struct for that endpoint:
| if err := oc.authenticatedRequest(verb, path, &diskEncryptionStatus, &resp); err != nil { | |
| if err := oc.authenticatedRequest(verb, path, &orbitPostDiskEncryptionKeyRequest{ | |
| EncryptionKey: diskEncryptionStatus.EncryptionKey, | |
| ClientError: diskEncryptionStatus.ClientError, | |
| }, &resp); err != nil { |
There was a problem hiding this comment.
Thanks! I'm working on getting test coverage for this.
| return constant.OrbitEnrollRetrySleep | ||
| } | ||
|
|
||
| type HostScriptResultPayload struct { |
There was a problem hiding this comment.
I think this was added by mistake? It's a real struct, but it already exists in the hosts.go file, should probably not be here.
There was a problem hiding this comment.
It was added by mistake, it is fixed now
| @@ -0,0 +1,574 @@ | |||
| //go:build windows | |||
| // +build windows | |||
There was a problem hiding this comment.
The old +build comment is not needed anymore.
There was a problem hiding this comment.
I forgot to remove this, sorry. It is now fixed
| resultRaw, err := oleutil.CallMethod(v.handle, "Encrypt", int32(method), int32(flags)) | ||
| if err != nil { | ||
| return fmt.Errorf("encrypt(%s): %w", v.letter, err) | ||
| } else if val, ok := resultRaw.Value().(int32); val != 0 || !ok { |
There was a problem hiding this comment.
Just to double-check, I presume you'll know soon enough when testing on a Win host if this is ok, but the microsoft docs mention that it returns an uint32.
| return fmt.Errorf("protectWithPassphrase(%s): %w", v.letter, encryptErrHandler(val)) | ||
| } | ||
|
|
||
| volumeKeyProtectorID.ToString() |
There was a problem hiding this comment.
This seems like something that needed to be removed or stored somewhere?
There was a problem hiding this comment.
Thanks, I've just fixed this. This function is not currently used. I've left the logic implemented for future usecase (fixed drives encryption)
| var conversionStatus int32 = 0 | ||
| var encryptionPercentage int32 = 0 | ||
| var encryptionFlags int32 = 0 | ||
| var wipingStatus int32 = 0 | ||
| var wipingPercentage int32 = 0 | ||
| var precisionFactor int32 = 4 | ||
| var protectionStatus int32 = 0 |
There was a problem hiding this comment.
Nit, but 0 will be automatically set, and you can group in a var ( ) block:
| var conversionStatus int32 = 0 | |
| var encryptionPercentage int32 = 0 | |
| var encryptionFlags int32 = 0 | |
| var wipingStatus int32 = 0 | |
| var wipingPercentage int32 = 0 | |
| var precisionFactor int32 = 4 | |
| var protectionStatus int32 = 0 | |
| var ( | |
| conversionStatus int32 | |
| encryptionPercentage int32 | |
| encryptionFlags int32 | |
| wipingStatus int32 | |
| wipingPercentage int32 | |
| precisionFactor int32 = 4 | |
| protectionStatus int32 | |
| ) |
There was a problem hiding this comment.
Thanks for taking the time to explain how Go manages this! This is useful for me to keep learning the language.
|
@marcosd4h Just a heads-up, as I likely won't be around for the final review, don't block waiting for me - feel free to go ahead and merge when you have @roperzh 's approval! |
Thanks for the heads up! I currently had the merge on hold because I'm seeing a weird build error on the Github actions The GA build fails with the following error about a var being declared, but that code does not exist on the code in the branch see here. I think I'm going to merge and fix it on the feature branch if this is still happening |

Checklist for submitter
This relates to #12842
If some of the following don't apply, delete the relevant line.
changes/ororbit/changes/.See Changes files for more information.