Skip to content

Bootstrap Token#760

Closed
ivanhata wants to merge 4 commits intomicromdm:mainfrom
ivanhata:bootstrap_token
Closed

Bootstrap Token#760
ivanhata wants to merge 4 commits intomicromdm:mainfrom
ivanhata:bootstrap_token

Conversation

@ivanhata
Copy link
Contributor

Rebased to current main and corrected the branch, otherwise this is identical with closed #755

This is a partial implementation of Bootstrap Token as discussed in #735
I had a short chat with @jessepeterson. He recommended doing a PR to get this worked on further.

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. Everything else should work.

Also earlier code for Bootstrap Token from commit 58c3782 "mdm: add SetBootstrapToken command." is removed

I have spent some time with the code trying to understand and figure out a way to implement what is missing. I'm quote stucked now. If someone wants to continue from this and implement what is needed, please do so, I'll be just happy to get the feature 🙂. Anyhow, I'm ready to continue, but I'd need help. Any tips or advice is appreciated.

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
@jessepeterson jessepeterson self-assigned this Jun 16, 2021
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 all looks really good!

The primary thing I think we need to do is to couple a new "BootstrapTokenGetter" (or similar) interface to the MDMService which knows how to retrieve the Bootstrap token. We can't really do this over the pub/sub interface because the request-response model here doesn't really fit the pub/sub paradigm. Basically we'll make the device service implement this new "BootstrapTokenGetter" interface and when we init the MDM interface we'll provide it this service (which is actually just the device interface).

I hope that makes sense and let me know of any questions!

@@ -1,11 +1,15 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// Code generated by protoc-gen-gogo. DO NOT EDIT.
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't seem right. Seems like protoc-gen-gogo generated this file but this file should be generated with normal protoc-gen-go. How did you create this file? go generate should be all that's needed once the required protoc and protoc-gen-go is installed.

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 had some trouble to run just go generate . I don't recall what I did exactly.

I tried to do everything by the book in the later commit. Still couldn't get the go generate to exit without errors. After some googling found a hint to add extra option to the proto file. After doing that, go generate exited ok.

I noticed there was some discussion in #757 about same kind of difficulties.

@@ -1,21 +1,15 @@
// Code generated by protoc-gen-go.
// Code generated by protoc-gen-gogo. DO NOT EDIT.
Copy link
Member

Choose a reason for hiding this comment

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

Here, too, I think this needs to be generated with protoc-gen-go instead of -gogo. I'm surprised you got this if you just ran go generate.


}

func (w *Worker) updateFromGetBootstrapToken(ctx context.Context, message []byte) error {
Copy link
Member

Choose a reason for hiding this comment

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

So I'm not sure there's any need to listen for a get request. Because we need to actively return data there's nothing really to "listen" for here. Indeed it only looks like we update the LastSeen and/or Await state here. I think this can go in lieu of coupling the device service to the check-in service, mentioned elsewhere.

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 forgot to do anything for this one. I need to check the code again if I figure out how to change it. And if you think that this is still a good idea.

@jessepeterson
Copy link
Member

I put together #764 which will probably help for the bootstrap token retrieval.

@jessepeterson
Copy link
Member

hey @ivanhata i've merged the other PR. this sets you up to do the work mentioned in the review after a rebase. no rush though, just letting you know. :)

@jessepeterson
Copy link
Member

just a ping on this :) @ivanhata

@ivanhata
Copy link
Contributor Author

Sorry for the horrible delivery time!

These commits should bring the earlier partial implementation to fully working feature. I have done only some testing, like

  • watching both micromdm and mdmclients logs in debug mode
  • toggling the state of bootstrap token with profiles command
  • evaluating the output of sysadminctl, diskutil and fdesetup for bootstrap and secure token

Let me know if further testing is needed in general or something needs to be tested more thoroughly.

Huge thank you to @jessepeterson for his patience and advice.

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 is great progress! in addition to the code changes I think you'll need to: rebase the PR on main as well as confirm working & testing (though it sounds like @korylprince might be willing to help test).

I suspect the biggest pain is going to be not changing the protobuf files/definitions (we want to consolidate that into #773). this implies running some older protoc and protobuf compiler versions.

return base64.StdEncoding.EncodeToString(b)
}

type BootstrapToken struct {
Copy link
Member

Choose a reason for hiding this comment

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

Needs a comment for exported (uppercased) symbol.

Comment on lines +56 to +57
var bt BootstrapToken
bt = BootstrapToken{b64Data(btBytes)}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
var bt BootstrapToken
bt = BootstrapToken{b64Data(btBytes)}
bt := &BootstrapToken{b64Data(btBytes)}

return nil, errors.Wrap(err, "marshal bootstrap token")
}

return resp, errors.Wrap(err, "getting 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.

i think we've already handled the errors, above, so shouldn't need to wrap this one.

Suggested change
return resp, errors.Wrap(err, "getting bootstrap token")
return resp, nil

syntax = "proto3";

package checkinproto;
option go_package = "/;checkinproto";
Copy link
Member

Choose a reason for hiding this comment

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

we should try not to modify our protobuf file too much in this diff - I'm hoping to refactor them in #773 but until then we should try and hobble along with the older gogo (to keep the changes minimal) :(

}

message SetBootstrapToken {
bytes bootstrap_token = 1;
Copy link
Member

Choose a reason for hiding this comment

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

spaces not tabs?

Suggested change
bytes bootstrap_token = 1;
bytes bootstrap_token = 1;


package deviceproto;

option go_package = "/;deviceproto";
Copy link
Member

Choose a reason for hiding this comment

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

same, see other comment.

golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
golang.org/x/net v0.0.0-20201021035429-f5854403a974
google.golang.org/appengine v1.2.0 // indirect
google.golang.org/protobuf v1.23.0
Copy link
Member

Choose a reason for hiding this comment

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

see comment below about protobuf


opts.FilterUDID = udids

devices, err := db.List(ctx, opts)
Copy link
Member

Choose a reason for hiding this comment

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

We should avoid db.List here. It enumerates every device and only filters after the fact. We should instead use db.DeviceByUDID() which then obviates the need for all the UDID stuff.


devices, err := db.List(ctx, opts)
for _, d := range devices {
btstring, _ := hex.DecodeString(string(d.BootstrapToken))
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 to store/encode/decode as hex? We can store the raw binary in the device record.

return datastore, nil
}

func (db *DB) GetBootstrapToken(ctx context.Context, udid string) ([]byte, 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: maybe return b64Data from the other definition?

Suggested change
func (db *DB) GetBootstrapToken(ctx context.Context, udid string) ([]byte, error) {
func (db *DB) GetBootstrapToken(ctx context.Context, udid string) (B64Data, error) {

@korylprince korylprince mentioned this pull request Oct 5, 2021
@ivanhata
Copy link
Contributor Author

ivanhata commented Oct 5, 2021

I guess we can just close this PR as everything is solved in #781 now.

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.

2 participants