-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Loose coupling: security module #1630
Conversation
…entials' into loose-coupling-security
…entials' into loose-coupling-security
…-before-credentials
…entials' into loose-coupling-security
…ectory' into loose-coupling-security
…ectory' into loose-coupling-security
…tor-core-directory
…tor-core-directory
…ectory' into loose-coupling-security
…ectory' into loose-coupling-security
…an_ask_event error
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.
Few minor things I spotted, otherwise LGTM 👍
lib/core/auth/tokenManager.js
Outdated
@@ -67,6 +69,11 @@ class TokenManager { | |||
this.timer = null; | |||
} | |||
|
|||
async init () { | |||
const anonymous = this.kuzzle.ask('core:security:user:anonymous'); |
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.
Missing await?
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.
It's there 🤔
You might be reviewing an older version, I caught this one recently when I completed the unit tests suite.
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.
Possible because I started this review a long time ago 😅
lib/api/controller/auth.js
Outdated
apiKeyId = request.input.resource._id || null, | ||
description = this.getBodyString(request, 'description'); | ||
const expiresIn = request.input.args.expiresIn || -1; | ||
const refresh = this.getRefresh(request); |
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.
const refresh = this.getRefresh(request); | |
const refresh = this.getRefresh(request, 'wait_for'); |
lib/api/controller/auth.js
Outdated
null, | ||
body, | ||
{ | ||
refresh: this.getRefresh(request), |
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.
Should be wait_for
by default
refresh: this.getRefresh(request), | |
refresh: this.getRefresh(request, 'wait_for'), |
lib/api/controller/document.js
Outdated
const id = request.input.resource._id; | ||
const content = this.getBody(request); | ||
async create (request) { | ||
const id = this.getId(request, ifMissingEnum.IGNORE); | ||
const userId = this.getUserId(request); | ||
const refresh = this.getString(request, 'refresh', '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.
const refresh = this.getString(request, 'refresh', 'false'); | |
const refresh = this.getRefresh(request); |
lib/core/plugin/manager.js
Outdated
const opts = Object.assign({}, strategy.config.strategyOptions, { | ||
passReqToCallback: true | ||
}); |
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.
Nitpicking
const opts = Object.assign({}, strategy.config.strategyOptions, { | |
passReqToCallback: true | |
}); | |
const opts = { ...strategy.config.strategyOptions, passReqToCallback: true }; |
lib/core/security/securityLoader.js
Outdated
promises.push(this.kuzzle.funnel.processRequest(request)); | ||
} | ||
|
||
await Promise.all(promises); |
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.
Bluebird is much faster for // execution
await Promise.all(promises); | |
await Bluebird.all(promises); |
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.
Changed for the sake of uniformity, but performances are not a concern in the security loader, which should be at most called 1 time during the life of a kuzzle instance.
'use strict'; | ||
|
||
const { isEmpty } = require('lodash'); | ||
const { Request } = require('kuzzle-common-objects'); |
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.
Bluebird is much faster for // execution
const { Request } = require('kuzzle-common-objects'); | |
const { Request } = require('kuzzle-common-objects'); | |
const Bluebird = require('bluebird'); | |
lib/core/security/roleRepository.js
Outdated
if ( action !== '*' | ||
&& !this.kuzzle.pluginsManager.isAction(roleController, action) | ||
) { | ||
if ( action !== '*' && !plugins.isAction(roleController, action)) { |
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.
if ( action !== '*' && !plugins.isAction(roleController, action)) { | |
if (action !== '*' && !plugins.isAction(roleController, action)) { |
@Aschen > suggestions applied. |
Kudos, SonarCloud Quality Gate passed! 0 Bugs |
# [2.3.2](/~https://github.com/kuzzleio/kuzzle/releases/tag/2.3.2) (2020-07-07) #### Bug fixes - [ [#1701](#1701) ] Fix: description should not be required for plugin custom errors ([scottinet](/~https://github.com/scottinet)) - [ [#1695](#1695) ] Fix dump generation ([Aschen](/~https://github.com/Aschen)) - [ [#1698](#1698) ] Fix generic events on search queries ([scottinet](/~https://github.com/scottinet)) #### Enhancements - [ [#1702](#1702) ] Update search indexes only when the "dynamic" setting changes from false to true/strict ([Aschen](/~https://github.com/Aschen)) - [ [#1630](#1630) ] Loose coupling: security module ([scottinet](/~https://github.com/scottinet)) - [ [#1604](#1604) ] Add request ID in log ([Aschen](/~https://github.com/Aschen)) ---
Description
Loosely couple the security module to any other objects.
Also makes the security module entirely responsible for managing its stored documents and cache:
security.[role|profile|user].not_found
) are now handled by the security module, preventing duplicated code in API methodsChanges / Fixes related to security API methods
body.content
argument is no longer required forsecurity:createRestrictedUser
: it's required (for now) forsecurity:createUser
because we need theprofileIds
argument in it, but createRestrictedUser forbids this argument... and the remaining user content is completely optional, so the whole object itself should be so as wellsecurity:updateUser
,security:updateProfile
,security:updateRole
: theretryOnConflict
option was accepted but undocumented (fixed). Also, the default value forretryOnConflict
has been set to10
(instead of0
) to prevent common support ticketssecurity:createFirstAdmin
:security:createRestrictedUser
, thecontent
argument is no longer requiredprofileIds
property is found in the body content (not a fix: previous versions of kuzzle silently overwrite this property)auth:updateSelf
now accepts the following options:refresh
,retryOnConflict
(behavior harmonized withsecurity:updateUser
)security:mGetRoles
now throws an exception if there is at least 1 role that doesn't exist. Before, empty objects were returned for non existing roles (this made a functional test return a false-positive success on an erroneous argument provided to that route)funnel:mExecute
method:security:m*
were the only ones using it. It's ugly and inefficient: now security repositories handle m* methods themselves, without duplicating API requestssecurity:search[Roles|Profiles|Users]
: thesize
option is now, by default, set to the maximum number of documents that a single request can fetch (taken from the kuzzlerc configuration)roleRepository
methodscheckRoleNativeRights
andcheckRolePluginsRights
content
andprofileIds
arguments separately in thecore:security:user
API, laying the groundwork for future Kuzzle API changes, and to store user documents differently / in a safer way.Other changes
core.fatal.assertion_failed
exception. This change was made because otherwise, debugging simple typos in event names is a nightmare 😑NativeController
secure getters instead of methods inutil/requestAssertions
as much as possible. It should soon be possible to get rid of requestAssertions (will need to move a few methods in NativeController beforehand though)getId
method in the NativeController class:ifMissing
option:error
(default: throws if id is missing),generate
(returns a UUIDv4 id if missing),ignore
(returnsnull
if missing)resetCache
has been removed fromroleRepository.loadRoles
andprofileRepository.loadProfiles
. It was only used byadmin:resetSecurity
to preload reinitialized roles and security, and it has been replaced by a global cache invalidation, letting the security module lazily load resetted roles/profiles when they are requested