Back to skill

Security audit

k8s skill

Security checks for vulnerabilities and agentic risk

Overview

This Kubernetes diagnostic skill is mostly purpose-aligned, but it can over-collect sensitive cluster Secret data and gives unsafe kubeconfig guidance.

Install only with a dedicated read-only kubeconfig scoped to the namespaces you intend to inspect. Do not use cluster-admin credentials or put kubeconfig files inside the skill directory, and avoid running Secret analysis until namespace scoping and Secret caching are fixed.

Vulnerability Patterns
  • Unauthorized Access and Privilege EscalationObtains permissions beyond the task's legitimate needs
  • Insecure DependenciesIntroduces malicious components through unsafe dependency sources
  • Skill Instruction HijackingAlters the agent's session goals or safety constraints when the skill loads
  • Agent Memory PoisoningWrites attacker-controlled rules into memory that affect later sessions
  • Remote Payload Retrieval and ExecutionFetches external code whose behavior can change after review
Findings (3)

T05 · Unauthorized Access and Privilege Escalation

Error
Location
scripts/analyzers/secret.py:41
Finding

Namespace-Scoped Analysis Retrieves and Caches Secrets from All Readable Namespaces

Content
View full analysis

Vulnerability Details

File Location: scripts/analyzers/secret.py:41-61; related caching behavior in scripts/core/base.py:511-572
Vulnerability Type: Excessive Kubernetes Secret access and sensitive-data retention
Risk Level: High

Vulnerable Code

python
secrets = self._list_resources_paginated(
    list_func=v1.list_secret_for_all_namespaces,
    cache_key="secrets",
    namespace=namespace,
    label_selector=label_selector
)

# 获取所有Pod以检查Secret使用情况
pods = self._list_resources_paginated(
    list_func=v1.list_pod_for_all_namespaces,
    cache_key="pods",
    namespace="",
    label_selector=""
)

used_secrets = self._get_used_secrets(pods)

for secret in secrets:
    if namespace and secret.metadata.namespace != namespace:
        continue

The shared pagination helper retains the complete API response objects:

python
full_cache_key = f"{cache_key}:{namespace}:{label_selector}"

cached = self._get_cached(full_cache_key)
if cached is not None:
    self._logger.debug(f"使用缓存数据: {full_cache_key}")
    return cached

all_items = []
continue_token = None
total_count = 0
iteration = 0
max_iterations = PERF_CONFIG["max_iterations"]

while iteration < max_iterations:
    iteration += 1
    try:
        if continue_token:
            response = list_func(
                limit=limit,
                _continue=continue_token,
                label_selector=label_selector if label_selector else None,
                _request_timeout=self._timeout
            )
        else:
            response = list_func(
                limit=limit,
                label_selector=label_selector if label_selector else None,
                _request_timeout=self._timeout
            )

        items = response.items if hasattr(response, 'items') else response
        if not isinstance(items, list):
            items = [items] if items else []


...[truncated 2831 chars]
Remediation
View remediation

Remediation Suggestions

  1. When a namespace is supplied, invoke the namespaced Kubernetes API:

    python
    if namespace:
        list_func = lambda **kwargs: v1.list_namespaced_secret(
            namespace=namespace,
            **kwargs
        )
    else:
        list_func = v1.list_secret_for_all_namespaces
    
  2. Avoid caching complete Kubernetes Secret objects. Disable caching for the Secret analyzer or immediately reduce each object to non-sensitive fields such as:

    • Name
    • Namespace
    • Secret type
    • Data key names
    • Presence or absence of required fields
  3. Explicitly discard Secret values after inspection and ensure they are never included in logs, exceptions, reports, or serialized diagnostic results.

  4. Split cache storage by sensitivity and prohibit Secret objects from entering the shared global resource cache.

  5. Document and provide a minimal Kubernetes RBAC policy. Prefer namespace-specific Roles and RoleBindings over a cluster-wide Secret-list permission.

  6. If cluster-wide Secret analysis is explicitly requested, require clear caller confirmation and disclose that Secret objects from all authorized namespaces will be accessed.

T05 · Unauthorized Access and Privilege Escalation

Warning
Location
scripts/analyzers/secret.py:49
Finding

Namespace-Scoped Secret Analysis Performs Cluster-Wide Pod Enumeration

Content
View full analysis

Vulnerability Details

File Location: scripts/analyzers/secret.py:49-55
Vulnerability Type: Excessive Kubernetes workload access
Risk Level: Medium

Vulnerable Code

python
# 获取所有Pod以检查Secret使用情况
pods = self._list_resources_paginated(
    list_func=v1.list_pod_for_all_namespaces,
    cache_key="pods",
    namespace="",
    label_selector=""
)

used_secrets = self._get_used_secrets(pods)

The resulting Pod objects are inspected and indexed only by unqualified Secret name:

python
used = {}

for pod in pods.items if hasattr(pods, 'items') else pods:
    spec = pod.spec
    if not spec:
        continue

    pod_name = pod.metadata.name

    for secret_ref in getattr(spec, 'image_pull_secrets', []) or []:
        secret_name = getattr(secret_ref, 'name', None)
        if secret_name:
            if secret_name not in used:
                used[secret_name] = []
            used[secret_name].append(pod_name)

Technical Analysis

The Secret analyzer deliberately discards the caller-provided namespace by passing an empty namespace and using list_pod_for_all_namespaces. Therefore, analysis of one namespace retrieves complete Pod specifications from every namespace readable by the active Kubernetes credential.

Pod specifications can reveal internal image names, commands, arguments, environment configuration, volume layouts, service-account associations, node selectors, Secret and ConfigMap references, and application topology. These objects are also processed through the shared global cache.

The analyzer additionally indexes Secret usage solely by secret_name, without including the namespace. Kubernetes Secret names are namespace-scoped, so two namespaces may legitimately contain Secrets with the same name. A Pod in one namespace can therefore cause a same-named Secret in another namespace to be incorrectly classified as used.

As with the Secret-list issue, ...[truncated 1515 chars]

Remediation
View remediation

Remediation Suggestions

  1. Use list_namespaced_pod(namespace=namespace) whenever analysis is restricted to a namespace.

  2. Represent Secret references using a namespace-qualified key:

    python
    secret_key = (pod.metadata.namespace, secret_name)
    
  3. Compare each Secret against (secret.metadata.namespace, secret.metadata.name) rather than only its name.

  4. Do not cache full Pod objects when only Secret references are required. Reduce each Pod immediately to a minimal set of namespace-qualified Secret references.

  5. Include env_from.secret_ref references in usage detection, in addition to direct environment-variable, volume, and image-pull references.

  6. Reserve cluster-wide Pod enumeration for an explicit cluster-wide request and ensure the active identity has only the minimum read permissions necessary.

T08 · Insecure Dependencies

Note
Location
requirements.txt:1
Finding

Unbounded Dependency Constraints Permit Installation of Unreviewed Future Releases

Content
View full analysis

Vulnerability Details

File Location: requirements.txt:1-3; installation documented at README_EN.md:7-12
Vulnerability Type: Non-reproducible and insufficiently constrained dependencies
Risk Level: Low

Vulnerable Code

text
# K8sSkill 依赖
kubernetes>=28.0.0
pyyaml>=6.0

The documented installation command resolves dependencies directly:

bash
cd <skill directory>
pip install -r requirements.txt

Technical Analysis

Both dependencies use unrestricted lower-bound constraints. Any future release satisfying the minimum version may be selected during installation. No upper bounds, lock file, exact pins, or package hashes are supplied.

This makes installations non-reproducible and prevents users from reliably installing the dependency artifacts that were reviewed with the Skill. It also increases exposure to future compromised releases, malicious dependency updates, or unexpected compatibility changes.

The Kubernetes client is particularly sensitive because it runs in the same process that loads kubeconfig credentials and communicates with the Kubernetes API. PyYAML also executes within that trusted process.

No malicious package name, typosquatting dependency, or currently compromised version was identified in the audit. The finding concerns the unsafe dependency-resolution policy rather than evidence that the listed packages are malicious.

Attack Path

  1. A user follows the documented pip install -r requirements.txt instruction.
  2. pip queries the configured package index and selects the newest versions satisfying the broad constraints.
  3. A future compromised, malicious, or unexpectedly incompatible release is resolved without a project change or review.
  4. Package installation hooks or imported package code execute in the user's environment.
  5. At runtime, malicious dependency code could access local files, environment variables, kubeconfig credentials, ...[truncated 868 chars]
Remediation
View remediation

Remediation Suggestions

  1. Pin reviewed dependency versions exactly rather than using unrestricted minimum versions.

  2. Generate and commit a lock file using a controlled dependency-management tool such as pip-tools, Poetry, or an equivalent reproducible workflow.

  3. Record package hashes and install with hash verification:

    bash
    pip install --require-hashes -r requirements.txt
    
  4. Review transitive dependencies and include them in the lock file rather than relying on resolution at installation time.

  5. Perform automated vulnerability and provenance checks during dependency updates.

  6. Update dependency pins through a controlled process that includes compatibility testing, security review, and regeneration of trusted hashes.

Vulnerability Patterns
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
  • MCP Tool PoisoningHidden Instructions, Unicode Deception, Parameter Description Injection
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Supply ChainUnpinned Dependencies, External Script Fetching, Obfuscated Code
Findings (106)

Credential Access

High
Category
Privilege Escalation
Confidence
93% confidence
Finding

The README normalizes use of kubeconfig for the skill without any security guardrails, despite kubeconfig being a sensitive credential container. In a Kubernetes diagnostic skill, encouraging credential use is expected, but failing to constrain privilege or warn about sensitivity materially raises the risk of credential exposure and overreach.

Content

Scanner excerpt · README.md (reported line 22)May include surrounding context.

md
### 2. 配置Kubernetes连接

**方式A: 使用项目自带的kubeconfig(已配置)**

项目已在 `config/` 目录下配置了kubeconfig文件:
- `config/k8s-Test-admin.conf`

Credential Access

High
Category
Privilege Escalation
Confidence
99% confidence
Finding

The README states that the project already includes a kubeconfig file at config/k8s-Test-admin.conf, which strongly suggests distribution of a cluster access credential inside the project. Bundling an admin kubeconfig with a skill is a severe security issue because anyone with repository or package access may obtain cluster credentials and potentially administrative control.

Content

Scanner excerpt · README.md (reported line 24)May include surrounding context.

md
**方式A: 使用项目自带的kubeconfig(已配置)**

项目已在 `config/` 目录下配置了kubeconfig文件:
- `config/k8s-Test-admin.conf`

**方式B: 手动配置到默认位置**

Credential Access

High
Category
Privilege Escalation
Confidence
94% confidence
Finding

The documentation around manually configuring kubeconfig encourages direct handling of cluster credentials for skill operation, but does not establish secure usage constraints. This is risky because users may point the skill at powerful production contexts and expose that access to an IDE-integrated automation environment.

Content

Scanner excerpt · README.md (reported line 29)May include surrounding context.

方式B: 手动配置到默认位置

bash
# 复制kubeconfig到默认位置(Linux/macOS)
cp ~/.kube/config.backup ~/.kube/config.backup 2>/dev/null || true
cp /path/to/your/kubeconfig ~/.kube/config

Credential Access

High
Category
Privilege Escalation
Confidence
96% confidence
Finding

Referencing and instructing use of ~/.kube/config in a skill README is dangerous because kubeconfig commonly contains live cluster credentials and may grant broad administrative access. In this skill's context, the danger is increased because the document explicitly encourages using a preconfigured admin kubeconfig for automated diagnosis, making credential exposure and misuse more likely.

Content

Scanner excerpt · README.md (reported line 30)May include surrounding context.

方式B: 手动配置到默认位置

bash
# 复制kubeconfig到默认位置(Linux/macOS)
cp ~/.kube/config.backup ~/.kube/config.backup 2>/dev/null || true
cp /path/to/your/kubeconfig ~/.kube/config

Credential Access

High
Category
Privilege Escalation
Confidence
96% confidence
Finding

This command operationalizes sensitive kubeconfig placement into the user's default Kubernetes config path, which can unintentionally broaden access to other local tools and sessions. In the context of an agent skill, that increases the blast radius if the environment is compromised or if the agent reads more than the user expected.

Content

Scanner excerpt · README.md (reported line 31)May include surrounding context.

bash
# 复制kubeconfig到默认位置(Linux/macOS)
cp ~/.kube/config.backup ~/.kube/config.backup 2>/dev/null || true
cp /path/to/your/kubeconfig ~/.kube/config

方式C: 设置环境变量

Credential Access

High
Category
Privilege Escalation
Confidence
96% confidence
Finding

This command operationalizes sensitive kubeconfig placement into the user's default Kubernetes config path, which can unintentionally broaden access to other local tools and sessions. In the context of an agent skill, that increases the blast radius if the environment is compromised or if the agent reads more than the user expected.

Content

Scanner excerpt · README.md (reported line 31)May include surrounding context.

bash
# 复制kubeconfig到默认位置(Linux/macOS)
cp ~/.kube/config.backup ~/.kube/config.backup 2>/dev/null || true
cp /path/to/your/kubeconfig ~/.kube/config

方式C: 设置环境变量

Credential Access

High
Category
Privilege Escalation
Confidence
95% confidence
Finding

The README instructs setting the KUBECONFIG environment variable to a skill-local config file, which makes a sensitive cluster credential available to the process environment and potentially to child processes, debugging output, or IDE integrations. This is especially concerning if the referenced file is an admin kubeconfig bundled with the project.

Content

Scanner excerpt · README.md (reported line 36)May include surrounding context.

方式C: 设置环境变量

powershell
# 设置KUBECONFIG环境变量指向skill目录下的配置文件(Windows)
$env:KUBECONFIG="<skill目录>\config\k8s-Test-admin.conf"

Credential Access

High
Category
Privilege Escalation
Confidence
95% confidence
Finding

Pointing KUBECONFIG at config/k8s-Test-admin.conf suggests a local project file contains privileged access material and encourages exposing it to the runtime environment. If that file is real, any compromise of the project directory, IDE, or agent context could lead to unauthorized cluster access.

Content

Scanner excerpt · README.md (reported line 37)May include surrounding context.

方式C: 设置环境变量

powershell
# 设置KUBECONFIG环境变量指向skill目录下的配置文件(Windows)
$env:KUBECONFIG="<skill目录>\config\k8s-Test-admin.conf"

3. 在IDE中使用

Credential Access

High
Category
Privilege Escalation
Confidence
87% confidence
Finding

Mentioning kubeconfig existence checks in troubleshooting is not inherently malicious, but it still concerns sensitive credential material and reinforces undocumented handling of secrets. In isolation this is lower risk than bundling or copying credentials, yet it contributes to a workflow where sensitive files are treated casually.

Content

Scanner excerpt · README.md (reported line 84)May include surrounding context.

连接失败

bash
# 检查kubeconfig是否存在
dir config\

# 手动测试连接

Credential Access

High
Category
Privilege Escalation
Confidence
95% confidence
Finding

The README references a project-included kubeconfig and specifically names an admin configuration file, indicating that cluster credentials may be stored within the skill package. Shipping or encouraging use of embedded admin kubeconfig files creates a serious risk of credential exposure, unauthorized cluster access, and compromise of production infrastructure if the file is leaked or reused.

Content

Scanner excerpt · README_EN.md (reported line 22)May include surrounding context.

md
### 2. Configure Kubernetes Connection

**Option A: Use project-included kubeconfig (already configured)**

The project has configured kubeconfig file in `config/` directory:
- `config/k8s-Test-admin.conf`

Credential Access

High
Category
Privilege Escalation
Confidence
95% confidence
Finding

Explicitly documenting config/k8s-Test-admin.conf as already configured strongly suggests an admin kubeconfig is expected to reside in the repository or skill directory. Even in documentation, normalizing repository-local admin credentials encourages unsafe handling of secrets and increases the likelihood of accidental source control exposure or credential reuse.

Content

Scanner excerpt · README_EN.md (reported line 24)May include surrounding context.

md
**Option A: Use project-included kubeconfig (already configured)**

The project has configured kubeconfig file in `config/` directory:
- `config/k8s-Test-admin.conf`

**Option B: Manually configure to default location**

Credential Access

High
Category
Privilege Escalation
Confidence
88% confidence
Finding

The documentation instructs users to set KUBECONFIG to a config file in the skill directory, which reinforces use of repository-local credentials and may expose powerful cluster access to the IDE/agent process automatically. In this context, environment-based credential loading can silently grant the skill broad access whenever it runs.

Content

Scanner excerpt · README_EN.md (reported line 35)May include surrounding context.

Option C: Set environment variable

powershell
# Set KUBECONFIG environment variable pointing to skill directory config file
$env:KUBECONFIG="<skill directory>\config\k8s-Test-admin.conf"

Credential Access

High
Category
Privilege Escalation
Confidence
90% confidence
Finding

Pointing KUBECONFIG to <skill directory>\config\k8s-Test-admin.conf specifically ties the agent to an apparent admin credential stored with the skill. This creates high risk of credential leakage, unauthorized reuse, and excessive privilege during automated diagnostics.

Content

Scanner excerpt · README_EN.md (reported line 36)May include surrounding context.

Option C: Set environment variable

powershell
# Set KUBECONFIG environment variable pointing to skill directory config file
$env:KUBECONFIG="<skill directory>\config\k8s-Test-admin.conf"

3. Use in IDE

Tp4

High
Category
MCP Tool Poisoning
Confidence
93% confidence
Finding

声明描述的是广泛的 Kubernetes 问题诊断技能,覆盖 Pod、部署、服务访问等常见运行故障;但实际代码只处理 BatchV1 的 CronJob 对象,并进行有限的静态配置检查。虽然 CronJob 也属于 Kubernetes 资源,代码可算是 K8s 诊断的一个子领域,但其主要用途与声明的通用问题排查并不一致,且无法支持描述中列举的核心场景。因此应判定为描述与行为不匹配。

Content

No source excerpt is available for this finding.

Tp4

High
Category
MCP Tool Poisoning
Confidence
92% confidence
Finding

声明描述的是广义的 Kubernetes 集群问题诊断技能,预期应覆盖 Pod、Deployment、Service 等常见故障场景。实际代码却是一个非常具体的 NetworkPolicy 配置检查器,重点在网络策略选择器与匹配范围分析,属于网络安全/配置审计子功能,而不是通用 K8s 运维诊断。虽然 NetworkPolicy 也属于 Kubernetes 问题排查的一部分,但该代码的主功能明显比声明窄且方向不同,因此描述未能准确代表代码实际行为,应判定为不匹配。

Content

No source excerpt is available for this finding.

Tp4

High
Category
MCP Tool Poisoning
Confidence
95% confidence
Finding

声明描述的是一个广泛的 Kubernetes 问题诊断技能,适用场景包括 Pod 崩溃、部署失败、服务不可访问等典型集群运维问题。但实际代码只实现了 SecretAnalyzer,功能范围明显更窄,主要做 Secret 使用情况与格式完整性检查:列出 Secret、列出 Pod、识别哪些 Secret 被引用,并报告未使用 Secret、空 Secret、TLS Secret 缺字段、docker-registry Secret 缺字段等问题。这属于配置审计/资源专项分析,而不是通用 K8s 故障诊断。虽然仍在 Kubernetes 域内,但其主要目的与声明不一致,且实际访问的核心资源集中在 Secret 和 Pod,而声明未体现这种专项能力,因此应判定为描述与行为不匹配。

Content

No source excerpt is available for this finding.

Credential Access

High
Category
Privilege Escalation
Confidence
89% confidence
Finding

The skill is built around kubeconfig-based authentication, which constitutes credential use for cluster access. Even if intended for diagnostics, access to cluster credentials materially increases risk because the skill can query sensitive infrastructure data and may operate under highly privileged identities if misconfigured.

Content

Scanner excerpt · SKILL.md (reported line 134)May include surrounding context.

md
## 配置

### kubeconfig支持
支持3种配置方式:
1. 项目自带:`config/k8s-Test-admin.conf`
2. 默认位置:`~/.kube/config`

Credential Access

High
Category
Privilege Escalation
Confidence
90% confidence
Finding

Referencing the default kubeconfig path indicates the skill can use locally stored Kubernetes credentials to access a cluster. In an agent environment, this is sensitive because unintended invocation or overbroad execution could leverage existing credentials to enumerate cluster state and disclose privileged operational information.

Content

Scanner excerpt · SKILL.md (reported line 137)May include surrounding context.

md
### kubeconfig支持
支持3种配置方式:
1. 项目自带:`config/k8s-Test-admin.conf`
2. 默认位置:`~/.kube/config`
3. 环境变量:`KUBECONFIG=/path/to/config`

### 快速验证配置

Credential Access

High
Category
Privilege Escalation
Confidence
89% confidence
Finding

Support for the KUBECONFIG environment variable means the skill can consume externally supplied cluster credentials from the runtime environment. Environment-based credential pickup is risky in shared agent runtimes because it can silently expand access to clusters the user did not intend to expose.

Content

Scanner excerpt · SKILL.md (reported line 138)May include surrounding context.

支持3种配置方式:

  1. 项目自带:config/k8s-Test-admin.conf
  2. 默认位置:~/.kube/config
  3. 环境变量:KUBECONFIG=/path/to/config

快速验证配置

python

Credential Access

High
Category
Privilege Escalation
Confidence
86% confidence
Finding

Requiring a valid kubeconfig file confirms dependency on cluster access credentials. This is dangerous in context because the skill is designed to inspect broad cluster resources, so misuse of those credentials can reveal topology, workloads, events, and other sensitive operational data.

Content

Scanner excerpt · SKILL.md (reported line 161)May include surrounding context.

md
- Python 3.8+
- kubernetes-python 客户端
- 有效的kubeconfig文件

---

Credential Access

High
Category
Privilege Escalation
Confidence
88% confidence
Finding

Telling users to ensure kubeconfig is configured correctly reinforces that the skill depends on active Kubernetes credentials and will use them when invoked. In combination with broad diagnostic scope, this elevates the consequence of accidental or unauthorized invocation because live cluster information can be accessed and surfaced.

Content

Scanner excerpt · SKILL.md (reported line 170)May include surrounding context.

md
- 本skill为**诊断工具**,不会修改集群资源
- 需要集群的**只读权限**即可运行
- 大型集群(>1000 Pod)分析可能需要等待数秒
- 首次使用前请确保kubeconfig配置正确

---

Credential Access

High
Category
Privilege Escalation
Confidence
60% confidence
Finding

Code accesses credential files (SSH keys, AWS credentials, etc.). This could indicate credential theft attempts.

Content

Scanner excerpt · SKILL_EN.md (reported line 138)May include surrounding context.

Supports 3 configuration methods:

  1. Project included: config/k8s-Test-admin.conf
  2. Default location: ~/.kube/config
  3. Environment variable: KUBECONFIG=/path/to/config

Quick Configuration Verification

python

Credential Access

High
Category
Privilege Escalation
Confidence
60% confidence
Finding

Code accesses credential files (SSH keys, AWS credentials, etc.). This could indicate credential theft attempts.

Content

Scanner excerpt · scripts/core/base.py (reported line 184)May include surrounding context.

python
Supports 3 configuration methods:
1. Project included: `config/k8s-Test-admin.conf`
2. Default location: `~/.kube/config`
3. Environment variable: `KUBECONFIG=/path/to/config`

### Quick Configuration Verification
```python

Credential Access

High
Category
Privilege Escalation
Confidence
60% confidence
Finding

Code accesses credential files (SSH keys, AWS credentials, etc.). This could indicate credential theft attempts.

Content

Scanner excerpt · README.md (reported line 123)May include surrounding context.

md
"updated_at": "2026-04-03",
    "source": "基于Kubernetes最佳实践和SRE经验设计",
    "config": {
        "kubeconfig_path": "~/.kube/config",
        "default_namespace": "default",
        "output_format": "markdown"
    },

Credential Access

High
Category
Privilege Escalation
Confidence
60% confidence
Finding

Code accesses credential files (SSH keys, AWS credentials, etc.). This could indicate credential theft attempts.

Content

Scanner excerpt · README_EN.md (reported line 29)May include surrounding context.

md
"updated_at": "2026-04-03",
    "source": "基于Kubernetes最佳实践和SRE经验设计",
    "config": {
        "kubeconfig_path": "~/.kube/config",
        "default_namespace": "default",
        "output_format": "markdown"
    },