Details
Impact:
- Cost Monitoring Disruption: Unable to retrieve GCP cloud cost data
- Operational Impact: FinOps processes dependent on cost data are blocked
- Availability Degradation: Manual intervention required to restore correct credentials
CVSS Impact Score: Availability impact is Low (A:L)
---
Scenario 2: Malicious Credential Injection for Data Hijacking
Attack Steps:
- Attacker creates their own GCP project and service account
- Injects attacker-controlled valid GCP credentials into OpenCost
- OpenCost uses attacker's credentials to send requests to GCP Billing API
- Target organization's cost data is sent to attacker's GCP project
Technical Details:
# Inject attacker credentials
ATTACKER_KEY='{
"type": "service_account",
"project_id": "attacker-billing-project",
"private_key": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n",
"client_email": "[email protected]"
}'
curl -X POST http://opencost:9003/serviceKey -d "key=${ATTACKER_KEY}"
Impact:
- Sensitive Data Leakage: Organization's cloud resource usage patterns and cost details
- Business Intelligence Leakage: Can infer business scale, growth trends, technology stack
- Compliance Risk: Cost data may contain protected business information
Data Leakage Examples:
- Kubernetes cluster size and node configuration
- Resource consumption per namespace (can map to business units)
- Cloud service usage patterns (databases, storage, compute instance types)
- Cost trends (can infer business growth or contraction)
CVSS Impact Score: Confidentiality impact is None (C:N), but business impact is High
---
Scenario 3: Cross-Origin Attack (CORS Exploitation)
Attack Steps:
- User visits attacker-controlled malicious website
- Malicious JavaScript sends POST request to
http://localhost:9003/serviceKey - Due to CORS set to
*, browser allows cross-origin request - User's browser acts as proxy to execute credential overwrite attack
Prerequisites:
- User exposes OpenCost service via
kubectl port-forwardor other means - User's browser can access OpenCost endpoint
Technical Details:
// JavaScript on malicious website
fetch('http://localhost:9003/serviceKey', {
method: 'POST',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
body: 'key={"type":"malicious"}'
});
Impact:
- User-Unaware Attack: No active user interaction required
- Difficult to Trace: Attack originates from victim's IP address
- Limited Exploitation Conditions: Requires OpenCost exposed to user-accessible network
---
Vulnerability Limitations
What Attacker Cannot Control:
- File Write Path: Fixed by
CONFIG_PATHenvironment variable, attacker cannot modify - File Name: Fixed as
key.json, cannot write to other files - File Permissions: Write permission is
0644, attacker cannot escalate
Actual Attack Capabilities:
- File Content Control: Complete control over
key.jsoncontent - Unauthenticated Exploitation: No credentials required to trigger
- Remote Accessibility: Can be exploited over network (if service exposed)
---
Real-World Impact Assessment
| Deployment Scenario | Risk Level | Description |
|---------------------|-----------|-------------|
| Cluster-Internal Only | Medium | Requires attacker to have cluster network access |
| Exposed via Ingress | High | Any internet user can exploit |
| Exposed via NodePort | High | Attackers with node network access can exploit |
| Via port-forward | Medium-High | Local dev environments vulnerable to CORS attacks |
Recommended Risk Rating:
- Default deployment (cluster-internal): Medium
- Improperly exposed (public internet): High
---
Remediation
Immediate Actions (P0)
1. Add Authentication
func (a *Accesses) AddServiceKey(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
// Add authentication check
if !a.isAuthorized(r) {
http.Error(w, "Unauthorized", http.StatusUnauthorized)
return
}
// ... existing logic
}
2. Implement Input Validation
func validateServiceKey(key string) error {
var keyData map[string]interface{}
if err := json.Unmarshal([]byte(key), &keyData); err != nil {
return fmt.Errorf("invalid JSON format")
}
requiredFields := []string{"type", "project_id", "private_key_id", "private_key"}
for _, field := range requiredFields {
if _, ok := keyData[field]; !ok {
return fmt.Errorf("missing required field: %s", field)
}
}
if keyData["type"] != "service_account" {
return fmt.Errorf("invalid key type")
}
return nil
}
3. Restrict CORS
w.Header().Set("Access-Control-Allow-Origin", os.Getenv("ALLOWED_ORIGIN"))
Long-term Solutions (P1)
- Use Kubernetes Secrets: Store credentials in Kubernetes Secrets instead of files
- Implement RBAC: Role-based access control for sensitive operations
- Add Audit Logging: Log all file write operations
- Apply Least Privilege: Minimize ClusterRole permissions
---
Workarounds
Until a patch is available, implement these mitigations:
- Network Segmentation: Restrict access to OpenCost service using NetworkPolicies
- Disable Endpoint: Remove or disable the
/serviceKeyendpoint if not required - Monitor File Changes: Alert on modifications to
key.jsonfile - Use Read-only Filesystem: Mount config directory as read-only where possible
---
References
- Vulnerable Code:
pkg/costmodel/router.go:365-379 - Environment Configuration:
core/pkg/env/core.go - OWASP: Broken Access Control
- CWE-306: Missing Authentication for Critical Function
- CWE-20: Improper Input Validation