-
Notifications
You must be signed in to change notification settings - Fork 465
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
Add agent bootstrap logic #94
Conversation
Commit light refactor of agent and cli code
PluginTypeMap = map[string]plugin.Plugin{ | ||
"KeyManager": &keymanager.KeyManagerPlugin{}, | ||
"NodeAttestor": &nodeattestor.NodeAttestorPlugin{}, | ||
"WorkloadAttestor": &workloadattestor.WorkloadAttestorPlugin{}, |
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.
maybe have const PluginType = "KeyManager" in
keymanagerso u can use
keymanager.PluginType here
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.
That's a good idea! That pattern will probably help to solve some of the other challenges we have been facing with plugin management
Most of the code related to this is pre-existing and this PR just moved it from one place to another. We also need to send a change to the plugin catalog to handle a call to Configure
so if it's OK, I'm thinking to reserve this for that PR since we'd probably want to update it across the board (server + agent).
MaxPlugins = map[string]int{ | ||
"KeyManager": 1, | ||
"NodeAttestor": 1, | ||
"WorkloadAttestor": 1, |
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.
here too
pkg/agent/agent.go
Outdated
|
||
go func() { | ||
listener, err := net.Listen(a.Config.BindAddress.Network(), a.Config.BindAddress.String()) | ||
if err != nil { |
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.
Is there a way to gracefully shut down the connection? I vaguely remember being able to make a listener that uses context.Context
.
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.
Good thought, I'll investigate this. Same code exists in spire server we'll need to update it there too
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.
pkg/agent/agent.go
Outdated
a.Config.Log.Log("msg", "Preparing to attest against %s", a.Config.ServerAddress.String()) | ||
|
||
// Look up the node attestor plugin | ||
pluginClients := a.Catalog.GetPluginsByType("NodeAttestor") |
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.
another use for nodeattestor.PluginType
pkg/agent/agent.go
Outdated
// Main event loop | ||
a.Config.Log.Log("msg", "SPIRE Agent is now running") | ||
for { | ||
select { |
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.
Awesome.
pkg/agent/agent.go
Outdated
} | ||
|
||
func (a *Agent) initPlugins() error { | ||
a.Config.Log.Log("msg", "Starting plugins") |
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.
Maybe logger is a better name.
a.Config.Logger.Log
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.
Yea :( I'm not a fan of the interface this logger exposes. When I wrote this originally I was hoping to directly access leveled logger here, but figured out later that it was more complicated than I thought. I'll change it on your suggestion
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.
Fixed
cmd/spire-agent/cli/command/run.go
Outdated
defaultDataDir = "." | ||
defaultLogFile = "spire-server.log" | ||
defaultLogLevel = "INFO" | ||
defaultPluginDir = "../../plugin/agent/.conf" |
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.
should this be a relative path? I guess I can see pro's and cons for each.
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.
Ultimately I think we'd want to make this something a little more usable (like etc or opt) but for now this works well during development. Definitely should change to absolute path at some point IMO
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.
🚢
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.
LGTM
@boz hmm I'm not sure I follow. The event loop in |
Thanks for the explanation @boz I updated the PR to pick up your second suggestion. I'll circle back around later on to make the channels private, and add proper Shutdown func etc |
* fix: added error return to AttestContainerSignatures method * fix: changed variable from camel to snake case * fix: add returned type to error message in getBundleSignatureContent method * fix: changed log from camel to snake case * fix: fixed nil payload test case * fix: fix import order * fix: sync with remote * fix: change import order
* fix: added error return to AttestContainerSignatures method * fix: changed variable from camel to snake case * fix: add returned type to error message in getBundleSignatureContent method * fix: changed log from camel to snake case * fix: fixed nil payload test case * fix: fix import order * fix: sync with remote * fix: change import order Signed-off-by: Willian Alves <wiilliian.alves@gmail.com>
* fix: added error return to AttestContainerSignatures method * fix: changed variable from camel to snake case * fix: add returned type to error message in getBundleSignatureContent method * fix: changed log from camel to snake case * fix: fixed nil payload test case * fix: fix import order * fix: sync with remote * fix: change import order Signed-off-by: Willian Alves <wiilliian.alves@gmail.com>
* fix: added error return to AttestContainerSignatures method * fix: changed variable from camel to snake case * fix: add returned type to error message in getBundleSignatureContent method * fix: changed log from camel to snake case * fix: fixed nil payload test case * fix: fix import order * fix: sync with remote * fix: change import order Signed-off-by: Willian Alves <wiilliian.alves@gmail.com> Signed-off-by: Matheus Santos <matheusdefariascs@gmail.com>
* fix: added error return to AttestContainerSignatures method * fix: changed variable from camel to snake case * fix: add returned type to error message in getBundleSignatureContent method * fix: changed log from camel to snake case * fix: fixed nil payload test case * fix: fix import order * fix: sync with remote * fix: change import order Signed-off-by: Willian Alves <wiilliian.alves@gmail.com> Signed-off-by: Matheus Santos <matheusdefariascs@gmail.com>
* fix: added error return to AttestContainerSignatures method * fix: changed variable from camel to snake case * fix: add returned type to error message in getBundleSignatureContent method * fix: changed log from camel to snake case * fix: fixed nil payload test case * fix: fix import order * fix: sync with remote * fix: change import order Signed-off-by: Willian Alves <wiilliian.alves@gmail.com> Signed-off-by: Matheus Santos <matheusdefariascs@gmail.com>
* fix: added error return to AttestContainerSignatures method * fix: changed variable from camel to snake case * fix: add returned type to error message in getBundleSignatureContent method * fix: changed log from camel to snake case * fix: fixed nil payload test case * fix: fix import order * fix: sync with remote * fix: change import order Signed-off-by: Willian Alves <wiilliian.alves@gmail.com> Signed-off-by: Matheus Santos <matheusdefariascs@gmail.com>
This is an initial pass at the spire agent bootstrap logic. This change includes all the core business logic for spire agent to get up and attest against spire server. It also does a few other things:
Tests are coming soon. Getting this out early for review
Outstanding:
Configure