Conversation
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
left a comment
There was a problem hiding this comment.
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. | |||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. | |||
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
I put together #764 which will probably help for the bootstrap token retrieval. |
|
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. :) |
|
just a ping on this :) @ivanhata |
…ootstrap token back to the client, when client requests it
|
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
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. |
jessepeterson
left a comment
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Needs a comment for exported (uppercased) symbol.
| var bt BootstrapToken | ||
| bt = BootstrapToken{b64Data(btBytes)} |
There was a problem hiding this comment.
| 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") |
There was a problem hiding this comment.
i think we've already handled the errors, above, so shouldn't need to wrap this one.
| return resp, errors.Wrap(err, "getting bootstrap token") | |
| return resp, nil |
| syntax = "proto3"; | ||
|
|
||
| package checkinproto; | ||
| option go_package = "/;checkinproto"; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
spaces not tabs?
| bytes bootstrap_token = 1; | |
| bytes bootstrap_token = 1; |
|
|
||
| package deviceproto; | ||
|
|
||
| option go_package = "/;deviceproto"; |
| 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 |
There was a problem hiding this comment.
see comment below about protobuf
|
|
||
| opts.FilterUDID = udids | ||
|
|
||
| devices, err := db.List(ctx, opts) |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
nit: maybe return b64Data from the other definition?
| func (db *DB) GetBootstrapToken(ctx context.Context, udid string) ([]byte, error) { | |
| func (db *DB) GetBootstrapToken(ctx context.Context, udid string) (B64Data, error) { |
|
I guess we can just close this PR as everything is solved in #781 now. |
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.