Files
Sankofa/docs/proxmox/CRITICAL_AUTHENTICATION_FIX.md
defiQUG 33d50fb91e
Some checks failed
API CI / API Lint (push) Successful in 47s
API CI / API Type Check (push) Failing after 47s
API CI / API Test (push) Successful in 1m0s
API CI / API Build (push) Failing after 50s
API CI / Build Docker Image (push) Has been skipped
Build Crossplane Provider / build (push) Failing after 5m51s
CD Pipeline / Deploy to Staging (push) Failing after 29s
CI Pipeline / Lint and Type Check (push) Failing after 36s
CI Pipeline / Build (push) Has been skipped
CI Pipeline / Test Backend (push) Failing after 1m33s
CI Pipeline / Test Frontend (push) Failing after 30s
CI Pipeline / Security Scan (push) Failing after 1m16s
Crossplane Provider CI / Go Test (push) Failing after 3m23s
Crossplane Provider CI / Go Lint (push) Failing after 7m27s
Crossplane Provider CI / Go Build (push) Failing after 3m27s
Deploy to Staging / Deploy to Staging (push) Failing after 30s
Portal CI / Portal Lint (push) Failing after 21s
Portal CI / Portal Type Check (push) Failing after 21s
Portal CI / Portal Test (push) Failing after 21s
Portal CI / Portal Build (push) Failing after 22s
Test Suite / frontend-tests (push) Failing after 30s
Test Suite / api-tests (push) Failing after 49s
Test Suite / blockchain-tests (push) Failing after 30s
Type Check / type-check (map[directory:. name:root]) (push) Failing after 23s
Type Check / type-check (map[directory:api name:api]) (push) Failing after 21s
Type Check / type-check (map[directory:portal name:portal]) (push) Failing after 19s
Validate Configuration Files / validate (push) Failing after 1m52s
CD Pipeline / Deploy to Production (push) Has been skipped
chore: consolidate local WIP (repo cleanup 20260707)
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-07 09:41:34 -07:00

183 lines
3.9 KiB
Markdown

# Critical Authentication Fix Required
**Date**: 2025-12-13
**Status**: ⚠️ **CRITICAL ISSUE IDENTIFIED - FIX APPLIED TO CODE**
---
## Problem
The provider is experiencing authentication failures when using token-based authentication:
```
ERROR: authentication failed: 401 authentication failure
```
**Root Cause**: The controller uses `proxmox.NewClient()` (username/password authentication) even when a token is provided. Proxmox API tokens require `proxmox.NewClientWithToken()` instead.
---
## Fix Applied
### Code Changes
**File**: `crossplane-provider-proxmox/pkg/controller/virtualmachine/controller.go`
#### 1. Updated `credentials` struct to include `Token` field:
```go
type credentials struct {
Username string
Password string
Token string // Added
}
```
#### 2. Updated `getCredentials()` to properly detect and store tokens:
```go
// Check if we have token-based authentication
if tokenData, ok := secret.Data["token"]; ok {
// Token-based authentication
token = string(tokenData)
if tokenidData, ok := secret.Data["tokenid"]; ok {
username = string(tokenidData)
} else {
return nil, fmt.Errorf("tokenid missing in secret (required for token authentication)")
}
} else {
// Username/password authentication
if userData, ok := secret.Data["username"]; ok {
username = string(userData)
}
if passData, ok := secret.Data["password"]; ok {
password = string(passData)
}
}
```
#### 3. Updated client creation to use token authentication when available:
```go
// Create Proxmox client - use token authentication if token is available
var proxmoxClient *proxmox.Client
if creds.Token != "" {
// Use token authentication: format is "tokenid=token"
token := fmt.Sprintf("%s=%s", creds.Username, creds.Token)
proxmoxClient, err = proxmox.NewClientWithToken(
site.Endpoint,
token,
site.InsecureSkipTLSVerify,
)
} else {
// Use username/password authentication
proxmoxClient, err = proxmox.NewClient(
site.Endpoint,
creds.Username,
creds.Password,
site.InsecureSkipTLSVerify,
)
}
```
#### 4. Updated cleanup function to use token authentication:
```go
if creds.Token != "" {
// Use token authentication
token := fmt.Sprintf("%s=%s", creds.Username, creds.Token)
client, err = proxmox.NewClientWithToken(
site.Endpoint,
token,
site.InsecureSkipTLSVerify,
)
} else {
// Use username/password authentication
client, err = proxmox.NewClient(
site.Endpoint,
creds.Username,
creds.Password,
site.InsecureSkipTLSVerify,
)
}
```
---
## Build and Deploy
### Prerequisites
- Go 1.21+ installed
- Make installed
- Docker (for building container image)
### Build Steps
```bash
cd crossplane-provider-proxmox
# Generate manifests
make manifests
# Build the provider
make build
# Build container image
docker build -t crossplane-provider-proxmox:latest .
# Load image into kind (if using kind)
kind load docker-image crossplane-provider-proxmox:latest
# Restart provider pod
kubectl delete pod -n crossplane-system -l app=crossplane-provider-proxmox
```
---
## Verification
After deploying the fix:
1. **Check provider logs**:
```bash
kubectl logs -n crossplane-system -l app=crossplane-provider-proxmox -f
```
2. **Verify authentication**:
- No more "401 authentication failure" errors
- VMs start being created successfully
3. **Check VM status**:
```bash
kubectl get proxmoxvm -A
```
---
## Impact
**Before Fix**:
- ❌ All VMs fail to authenticate
- ❌ No VMs can be created
- ❌ Provider logs show repeated authentication errors
**After Fix**:
- ✅ Token authentication works correctly
- ✅ VMs can be created on both Proxmox nodes
- ✅ No authentication errors in logs
---
## Current Status
- ✅ **Code Fix**: Applied to `controller.go`
- ⚠️ **Build Required**: Provider needs to be rebuilt and redeployed
- ⚠️ **Deployment**: Provider pod needs to be restarted after rebuild
---
**Last Updated**: 2025-12-13
**Priority**: 🔴 **CRITICAL** - Blocks all VM deployments