-
Notifications
You must be signed in to change notification settings - Fork 734
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
Allow Fleet Server to be run without TLS. #6020
Conversation
E2e test verifying Fleet server + Agent w/o TLS. Unit test for Fleet Server pod template without TLS.
run/e2e-tests |
note. Need to test this against an older version of the stack to ensure that this works against older version, or restrict this to newer versions of the stack if not functional against older versions. |
+1 for this functionality |
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.
Code looks good, just a few nits. But I have questions about the practicality of running Elastic Agent through a service mesh like Istio. Many of our recipes use hostNetwork: true
for the Agents but that is a configuration that is not supported by Istio sidecar injection. Maybe I am missing a clever workaround for this issue?
pkg/controller/agent/pod.go
Outdated
@@ -507,6 +520,16 @@ func getFleetSetupFleetEnvVars(_ context.Context, agent agentv1alpha1.Agent, cli | |||
return nil, err | |||
} | |||
fleetCfg[FleetURL] = assocConf.GetURL() | |||
|
|||
u, err := url.Parse(fleetCfg[FleetURL]) |
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.
This parsing seems redundant. You could either look at agent.Spec.HTTP.Protocol()
once more which is used to construct the Fleet URL IIUC. Or look at agent.Spec.HTTP.TLS.Enabled()
Or am I missing something important?
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.
Very true. I'd forgotten about his method on the spec. Fixed.
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.
Turns out that it's the associated agent that we need to inspect (the fleet agent). I updated this to just strings.Contains(url, "https://")
to test if the associated fleet is running with/without tls. Lmk your thoughts.
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.
You are right I missed this. I think the downside of deriving this from the URL is that we effectively disable the safeguard the Fleet team has built in here. They could have just done the same thing and look at the URL to decide whether they allow Agent to talk to an insecure Fleet server. But they opted to add another configuration setting to make this an explicit decision.
pkg/controller/agent/pod.go
Outdated
)) | ||
} else { | ||
// Force FLEET_SERVER_HOST environment variable to Pod IP, as without this, Fleet Server only binds to localhost. | ||
builder = builder.WithEnv(corev1.EnvVar{Name: "FLEET_SERVER_HOST", Value: "", ValueFrom: &corev1.EnvVarSource{ |
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 FLEET_SERVER_HOST be a constant?
- Also the need for this only in HTTP mode confuses me. In my experiments I did not seem to need this even with Istio enabled.
- Should this be inside the existing
applyEnvVars
function?
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.
-
Yes it should. Fixed.
-
Absolutely. I've moved that into the function.
-
Longer answer. Let me test this one additional time. IIRC, everything worked up until I started trying to use an actual agent attached to fleet. Let me re-verify.
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.
After testing 3: It turns out that environment variable isn't needed after all. I've removed it, and updated our agent tests to use actual URLs in the tests instead of "url"
or similar.
Don't use url.Parse, just use agent.Spec.HTTP.Protocol(). Move envvar addition to applyEnvVars function. Fix wording.
Add insecure flag when agent is running with associated fleet running without tls
pkg/controller/agent/pod.go
Outdated
@@ -507,6 +520,16 @@ func getFleetSetupFleetEnvVars(_ context.Context, agent agentv1alpha1.Agent, cli | |||
return nil, err | |||
} | |||
fleetCfg[FleetURL] = assocConf.GetURL() | |||
|
|||
u, err := url.Parse(fleetCfg[FleetURL]) |
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.
You are right I missed this. I think the downside of deriving this from the URL is that we effectively disable the safeguard the Fleet team has built in here. They could have just done the same thing and look at the URL to decide whether they allow Agent to talk to an insecure Fleet server. But they opted to add another configuration setting to make this an explicit decision.
Co-authored-by: Peter Brachwitz <[email protected]>
closes #6000
This potential change allows Fleet Server, running as Elastic Agent, to be run without TLS for such scenarios as running within a service mesh which could provide mTLS between applications/services, similar to how we allow Elasticsearch, and Kibana to run without TLS.
This additionally solves a panic when currently attempting to disable TLS on Fleet server:
Also, an e2e test was added to ensure the full functionality all the way back to data within Elasticsearch.