Skip to content

Add External Config Helper Support for Enhanced Credential Management #441

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

gregod-com
Copy link

Summary

This PR implements external config helper functionality for the Rancher CLI, enabling integration with external credential management systems, password managers, and CI/CD pipelines.

Motivation

Users and organizations often need to integrate the Rancher CLI with their existing credential management infrastructure rather than storing sensitive credentials in local files. This feature addresses that need by providing a pluggable config helper system, similar to Hashicorp Vault credential helper or AWS CLI credential helper.

What's Changed

Core Features

  • New CLI Flag: --config-helper with RANCHER_CONFIG_HELPER environment variable support
  • Helper Protocol: Simple get/store command interface with JSON config exchange
  • Backward Compatibility: Default "built-in" helper maintains existing file-based behavior
  • Documentation: Complete README section with examples and integration patterns

Implementation Details

  • Config Loading: config.LoadWithHelper() function for external helper support
  • Config Writing: Helper-aware Config.Write() method with automatic helper detection
  • CLI Integration: Modified loadConfig() in cmd/common.go to respect helper settings

Use Cases Enabled

  • Corporate credential management systems
  • Cloud provider secret stores (AWS Secrets Manager, Azure Key Vault, etc.)
  • CI/CD pipeline secret injection
  • Multi-environment configuration management
  • Password manager integration

Testing

Comprehensive Test Coverage

  • Unit Tests: All config helper functions with edge cases
  • Integration Tests: End-to-end helper protocol verification
  • Error Scenarios: Missing helpers, invalid JSON, command failures
  • Protocol Tests: Verify correct command/data exchange

Test Results

All tests pass including:

  • TestLoadWithHelper - External helper loading scenarios
  • TestConfigWrite - Config persistence with helpers
  • TestHelperProtocol - Command protocol verification
  • TestConfigHelperIntegration - End-to-end integration tests

Breaking Changes

None. This is a fully backward-compatible addition.

Usage Examples

Basic Usage

# Use external helper
rancher --config-helper /path/to/my-helper login

# Use environment variable
export RANCHER_CONFIG_HELPER=/path/to/my-helper
rancher login

# Explicit built-in (default behavior)
rancher --config-helper built-in login
# which is the same as:
rancher login

Example Helper Script

#!/bin/bash
case "$1" in
  get)
    # Load config from your external system
    gopass show -o -y rancher-config
    ;;

  store)
    # Store config to your external system
    echo $2 | gopass insert -f rancher-config
    ;;
  *)
    echo "Usage: $0 {get|store}"
    exit 1
    ;;
esac

Files Changed

  • main.go: Added --config-helper CLI flag
  • cmd/common.go: Modified loadConfig() for helper support
  • config/config.go: Added helper loading/writing functionality
  • config/config_test.go: Comprehensive test suite
  • cmd/common_test.go: Integration tests
  • README.md: Complete documentation with examples

Documentation

The README now includes a dedicated "External Config Helper Support" section with:

  • Usage instructions and examples
  • Helper creation guide with sample script
  • Integration patterns and use cases
  • Complete API reference

Type: Feature
Breaking Changes: None
Documentation: Updated README with comprehensive guide
Testing: Full test coverage with integration tests

@gregod-com gregod-com requested a review from a team as a code owner May 29, 2025 16:26
@gregod-com gregod-com mentioned this pull request May 29, 2025
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.

1 participant