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

API docs does not fully reflect the actual implementation: enroll accept null tags #3702

Open
AndersonQ opened this issue Jul 9, 2024 · 0 comments
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team

Comments

@AndersonQ
Copy link
Member

For confirmed bugs, please report:

  • Version: 8.14.2, main, most likely others
  • Operating System: N/A
  • Discuss Forum URL: N/A
  • Steps to Reproduce: N/A

The api/fleet/agents/enroll, API states on the openAPI definition tags is required, however fleet-server accepts it as null.

In the code we don't fully validate the received data:

func validateRequest(ctx context.Context, data io.Reader) (*EnrollRequest, error) {
span, _ := apm.StartSpan(ctx, "validateRequest", "validate")
defer span.End()
var req EnrollRequest
decoder := json.NewDecoder(data)
if err := decoder.Decode(&req); err != nil {
return nil, &BadRequestErr{msg: "unable to decode enroll request", nextErr: err}
}
// Validate
switch req.Type {
case EnrollEphemeral, EnrollPermanent, EnrollTemporary:
default:
return nil, ErrUnknownEnrollType
}
return &req, nil
}

the model allows for a null or absent tags property:

// EnrollMetadata Metadata associated with the agent that is enrolling to fleet.
type EnrollMetadata struct {
// Local An embedded JSON object that holds meta-data values.
// Defined in fleet-server as a `json.RawMessage`, defined as an object in the elastic-agent.
// elastic-agent will populate the object with information from the binary and host/system environment.
// If not empty fleet-server will update the value of `local["elastic"]["agent"]["id"]` to the agent ID (assuming the keys exist).
// The (possibly updated) value is sent by fleet-server when creating the record for a new agent.
Local json.RawMessage `json:"local"`
// Tags User provided tags for the agent.
// fleet-server will pass the tags to the agent record on enrollment.
Tags []string `json:"tags"`
// UserProvided An embedded JSON object that holds user-provided meta-data values.
// Defined in fleet-server as a `json.RawMessage`.
// fleet-server does not use these values on enrollment of an agent.
//
// Defined in the elastic-agent as a `map[string]interface{}` with no way to specify any values.
// Deprecated:
UserProvided json.RawMessage `json:"user_provided"`
}

Perhaps it'd be worth to double check our whole OpenAPI definition against the actual implementation

@AndersonQ AndersonQ added documentation Improvements or additions to documentation Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team labels Jul 9, 2024
@ycombinator ycombinator added the good first issue Good for newcomers label Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team
Projects
None yet
Development

No branches or pull requests

2 participants