Skip to content
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

Merged
merged 9 commits into from
Aug 30, 2017
Merged

Add agent bootstrap logic #94

merged 9 commits into from
Aug 30, 2017

Conversation

evan2645
Copy link
Member

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:

  • Reorganizes agent codebase to be more idiomatic
  • Commits fixes to keymanager
  • Fixes node attestor following upstream interface changes
  • Checks in dev config and trust bundle

Tests are coming soon. Getting this out early for review

Outstanding:

  • Plugin manager should call Configure

PluginTypeMap = map[string]plugin.Plugin{
"KeyManager": &keymanager.KeyManagerPlugin{},
"NodeAttestor": &nodeattestor.NodeAttestorPlugin{},
"WorkloadAttestor": &workloadattestor.WorkloadAttestorPlugin{},
Copy link
Contributor

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 usekeymanager.PluginType here

Copy link
Member Author

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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here too


go func() {
listener, err := net.Listen(a.Config.BindAddress.Network(), a.Config.BindAddress.String())
if err != nil {
Copy link
Contributor

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.

Copy link
Member Author

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@boz I looked into this. No support for context that I could find, however I was able to get graceful shutdown by maintaining a pointer to the grpc server on the agent struct: 7d54205

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")
Copy link
Contributor

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

kunzimariano
kunzimariano previously approved these changes Aug 30, 2017
// Main event loop
a.Config.Log.Log("msg", "SPIRE Agent is now running")
for {
select {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome.

}

func (a *Agent) initPlugins() error {
a.Config.Log.Log("msg", "Starting plugins")
Copy link
Member

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

Copy link
Member Author

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

defaultDataDir = "."
defaultLogFile = "spire-server.log"
defaultLogLevel = "INFO"
defaultPluginDir = "../../plugin/agent/.conf"
Copy link
Contributor

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.

Copy link
Member Author

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

y2bishop2y
y2bishop2y previously approved these changes Aug 30, 2017
Copy link
Contributor

@y2bishop2y y2bishop2y left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚢

kunzimariano
kunzimariano previously approved these changes Aug 30, 2017
Copy link
Member

@kunzimariano kunzimariano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@evan2645
Copy link
Member Author

@boz hmm I'm not sure I follow. The event loop in Run receives on the error channel, and grpc.Serve blocks indefinitely. Can you explain a bit differently?

@evan2645 evan2645 dismissed stale reviews from kunzimariano and y2bishop2y via 7933cfc August 30, 2017 19:52
@evan2645
Copy link
Member Author

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

@evan2645 evan2645 merged commit b56a62e into spiffe:master Aug 30, 2017
@evan2645 evan2645 deleted the add-agent-bootstrap-logic branch August 30, 2017 20:03
rodrigolc pushed a commit to rodrigolc/spire that referenced this pull request Sep 22, 2022
* 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
rodrigolc pushed a commit to rodrigolc/spire that referenced this pull request Oct 14, 2022
* 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>
rodrigolc pushed a commit to rodrigolc/spire that referenced this pull request Oct 17, 2022
* 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>
rodrigolc pushed a commit to rodrigolc/spire that referenced this pull request Oct 25, 2022
* 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>
rodrigolc pushed a commit to rodrigolc/spire that referenced this pull request Nov 21, 2022
* 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>
rodrigolc pushed a commit to rodrigolc/spire that referenced this pull request Dec 6, 2022
* 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>
rodrigolc pushed a commit to rodrigolc/spire that referenced this pull request Dec 7, 2022
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants