Skip to content

feat(k8s): cluster default-deny NetworkPolicies for monitoring and argocd namespaces - #47

Merged
dan-petty merged 3 commits into
release/v0.2.12from
feat/k8s-network-policies
Sep 6, 2026
Merged

dan-petty merged 3 commits into
release/v0.2.12from
feat/k8s-network-policies

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

Summary

This pull request implements Cluster Default-Deny NetworkPolicies (Issue #40) across the monitoring and argocd namespaces in accordance with Phase 48 zero-trust infrastructure perimeter standards.

Security & Architecture Details

  • Namespace-Wide Default Perimeter:
    • Authored k8s/monitoring/networkpolicy.yaml and k8s/argocd/networkpolicy.yaml applying spec.podSelector: {} and enforcing explicit policies for both Ingress and Egress.
  • SSRF Attack Vector Elimination:
    • All outbound internet/egress rules use ipBlock.except: ["169.254.169.254/32"] to strictly prohibit internal pods from accessing cloud instance metadata services (AWS IMDS, GCP metadata, Azure metadata).
  • CoreDNS Name Resolution:
    • Explicitly permits DNS resolution to kube-system over UDP/TCP port 53.
  • Namespace Communication Boundaries:
    • monitoring:
      • Permits intra-namespace pod communications (Prometheus, Grafana, Node Exporter, Kube State Metrics).
      • Permits UI/dashboard access to Grafana (port 3000) and Prometheus (port 9090) from workstation / ingress controllers.
      • Permits OTEL collector in otel namespace to push metrics to Prometheus remote-write receiver (port 9090).
      • Permits Prometheus and Kube State Metrics to query Kubernetes API server endpoints (ports 443, 6443, 8443, 10250) and scrape target endpoints in llm (qdrant:6333, ollama:11434) and otel (jaeger:16686, otel-collector:8888).
    • argocd:
      • Permits intra-namespace pod communications (ArgoCD Server, Repo Server, Application Controller, Valkey/Redis).
      • Permits external / NodePort / Ingress access to ArgoCD Server UI and API (ports 8080 and 443).
      • Permits Prometheus in monitoring namespace to scrape component metrics (ports 8082, 8084, 9121).
      • Permits Kubernetes API server communications across namespaces for cluster resource reconciliation.
      • Permits Git (HTTPS 443, SSH 22, Git daemon 9418) and Helm chart pulls with cloud metadata SSRF blocked.
  • Kustomize Integration:
    • Registered networkpolicy.yaml in k8s/monitoring/kustomization.yaml and k8s/argocd/kustomization.yaml.
  • Living Contract Test Suite:
    • Authored tests/test_k8s_network_policies.py (14/14 green) validating schema structure, policyTypes, DNS egress, SSRF exception rules, and namespace-specific port allocations across all target namespaces.
    • Verified with Kubeconform OpenAPI schema validation (devops k8s validate) and Checkov IaC compliance scan (devops scan iac — 0 violations).

Closes #40

@dan-petty dan-petty added type/security Type security: a vulnerability or a leak scope/k8s Kubernetes commands, Helm charts, pods, services, and policies priority/p1-high Priority P1: high-impact work for the next planned milestone labels Sep 6, 2026
Copilot AI lite review requested due to automatic review settings September 6, 2026 22:36
@dan-petty dan-petty added type/security Type security: a vulnerability or a leak scope/k8s Kubernetes commands, Helm charts, pods, services, and policies priority/p1-high Priority P1: high-impact work for the next planned milestone labels Sep 6, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

There are correctness and security-scope issues (test assertions not matching stated contract, and an overly broad ArgoCD egress selector) that should be fixed before approval.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR implements default-deny Kubernetes NetworkPolicy perimeters for the monitoring and argocd namespaces (Phase 48 / Issue #40), wiring them into Kustomize and documenting/verifying the expected rule structure via pytest.

Changes:

  • Added namespace-scoped default-deny NetworkPolicies for monitoring and argocd with explicit ingress/egress allowances (DNS, cross-namespace scraping, external egress with IMDS SSRF block).
  • Registered the new manifests in each namespace’s kustomization.yaml.
  • Added/updated documentation and a test suite to validate presence and key invariants of NetworkPolicies across relevant namespaces.
File summaries
File Description
tests/test_k8s_network_policies.py Adds pytest coverage for NetworkPolicy presence, schema expectations, DNS egress, SSRF block, and namespace-specific ports.
k8s/monitoring/networkpolicy.yaml Introduces a default-deny policy for the monitoring namespace with explicit ingress/egress rules.
k8s/monitoring/kustomization.yaml Includes networkpolicy.yaml in the monitoring kustomization resources.
k8s/argocd/networkpolicy.yaml Introduces a default-deny policy for the argocd namespace with explicit ingress/egress rules.
k8s/argocd/kustomization.yaml Includes networkpolicy.yaml in the ArgoCD kustomization resources.
docs/ROADMAP.md Marks “Cluster Default-Deny NetworkPolicies” as completed for Phase 48.
docs/LOG.md Records the Phase 48.3 NetworkPolicy work and verification steps in the changelog-style log.
docs/agent/task.md Updates task tracking: marks Phase 48.2 complete and adds Phase 48.3 as current WIP.
Review details
  • Files reviewed: 8/8 changed files
  • Comments generated: 4
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread k8s/argocd/networkpolicy.yaml Resolved
Comment thread tests/test_k8s_network_policies.py Resolved
Comment thread k8s/argocd/networkpolicy.yaml Resolved
Comment thread k8s/monitoring/networkpolicy.yaml Resolved
…PI server egress selector, and test assertions
@dan-petty

Copy link
Copy Markdown
Owner Author

Copilot Review Remediation Addressed in commit 1003b75

  1. Scoped Kubernetes API Server Egress in ArgoCD:

    • In k8s/argocd/networkpolicy.yaml, replaced the unbounded namespaceSelector: {} with explicit selectors targeting default (the kubernetes Service port 443) and kube-system (API server endpoints 6443/8443), maintaining strict default-deny isolation against non-control-plane namespaces.
  2. Tightened Living Contract Test Assertions:

    • In tests/test_k8s_network_policies.py, updated test_argocd_networkpolicy_specifics to assert that both port 8080 and port 443 are allowed for UI/API ingress, and added an explicit assertion verifying Git SSH port 22 is permitted for repository fetching.
  3. Accurate Manifest Documentation:

    • Updated ingress comments in both k8s/argocd/networkpolicy.yaml and k8s/monitoring/networkpolicy.yaml to explicitly describe that external ingress over 0.0.0.0/0 accommodates NodePort, LoadBalancer, or ingress controller traffic.

All 4 remote GitHub Actions CI checks (CodeQL Actions, CodeQL Python, CodeQL, CI Quality Gate) are 100% green.

@dan-petty
dan-petty merged commit b7657a9 into release/v0.2.12 Sep 6, 2026
4 checks passed
@dan-petty
dan-petty deleted the feat/k8s-network-policies branch September 6, 2026 23:11
dan-petty added a commit that referenced this pull request Sep 7, 2026
* feat(devcontainer): automate PR devcontainer cleanup on PR merge in GHCR (#44)

* feat(devcontainer): automate PR devcontainer cleanup on PR merge in GHCR

- Add GitHub Actions workflow .github/workflows/cleanup-devcontainer.yml triggered on pull_request [closed] and workflow_dispatch
- Scope GHCR image pruning to pr-<number> or wildcard tags while preserving release tags (latest, v*, main)
- Reclaim multi-architecture storage via delete-untagged and delete-ghost-images
- Pin dataaxiom/ghcr-cleanup-action to commit SHA for supply chain security
- Enhance devops_cli.commands.gh token resolution (Keyring github.token and gh auth token) and use REST API for milestones
- Update agent instructions in AGENTS.md, ROUTINE_TASKS.md, docs/agent/README.md to leverage GitHub project integrations and issue tracking
- Sync roadmap milestones and track Phase 47.4 deliverables

Closes #39

* docs(task): update Phase 47.4 tracking with PR 44 and commit 21711bd

* fix(gh): support DEVOPS_CLI_GITHUB_TOKEN and add pagination to milestone api

- Address Copilot review comments on PR #44
- Check DEVOPS_CLI_GITHUB_TOKEN in _get_github_client()
- Pass --paginate and per_page=100 in _get_repo_milestones()
- Add regression tests in tests/test_gh_cmd.py

* feat(ci): pin GitHub Actions to immutable commit SHAs (#45)

* feat(ci): pin GitHub Actions to immutable commit SHAs

* docs(task): update Phase 48.1 tracking with PR 45

* docs(roadmap): update action SHA pinning status to completed

* docs(task): record Copilot review resolution on PR 45

* feat(security): isolate subprocess environment and enforce credential boundary (#46)

* feat(security): isolate subprocess environment and enforce credential boundary

* fix(security): normalize env var key case for cross-platform matching and ensure test determinism

* docs(task): update Phase 48.2 tracking with PR #46 and Copilot review resolution

* feat(k8s): cluster default-deny NetworkPolicies for monitoring and argocd namespaces (#47)

* feat(k8s): cluster default-deny NetworkPolicies for monitoring and argocd namespaces

* fix(k8s): address Copilot review on NetworkPolicy ingress comments, API server egress selector, and test assertions

* docs(task): record PR #47 and Copilot review remediation in Phase 48.3 tracking

* feat(security): qdrant vector database api key secret protection and clusterip default (#48)

* feat(security): qdrant vector database api key secret protection and clusterip default

* fix(review): address Copilot findings for stdin secret apply, fail-fast lifecycle, and debug logging

* docs(agent): update task tracking for PR #48 and Copilot review resolutions

* docs(agent): record Phase 48.4 PR #48 squash-merge and issue #43 closure

* feat(review): review finding remediation, github project automation, and runtime duration formatting (#49)

* refactor(review): address session 164259 findings and harden self-improvement loop

* docs(agent): mark Phase 48.5 task completed and PR 49 verified

* feat(github): remote project sync, automated milestone closure, and submodule test grouping

* feat(devcontainer): enhance mcp lifecycle sync and enforce commit message hygiene

* feat(output): format command elapsed duration in human readable units

Upgrade format_duration to support microsecond, millisecond, second, minute, hour, and day formatting across CLI command completion, CI summaries, AI reviews, and benchmarks.

* refactor(github): omit status from milestone description

Ensure milestone descriptions extracted from roadmap use strictly the feature name without appending status strings in parentheses.

* feat(valkey): valkey workstation caching, rate limiting, and v0.2.12 release preparation

- Implement pure-Python RESP2/RESP3 encoder and stream parser without C dependencies
- Add TCP socket client (ValkeyClient) with connection pooling, timeouts, and zero-trust SSRF validation
- Implement atomic token bucket rate limiter with embedded Lua script
- Implement distributed AI cache provider (ValkeyCacheProvider) for embeddings and review findings
- Implement devops valkey CLI command group (ping, info, stats, keys, get, set, flush, backup, cli)
- Register 6 FastMCP Valkey tools and dynamic system resource resource://valkey/status
- Bump package version to 0.2.12 and synchronize release documentation
- Pass all 10 devops ci quality gates with 95% test coverage

* docs(agents): codify strict release PR title convention feat(release): v<version>

* fix(review): remediate pull request review findings across valkey, output, and github subsystems
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority/p1-high Priority P1: high-impact work for the next planned milestone scope/k8s Kubernetes commands, Helm charts, pods, services, and policies type/security Type security: a vulnerability or a leak

Projects

No open projects

Development

Successfully merging this pull request may close these issues.

2 participants