Skip to content

Add autoregistration functionality to agentsΒ #3319

@ViktorOrda

Description

@ViktorOrda

What would you like to be added?

In this #3202 PR possibility to automatically register machines in LAPI was introduced. As far as I can see, there are no such automatical fuctionality for agents: as pointed in the docs, after LAPI configuration one should manually register agent machine. We wanna use containerized solution with autoscaling, so agents autoregistration is crucial for us.

I've tried several ways to implement such a solution locally:

  1. Start agent container with LAPI disabled (and try to configure remote LAPI server in runtime) - agent container didn't start because of the next errors:
level=debug msg="running agent after 625.768181ms ms"
level=debug msg="[URL] POST http://0.0.0.0:8080/v1/watchers/login"
level=debug msg="resetting jwt token"
level=fatal msg="unable to start crowdsec routines: authenticate watcher (): Post \"http://0.0.0.0:8080/v1/watchers/login\": performing jwt auth: dial tcp 0.0.0.0:8080: connect: connection refused" 
  1. Start agent container with LAPI enabled, register it to the remote LAPI and restart agent (as described in the blog post) - there were 2 cases:
  • after agent registration in remote LAPI, local LAPI was disabled in config (as mentioned in article). After container restart it didn't start becase of the next errors
Error: no matches found
Generate local agent credentials
level=warning msg="crowdsec local API is disabled because 'enable' is set to false"
level=fatal msg="local API is disabled -- this command must be run on the local API machine"

Even if container started without any errors, this solution is not suitable for us - we use AWS Fargate as container runtime, so container restart would lead to its re-creation.

  1. Start agent container with remote LAPI configured initially:
  • token can't be passed in local_api_credentials.yaml
level=fatal msg="loading api client: failed unmarshaling api client credential configuration file '/etc/crowdsec/local_api_credentials.yaml': yaml: unmarshal errors:\n  line 1: field token not found in type csconfig.ApiCredentialsCfg"
  • passing token via password parameter doesn't work (expected πŸ˜„)

Why is this needed?

It would be great to have possibility to pass autoregistration token to agent machines (either via local_api_credentials.yaml or via env vars)

Metadata

Metadata

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions