Skip to content

Conversation

dmerrill6
Copy link
Contributor

Change log

  • Now all endpoints require the client to send an App Token, otherwise the request gets rejected.

  • Add InitializeMasterAppToken, which returns a token with full access only if there's no other master token already created.

  • Add tests

  • Add a stub for GenerateAppToken. Didn't implement it yet (but the logic is there) since it will require some kind of "app store" view on the client so that users can selectively authorize apps with scoped access (e.g. Do you authorize X to ListDir and OpenFile?).

Tested it on the client-side in this PR FleekHQ/space-client#102

Copy link
Contributor

@perfectmak perfectmak left a comment

Choose a reason for hiding this comment

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

LGTM... I left some questions.

Comment on lines 33 to 54
err = ring.Set(keyring.Item{
Key: AppTokenStoreKey + "_" + tok.Key,
Data: []byte(permissions.MarshalFullToken(tok)),
Label: "Space App - App Token",
})
if err != nil {
return err
}

if tok.IsMaster {
if err := kc.st.Set([]byte(getMasterTokenStKey()), []byte(tok.Key)); err != nil {
return err
}

if err := ring.Set(keyring.Item{
Key: getMasterTokenStKey(),
Data: []byte(permissions.MarshalFullToken(tok)),
Label: "Space App - Master App Token",
}); err != nil {
return err
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

If tok.IsMaster is true, wouldn't this mean that we would store the token's information twice one for the "Space App - App Token" label and then for "Space App - Master App Token"? Is this the intended behaviour

--
Update: I see you tested for this exact case in the test cases, but still want to confirm

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, wanted to access both master and regular tokens with the same logic, but at the same time needed some way to know if there was a master token present to prevent overwrites.

err = ring.Set(keyring.Item{
Key: AppTokenStoreKey + "_" + tok.Key,
Data: []byte(permissions.MarshalFullToken(tok)),
Label: "Space App - App Token",
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we move this "Space App - App Token" string into a constant above as well. Same for the "Space App - Master App Token"

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 don't really think it's necessary as this is just so that it gets displayed like that when you browse them in the keychain. It's not like the key to access the data later on.

Permissions []string
}

// Token structure is [KEY].[SECRET].[IS_ADMIN].[PERMISSION1]_[PERMISSION2]...
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps marshalling into a json string might be better and less error prone? Is there a reason why this format was chosen?

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 can't recall why I went for this approach but you're right, I'll update it to a json marshal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 9fe539a

@dmerrill6 dmerrill6 merged commit ac7c728 into develop Nov 14, 2020
dmerrill6 added a commit that referenced this pull request Nov 16, 2020
* SentFile: use db.OrderByID()

* Fix search db reinstantiation and mirror bucket creation failure (#253)

* Security: App tokens (#246)

* App token flow ready. Tests WIP.

* Remove comment

* Add tests

* Fix github actions set-env deprecation

Co-authored-by: maurycy <5383+maurycy@users.noreply.github.com>
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