This repository was archived by the owner on Jan 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 110
auth: add authentication and authorization interface #496
Merged
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3b3b8b0
server: create session when needed
jfontan 9361fcd
auth: add authentication and authorization interface
jfontan e678357
auth: use go-errors to better identify causes
jfontan de8c11a
server: do not use extra function to call builder
jfontan 20d732a
integration: fix test server
jfontan f4aabc3
auth: fix both clean and native password
jfontan 277877e
auth: test auth modules
jfontan e04a75b
auth: use go-errors.v1
jfontan 9271159
auth: add documentation to auth.Auth interface
jfontan 01ffab1
auth: specify permissions in NewNativeSingle
jfontan c874286
analyzer: delete readonly rule
jfontan 8cb84a7
integration: fix integration server
jfontan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
auth: add documentation to auth.Auth interface
Signed-off-by: Javi Fontan <jfontan@gmail.com>
- Loading branch information
commit 927115964f9f7a15ffd9095976ad93096cba8866
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,10 @@ func (p Permission) String() string { | |
// Auth interface provides mysql authentication methods and permission checking | ||
// for users. | ||
type Auth interface { | ||
// Mysql returns a configured authentication method used by server.Server. | ||
Mysql() mysql.AuthServer | ||
// Allowed checks user's permissions with needed permission. If the user | ||
// does not have enough permissions it returns ErrNotAuthorized. | ||
// Otherwise is an error using the authentication method. | ||
Allowed(user string, permission Permission) error | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please, add godoc to the interface. Specially a mention to errors returned fo There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe return
(bool, error)
?This would allow to differentiate from not having permissions and failing to check permissions. The former would probably produce a warning audit log (when we have audit logs), the second would probably also produce a regular error log.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(bool, error)
sounds to me like a fuzzy logic:(true, nil)
(false, nil)
(false, err)
and hopefully it's not possible to have:
(true, err)
It's like returning
*bool
it can give you (nil, *true, *false)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kuba-- It's a common pattern in Go, also in our own codebase.
(true, err)
is usually not relevant since the value would not be even checked iferr != nil
.But alternatively, you can keep just
err
as return value and use a special error kindErrNotAuthorized
to differentiate from other errors.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@smola - totally understand, just as I mentioned, personally I don't like this pattern, because have a feeling that it's a boolean logic with extra dimension.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm moving to use
go-errors
and returningErrNotAuthorized
so is easier to tell apart.