Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement multiple users with policies (#100)
* Update getting-started * [WIP] Add RBAC proposal * [WIP] Add RBAC proposal * Update Config struct - Add JWT Configuration to prepare rework authentication & authorization. - Remove GlobalConfig. * Init a new Auth module * Update getting-started * Update Config struct - Add JWT Configuration to prepare rework authentication & authorization. - Remove GlobalConfig. * Init a new Auth module * Nit:Remove return * WIP Init user logic * Add bcrypt functions * Init a new Authentication mechanism Using jwt-auth lib [1], there are two authentication options now: - Cookie. - Bearer tokens. [1] https://github.com/adam-hanna/jwt-auth * Update rbac proposal * Update go.mod * Use ntk148v/jwt-auth module * Revert disable CSRF * Move signout to restricted route * Grant role with valid permissions when creating user * Fix wrong HTTP status code in error response HTTP status code always be 200 OK even if there is an error response due to missing the override header logic. * Rename methods * Don't create Etcd user * Use ntk148v/jwt-middleware jwt-auth returns an access_token, refresh_token & csrf string. It seems be too much in our case, just keep it simple as much as possible. jwt-middleware allows to set the custom content in request context. It would be useful if there is other middlewares suppose to use this data. * Create admin user * Update getting-started * [WIP] Add RBAC proposal * Update Config struct - Add JWT Configuration to prepare rework authentication & authorization. - Remove GlobalConfig. * Init a new Auth module * Nit:Remove return * Update getting-started * WIP Init user logic * Add bcrypt functions * Init a new Authentication mechanism Using jwt-auth lib [1], there are two authentication options now: - Cookie. - Bearer tokens. [1] https://github.com/adam-hanna/jwt-auth * Update rbac proposal * Update go.mod * Use ntk148v/jwt-auth module * Revert disable CSRF * Move signout to restricted route * Grant role with valid permissions when creating user * Fix wrong HTTP status code in error response HTTP status code always be 200 OK even if there is an error response due to missing the override header logic. * Rename methods * Don't create Etcd user * Use ntk148v/jwt-middleware jwt-auth returns an access_token, refresh_token & csrf string. It seems be too much in our case, just keep it simple as much as possible. jwt-middleware allows to set the custom content in request context. It would be useful if there is other middlewares suppose to use this data. * Create admin user * Update vendor * Add Casbin policy engine for authorization Use an authorization library Casbin [1] [1] https://github.com/casbin/casbin * Create users API is restricted * If this is an existing user, 400 is more suitable than 401 * Create users and token submodules * Trim the key(s) - Without trim, the key path may include double sequential slash '/', for example: 'test//users'. - The etcd namespace should end with slash '/'. Here is the workaround, without it, the key path will be `<namespace><key>`. * Include only the username * Add Authorizer middleware Authorizer is a middleware checks whether the user is allowed to perform the request. It uses Casbin Enforcer as the Policy Engine. * Add LICENSE header * Update method name * Force reload the policies before enforcing * Add RemoveUser handler * Add policy handlers - AddPolicy & RemovePolicy - TODO - ListPolicies * Update routing * Remove etcd-adapter v1.1.0 * Update proposal * Add listUsers API * Package-scope, not public * Use request's body to add/remove policies Using body instead of form is more flexible, allow user to add/remove more than one policy at once. * Update docs * Update vendor * Remove unknown characters * Update docs * Allow user to configure bcrypt cost * Remove redundant middlewares * Return status code 401 Follow: https://i.stack.imgur.com/ppsbq.jpg * Update api/token.go Co-authored-by: vtdat <tuandatk25a@gmail.com> * Raise JWT TTL to 60m * Allow everyone to view clouds * Remove user in etcd * Remove redundant block * Revert trim path Co-authored-by: vtdat <tuandatk25a@gmail.com>
- Loading branch information