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

Add SPIRE server entries to sysdump #2059

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sysdump/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (
hubbleRelayContainerName = defaults.RelayContainerName
hubbleRelayDeploymentName = defaults.RelayDeploymentName
hubbleUIDeploymentName = defaults.HubbleUIDeploymentName
spireServerContainerName = "spire-server"
meyskens marked this conversation as resolved.
Show resolved Hide resolved
redacted = "XXXXXX"
)

Expand All @@ -51,6 +52,7 @@ const (
ciliumSPIREAgentConfigMapFileName = "cilium-spire-agent-configmap-<ts>.yaml"
ciliumSPIREServerStatefulSetFileName = "cilium-spire-server-statefulset-<ts>.yaml"
ciliumSPIREServerConfigMapFileName = "cilium-spire-server-configmap-<ts>.yaml"
ciliumSPIREServerEntriesFileName = "cilium-spire-server-entries-%s-<ts>.json"
ciliumIngressesFileName = "ciliumingresses-<ts>.yaml"
ciliumEgressNATPoliciesFileName = "ciliumegressnatpolicies-<ts>.yaml"
ciliumEgressGatewayPoliciesFileName = "ciliumegressgatewaypolicies-<ts>.yaml"
Expand Down
50 changes: 50 additions & 0 deletions sysdump/sysdump.go
Original file line number Diff line number Diff line change
Expand Up @@ -1565,6 +1565,23 @@ func (c *Collector) getSPIRETasks() []Task {
return nil
},
},
{
CreatesSubtasks: true,
Description: "Collecting the Cilium SPIRE server identity entries",
Quick: false,
Task: func(ctx context.Context) error {
p, err := c.Client.ListPods(ctx, c.Options.CiliumSPIRENamespace, metav1.ListOptions{
LabelSelector: c.Options.CiliumSPIREServerLabelSelector,
})
if err != nil {
return fmt.Errorf("failed to get identity entries from Cilium SPIRE server pods")
}
if err := c.submitSpireEntriesTasks(FilterPods(p, c.NodeList)); err != nil {
return fmt.Errorf("failed to collect identity entries from Cilium SPIRE server pods")
}
return nil
},
},
}
}

Expand Down Expand Up @@ -1916,6 +1933,39 @@ func (c *Collector) submitHubbleFlowsTasks(_ context.Context, pods []*corev1.Pod
return nil
}

func (c *Collector) submitSpireEntriesTasks(pods []*corev1.Pod) error {
for _, p := range pods {
p := p
if err := c.Pool.Submit(fmt.Sprintf("spire-entries-"+p.Name), func(ctx context.Context) error {
p, containerName, cleanupFunc, err := c.ensureExecTarget(ctx, p, spireServerContainerName)
if err != nil {
return fmt.Errorf("failed to pick exec target: %w", err)
}
defer func() {
err := cleanupFunc(ctx)
if err != nil {
c.logWarn("Failed to clean up exec target: %v", err)
}
}()

command := []string{"/opt/spire/bin/spire-server", "entry", "show", "-output", "json"}
o, err := c.Client.ExecInPod(ctx, p.Namespace, p.Name, containerName, command)
if err != nil {
return fmt.Errorf("failed to collect 'spire-server' output for %q in namespace %q: %w", p.Name, p.Namespace, err)
}

if err := c.WriteBytes(fmt.Sprintf(ciliumSPIREServerEntriesFileName, p.Name), o.Bytes()); err != nil {
return fmt.Errorf("failed to write spireserver stdout for %q in namespace %q: %w", p.Name, p.Namespace, err)
}

return nil
}); err != nil {
return fmt.Errorf("failed to submit SPIRE entries task for %q: %w", p.Name, err)
}
}
return nil
}

func extractGopsPID(output string) (string, error) {
entries := strings.Split(output, "\n")
for _, entry := range entries {
Expand Down
Loading