Details
$() Syntax Injection:
curl -s -X POST \
-H "Content-Type: text/plain" \
-H 'x-nuclio-arguments: $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)' \
-d "test" \
http://nuclio-shell-func:8080
Both methods successfully extract the token.
Impact
Severity Assessment
This vulnerability enables complete cluster compromise through a multi-stage attack:
Stage 1: Command Injection
- Attacker injects malicious commands via HTTP header
- Commands execute with root privileges in function container
- No authentication or authorization checks on command content
Stage 2: Credential Theft
- Attacker reads ServiceAccount token from mounted secret
- Token belongs to
system:serviceaccount:nuclio:default - Token has cluster-admin level permissions
Stage 3: Privilege Escalation
- Attacker uses stolen token to authenticate to Kubernetes API
- Gains full control over all cluster resources
- Can read all secrets, create/modify/delete any resource
Affected Resources
Confidentiality Impact: High
- All secrets across all namespaces can be read
- Database credentials, API keys, certificates exposed
- Application data and configuration accessible
Integrity Impact: High
- Attacker can modify any cluster resource
- Can deploy malicious workloads
- Can alter RBAC policies and security controls
- Can inject backdoors for persistent access
Availability Impact: Medium
- Attacker can delete critical resources
- Can deploy resource-intensive workloads causing DoS
- Can disrupt cluster operations
Real-World Attack Scenarios
Scenario 1: Data Breach
- Attacker gains function invocation access (low privilege)
- Injects command to extract ServiceAccount token
- Uses token to read all secrets in production namespace
- Exfiltrates database credentials and API keys
- Accesses production databases and external services
Scenario 2: Supply Chain Compromise
- Attacker compromises CI/CD pipeline
- Deploys malicious Nuclio function
- Function automatically executes on deployment
- Establishes persistent backdoor in cluster
- Pivots to compromise other applications
Scenario 3: Ransomware Attack
- Attacker exploits vulnerability to gain cluster access
- Deploys crypto-mining or ransomware pods
- Encrypts persistent volumes
- Demands ransom for decryption keys
Severity
CVSS v3.1 Vector: CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:L
CVSS Score: 9.1 (Critical)
Justification:
- Attack Vector (Network): Exploitable remotely via HTTP
- Attack Complexity (Low): No special conditions required
- Privileges Required (Low): Only function invocation permission needed
- User Interaction (None): Fully automated exploitation
- Scope (Changed): Breaks out of function container to cluster level
- Confidentiality (High): Complete access to all secrets
- Integrity (High): Full control over cluster resources
- Availability (Low): Limited direct availability impact
Affected Versions
- Nuclio: All versions up to and including 1.15.19
- Component: Shell Runtime (
pkg/processor/runtime/shell)
The vulnerability exists in all versions that include the Shell Runtime component, as the vulnerable code pattern has been present since the feature's introduction.
Patched Versions
No patch is currently available. Users should implement workarounds until an official fix is released.
Workarounds
Immediate Mitigation (Choose One)
Option 1: Disable Shell Runtime
Add to Nuclio platform configuration:
platformConfig:
runtimes:
shell:
enabled: false
This completely disables the vulnerable component but breaks existing Shell Runtime functions.
Option 2: Restrict Function Deployment
Limit who can deploy functions using RBAC:
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: nuclio-function-deployer
namespace: nuclio
rules:
- apiGroups: ["nuclio.io"]
resources: ["nucliofunctions"]
verbs: ["create", "update", "patch"]
# Only grant to trusted users
Remove default function deployment permissions from untrusted users.
Option 3: Network Isolation
Restrict egress traffic from function pods:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: nuclio-processor-egress
namespace: nuclio
spec:
podSelector:
matchLabels:
nuclio.io/component: processor
policyTypes:
- Egress
egress:
- to:
- podSelector: {}
ports:
- protocol: TCP
port: 443 # Only allow HTTPS to cluster API
This limits the attacker's ability to exfiltrate data but doesn't prevent the initial exploitation.
Long-Term Fixes
Fix 1: Input Validation
Implement strict validation in getCommandArguments:
import "regexp"
var argumentsRegex = regexp.MustCompile(`^[a-zA-Z0-9_\-=., ]+$`)
func (s *shell) getCommandArguments(event nuclio.Event) []string {
arguments := event.GetHeaderString(headers.Arguments)
if arguments == "" {
arguments = s.configuration.Arguments
}
if !argumentsRegex.MatchString(arguments) {
s.Logger.ErrorWith("Invalid arguments: contains unsafe characters")
return []string{}
}
return strings.Split(arguments, " ")
}
Fix 2: Remove sh -c Execution
Use parameterized command execution:
func (s *shell) processEvent(context context.Context,
command []string,
event nuclio.Event,
responseChan chan nuclio.Response) {
var cmd *exec.Cmd
if len(command) > 0 {
cmd = exec.CommandContext(context, command[0], command[1:]...)
} else {
// Handle error
return
}
cmd.Stdin = strings.NewReader(string(event.GetBody()))
// ... rest of code
}
Fix 3: Limit ServiceAccount Permissions
Create restricted ServiceAccount for function pods:
apiVersion: v1
kind: ServiceAccount
metadata:
name: nuclio-function-sa
namespace: nuclio
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: nuclio-function-role
namespace: nuclio
rules:
- apiGroups: [""]
resources: ["configmaps"]
verbs: ["get", "list"]
# Do not grant secrets or cross-namespace access
Resources
- Nuclio GitHub: https://github.com/nuclio/nuclio
- CWE-78: OS Command Injection: https://cwe.mitre.org/data/definitions/78.html
- OWASP Command Injection: https://owasp.org/www-community/attacks/Command_Injection
- Kubernetes Security Best Practices: https://kubernetes.io/docs/concepts/security/
Credits
credit for:
@b0b0haha ([email protected])
@j311yl0v3u ([email protected])