Skip to content

Fleetd bitlocker management - #14022

Merged
marcosd4h merged 4 commits into
feat-bitlockerfrom
12842-fleetd-bitlocker-management-feat-branch
Sep 20, 2023
Merged

Fleetd bitlocker management#14022
marcosd4h merged 4 commits into
feat-bitlockerfrom
12842-fleetd-bitlocker-management-feat-branch

Conversation

@marcosd4h

Copy link
Copy Markdown
Contributor

Checklist for submitter

This relates to #12842

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

  • Changes file added for user-visible changes in changes/ or orbit/changes/.
    See Changes files for more information.
  • [ ] Added/updated tests
  • Manual QA for all new/changed functionality

@marcosd4h
marcosd4h temporarily deployed to Docker Hub September 20, 2023 15:45 — with GitHub Actions Inactive
@marcosd4h
marcosd4h marked this pull request as ready for review September 20, 2023 15:53
@marcosd4h
marcosd4h requested a review from a team as a code owner September 20, 2023 15:53
@codecov

codecov Bot commented Sep 20, 2023

Copy link
Copy Markdown

Codecov Report

Patch coverage has no change and project coverage change: -0.10% ⚠️

Comparison is base (32ec1e1) 58.82% compared to head (935991a) 58.73%.
Report is 3 commits behind head on feat-bitlocker.

❗ Current head 935991a differs from pull request most recent head ed06454. Consider uploading reports for the commit ed06454 to get more accurate results

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     
Flag Coverage Δ
backend 59.27% <0.00%> (-0.11%) ⬇️

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

Files Changed Coverage Δ
orbit/pkg/update/execwinapi_stub.go 0.00% <0.00%> (ø)
orbit/pkg/update/notifications.go 58.43% <0.00%> (-12.53%) ⬇️
server/service/orbit_client.go 0.00% <0.00%> (ø)

... and 2 files with indirect coverage changes

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

Comment thread orbit/pkg/update/notifications.go Outdated
Comment thread orbit/pkg/update/notifications.go Outdated
Comment thread orbit/pkg/update/notifications.go Outdated

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
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")

Comment thread orbit/pkg/update/notifications.go Outdated
return
}

// Performing Bitlocker encryption operation against C: volum

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

old comment?

Comment on lines +479 to +483
payload := fleet.OrbitHostDiskEncryptionKeyPayload{
EncryptionKey: []byte(recoveryKey),
ClientError: err.Error(),
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

two notes:

  1. if err != nil we're early returning, so we will never report the error
  2. if err == nil, isn't this going to panic? I think we probably need to add the error to the payload inside the if that's right above

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.

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().

Comment thread orbit/pkg/update/notifications.go Outdated
// executions of the windows MDM enrollment attempt.
Frequency time.Duration
// HostUUID is the current host's UUID.
HostUUID string

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like the host uuid is not needed after all?

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.

yes, not needed. Just removed it from the type

Comment thread orbit/pkg/update/notifications.go
Comment thread server/service/orbit_client.go Outdated
verb, path := "POST", "/api/fleet/orbit/disk_encryption_key"

var resp orbitPostDiskEncryptionKeyResponse
if err := oc.authenticatedRequest(verb, path, &diskEncryptionStatus, &resp); err != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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:

Suggested change
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 {

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.

Thanks! I'm working on getting test coverage for this.

Comment thread server/service/orbit_client.go Outdated
return constant.OrbitEnrollRetrySleep
}

type HostScriptResultPayload struct {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

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.

It was added by mistake, it is fixed now

@@ -0,0 +1,574 @@
//go:build windows
// +build windows

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The old +build comment is not needed anymore.

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 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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems like something that needed to be removed or stored somewhere?

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.

Thanks, I've just fixed this. This function is not currently used. I've left the logic implemented for future usecase (fixed drives encryption)

Comment on lines +243 to +249
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit, but 0 will be automatically set, and you can group in a var ( ) block:

Suggested change
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
)

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.

Thanks for taking the time to explain how Go manages this! This is useful for me to keep learning the language.

@mna

mna commented Sep 20, 2023

Copy link
Copy Markdown
Contributor

@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!

@marcosd4h

Copy link
Copy Markdown
Contributor Author

@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

image

@marcosd4h
marcosd4h merged commit dc8a086 into feat-bitlocker Sep 20, 2023
@marcosd4h
marcosd4h deleted the 12842-fleetd-bitlocker-management-feat-branch branch September 20, 2023 21:11
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