feat: add ! kubectl command to terminal + restrict RBAC (no secrets/configmaps)
Build & Push Portfolio Image / build-push (push) Successful in 3m29s

This commit is contained in:
Story Crater Bot
2026-09-03 23:19:56 -07:00
parent 0dd9391fdc
commit 054c94dc7f
2 changed files with 123 additions and 1 deletions
+50 -1
View File
@@ -35,7 +35,9 @@ function useTheme() {
}
const commands: Record<string, string> = {
help: `QUESTIONS TO EXPLORE:
help: `COMMANDS: help, /clear, ! kubectl
QUESTIONS TO EXPLORE:
Homelab & Infrastructure
• Did you build Kubernetes from scratch? How hard?
@@ -173,6 +175,53 @@ export function InteractiveTerminal() {
return
}
// Handle ! kubectl commands
if (trimmed.startsWith('!')) {
const kubectlCmd = trimmed.slice(1).trim()
if (!kubectlCmd.startsWith('kubectl ')) {
setHistory(prev => [...prev, { cmd: trimmed, output: 'Error: only kubectl commands supported (e.g. ! kubectl get pods)' }])
setInput('')
return
}
setIsLoading(true)
setInput('')
setHistory(prev => [...prev, { cmd: trimmed, output: '', isStreaming: true }])
const entryIndex = history.length
try {
const response = await fetch('/api/kubectl', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ command: kubectlCmd }),
})
const data = await response.json()
setHistory(prev => {
const updated = [...prev]
const entry = updated[entryIndex]
if (entry) {
entry.output = data.error || data.output || 'No output'
entry.isStreaming = false
}
return updated
})
} catch (err) {
setHistory(prev => {
const updated = [...prev]
const entry = updated[entryIndex]
if (entry) {
entry.output = `Error: ${err instanceof Error ? err.message : 'Request failed'}`
entry.isStreaming = false
}
return updated
})
} finally {
setIsLoading(false)
}
return
}
// Check for built-in commands
if (commands[lowerCmd]) {
setHistory(prev => [...prev, { cmd: trimmed, output: commands[lowerCmd] }])