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

remove flags for policy defaulting #30256

Closed
wants to merge 14 commits into from

Conversation

lykkin
Copy link
Contributor

@lykkin lykkin commented Feb 8, 2022

What does this PR do?

Updates the agent policy selection logic to avoid using the is_default* flags.
Fixes #29774

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

How to test this PR locally

Unit tests are added for the new code.

Related issues

Closes #29774

Use cases

Screenshots

Logs

@lykkin lykkin added enhancement Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team backport-v8.2.0 Automated backport with mergify labels Feb 8, 2022
@lykkin lykkin self-assigned this Feb 8, 2022
@botelastic botelastic bot added needs_team Indicates that the issue/PR needs a Team:* label and removed needs_team Indicates that the issue/PR needs a Team:* label labels Feb 8, 2022
@lykkin lykkin changed the title remove default flags for policy defaulting remove flags for policy defaulting Feb 8, 2022
@elasticmachine
Copy link
Collaborator

elasticmachine commented Feb 8, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-02-16T19:21:36.605+0000

  • Duration: 105 min 32 sec

Test stats 🧪

Test Results
Failed 0
Passed 5484
Skipped 12
Total 5496

💚 Flaky test report

Tests succeeded.

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • /package : Generate the packages and run the E2E tests.

  • /beats-tester : Run the installation tests with beats-tester.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@lykkin lykkin marked this pull request as ready for review February 8, 2022 15:31
@elasticmachine
Copy link
Collaborator

Pinging @elastic/elastic-agent-control-plane (Team:Elastic-Agent-Control-Plane)

@lykkin lykkin added the v8.2.0 label Feb 8, 2022
@jlind23 jlind23 requested a review from a team February 8, 2022 16:45
@jlind23 jlind23 requested review from ph and a team February 8, 2022 16:46
x-pack/elastic-agent/pkg/agent/cmd/container.go Outdated Show resolved Hide resolved
x-pack/elastic-agent/pkg/agent/cmd/container.go Outdated Show resolved Hide resolved
x-pack/elastic-agent/pkg/agent/cmd/container.go Outdated Show resolved Hide resolved
x-pack/elastic-agent/pkg/agent/cmd/container.go Outdated Show resolved Hide resolved
x-pack/elastic-agent/pkg/agent/cmd/container.go Outdated Show resolved Hide resolved
@lykkin lykkin requested a review from ph February 16, 2022 15:02
Copy link
Contributor

@ph ph left a comment

Choose a reason for hiding this comment

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

This looks good to me, I would like a second reviewer @blakerouse can you review this please.

@lykkin Thanks for the test and the clarify in the log statement.

return &policy, nil
}
} else {
if policy.IsDefault {
if policy.Name == cfg.Fleet.DefaultTokenPolicyName {
logWarn(streams, "using default policy name:", policy.Name)
return &policy, nil
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the added logging and making it explicit this will helps us.

if policyName == "" {
logWarn(streams, "No policy name set, please set the FLEET_TOKEN_POLICY_NAME environment variable to the agent policy name.")
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

@blakerouse I need to relearn the quirks of the enrollment process, but should we just error out?

@@ -81,6 +81,7 @@ The following actions are possible and grouped based on the actions.
KIBANA_FLEET_HOST - kibana host to enable create enrollment token on [$KIBANA_HOST]
FLEET_TOKEN_NAME - token name to use for fetching token from Kibana. This requires Kibana configs to be set.
FLEET_TOKEN_POLICY_NAME - token policy name to use for fetching token from Kibana. This requires Kibana configs to be set.
DEFAULT_FLEET_TOKEN_POLICY_NAME - token policy name to use when [$FLEET_TOKEN_POLICY_NAME] is not set. Defaults to "Default policy".
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this extra needed? Can't the default just be there for FLEET_TOKEN_POLICY_NAME when one is not provided?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is in response to the above conversation saying the default should be configurable. maybe i misunderstood what was being said?

it does seem a bit redundant to me though, since someone could just set the policy id up front when they are configuring their instance.

i suppose it could be useful if someone wanted to set up different defaults assuming the policy an agent is looking for disappears. not too sure how much we want to worry about that situation.

@@ -95,7 +96,8 @@ The following actions are possible and grouped based on the actions.
FLEET_SERVER_ELASTICSEARCH_CA_TRUSTED_FINGERPRINT - The sha-256 fingerprint value of the certificate authority to trust
FLEET_SERVER_ELASTICSEARCH_INSECURE - disables cert validation for communication with Elasticsearch
FLEET_SERVER_SERVICE_TOKEN - service token to use for communication with elasticsearch
FLEET_SERVER_POLICY_ID - policy ID for Fleet Server to use for itself ("Default Fleet Server policy" used when undefined)
FLEET_SERVER_POLICY_ID - policy ID for Fleet Server to use for itself ([$DEFAULT_FLEET_SERVER_POLICY_ID] used when undefined)
DEFAULT_FLEET_SERVER_POLICY_ID - policy ID for Fleet Server to use for itself when none is specified. (defaults to "fleet-server-policy")
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't see the need for this option. Just make the default for FLEET_SERVER_POLICY_ID when one is not provided.


if cfg.FleetServer.Enable {
if policyID == "" {
logWarn(streams, "No policy id set, please set the FLEET_SERVER_POLICY_ID environment variable to the fleet server policy id.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe I missed part of a conversation, but whats the point of this warning? I believe that Fleet Server will find the policy correctly without an ID. So is a warning here really needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

here's what i understand this code to mean:

this would be hit if the user didn't configure either a policy id or default when hosting a fleet server under the agent. this gives more specific information to the user assuming the agent fails to find a policy to get a token from.
this coincides with a path that halts start up of the agent.

i'll add comments for both of this situation, and the one below.

}
} else {
if policyName == "" {
logWarn(streams, "No policy name set, please set the FLEET_TOKEN_POLICY_NAME environment variable to the agent policy name.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Again can you give me more detail here? Maybe a code comment would be good to explain the flow here.

@mergify
Copy link
Contributor

mergify bot commented Feb 24, 2022

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b fleet-policy-updates upstream/fleet-policy-updates
git merge upstream/main
git push upstream fleet-policy-updates

@ph
Copy link
Contributor

ph commented Mar 23, 2022

@lykkin can you apply the comments / changes from @blakerouse?

@jlind23
Copy link
Collaborator

jlind23 commented Mar 29, 2022

@lykkin can we close this one as it's targeting the old elastic agent folder?

@jlind23
Copy link
Collaborator

jlind23 commented Mar 31, 2022

This PR is not relevant anymore as agent was moved.

@jlind23 jlind23 closed this Mar 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-v8.2.0 Automated backport with mergify enhancement Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team v8.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Agent] Change logic to find agent policy during Fleet enrollment
7 participants