Skip to content

Bootstrap Token#781

Merged
jessepeterson merged 12 commits intomicromdm:mainfrom
korylprince:bootstrap_token
Oct 5, 2021
Merged

Bootstrap Token#781
jessepeterson merged 12 commits intomicromdm:mainfrom
korylprince:bootstrap_token

Conversation

@korylprince
Copy link
Contributor

I hope I'm not stepping on @ivanhata's toes (:heart:). I've taken his existing work in #760 and made the following changes to hopefully get this PR merged:

  • Rebased on main
  • Reverted unnecessary changes to proto files and generated files
    • Note: @ivanhata changed three proto files, and each file needed a different protoc compiler version to match existing code 🤦‍♂️. Check the commit for a note on the versions used
  • Fixed some spacing/syntax/naming issues pointed out by @jessepeterson and some I noticed as well
  • Cleaned up the writing/reading of the Bootstrap token (no unnecessary conversions to hex or base64)
  • Added a small test for GetBootstrapToken
  • Fixed the GetBootstrapToken checkin event not being send to the webhook
    • Note: the []byte returned from MDMService.Checkin isn't sent to pubsub/webhook. Not sure if that's something that would be wanted, but that's probably for another PR. I'm not sure it could be done without breaking compatibility somewhere.

I've done some testing with a few different MacBooks:

  • Ran sudo profiles install -type bootstraptoken then sudo profiles validate -type bootstraptoken to verify proper escrow
    • Note: sudo profiles status -type bootstraptoken will lie to you and tell you the server has the token just because it sent it. You need to use validate to verify the MacBook can actually get the token from the server and use it properly.
  • Verified messages are passing properly via webhook and HTTP debug logs
  • Verified users get a SecureToken when they login after escrowing the Bootstrap Token
    • a GetBootstrapToken request is sent each time a user without a SecureToken logs in
    • this works even if you're using NoMAD Login AD 🎉

As a final note, this PR addresses all of @jessepeterson's reviews on #740 except for his note on platform/device/worker.go: Worker.updateFromGetBootstrapToken. From my understanding, you're saying to move the logic from the worker to mdm/checkin.go: MDMService.Checkin. I guess where I'm confused, is why you wouldn't do the same thing for updateFromCheckout, updateFromTokenUpdate, etc. It seems like pretty much everything in the work is just accessing the db and pubsub.

In any case, I can make any changes to this PR to get it merged, so just let me know!

ivanhata and others added 10 commits June 14, 2021 23:14
Fetching the token from the db and sending it back to the client when the client asks for it ie sends the GetBootstrapTokenRequest is not implemented

Also earlier code for Bootstrap Token from commit 58c3782 "mdm: add SetBootstrapToken command." is removed
…ootstrap token back to the client, when client requests it
    checkin.pb.go: golang/[email protected]
    mdm.pb.go: gogo/[email protected]
    device.pb.go: golang/[email protected]
Copy link
Member

@jessepeterson jessepeterson left a comment

Choose a reason for hiding this comment

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

This looks good. Much thanks to you and @ivanhata!

each file needed a different protoc compiler version to match existing code

Yikes, how annoying. Thanks for slogging through! Mentioned in #760 I really want to unify all that with #773; but it'll take time & testing.

Added a small test for GetBootstrapToken

❤️

Note: the []byte returned from MDMService.Checkin isn't sent to pubsub/webhook. Not sure if that's something that would be wanted, but that's probably for another PR. I'm not sure it could be done without breaking compatibility somewhere.

Yeah the issue here is, conceptually, the webhook publishes the Checkin request messages of which GetBootstrapToken is just that — a request. We don't really publish Checkin responses — which actually were only added recently. This is true of any Checkin, or Acknowledge (command) requests, too. We publish the request, but not the MDM server response. There could be another PubSub topic, I suppose, for GetBootstrapToken responses, but as you said: probably another discussion from another PR (if it's even something that's worth doing). It works the same way in NanoMDM fwiw, too.

except for his note on platform/device/worker.go: Worker.updateFromGetBootstrapToken. From my understanding, you're saying to move the logic from the worker to mdm/checkin.go: MDMService.Checkin. I guess where I'm confused, is why you wouldn't do the same thing for updateFromCheckout, updateFromTokenUpdate, etc. It seems like pretty much everything in the work is just accessing the db and pubsub.

Thanks, yeah. This was a misconception from the original suggestion to include the 'full' device database in the Checkin service when, in fact, we only have a BootstrapTokenRetriever interface. If it were the full device database then we wouldn't need to publish to the PubSub because we'd have the device right there (which we don't, of course). So, that's my bad. And as you note the code in the PR is actually consistent with the other checkin requests, too. So: ignore me, carry on. :)


Again, thanks for this! I'll have another look-see hopefully tomorrow and we can get this in!

@ivanhata
Copy link
Contributor

ivanhata commented Oct 5, 2021

This is great! Thanks to @korylprince for fixing all the issues and getting this done! I'm totally fine with it if this PR gets merged. I guess the #760 can be just closed.

@ivanhata ivanhata mentioned this pull request Oct 5, 2021
Co-authored-by: Jesse Peterson <[email protected]>
Copy link
Member

@jessepeterson jessepeterson left a comment

Choose a reason for hiding this comment

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

Just a couple really minor things, but overall looking good!

NotOnConsole bool `plist:",omitempty"`
}

// Get Bootstrap Token Message Type # GetBootstrapTokenRequest
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated these to match existing code. For example auth struct has the comment // Authenticate Message Type, not auth Message Type. These are private structs so they're not going to show up in godoc anyways. If you want it to actually be //getBootstrap ... I can do that too.

GetAwaitingConfiguration bool
}

// Set Bootstrap Token Message Type # SetBootstrapTokenRequest
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same as above

DEPProfileAssignedDate time.Time `db:"dep_profile_assigned_date"`
DEPProfileAssignedBy string `db:"dep_profile_assigned_by"`
LastSeen time.Time `db:"last_seen"`
BootstrapToken string `db:"bootstrap_token"`
Copy link
Member

Choose a reason for hiding this comment

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

Any reason this, too, shouldn't be a byte slice? I see a few string() and []byte() type conversions and I wonder if they're necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I mainly left these as is because it matches existing code (namely, Token and Unlock Token are also stored as strings). I agree it would make more sense to store it as a byte (same in the protobuf), but figured consistency with the rest of the codebase was better. []byte-string conversions cost very little I would think. If you want to move it to a []byte, I can make those changes (proto file, generated code, services, etc). Just let me know.

Copy link
Member

Choose a reason for hiding this comment

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

Sure, sounds good. :)

@jessepeterson jessepeterson linked an issue Oct 5, 2021 that may be closed by this pull request
@jessepeterson jessepeterson merged commit fcf1d18 into micromdm:main Oct 5, 2021
@korylprince korylprince deleted the bootstrap_token branch October 5, 2021 18:27
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.

Bootstrap Token

3 participants