forked from choria-io/asyncjobs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(choria-io#109) Sign and Verify tasks in the client and cli
Signed-off-by: R.I.Pienaar <[email protected]>
- Loading branch information
Showing
8 changed files
with
113 additions
and
33 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,39 @@ | ||
+++ | ||
title = "Security" | ||
toc = true | ||
weight = 50 | ||
+++ | ||
|
||
Sometimes you want to run a handler in a insecure location and want to be sure it only executes tasks from trusted creators. | ||
|
||
Tasks can be signed using ed25519 private keys and clients can be configured to only accept tasks created and signed using | ||
a specific key. We support requiring all tasks are signed when keys are configured (the default), or accepting unsigned tasks | ||
but requiring signed tasks are verified. | ||
|
||
First we need to create some keys, these should be saved to a file encoded using `hex.Encode()`. | ||
|
||
```go | ||
pubk, prik, err = ed25519.GenerateKey(nil) | ||
panicIfErr(err) | ||
``` | ||
|
||
Then we can configure the client: | ||
|
||
```go | ||
client, err := asyncjobs.NewClient( | ||
asyncjobs.NatsContext("AJC"), | ||
|
||
// when tasks are created sign using this ed25519.PrivateKey, see also TaskSigningSeedFile() | ||
asyncjobs.TaskSigningKey(prik), | ||
|
||
// when loading tasks verify using this ed25519.PublicKey, see also TaskVerificationKeyFile() | ||
asyncjobs.TaskVerificationKey(pubk), | ||
|
||
// support loading unsigned tasks when a verification method is set, disabled by default | ||
asyncjobs.TaskSignaturesOptional(), | ||
) | ||
panicIfErr(err) | ||
``` | ||
|
||
On the command line the `ajc tasks` command has `--sign` and `--verify` flags which can either be hex encoded keys | ||
or paths to files holding them in hex encoded format. |
This file contains 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 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 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