-
Notifications
You must be signed in to change notification settings - Fork 718
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 Elastic Agent in different namespace than Elastic Stack. #7353
Changes from all commits
45ce468
5a9ca73
d343915
e85c9a5
90b1516
bea0854
67085b4
afba5a8
6262f66
6523402
d852ace
0ac073f
447f851
33e4bfa
a0b6bd2
e01252b
28595fc
53b5333
e68326b
fae3c58
ba8c654
716c7d2
d6529c9
353a68b
20c7eea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -302,6 +302,7 @@ func getRelatedEsAssoc(params Params) (commonv1.Association, error) { | |
return nil, err | ||
} | ||
} else if params.Agent.Spec.FleetServerRef.IsDefined() { | ||
agent := params.Agent | ||
// As the reference chain is: Elastic Agent ---> Fleet Server ---> Elasticsearch, | ||
// we need first to identify the Fleet Server and then identify its reference to Elasticsearch. | ||
fsAssociation, err := association.SingleAssociationOfType(params.Agent.GetAssociations(), commonv1.FleetServerAssociationType) | ||
|
@@ -320,7 +321,11 @@ func getRelatedEsAssoc(params Params) (commonv1.Association, error) { | |
return nil, pkgerrors.Wrap(err, "while fetching associated fleet server") | ||
} | ||
|
||
esAssociation, err = association.SingleAssociationOfType(fs.GetAssociations(), commonv1.ElasticsearchAssociationType) | ||
// We copy the Fleet Server Refs to the Agent so that the association appears to come from | ||
// the Elastic Agent, not the Fleet Server and is named appropriately. | ||
agent.Spec.ElasticsearchRefs = fs.Spec.ElasticsearchRefs | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? |
||
|
||
esAssociation, err = association.SingleAssociationOfType(agent.GetAssociations(), commonv1.ElasticsearchAssociationType) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
@@ -333,26 +338,30 @@ func applyRelatedEsAssoc(agent agentv1alpha1.Agent, esAssociation commonv1.Assoc | |
return builder, nil | ||
} | ||
|
||
esRef := esAssociation.AssociationRef() | ||
if !esRef.IsExternal() && !agent.Spec.FleetServerEnabled && agent.Namespace != esRef.Namespace { | ||
// check agent and ES share the same namespace | ||
return nil, fmt.Errorf( | ||
"agent namespace %s is different than referenced Elasticsearch namespace %s, this is not supported yet", | ||
agent.Namespace, | ||
esAssociation.AssociationRef().Namespace, | ||
) | ||
} | ||
|
||
// no ES CA to configure, skip | ||
assocConf, err := esAssociation.AssociationConf() | ||
if err != nil { | ||
return nil, err | ||
} | ||
if !assocConf.CAIsConfigured() { | ||
|
||
// A transitive association is an association that is not directly configured by the user but is created | ||
// by associating a Fleet-enabled Agent with a Fleet Server. The transitive association in that case | ||
// will be Elastic Agent => Fleet-Server => Elasticsearch. | ||
transitiveAssociation := isTransitiveAssociation(agent, esAssociation) | ||
if !assocConf.CAIsConfigured() && !transitiveAssociation { | ||
return builder, nil | ||
} | ||
// If the association configuration has the CA configuration directly in the annotation | ||
// then we can simply use the secret specified in the annotation. | ||
caSecretName := assocConf.GetCASecretName() | ||
if transitiveAssociation { | ||
// In the case of a transitive association, no CA is configured in the annotation, so we need to | ||
// use the method used within the Association controller to generate the expected secret name. | ||
caSecretName = association.CACertSecretName(esAssociation, "agent-fleetserver") | ||
Comment on lines
+358
to
+360
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you think this is true? In case of a transitive association this would be the relationship between FleetServer and Elasticsearch and if that relationship is suing self-signed certs managed by ECK there should be a CA. I am confused as to why this is needed. Can you explain? |
||
} | ||
|
||
builder = builder.WithVolumeLikes(volume.NewSecretVolumeWithMountPath( | ||
assocConf.GetCASecretName(), | ||
caSecretName, | ||
fmt.Sprintf("%s-certs", esAssociation.AssociationType()), | ||
certificatesDir(esAssociation), | ||
)) | ||
|
@@ -371,6 +380,15 @@ func applyRelatedEsAssoc(agent agentv1alpha1.Agent, esAssociation commonv1.Assoc | |
return builder, nil | ||
} | ||
|
||
// isTransitiveAssociation returns true if the given association is a transitive association, which is defined | ||
// as an association that is not directly configured by the user but is created by associating a Fleet-enabled | ||
// Agent with a Fleet Server which indirectly associates Elastic Agent with Elasticsearch. | ||
func isTransitiveAssociation(agent agentv1alpha1.Agent, association commonv1.Association) bool { | ||
return association.AssociationType() == commonv1.ElasticsearchAssociationType && | ||
agent.Spec.FleetModeEnabled() && | ||
agent.Spec.FleetServerRef.IsDefined() | ||
} | ||
|
||
func runningAsRoot(agent agentv1alpha1.Agent) bool { | ||
if agent.Spec.DaemonSet != nil { | ||
return runningContainerAsRoot(agent.Spec.DaemonSet.PodTemplate) | ||
|
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.
Why are we generating certificates for non Fleet server agents?