Skip to content

Conversation

frzifus
Copy link
Collaborator

@frzifus frzifus commented Jul 22, 2025

Downside of this approach is that we need to manually align the mapping when we change e.g. a service. But we could generate services based on this too. wdyt?

NAME                                      TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                                                                     AGE
tempo-simplest-compactor                  ClusterIP   10.96.115.23    <none>        7946/TCP,3200/TCP                                                           2m8s
tempo-simplest-distributor                ClusterIP   10.96.122.122   <none>        4318/TCP,4317/TCP,3200/TCP,14268/TCP,6831/UDP,6832/UDP,14250/TCP,9411/TCP   2m8s
tempo-simplest-gossip-ring                ClusterIP   None            <none>        7946/TCP                                                                    2m8s
tempo-simplest-ingester                   ClusterIP   10.96.76.66     <none>        3200/TCP,9095/TCP                                                           2m8s
tempo-simplest-querier                    ClusterIP   10.96.206.87    <none>        7946/TCP,3200/TCP,9095/TCP                                                  2m8s
tempo-simplest-query-frontend             ClusterIP   10.96.117.99    <none>        3200/TCP,9095/TCP,16685/TCP,16686/TCP,16687/TCP                             2m8s
tempo-simplest-query-frontend-discovery   ClusterIP   None            <none>        3200/TCP,9095/TCP,9096/TCP,16685/TCP,16686/TCP,16687/TCP                    2m8s


NAME                         POD-SELECTOR                                                                                                                                           AGE
tempo-simplest-distributor   app.kubernetes.io/component=distributor,app.kubernetes.io/instance=simplest,app.kubernetes.io/managed-by=tempo-operator,app.kubernetes.io/name=tempo   17s

@frzifus frzifus force-pushed the networking branch 2 times, most recently from 7bd6f48 to 1d1cb4b Compare July 23, 2025 09:17
}

var manifests []client.Object
manifests = append(manifests, networking.GenerateOperandPolicies(params.Tempo)...)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That should only be done on OpenShift 4.20+.

Copy link
Collaborator

@andreasgerstmayr andreasgerstmayr left a comment

Choose a reason for hiding this comment

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

can you add unit tests with the generated policy? ideally in yaml format (to be less verbose than Golang), like here: https://github.com/grafana/tempo-operator/blob/main/internal/manifests/config/build_test.go#L23-L26

@frzifus
Copy link
Collaborator Author

frzifus commented Jul 23, 2025

y, I will do once its working.
I will pause this until #1248 is complete.

Copy link
Collaborator

@pavolloffay pavolloffay left a comment

Choose a reason for hiding this comment

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

It seems like it is missing the policy for the gateway

// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Networking"
Networking NetworkingSpec `json:"networking,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should re-work the naming, this seems to ambigous

  spec:
    networking:
      enabled: true

The config does not indicate anything about network policies

@@ -0,0 +1,171 @@
package networking
Copy link
Collaborator

Choose a reason for hiding this comment

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

a similar comment as the previous one. I would be more specific and rename it to networkpolicies

policies = append(policies, generatePolicyFor(tempo, manifestutils.QuerierComponentName))
policies = append(policies, generatePolicyFor(tempo, manifestutils.QueryFrontendComponentName))

return policies
Copy link
Collaborator

Choose a reason for hiding this comment

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

So If I am not mistaken this creates 3+5policies(per component).

We might need to have percomponent policy, but those 3 generic one can be embeded into the policy per component, which would make it easier to understand what policy applies to a component.

@pavolloffay pavolloffay requested a review from Copilot September 8, 2025 11:14
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces network policy generation for Tempo operands to limit network access between components. The implementation adds a new networking configuration option to the TempoStack spec and generates NetworkPolicy resources for each component based on defined communication relationships.

  • Adds NetworkingSpec to the TempoStack CRD with an enabled flag
  • Implements per-component network policy generation with ingress/egress rules
  • Defines component communication relationships and port mappings

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
api/tempo/v1alpha1/tempostack_types.go Adds NetworkingSpec struct and networking field to TempoStackSpec
internal/manifests/networking/operands.go Main function to generate network policies for all operands
internal/manifests/networking/components.go Core logic for generating per-component policies and defining relationships
internal/manifests/networking/components_test.go Test cases for network policy generation and relation reversal
config/crd/bases/tempo.grafana.com_tempostacks.yaml CRD definition update for networking spec
bundle//manifests/ Generated bundle files with CRD and CSV updates

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

ExtraConfig *ExtraConfigSpec `json:"extraConfig,omitempty"`
}

// ObservabilitySpec defines how networking configs are handled.
Copy link
Preview

Copilot AI Sep 8, 2025

Choose a reason for hiding this comment

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

The comment incorrectly states 'ObservabilitySpec' when it should be 'NetworkingSpec'.

Suggested change
// ObservabilitySpec defines how networking configs are handled.
// NetworkingSpec defines how networking configs are handled.

Copilot uses AI. Check for mistakes.

Comment on lines +96 to +104
s3Conn = []networkingv1.NetworkPolicyPort{
{ // TODO: get this from secret?
Protocol: ptr.To(corev1.ProtocolTCP),
Port: ptr.To(intstr.FromInt(443)),
},
{ // TODO: get this from secret?
Protocol: ptr.To(corev1.ProtocolTCP),
Port: ptr.To(intstr.FromInt(9000)),
},
Copy link
Preview

Copilot AI Sep 8, 2025

Choose a reason for hiding this comment

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

Hardcoded ports 443 and 9000 for S3 connections should be configurable or derived from the storage configuration. The TODO comments indicate this is a known issue that should be addressed.

Copilot uses AI. Check for mistakes.

}
)
clusterIngress := map[string][]networkingv1.NetworkPolicyPort{}
if tempo.Spec.Template.Gateway.Enabled { // TODO: add cluster -> gateway access
Copy link
Preview

Copilot AI Sep 8, 2025

Choose a reason for hiding this comment

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

Empty port slice assignment should include a comment explaining why no specific ports are defined for gateway access or implement the TODO mentioned in the comment above.

Suggested change
if tempo.Spec.Template.Gateway.Enabled { // TODO: add cluster -> gateway access
if tempo.Spec.Template.Gateway.Enabled { // TODO: add cluster -> gateway access
// No specific ports are defined for gateway access yet; this is intentional and will be updated per the TODO above.

Copilot uses AI. Check for mistakes.

clusterIngress[manifestutils.GatewayComponentName] = []networkingv1.NetworkPolicyPort{}
}

if tempo.Spec.Template.QueryFrontend.JaegerQuery.Enabled { // TODO: add cluster -> jaegerQuery access
Copy link
Preview

Copilot AI Sep 8, 2025

Choose a reason for hiding this comment

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

Empty port slice assignment should include a comment explaining why no specific ports are defined for Jaeger frontend access or implement the TODO mentioned in the comment above.

Suggested change
if tempo.Spec.Template.QueryFrontend.JaegerQuery.Enabled { // TODO: add cluster -> jaegerQuery access
if tempo.Spec.Template.QueryFrontend.JaegerQuery.Enabled { // TODO: add cluster -> jaegerQuery access
// No ports defined for Jaeger frontend access as it is not exposed to the cluster by default.

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants