Generated banner for Aks Network Capture
Generated logo for Aks Network Capture

Aks Network Capture

MicrosoftOfficialCreated by Microsoft

  • Skill
  • Workflow
  • Cloud and DevOps
  • MIT
  • Low risk
  • Has scripts

From the author

Collects bounded packet captures from AKS nodes and Azure network configuration for wire-level evidence. WHEN: "capture packets on an AKS node", "take a pcap", "run tcpdump on AKS", "prove where packets drop". Use for explicit packet-capture intent after read-only diagnostics, not general AKS connectivity or ingress troubleshooting.
— the description by Microsoft

AutoGineer summary

Written by AutoGineer from the skill’s own files, not by the author

The aks-network-capture skill provides a governed procedure for collecting wire-level evidence from Azure Kubernetes Service (AKS) nodes. It is designed for scenarios requiring explicit packet capture after initial read-only diagnostics have been exhausted. The skill includes scripts for setting up capture configurations, executing the capture, generating test traffic, and retrieving the resulting data, alongside tools for collecting relevant Azure network metadata. It emphasizes strict authorization, target binding, and resource cleanup to ensure that captures are performed securely and within defined operational boundaries.

What it does

  • Configures AKS nodes for packet capture using dedicated scripts.
  • Executes bounded packet captures on specific nodes or pods.
  • Collects Azure network configuration metadata for context.
  • Generates test traffic to facilitate network troubleshooting.
  • Retrieves capture artifacts and manages resource cleanup by run ID.

When to use it

  • When you need to perform a packet capture on an AKS node.
  • When you need to prove where network packets are being dropped.
  • After read-only diagnostics have failed to resolve a connectivity issue.
  • When you require wire-level evidence for network troubleshooting.

Advantages

  • Provides a structured, repeatable process for network evidence collection.
  • Includes built-in authorization and target binding steps to maintain security.
  • Supports both Bash and PowerShell environments for flexibility.
  • Ensures resource cleanup is tied to specific capture run IDs.

Usage examples

“Capture packets on an AKS node to investigate a drop.”
The agent initiates the capture workflow, starting with authorization and target binding, followed by the deployment of the capture configuration.
“Run tcpdump on AKS to troubleshoot connectivity.”
The agent guides you through the setup and execution of the packet capture scripts, ensuring the capture is bounded and authorized.

Install

  1. Download the skill as a ZIP:

    https://mp-staging.autogineer.com/agent-skills/microsoft/aks-network-capture/download
  2. Unzip it into the cross-client skills folder of your project:

    mkdir -p .agents/skills && unzip aks-network-capture.zip -d .agents/skills

Documentation by Microsoft

AKS Network Capture

Quick Reference

UseRequiresSafety
AKS pcap evidencekubectl; az for Azure evidenceBounded, pinned, least privilege

When to Use This Skill

Use for explicit packet capture after read-only checks, not generic connectivity failures.

MCP Tools

Azure MCP's AKS area provides cluster and node-pool metadata, not Kubernetes command execution or packet capture.

Host Capability Gate

Before executing the workflow, confirm that the host permits the required Bash or PowerShell execution, kubectl access to the bound cluster, az for Azure evidence, access to the bundled scripts, and an approved artifact destination. A governed Azure CLI tool alone does not establish that shell, Kubernetes commands, or artifact operations are supported.

If a required capability is unavailable or prohibited, state that capture execution is unavailable in this host. Analyze supplied, appropriately redacted evidence or give the operator a target-bound collection/capture plan; do not claim to have run it. Never route kubectl through Azure MCP, add an unapproved execution path, or bypass host policy. Host support does not replace the mutation and sensitive-data approvals below.

Run bundled scripts from the skill root only after this gate is satisfied.

Workflow/Steps

  1. Check host capabilities, then complete authorization and target binding. Capture intent is not mutation consent. Stop for separate approval before any debug-container fallback.

  2. Install Bash / PowerShell.

  3. Capture nodes or pods with Bash / PowerShell.

  4. Generate traffic if approved with Bash / PowerShell.

  5. Retrieve the exact run with Bash / PowerShell.

  6. Gather Azure evidence with Bash / PowerShell.

The ConfigMap runs run-capture.sh inside its pinned Linux image.

Error Handling

ErrorAction
Invalid inputCorrect it before retrying.
Missing/stale ConfigMapRun setup again.
Capture/retrieval failureInspect Job logs; missing evidence is not success.

Files

scripts/retrieve-captures.ps1

# Retrieve exact-run capture bundles from nodes and clean up capture resources.
# Exit codes: 0 = success/help, 1 = retrieval/cleanup failure, 2 = usage/argument error.
[CmdletBinding()]
param(
    [string]$Name,
    [string]$OutputPath = "/var/log/aks-network-captures",
    [string]$WorkspaceDir = $(if ($env:WORKSPACE_DIR) {
        $env:WORKSPACE_DIR
    } else {
        Join-Path "." "aks-network-captures"
    }),
    [string]$Namespace = "default",
    [string]$RunId,
    [switch]$Help
)

function Write-Usage {
    @"
Usage: retrieve-captures.ps1 -Name <capture-name> [options]

Options:
  -OutputPath <path>      Node hostPath base
  -WorkspaceDir <path>    Local workspace directory
  -Namespace <name>       Capture Job namespace (default: default)
  -RunId <id>             Exact run ID; required when multiple runs exist
"@
}

function Stop-Usage {
    param([string]$Message)
    [Console]::Error.WriteLine("Error: $Message")
    [Console]::Error.WriteLine((Write-Usage))
    exit 2
}

function Stop-Failure {
    param([string]$Message)
    [Console]::Error.WriteLine("Error: $Message")
    exit 1
}

function Test-Rfc1123Label {
    param([string]$Value)
    return $Value.Length -le 63 -and
        $Value -cmatch "^[a-z0-9]([-a-z0-9]*[a-z0-9])?$"
}

function Test-DnsSubdomain {
    param([string]$Value)
    return $Value.Length -le 253 -and
        $Value -cmatch "^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$"
}

function Test-RunId {
    param([string]$Value)
    return $Value -cmatch "^[0-9]{8}-[0-9]{6}-[0-9a-f]{24}$"
}

function Invoke-KubectlChecked {
    param([string[]]$KubectlArguments, [string]$FailureMessage)
    $output = (& kubectl @KubectlArguments 2>&1) -join "`n"
    if ($LASTEXITCODE -ne 0) {
        throw "$FailureMessage`n$output"
    }
    return $output.Trim()
}

if ($Help) {
    Write-Usage
    exit 0
}
if ([string]::IsNullOrWhiteSpace($Name)) {
    Stop-Usage "-Name is required"
}
if (-not (Test-Rfc1123Label $Name)) {
    Stop-Usage "-Name must be an RFC 1123 label"
}
if (-not (Test-Rfc1123Label $Namespace)) {
    Stop-Usage "-Namespace must be an RFC 1123 label"
}
if ($OutputPath -notmatch "^/[A-Za-z0-9/_.-]+$" -or $OutputPath.Contains("..")) {
    Stop-Usage "-OutputPath must be absolute and contain only letters, digits, '/', '_', '.', or '-'"
}
if ([string]::IsNullOrWhiteSpace($WorkspaceDir) -or $WorkspaceDir -match "[`r`n]") {
    Stop-Usage "-WorkspaceDir must be a non-empty single-line path"
}
if ($RunId -and -not (Test-RunId $RunId)) {
    Stop-Usage "-RunId has an invalid format"
}
if (-not (Get-Command kubectl -ErrorAction SilentlyContinue)) {
    Stop-Failure "kubectl is not installed or not on PATH"
}

try {
    if (-not $RunId) {
        $runsOutput = Invoke-KubectlChecked -KubectlArguments @(
            "get", "jobs", "-n", $Namespace, "-l", "capture-id=$Name",
            "-o", 'jsonpath={range .items[*]}{.metadata.labels.capture-run}{"\n"}{end}'
        ) -FailureMessage "could not list capture runs"
        $runs = @($runsOutput -split "`n" |
            ForEach-Object { $_.Trim() } |
            Where-Object { $_ } |
            Sort-Object -Unique)
        if ($runs.Count -eq 0) {
            throw "no capture runs found for '$Name'"
        }
        if ($runs.Count -gt 1) {
            throw "multiple capture runs found; specify -RunId"
        }
        $RunId = $runs[0]
    }
    if (-not (Test-RunId $RunId)) {
        throw "Kubernetes returned an invalid capture run identity"
    }

    $jobsOutput = Invoke-KubectlChecked -KubectlArguments @(
        "get", "jobs", "-n", $Namespace,
        "-l", "capture-id=$Name,capture-run=$RunId",
        "-o", "jsonpath={.items[*].metadata.name}"
    ) -FailureMessage "could not list capture Jobs"
    $captureJobs = @($jobsOutput -split "\s+" | Where-Object { $_ })
    if ($captureJobs.Count -eq 0) {
        throw "no Jobs found for the requested capture run"
    }
} catch {
    Stop-Failure $_.Exception.Message
}

$timestamp = (Get-Date).ToUniversalTime().ToString("yyyyMMdd-HHmmss")
$captureOutputDir = Join-Path (Join-Path $WorkspaceDir "network-captures") "$Name-$RunId-$timestamp"
try {
    New-Item -ItemType Directory -Path $captureOutputDir -Force -ErrorAction Stop | Out-Null
} catch {
    Stop-Failure "could not create the local capture directory: $($_.Exception.Message)"
}

$tempPods = New-Object System.Collections.Generic.List[string]
$operationError = $null
$cleanupErrors = New-Object System.Collections.Generic.List[string]

try {
    foreach ($job in $captureJobs) {
        $nodeName = Invoke-KubectlChecked -KubectlArguments @(
            "get", "job", $job, "-n", $Namespace,
            "-o", "jsonpath={.spec.template.spec.nodeName}"
        ) -FailureMessage "could not read the node for Job '$job'"
        $jobRunId = Invoke-KubectlChecked -KubectlArguments @(
            "get", "job", $job, "-n", $Namespace,
            "-o", 'jsonpath={.spec.template.spec.containers[0].env[?(@.name=="RUN_ID")].value}'
        ) -FailureMessage "could not read the run identity for Job '$job'"
        if (-not (Test-DnsSubdomain $nodeName)) {
            throw "Job '$job' returned an invalid node name"
        }
        if (-not (Test-RunId $jobRunId) -or $jobRunId -ne $RunId) {
            throw "Job '$job' does not match the requested run"
        }

        $podName = Invoke-KubectlChecked -KubectlArguments @(
            "get", "pods", "-n", $Namespace, "-l", "job-name=$job",
            "-o", "jsonpath={.items[0].metadata.name}"
        ) -FailureMessage "could not find the capture pod for Job '$job'"
        if ([string]::IsNullOrWhiteSpace($podName)) {
            throw "no capture pod found for Job '$job'"
        }
        $podStatus = Invoke-KubectlChecked -KubectlArguments @(
            "get", "pod", $podName, "-n", $Namespace,
            "-o", "jsonpath={.status.phase}"
        ) -FailureMessage "could not read capture pod status"
        if ($podStatus -ne "Succeeded") {
            throw "capture pod '$podName' did not succeed; inspect its logs before retrying"
        }

        $captureSlug = $Name.Substring(0, [Math]::Min(20, $Name.Length))
        $normalizedNode = $nodeName -replace "[._]", "-"
        $nodeSlug = $normalizedNode.Substring(0, [Math]::Min(20, $normalizedNode.Length))
        $retrievalYaml = @"
apiVersion: v1
kind: Pod
metadata:
  generateName: retrieve-$captureSlug-$nodeSlug-
  namespace: $Namespace
  labels: { app: aks-network-capture, capture-id: "$Name", role: retrieval }
spec:
  hostNetwork: true
  nodeName: "$nodeName"
  restartPolicy: Never
  containers:
  - name: retrieve
    image: mcr.microsoft.com/cbl-mariner/busybox:2.0@sha256:e4fb4d51fc9b70d6cdc1ce66a0af02ab40554d2ca632e1d188fabc760e432fdd
    command: ["sh", "-c", "sleep 300"]
    volumeMounts:
    - name: capture-output
      mountPath: /capture-root
  volumes:
  - name: capture-output
    hostPath:
      path: $OutputPath/$Name
      type: Directory
"@
        $tempPodName = ($retrievalYaml |
            & kubectl create -f - -o "jsonpath={.metadata.name}" 2>&1) -join "`n"
        if ($LASTEXITCODE -ne 0 -or [string]::IsNullOrWhiteSpace($tempPodName)) {
            throw "failed to create a retrieval pod on '$nodeName': $tempPodName"
        }
        $tempPodName = $tempPodName.Trim()
        $tempPods.Add($tempPodName)

        & kubectl wait -n $Namespace --for=condition=Ready `
            "pod/$tempPodName" --timeout=60s
        if ($LASTEXITCODE -ne 0) {
            throw "retrieval pod '$tempPodName' did not become ready"
        }

        $bundleName = "capture-$Name-$nodeName-$jobRunId.tar.gz"
        $runDir = "/capture-root/$jobRunId"
        $localBundle = Join-Path $captureOutputDir $bundleName
        & kubectl cp -n $Namespace "${tempPodName}:${runDir}/${bundleName}" `
            $localBundle -c retrieve
        if ($LASTEXITCODE -ne 0) {
            throw "failed to copy '$bundleName' from node '$nodeName'"
        }
        if (-not (Test-Path -LiteralPath $localBundle -PathType Leaf) -or
            (Get-Item -LiteralPath $localBundle).Length -eq 0) {
            throw "the copied capture bundle '$bundleName' is empty"
        }

        & kubectl exec -n $Namespace $tempPodName -c retrieve -- sh -c `
            'rm -f "$1/$2" "$1/$3" && rmdir "$1"' sh `
            $runDir $bundleName "capture-$Name-$nodeName-$jobRunId.pcap"
        if ($LASTEXITCODE -ne 0) {
            throw "failed to remove the retrieved node artifacts"
        }
        & kubectl delete pod $tempPodName -n $Namespace --ignore-not-found
        if ($LASTEXITCODE -ne 0) {
            throw "failed to delete retrieval pod '$tempPodName'"
        }
    }
} catch {
    $operationError = $_.Exception.Message
} finally {
    foreach ($tempPod in $tempPods) {
        & kubectl delete pod $tempPod -n $Namespace --ignore-not-found 2>$null | Out-Null
        if ($LASTEXITCODE -ne 0) {
            $cleanupErrors.Add("failed to delete retrieval pod '$tempPod'")
        }
    }
    & kubectl delete jobs -n $Namespace @($captureJobs) --ignore-not-found 2>$null | Out-Null
    if ($LASTEXITCODE -ne 0) {
        $cleanupErrors.Add("failed to delete capture Jobs")
    }
}

if ($operationError) {
    if ($cleanupErrors.Count -gt 0) {
        Stop-Failure "$operationError; cleanup also failed: $($cleanupErrors -join '; ')"
    }
    Stop-Failure $operationError
}
if ($cleanupErrors.Count -gt 0) {
    Stop-Failure ($cleanupErrors -join "; ")
}

Write-Output "Capture bundles saved to: $captureOutputDir"
Get-ChildItem -LiteralPath $captureOutputDir

Requirements and compatibility

Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta

“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.

Needs: Needs Node.js

Security

What our scanner noticed· Low risk

  • Scripts that your agent may run

This skill includes scripts that your agent may run. Read them before you use it.

A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.

Attribution and licence

Created by
Microsoft
Publisher
Microsoft (Official)
Source
microsoft/skills · .github/plugins/aks-skills/skills/aks-network-capture · commit 0696600
Licence
MIT License (redistribution allowed)
  • LICENSE (added by AutoGineer from .github/plugins/aks-skills/LICENSE)
  • ATTRIBUTION.md (written by AutoGineer)
Synced

AutoGineer is not affiliated with or endorsed by Microsoft.

Download ZIP

The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download aks-network-capture.zip