-
Notifications
You must be signed in to change notification settings - Fork 70
feature: define Signal K security protocols #506
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
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
84d9ca3
feature: define Signal K security protocols
sbender9 9668448
docs: update path urls to include auth
sbender9 9afca46
doc: reorg, Authentication, generalise JWT and cookie (#509)
tkurki 72722ba
docs: add Web Sockets login example
sbender9 799f989
Spelling
timmathews d50dc73
Formatting
timmathews e815359
Changed Authentication URLs to be Generic
timmathews b1d60d6
add authenticationRequired
sbender9 d457d85
add authenticationRequired
sbender9 5bd32a9
remove: authenticationRequired
sbender9 9a30f55
remove: authenticationRequired
sbender9 19d7cd5
Merge branch 'master' into security
tkurki 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
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,118 @@ | ||
| # Security | ||
|
|
||
| ## Communications Security | ||
|
|
||
| For privacy and data integrity REST and WebSockets communications should be secured with Transport Layer Security | ||
| (TLS). All communications over unsecure protocols like HTTP and WebSockets without TLS must be considered insecure even | ||
| with authentication and access control mechanisms in place. | ||
|
|
||
| ## Authentication | ||
|
|
||
| Authentication for Signal K REST and WebSockets connections is based on HTTP cookies or tokens carried in the HTTP | ||
| header. | ||
|
|
||
| ### Authentication via HTTP | ||
|
|
||
| A device or a web client can authenticate with a Signal K server by providing a username and password via a standard | ||
| HTTP POST request to `/signalk/«version»/auth/login`. | ||
|
|
||
| The `«version»` field is the endpoint version identifier chosen by the client from those offered by the server. See the | ||
tkurki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| [REST API](rest_api.md) documentation for the structure of these identifiers. | ||
|
|
||
| The client may send the login request with a `Content-Type` of `application/json` with the properties `username` and | ||
| `password` in the body OR with a `Content-Type` of `application/x-www-form-urlencoded` with the `username` and | ||
| `password` fields. | ||
|
|
||
| ```json | ||
| { | ||
| "username": "[email protected]", | ||
| "password": "my password" | ||
| } | ||
| ``` | ||
|
|
||
| In response to a valid login, the server shall respond with a 200 (OK) status, set an HTTP session cookie and include | ||
| the token type and the token value in the body of the response. The response `Content-Type` must be `application/json`. | ||
|
|
||
| ```json | ||
| { | ||
| "type": "JWT", | ||
| "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkZXZpY2UiOiIxMjM0LTQ1NjUz" | ||
| } | ||
| ``` | ||
|
|
||
| In response to invalid login information the server must return HTTP error code 401 (Unauthorized). | ||
|
|
||
| If the server does not implement this authentication mechanism it must return HTTP error code 501 (Not Implemented). | ||
|
|
||
| ### Authentication via WebSockets and Similar Transports | ||
|
|
||
| The client should send a message like the following. | ||
|
|
||
| ```json | ||
| { | ||
| "requestId": "1234-45653-343454", | ||
| "login": { | ||
| "username": "john_doe", | ||
| "password": "password" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| If the login is successful, the server will send a response like the following: | ||
|
|
||
| ```json | ||
| { | ||
| "requestId": "1234-45653-343454", | ||
| "state": "COMPLETED", | ||
| "result": 200, | ||
| "login": { | ||
| "token": "eyJhbGciOiJIUzI1NiIsI...ibtv41fOnJObT4RdOyZ_UI9is8" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| If the login fails, the server will send a response like the following: | ||
|
|
||
| ```json | ||
| { | ||
| "requestId": "1234-45653-343454", | ||
| "state": "COMPLETED", | ||
| "result": 401 | ||
| } | ||
| ``` | ||
|
|
||
| ### Providing Authorization to the Server in Subsequent Requests | ||
|
|
||
| #### Web Based Clients | ||
|
|
||
| Web based clients should be sure to include the cookie set in the authentication response in all subsequent requests. | ||
|
|
||
| To logout, a web based client should send an HTTP PUT request to `/signalk/«version»/auth/logout`. | ||
|
|
||
| #### WebSockets Clients | ||
|
|
||
| Clients can include the authentication cookie with the initial request. | ||
|
|
||
| Clients can include the `Authorization` HTTP header with the initial connect request. The format of the header should | ||
| be `{type} {token}`, for example `Authorization: JWT eyJhbGciOiJIUzI1NiIsI...ibtv41fOnJObT4RdOyZ_UI9is8` | ||
|
|
||
| #### Other Clients | ||
|
|
||
| Clients using other kinds of protocols can include the `token` in the Signal K messages they send. | ||
|
|
||
| ```json | ||
| { | ||
| "context": "*", | ||
| "token": "eyJhbGciOiJIUzI1NiIsI...ibtv41fOnJObT4RdOyZ_UI9is8" | ||
| "unsubscribe": [ | ||
| { | ||
| "path": "*" | ||
| } | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| ## Device Access | ||
|
|
||
| Devices which don’t have any user interaction such as sensors with no input mechanisms should acquire a token using | ||
| the [Access Requests](access_requests.md) mechanism. | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.