Add controller-led worker auth flow (#2413)

This adds an action to the API that allows pulling out an activation
token that can be given to a worker in its config (directly or via env
or file). The worker can pass this along with its normal request in
place of its normal nonce and the server will automatically accept it.

Co-authored-by: Irena Rindos <irenarindos@users.noreply.github.com>
This commit is contained in:
Jeff MitchellandIrena Rindos authored and GitHub committed 2022-09-02 14:32:41 -04:00
1 parent a1be125f5b
commit 01fb949d0b
55 files changed
+2728 -625

No files matched your search

+13
View File
@@ -251,6 +251,10 @@ func (w *Worker) Start() error {
// the controller, we don't want to invalidate that request on restart
// by generating a new set of credentials. However it's safe to output a
// new fetch request so we do in fact do that.
//
// Note that if a controller-generated activation token has been
// supplied, we do not output a fetch request; we attempt to use that
// directly later.
var err error
w.WorkerAuthStorage, err = nodeefile.New(w.baseContext,
nodeefile.WithBaseDirectory(w.conf.RawConfig.Worker.AuthStoragePath))
@@ -311,6 +315,15 @@ func (w *Worker) Start() error {
return fmt.Errorf("error loading worker auth creds: %w", err)
}
// Don't output a fetch request if an activation token has been
// provided. Technically we _could_ still output a fetch request, and it
// would be valid to do so, but if a token was provided it may well be
// confusing to a user if it seems like it was ignored because a fetch
// request was still output.
if actToken := w.conf.RawConfig.Worker.ControllerGeneratedActivationToken; actToken != "" {
createFetchRequest = false
}
// NOTE: this block _must_ be before the `if createFetchRequest` block
// or the fetch request may have no credentials to work with
if createNodeAuthCreds {