Skip to content

Allow the Agent to retrieve configuration from the Fleet API.#15027

Merged
ph merged 31 commits intoelastic:fleetfrom
ph:agent/action-handlers
Dec 18, 2019
Merged

Allow the Agent to retrieve configuration from the Fleet API.#15027
ph merged 31 commits intoelastic:fleetfrom
ph:agent/action-handlers

Conversation

@ph
Copy link
Copy Markdown
Contributor

@ph ph commented Dec 10, 2019

Correctly Fetch a configuration from the Fleet API and send everything to the operator.
This PR doesn't include errors reportings.

Ref: #14951

depends on: #15089


How to test?

@ph ph added in progress Pull request is currently in progress. [zube]: In Progress Project:fleet labels Dec 10, 2019
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/ingest (Project:fleet)

@ph ph changed the title Allow the Agent to retrieve configuration from the Fleet API. [WIP] Allow the Agent to retrieve configuration from the Fleet API. Dec 10, 2019
@ph ph self-assigned this Dec 11, 2019
Comment thread x-pack/agent/pkg/agent/application/action_dispatch.go Outdated
Comment thread x-pack/agent/pkg/agent/application/action_dispatch.go Outdated
ph added 22 commits December 17, 2019 10:54
    This PR add a few things

    - It takes the keystore encryption implementation and create an
      io.Reader and io.Writer for it, we currently work with variable lenght
      blocks and we are not compatible for now with the one in libbeat.

    - It implements a few storage mechanism and wrapper:
      - DiskStore: Save a io.reader directly to disk, the content is saved
        in a temporary file and the target is replace in an atomic
        operation.
      - EncryptedDiskStore: Same as Keystore but use the encrypted io.Reader
        and io.Writer.

    - A fleet configuration is created in _meta/agent.fleet.yml, the content
      of this file is packed in the binary. When a user enroll the agent,
      we do a backup of the current agent.yml and the content is replaced
      with the agent.fleet.yml

    - The enrollment information is saved into a "fleet.yml"

    - The managed mode now read the content of the fleet.yml and creates a
      Kibana API client.

    - A Separates Fleet Config struct is created.

    - Enroll will now ask for confirmation before replacing the user
      configuration.
implement the required gateway and the action handling to allow to
start, restart or stops processes based on the received configuration.

Ref: #14951
Add two kind of scheduler one which is a `Stepper` schedule were the
unblock is manually triggered by an out of bound call and a `Periodic`
schedule which is based on the time.Ticker.
@ph ph requested a review from michalpristas December 17, 2019 20:50
@ph
Copy link
Copy Markdown
Contributor Author

ph commented Dec 17, 2019

@michalpristas you can do a review on this.

@ph ph added review [zube]: In Review and removed [zube]: In Progress in progress Pull request is currently in progress. labels Dec 17, 2019
@ph ph changed the title [WIP] Allow the Agent to retrieve configuration from the Fleet API. Allow the Agent to retrieve configuration from the Fleet API. Dec 17, 2019
Copy link
Copy Markdown
Contributor

@michalpristas michalpristas left a comment

Choose a reason for hiding this comment

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

LGTM small comments here and there but i think once you resolve formatting issues we're close to getting this in.

}

// WaitTick returns a channel to watch for ticks.
func (s *Stepper) WaitTick() <-chan time.Time {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i'm thinking about the name, as this does not actually wait

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@michalpristas what if we use Tick() instead?

Comment thread x-pack/agent/pkg/scheduler/scheduler.go Outdated
"net/http"
"net/url"

"time"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i think format will complain

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

looks fine, I've ran make fmt and nothing was raised.

log *logger.Logger
Config FleetAgentConfig
api apiClient
agentID string
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this will be conflicting with my PR but let's push this one first. my will be easier to solve conflicts in

Dispatch(...action) error
}

type fleetGateway struct {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can you add a comment with the purpose of this? so it's easier to find when i forget it in a future :D

return nil, err
}

actionDispatcher.MustRegister(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is ok, i'm thinking also about having

&handlerPolicyChange{...}.Register(actionDispatcher)

so handler register itself and it know which action it registers for. let's keep it like you have it for now, this is really minor thing which can be addressed sometimes in a future or not at all

func (f *fleetGateway) execute() (*fleetapi.CheckinResponse, error) {
cmd := fleetapi.NewCheckinCmd(f.agentID, f.client)

req := &fleetapi.CheckinRequest{}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can you add TODO to provide events?

continue
}

actions := make([]action, len(resp.Actions))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why do you need to repack this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Because the actionDispatcher doesn't have hard dependencies on fleetapi.Action

@ph
Copy link
Copy Markdown
Contributor Author

ph commented Dec 18, 2019

@michalpristas updated with all the changes.

@ph
Copy link
Copy Markdown
Contributor Author

ph commented Dec 18, 2019

@michalpristas I have addressed all the above, merging this to unblock agent uuid.

@ph ph merged commit 06a7a0f into elastic:fleet Dec 18, 2019
leweafan pushed a commit to leweafan/beats that referenced this pull request Apr 28, 2023
…c#15027)

*  Feature: Allow to persist AccessToken and other connection data on disk
    This PR add a few things

    - It takes the keystore encryption implementation and create an
      io.Reader and io.Writer for it, we currently work with variable lenght
      blocks and we are not compatible for now with the one in libbeat.

    - It implements a few storage mechanism and wrapper:
      - DiskStore: Save a io.reader directly to disk, the content is saved
        in a temporary file and the target is replace in an atomic
        operation.
      - EncryptedDiskStore: Same as Keystore but use the encrypted io.Reader
        and io.Writer.

    - A fleet configuration is created in _meta/agent.fleet.yml, the content
      of this file is packed in the binary. When a user enroll the agent,
      we do a backup of the current agent.yml and the content is replaced
      with the agent.fleet.yml

    - The enrollment information is saved into a "fleet.yml"

    - The managed mode now read the content of the fleet.yml and creates a
      Kibana API client.

    - A Separates Fleet Config struct is created.

    - Enroll will now ask for confirmation before replacing the user
      configuration.

* allow to use the obfuscated store.

* Allow the Agent to retrieve configuration from the Fleet API.

implement the required gateway and the action handling to allow to
start, restart or stops processes based on the received configuration.

Ref: elastic#14951
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants