-
Notifications
You must be signed in to change notification settings - Fork 17
Security controller documentation #417
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
Merged
Merged
Changes from 14 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
81bb1b1
security controller
benoitvidis 7177ddf
doc/security - fixes
benoitvidis cd6882f
doc/security - lighten yml test files
benoitvidis d99807f
Merge branch 'master' into kzl-1174-doc-security-controller
jenow 2a92a0b
Update doc/6/controllers/security/delete-user/index.md
benoitvidis 720a654
Update doc/6/controllers/security/delete-user/index.md
benoitvidis a3b0945
Merge branch '6-dev' into kzl-1174-doc-security-controller
Aschen aab3a84
Merge branch 'kzl-1174-doc-security-controller' of github.com:kuzzlei…
Aschen 5b04bf3
wip
Aschen a16558c
Merge branch '6-dev' into kzl-1174-doc-security-controller
Aschen e24a2e5
add gem
Aschen bf07b41
Merge branch '6-dev' into kzl-1174-doc-security-controller
Aschen 0d20609
add travis dead links
Aschen af4ec80
remove deploy
Aschen e5f31e6
Update doc/6/controllers/security/create-first-admin/index.md
benoitvidis 525c56c
Update doc/6/controllers/security/create-or-replace-profile/snippets/…
benoitvidis 7d2631f
Update doc/6/controllers/security/update-user/index.md
benoitvidis 9accf63
Update doc/6/controllers/security/get-profile-rights/index.md
benoitvidis 1730b35
Update doc/6/controllers/security/delete-user/snippets/delete-user.te…
benoitvidis e6c64e6
Update doc/6/controllers/security/delete-role/snippets/delete-role.te…
benoitvidis 03756fd
Update doc/6/controllers/security/delete-profile/snippets/delete-prof…
benoitvidis 17cdf92
Update doc/6/controllers/security/create-user/index.md
benoitvidis 916b230
Update doc/6/controllers/security/create-profile/snippets/create-prof…
benoitvidis b4e8fd2
Update doc/6/controllers/security/create-restricted-user/index.md
benoitvidis 17753c3
Update doc/6/controllers/security/create-or-replace-role/snippets/cre…
benoitvidis fb6c147
Update doc/6/controllers/security/create-restricted-user/snippets/cre…
benoitvidis 1c080dd
Update doc/6/controllers/security/create-role/snippets/create-role.te…
benoitvidis f0b18ce
Update doc/6/controllers/security/create-user/index.md
benoitvidis 5607a33
Update doc/6/controllers/security/delete-credentials/snippets/delete-…
benoitvidis 3cafcc2
Merge remote-tracking branch 'origin/6-dev' into kzl-1174-doc-securit…
benoitvidis b9fa7ce
Merge branch '6-dev' into kzl-1174-doc-security-controller
Aschen 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
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
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 |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| --- | ||
| code: true | ||
| type: page | ||
| title: createCredentials | ||
| description: Creates authentication credentials for a user | ||
| --- | ||
|
|
||
| # createCredentials | ||
|
|
||
| Creates authentication credentials for a user. | ||
|
|
||
| <br /> | ||
|
|
||
| ```js | ||
| createCredentials(strategy, kuid, credentials, [options]); | ||
| ``` | ||
|
|
||
| <br /> | ||
|
|
||
| | Property | Type | Description | | ||
| | --- | --- | --- | | ||
| | `strategy` | <pre>string</pre> | Strategy to use | | ||
| | `kuid` | <pre>string</pre> | User [kuid](/core/1/guides/essentials/user-authentication/#kuzzle-user-identifier-kuid) | | ||
| | `credentials` | <pre>object</pre> | New credentials | | ||
| | `options` | <pre>object</pre> | Query options | | ||
|
|
||
| ### credentials | ||
|
|
||
| The credentials to send. The expected properties depend on the target authentication strategy. | ||
|
|
||
| Example for the `local` strategy: | ||
|
|
||
| ```js | ||
| { | ||
| username: 'foo', | ||
| password: 'bar' | ||
| } | ||
| ``` | ||
|
|
||
| ### options | ||
|
|
||
| Additional query options | ||
|
|
||
| | Property | Type<br />(default) | Description | | ||
| | --- | --- | --- | | ||
| | `queuable` | <pre>boolean</pre><br />(`true`) | If true, queues the request during downtime, until connected to Kuzzle again | | ||
| | `refresh` | <pre>boolean</pre><br />(`false`) | If set to `wait_for`, Kuzzle will not respond until the credentials are indexed | | ||
|
|
||
| ## Resolves | ||
|
|
||
| An `object` representing the new credentials. | ||
| The content depends on the authentication strategy. | ||
|
|
||
| ## Usage | ||
|
|
||
| <<< ./snippets/create-credentials.js |
23 changes: 23 additions & 0 deletions
23
doc/6/controllers/security/create-credentials/snippets/create-credentials.js
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 |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| try { | ||
| await kuzzle.security.createUser('foo', { | ||
| content: { | ||
| profileIds: ['default'], | ||
| fullName: 'John Doe' | ||
| }, | ||
| credentials: {} | ||
| }); | ||
|
|
||
| const response = await kuzzle.security.createCredentials( | ||
| 'local', | ||
| 'foo', | ||
| { username: 'foo', password: 'bar' } | ||
| ); | ||
| console.log(response); | ||
| /* | ||
| { username: 'foo' } | ||
| */ | ||
|
|
||
| console.log('Credentials successfully created'); | ||
| } catch (e) { | ||
| console.error(e); | ||
| } |
6 changes: 6 additions & 0 deletions
6
doc/6/controllers/security/create-credentials/snippets/create-credentials.test.yml
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 |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| name: security#createCredentials | ||
| description: Creates credentials for the specified strategy | ||
| hooks: | ||
| after: curl -X DELETE kuzzle:7512/users/foo?refresh=wait_for | ||
| template: default | ||
| expected: Credentials successfully created |
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 |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| --- | ||
| code: true | ||
| type: page | ||
| title: createFirstAdmin | ||
| description: Creates a Kuzzle administrator account, only if none exist. | ||
| --- | ||
|
|
||
| # createFirstAdmin | ||
|
|
||
| Creates a Kuzzle administrator account, only if none exist. | ||
|
|
||
| <br /> | ||
|
|
||
| ```js | ||
| createFirstAdmin(kuid, body, [options]); | ||
| ``` | ||
|
|
||
| <br /> | ||
|
|
||
| | Property | Type | Description | | ||
| | --- | --- | --- | | ||
| | `kuid` | <pre>string</pre> | Administrator [kuid](/core/1/guides/essentials/user-authentication/#kuzzle-user-identifier-kuid) | | ||
| | `body` | <pre>object</pre> | Administrator content & credentials | | ||
| | `options` | <pre>object</pre> | Query options | | ||
|
|
||
| ### body | ||
|
|
||
| The `body` property must contain two objects: | ||
| - `content`: Administrator additional information. Can be left empty. | ||
| Any other attribute can be added. | ||
| Make sure to [update the user mapping](/sdk/js/6/controllers/security/update-user-mapping) collection to match your custom attributes. | ||
| - `credentials`: Describe how the new administrator can be authenticated. This object must contain one or more | ||
| properties, named after the target authentication strategy to use. Each one of these properties are objects | ||
| containing the credentials information, corresponding to that authentication strategy. | ||
|
|
||
| Example: | ||
|
|
||
| ```js | ||
| { | ||
| content: { | ||
| firstName: 'John', | ||
| lastName: 'Doe' | ||
| }, | ||
| credentials: { | ||
| local: { | ||
| username: 'admin', | ||
| password: 'myPassword' | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### options | ||
|
|
||
| | Property | Type<br />(default) | Description | | ||
| | --- | --- | --- | | ||
| | `queuable` | <pre>boolean</pre><br />(`true`) | If true, queues the request during downtime, until connected to Kuzzle again | | ||
| | `reset` | <pre>boolean</pre><br />(`false`) | If true, restricted permissions are applied to `anonymous` and `default` roles | | ||
|
|
||
| ## Resolves | ||
|
|
||
| An [`User`](sdk/js/6/core-classes/user/introduction) object containing information about the newly created administrator. | ||
benoitvidis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Usage | ||
|
|
||
| <<< ./snippets/create-first-admin.js | ||
37 changes: 37 additions & 0 deletions
37
doc/6/controllers/security/create-first-admin/snippets/create-first-admin.js
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 |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| try { | ||
| const response = await kuzzle.security.createFirstAdmin( | ||
| 'admin', | ||
| { | ||
| content: { | ||
| firstName: 'John', | ||
| lastName: 'Doe' | ||
| }, | ||
| credentials: { | ||
| local: { | ||
| username: 'admin', | ||
| password: 'myPassword' | ||
| } | ||
| } | ||
| } | ||
| ); | ||
|
|
||
| console.log(response); | ||
| /* | ||
| User { | ||
| _id: 'admin', | ||
| content: | ||
| { profileIds: [ 'admin' ], | ||
| firstName: 'John', | ||
| lastName: 'Doe', | ||
| _kuzzle_info: | ||
| { author: '-1', | ||
| createdAt: 1560351009496, | ||
| updatedAt: null, | ||
| updater: null } } } | ||
| */ | ||
|
|
||
| console.log('First admin successfully created'); | ||
|
|
||
| } catch (e) { | ||
| console.error(e); | ||
| } |
6 changes: 6 additions & 0 deletions
6
doc/6/controllers/security/create-first-admin/snippets/create-first-admin.test.yml
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 |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| name: security#createFirstAdmin | ||
| description: Creates first admin | ||
| hooks: | ||
| after: curl -X DELETE kuzzle:7512/users/admin?refresh=wait_for | ||
| template: default | ||
| expected: First admin successfully created |
45 changes: 45 additions & 0 deletions
45
doc/6/controllers/security/create-or-replace-profile/index.md
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 |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| --- | ||
| code: true | ||
| type: page | ||
| title: createOrReplaceProfile | ||
| description: Creates a new profile or, if the provided profile identifier already exists, replaces it. | ||
| --- | ||
|
|
||
| # createOrReplaceProfile | ||
|
|
||
| Creates a new profile or, if the provided profile identifier already exists, replaces it. | ||
|
|
||
| <br /> | ||
|
|
||
| ```js | ||
| createOrReplaceProfile(id, body, [options]); | ||
| ``` | ||
|
|
||
| <br /> | ||
|
|
||
| | Property | Type | Description | | ||
| | --- | --- | --- | | ||
| | `id` | <pre>string</pre> | Profile identifier | | ||
| | `body` | <pre>object</pre> | Profile definition content | | ||
| | `options` | <pre>object</pre> | Query options | | ||
|
|
||
| ### body | ||
|
|
||
| | Property | Type | Description | | ||
| | --- | --- | --- | | ||
| | `policies` | <pre>object</pre> | [Profile content](/core/1/guides/essentials/security/#defining-profiles) | | ||
|
|
||
| ### options | ||
|
|
||
| | Property | Type<br />(default) | Description | | ||
| | --- | --- | --- | | ||
| | `queuable` | <pre>boolean</pre><br />(`true`) | If true, queues the request during downtime, until connected to Kuzzle again | | ||
| | `refresh` | <pre>boolean</pre><br />(`false`) | If set to `wait_for`, Kuzzle will not respond until the created/replaced profile is indexed | | ||
|
|
||
| ## Resolves | ||
|
|
||
| A [`Profile`](/sdk/js/6/core-classes/profile/introduction) object representing the updated/created profile. | ||
|
|
||
| ## Usage | ||
|
|
||
| <<< ./snippets/create-or-replace-profile.js |
37 changes: 37 additions & 0 deletions
37
doc/6/controllers/security/create-or-replace-profile/snippets/create-or-replace-profile.js
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 |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| try { | ||
| const response = await kuzzle.security.createOrReplaceProfile( | ||
| 'myProfile', | ||
| { | ||
| policies: [ | ||
| { | ||
| roleId: 'default' | ||
| }, | ||
| { | ||
| roleId: 'admin', | ||
| restrictedTo: [ | ||
| { | ||
| index: 'someIndex', | ||
| collections: [ | ||
| 'collection1', | ||
| 'collection2' | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| ); | ||
| console.log(response); | ||
|
|
||
| /* | ||
| Profile { | ||
| _id: 'myProfile', | ||
| policies: | ||
| [ { roleId: 'default' }, | ||
| { roleId: 'admin', restrictedTo: [Array] } ] } | ||
| */ | ||
|
|
||
| console.log('Profile successfully updated'); | ||
| } catch (e) { | ||
| console.error(e); | ||
| } |
6 changes: 6 additions & 0 deletions
6
...ontrollers/security/create-or-replace-profile/snippets/create-or-replace-profile.test.yml
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 |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| name: security#createOrReplaceProfile | ||
| description: Create or replace a profile | ||
benoitvidis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| hooks: | ||
| after: curl -XDELETE kuzzle:7512/profiles/myProfile?refresh=wait_for | ||
| template: default | ||
| expected: Profile successfully updated | ||
45 changes: 45 additions & 0 deletions
45
doc/6/controllers/security/create-or-replace-role/index.md
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 |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| --- | ||
| code: true | ||
| type: page | ||
| title: createOrReplaceRole | ||
| description: Creates a new role or, if the provided role identifier already exists, replaces it. | ||
| --- | ||
|
|
||
| # createOrReplaceRole | ||
|
|
||
| Creates a new role or, if the provided role identifier already exists, replaces it. | ||
|
|
||
| <br /> | ||
|
|
||
| ```js | ||
| createOrReplaceRole(id, body, [options]); | ||
| ``` | ||
|
|
||
| <br /> | ||
|
|
||
| | Property | Type | Description | | ||
| | --- | --- | --- | | ||
| | `id` | <pre>string</pre> | Role identifier | | ||
| | `body` | <pre>object</pre> | Role definition content | | ||
| | `options` | <pre>object</pre> | Query options | | ||
|
|
||
| ### body | ||
|
|
||
| | Property | Type | Description | | ||
| | --- | --- | --- | | ||
| | `controllers` | <pre>object</pre> | [Role definition](/core/1/guides/essentials/security/#defining-roles) | | ||
|
|
||
| ### options | ||
|
|
||
| | Property | Type<br />(default) | Description | | ||
| | --- | --- | --- | | ||
| | `queuable` | <pre>boolean</pre><br />(`true`) | If true, queues the request during downtime, until connected to Kuzzle again | | ||
| | `refresh` | <pre>boolean</pre><br />(`false`) | If set to `wait_for`, Kuzzle will not respond until the created/replaced role is indexed | | ||
|
|
||
| ## Resolves | ||
|
|
||
| A [`Role`](/sdk/js/6/core-classes/role) object representing the created/replaced role. | ||
|
|
||
| ## Usage | ||
|
|
||
| <<< ./snippets/create-or-replace-role.js |
52 changes: 52 additions & 0 deletions
52
doc/6/controllers/security/create-or-replace-role/snippets/create-or-replace-role.js
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 |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| try { | ||
| const response = await kuzzle.security.createOrReplaceRole( | ||
| 'read-only', | ||
| { | ||
| controllers: { | ||
| auth: { | ||
| actions: { | ||
| getCurrentUser: true, | ||
| getMyCredentials: true, | ||
| getMyRights: true, | ||
| logout: true | ||
| } | ||
| }, | ||
| collection: { | ||
| actions: { | ||
| getMapping: true, | ||
| list: true | ||
| } | ||
| }, | ||
| document: { | ||
| actions: { | ||
| count: true, | ||
| get: true, | ||
| mGet: true, | ||
| scroll: true, | ||
| search: true | ||
| } | ||
| }, | ||
| index: { | ||
| actions: { | ||
| list: true | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ); | ||
| console.log(response); | ||
| /* | ||
| Role { | ||
| _id: 'read-only', | ||
| controllers: | ||
| { auth: { actions: [Object] }, | ||
| collection: { actions: [Object] }, | ||
| document: { actions: [Object] }, | ||
| index: { actions: [Object] } } } | ||
| */ | ||
|
|
||
| console.log('Role successfully updated'); | ||
|
|
||
| } catch (e) { | ||
| console.error(e); | ||
| } |
Oops, something went wrong.
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.
The kuid is optional and should be put in the options object
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 is not in the sdk and would induce a breaking change.
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.
we should fix our documentation then