Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 10, 2025

Kubeconfig Parsing & Context Storage Implementation Plan

  • Create kubeconfig model for storing cluster, user, and context data
  • Implement encryption utilities for sensitive data (tokens, certificates, keys)
  • Create kubeconfig parser for YAML parsing with validation
  • Implement repository layer for CRUD operations on kubeconfig contexts
  • Create service layer for business logic
  • Implement API handlers for kubeconfig management endpoints
  • Add API routes for kubeconfig operations
  • Write comprehensive unit tests for parser, encryption, and repository
  • Register routes and dependencies in main.go
  • Test all endpoints manually with curl/httpie
  • Run linter to ensure code quality

This implementation enables users to:

  • Import kubeconfig files with multiple contexts ✅
  • Parse and validate kubeconfig YAML ✅
  • Store contexts securely with encrypted sensitive data ✅
  • List, select active, and delete contexts ✅
  • Persist data across app restarts securely ✅

Implementation Summary

Models (internal/models/kubeconfig.go)

  • KubeContext: Database model with encrypted sensitive fields
  • KubeContextResponse: API response with masked sensitive data
  • Request models for import and set-active operations

Encryption (internal/utils/encryption/)

  • AES-GCM encryption for sensitive data
  • Uses JWT secret from config for key derivation
  • Comprehensive tests for encryption/decryption

Parser (internal/utils/kubeconfig/)

  • Full kubeconfig YAML parsing with validation
  • Supports clusters, users, contexts
  • Detailed validation errors for bad configs
  • 17 test cases covering valid and invalid scenarios

Repository (internal/repos/kubeconfig/)

  • CRUD operations with automatic encryption/decryption
  • Support for setting active context
  • User isolation (contexts owned by users)
  • 11 test cases for all operations

Service & API (internal/services/kubeconfig/, internal/apis/kubeconfig.go)

  • Import, list, get, set-active, delete operations
  • Proper HTTP status codes and error handling
  • Integrated with authentication middleware

Routes

  • POST /api/v1/kubeconfig/import - Import kubeconfig YAML
  • GET /api/v1/kubeconfig - List all contexts
  • GET /api/v1/kubeconfig/active - Get active context
  • GET /api/v1/kubeconfig/:id - Get specific context
  • PUT /api/v1/kubeconfig/active - Set active context
  • DELETE /api/v1/kubeconfig/:id - Delete context
Original prompt

Kubeconfig Parsing & Context Storage

Project Context

Enables user to import and persist Kubernetes contexts and credentials—fundamental for subsequent resource access.

Details

  • Implement kubeconfig YAML parsing supporting clusters, users, contexts (basic fields: server, certificate-authority-data, token, client cert/key if present—store but not yet used beyond token).
  • Validate minimal required fields; show descriptive error messages.
  • Data model & persistence (encrypted) for multiple contexts.
  • CRUD: add (import), list, select active, delete context.
  • Mask sensitive token fields in detail UI.
  • Handle base64 CA data association.
  • Unit tests for parsing variations & invalid inputs.

System Context

Uses secure storage interface (implementation pending separate task if not here).

Dependencies & Integration

Depends on bootstrap scaffolding.

Acceptance Criteria

  • User can paste valid kubeconfig containing multiple contexts; they are parsed and listed.
  • Selecting a context sets it active.
  • Invalid kubeconfig shows structured validation error.
  • Data persists across app restarts securely.

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: dkhalife <1736645+dkhalife@users.noreply.github.com>
@dkhalife dkhalife closed this Oct 10, 2025
Copilot AI requested a review from dkhalife October 10, 2025 04:41
dkhalife added a commit that referenced this pull request Oct 11, 2025
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.

2 participants