codeslick-cli 1.4.0 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/packages/cli/src/commands/scan.d.ts.map +1 -1
- package/dist/packages/cli/src/commands/scan.js +7 -3
- package/dist/packages/cli/src/commands/scan.js.map +1 -1
- package/dist/packages/cli/src/reporters/cli-reporter.d.ts +11 -0
- package/dist/packages/cli/src/reporters/cli-reporter.d.ts.map +1 -1
- package/dist/packages/cli/src/reporters/cli-reporter.js +150 -45
- package/dist/packages/cli/src/reporters/cli-reporter.js.map +1 -1
- package/dist/packages/cli/src/scanner/local-scanner.d.ts +2 -2
- package/dist/packages/cli/src/scanner/local-scanner.d.ts.map +1 -1
- package/dist/packages/cli/src/scanner/local-scanner.js +40 -9
- package/dist/packages/cli/src/scanner/local-scanner.js.map +1 -1
- package/dist/src/lib/analyzers/go-analyzer.d.ts +12 -0
- package/dist/src/lib/analyzers/go-analyzer.d.ts.map +1 -1
- package/dist/src/lib/analyzers/go-analyzer.js +113 -0
- package/dist/src/lib/analyzers/go-analyzer.js.map +1 -1
- package/dist/src/lib/analyzers/iac/pii-detector.d.ts +27 -0
- package/dist/src/lib/analyzers/iac/pii-detector.d.ts.map +1 -0
- package/dist/src/lib/analyzers/iac/pii-detector.js +199 -0
- package/dist/src/lib/analyzers/iac/pii-detector.js.map +1 -0
- package/dist/src/lib/analyzers/iac/pii-patterns.d.ts +43 -0
- package/dist/src/lib/analyzers/iac/pii-patterns.d.ts.map +1 -0
- package/dist/src/lib/analyzers/iac/pii-patterns.js +228 -0
- package/dist/src/lib/analyzers/iac/pii-patterns.js.map +1 -0
- package/dist/src/lib/analyzers/java-analyzer.d.ts +5 -0
- package/dist/src/lib/analyzers/java-analyzer.d.ts.map +1 -1
- package/dist/src/lib/analyzers/java-analyzer.js +51 -0
- package/dist/src/lib/analyzers/java-analyzer.js.map +1 -1
- package/dist/src/lib/analyzers/javascript/quality-checks/ai-hallucinations.d.ts +8 -4
- package/dist/src/lib/analyzers/javascript/quality-checks/ai-hallucinations.d.ts.map +1 -1
- package/dist/src/lib/analyzers/javascript/quality-checks/ai-hallucinations.js +109 -13
- package/dist/src/lib/analyzers/javascript/quality-checks/ai-hallucinations.js.map +1 -1
- package/dist/src/lib/analyzers/javascript/quality-checks/reference-errors.d.ts.map +1 -1
- package/dist/src/lib/analyzers/javascript/quality-checks/reference-errors.js +7 -8
- package/dist/src/lib/analyzers/javascript/quality-checks/reference-errors.js.map +1 -1
- package/dist/src/lib/analyzers/javascript-analyzer.d.ts.map +1 -1
- package/dist/src/lib/analyzers/javascript-analyzer.js +16 -12
- package/dist/src/lib/analyzers/javascript-analyzer.js.map +1 -1
- package/dist/src/lib/analyzers/kubernetes/checks/network-security.d.ts +33 -0
- package/dist/src/lib/analyzers/kubernetes/checks/network-security.d.ts.map +1 -0
- package/dist/src/lib/analyzers/kubernetes/checks/network-security.js +184 -0
- package/dist/src/lib/analyzers/kubernetes/checks/network-security.js.map +1 -0
- package/dist/src/lib/analyzers/kubernetes/checks/pod-security.d.ts +60 -0
- package/dist/src/lib/analyzers/kubernetes/checks/pod-security.d.ts.map +1 -0
- package/dist/src/lib/analyzers/kubernetes/checks/pod-security.js +418 -0
- package/dist/src/lib/analyzers/kubernetes/checks/pod-security.js.map +1 -0
- package/dist/src/lib/analyzers/kubernetes/checks/rbac-security.d.ts +44 -0
- package/dist/src/lib/analyzers/kubernetes/checks/rbac-security.d.ts.map +1 -0
- package/dist/src/lib/analyzers/kubernetes/checks/rbac-security.js +275 -0
- package/dist/src/lib/analyzers/kubernetes/checks/rbac-security.js.map +1 -0
- package/dist/src/lib/analyzers/kubernetes/checks/resource-management.d.ts +32 -0
- package/dist/src/lib/analyzers/kubernetes/checks/resource-management.d.ts.map +1 -0
- package/dist/src/lib/analyzers/kubernetes/checks/resource-management.js +176 -0
- package/dist/src/lib/analyzers/kubernetes/checks/resource-management.js.map +1 -0
- package/dist/src/lib/analyzers/kubernetes/checks/secrets-management.d.ts +38 -0
- package/dist/src/lib/analyzers/kubernetes/checks/secrets-management.d.ts.map +1 -0
- package/dist/src/lib/analyzers/kubernetes/checks/secrets-management.js +266 -0
- package/dist/src/lib/analyzers/kubernetes/checks/secrets-management.js.map +1 -0
- package/dist/src/lib/analyzers/kubernetes/checks/service-security.d.ts +26 -0
- package/dist/src/lib/analyzers/kubernetes/checks/service-security.d.ts.map +1 -0
- package/dist/src/lib/analyzers/kubernetes/checks/service-security.js +120 -0
- package/dist/src/lib/analyzers/kubernetes/checks/service-security.js.map +1 -0
- package/dist/src/lib/analyzers/kubernetes/parser.d.ts +74 -0
- package/dist/src/lib/analyzers/kubernetes/parser.d.ts.map +1 -0
- package/dist/src/lib/analyzers/kubernetes/parser.js +233 -0
- package/dist/src/lib/analyzers/kubernetes/parser.js.map +1 -0
- package/dist/src/lib/analyzers/kubernetes/pii-detector.d.ts +34 -0
- package/dist/src/lib/analyzers/kubernetes/pii-detector.d.ts.map +1 -0
- package/dist/src/lib/analyzers/kubernetes/pii-detector.js +182 -0
- package/dist/src/lib/analyzers/kubernetes/pii-detector.js.map +1 -0
- package/dist/src/lib/analyzers/kubernetes/types.d.ts +266 -0
- package/dist/src/lib/analyzers/kubernetes/types.d.ts.map +1 -0
- package/dist/src/lib/analyzers/kubernetes/types.js +77 -0
- package/dist/src/lib/analyzers/kubernetes/types.js.map +1 -0
- package/dist/src/lib/analyzers/kubernetes-analyzer.d.ts +93 -0
- package/dist/src/lib/analyzers/kubernetes-analyzer.d.ts.map +1 -0
- package/dist/src/lib/analyzers/kubernetes-analyzer.js +215 -0
- package/dist/src/lib/analyzers/kubernetes-analyzer.js.map +1 -0
- package/dist/src/lib/analyzers/python-analyzer.d.ts.map +1 -1
- package/dist/src/lib/analyzers/python-analyzer.js +32 -48
- package/dist/src/lib/analyzers/python-analyzer.js.map +1 -1
- package/dist/src/lib/analyzers/secrets/patterns/api-keys/ai-providers.d.ts +1 -1
- package/dist/src/lib/analyzers/secrets/patterns/api-keys/ai-providers.d.ts.map +1 -1
- package/dist/src/lib/analyzers/secrets/patterns/api-keys/aws.d.ts +1 -1
- package/dist/src/lib/analyzers/secrets/patterns/api-keys/aws.d.ts.map +1 -1
- package/dist/src/lib/analyzers/secrets/patterns/api-keys/cloud-providers.d.ts +1 -1
- package/dist/src/lib/analyzers/secrets/patterns/api-keys/cloud-providers.d.ts.map +1 -1
- package/dist/src/lib/analyzers/secrets/patterns/api-keys/communication.d.ts +1 -1
- package/dist/src/lib/analyzers/secrets/patterns/api-keys/communication.d.ts.map +1 -1
- package/dist/src/lib/analyzers/secrets/patterns/api-keys/generic.d.ts +1 -1
- package/dist/src/lib/analyzers/secrets/patterns/api-keys/generic.d.ts.map +1 -1
- package/dist/src/lib/analyzers/secrets/patterns/api-keys/github.d.ts +1 -1
- package/dist/src/lib/analyzers/secrets/patterns/api-keys/github.d.ts.map +1 -1
- package/dist/src/lib/analyzers/secrets/patterns/api-keys/stripe.d.ts +1 -1
- package/dist/src/lib/analyzers/secrets/patterns/api-keys/stripe.d.ts.map +1 -1
- package/dist/src/lib/analyzers/secrets/patterns/api-keys.d.ts +1 -1
- package/dist/src/lib/analyzers/secrets/patterns/api-keys.d.ts.map +1 -1
- package/dist/src/lib/analyzers/secrets/patterns/credentials.d.ts +1 -1
- package/dist/src/lib/analyzers/secrets/patterns/credentials.d.ts.map +1 -1
- package/dist/src/lib/analyzers/secrets/patterns/private-keys.d.ts +1 -1
- package/dist/src/lib/analyzers/secrets/patterns/private-keys.d.ts.map +1 -1
- package/dist/src/lib/analyzers/secrets/patterns/tokens.d.ts +1 -1
- package/dist/src/lib/analyzers/secrets/patterns/tokens.d.ts.map +1 -1
- package/dist/src/lib/analyzers/secrets/secrets-analyzer.d.ts +2 -32
- package/dist/src/lib/analyzers/secrets/secrets-analyzer.d.ts.map +1 -1
- package/dist/src/lib/analyzers/secrets/secrets-analyzer.js.map +1 -1
- package/dist/src/lib/analyzers/secrets/types.d.ts +40 -0
- package/dist/src/lib/analyzers/secrets/types.d.ts.map +1 -0
- package/dist/src/lib/analyzers/secrets/types.js +10 -0
- package/dist/src/lib/analyzers/secrets/types.js.map +1 -0
- package/dist/src/lib/analyzers/terraform-analyzer.d.ts +1 -0
- package/dist/src/lib/analyzers/terraform-analyzer.d.ts.map +1 -1
- package/dist/src/lib/analyzers/terraform-analyzer.js +28 -0
- package/dist/src/lib/analyzers/terraform-analyzer.js.map +1 -1
- package/dist/src/lib/analyzers/typescript-analyzer.d.ts +5 -0
- package/dist/src/lib/analyzers/typescript-analyzer.d.ts.map +1 -1
- package/dist/src/lib/analyzers/typescript-analyzer.js +76 -0
- package/dist/src/lib/analyzers/typescript-analyzer.js.map +1 -1
- package/dist/src/lib/analyzers/utils/false-positive-filter.d.ts +27 -0
- package/dist/src/lib/analyzers/utils/false-positive-filter.d.ts.map +1 -0
- package/dist/src/lib/analyzers/utils/false-positive-filter.js +176 -0
- package/dist/src/lib/analyzers/utils/false-positive-filter.js.map +1 -0
- package/dist/src/lib/security/epss-service.d.ts.map +1 -1
- package/dist/src/lib/security/epss-service.js +27 -8
- package/dist/src/lib/security/epss-service.js.map +1 -1
- package/dist/src/lib/security/severity-scoring.d.ts.map +1 -1
- package/dist/src/lib/security/severity-scoring.js +24 -0
- package/dist/src/lib/security/severity-scoring.js.map +1 -1
- package/dist/src/lib/types/index.d.ts +3 -3
- package/dist/src/lib/types/index.d.ts.map +1 -1
- package/dist/src/lib/utils/ignore-patterns.d.ts +60 -0
- package/dist/src/lib/utils/ignore-patterns.d.ts.map +1 -0
- package/dist/src/lib/utils/ignore-patterns.js +212 -0
- package/dist/src/lib/utils/ignore-patterns.js.map +1 -0
- package/package.json +1 -1
- package/src/commands/scan.ts +7 -3
- package/src/reporters/cli-reporter.ts +174 -48
- package/src/scanner/local-scanner.ts +54 -10
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Kubernetes Network Security Checks
|
|
4
|
+
*
|
|
5
|
+
* WR3 Week 6: 3 High/Medium Severity Network Security Checks
|
|
6
|
+
* - Missing network policies
|
|
7
|
+
* - Unrestricted ingress
|
|
8
|
+
* - Public LoadBalancer services
|
|
9
|
+
*
|
|
10
|
+
* Created: February 5, 2026
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.checkMissingNetworkPolicies = checkMissingNetworkPolicies;
|
|
14
|
+
exports.checkUnrestrictedIngress = checkUnrestrictedIngress;
|
|
15
|
+
exports.checkPublicLoadBalancer = checkPublicLoadBalancer;
|
|
16
|
+
exports.runNetworkSecurityChecks = runNetworkSecurityChecks;
|
|
17
|
+
const parser_1 = require("../parser");
|
|
18
|
+
/**
|
|
19
|
+
* Check #18: Missing Network Policies (Medium - CVSS 6.5)
|
|
20
|
+
* Detects namespaces without NetworkPolicy resources (context-sensitive)
|
|
21
|
+
* Note: This check flags pods that may not have network policies applied
|
|
22
|
+
*/
|
|
23
|
+
function checkMissingNetworkPolicies(resource) {
|
|
24
|
+
// This is a simplified check - in production, you'd cross-reference with actual NetworkPolicies
|
|
25
|
+
// For now, we'll just warn about services that might need network policies
|
|
26
|
+
if (resource.kind === 'Service') {
|
|
27
|
+
const spec = resource.spec;
|
|
28
|
+
const type = spec?.type || 'ClusterIP';
|
|
29
|
+
// Public-facing services should have network policies
|
|
30
|
+
if (['LoadBalancer', 'NodePort'].includes(type)) {
|
|
31
|
+
return {
|
|
32
|
+
severity: 'medium',
|
|
33
|
+
message: `Public service ${(0, parser_1.getResourceIdentifier)(resource)} may lack NetworkPolicy protection`,
|
|
34
|
+
suggestion: 'Create NetworkPolicy resources to restrict pod-to-pod and ingress/egress traffic. Implement zero-trust networking.',
|
|
35
|
+
category: 'kubernetes-missing-network-policy',
|
|
36
|
+
cvssScore: 6.5,
|
|
37
|
+
exploitLikelihood: 'medium',
|
|
38
|
+
impact: 'network-exposure',
|
|
39
|
+
owasp: 'A05:2021',
|
|
40
|
+
cwe: 'CWE-284',
|
|
41
|
+
attackVector: {
|
|
42
|
+
description: 'Without NetworkPolicies, all pods can communicate freely, enabling lateral movement after initial compromise.',
|
|
43
|
+
exploitExample: 'Attacker compromises web pod → No network segmentation → Accesses database pod directly → Exfiltrates data',
|
|
44
|
+
realWorldImpact: [
|
|
45
|
+
'Unrestricted pod-to-pod communication',
|
|
46
|
+
'Lateral movement opportunities',
|
|
47
|
+
'No network segmentation',
|
|
48
|
+
'Flat network topology enables attacks',
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
remediation: {
|
|
52
|
+
before: `# No NetworkPolicy defined\napiVersion: v1\nkind: Service\nmetadata:\n name: public-api`,
|
|
53
|
+
after: `apiVersion: networking.k8s.io/v1\nkind: NetworkPolicy\nmetadata:\n name: api-netpol\nspec:\n podSelector:\n matchLabels:\n app: api\n policyTypes:\n - Ingress\n - Egress\n ingress:\n - from:\n - podSelector:\n matchLabels:\n role: frontend\n egress:\n - to:\n - podSelector:\n matchLabels:\n role: database`,
|
|
54
|
+
explanation: 'Define NetworkPolicy to explicitly allow only required traffic between pods. Default deny all, then whitelist specific connections.',
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Check #19: Unrestricted Ingress (High - CVSS 7.5)
|
|
63
|
+
* Detects Ingress resources without authentication or IP whitelisting
|
|
64
|
+
*/
|
|
65
|
+
function checkUnrestrictedIngress(resource) {
|
|
66
|
+
if (resource.kind !== 'Ingress') {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
const annotations = resource.metadata.annotations || {};
|
|
70
|
+
const spec = resource.spec;
|
|
71
|
+
// Check for authentication annotations (common ingress controller patterns)
|
|
72
|
+
const hasAuth = annotations['nginx.ingress.kubernetes.io/auth-type'] ||
|
|
73
|
+
annotations['nginx.ingress.kubernetes.io/whitelist-source-range'] ||
|
|
74
|
+
annotations['alb.ingress.kubernetes.io/auth-type'] ||
|
|
75
|
+
annotations['traefik.ingress.kubernetes.io/auth-type'] ||
|
|
76
|
+
annotations['cert-manager.io/cluster-issuer']; // TLS cert alone doesn't provide auth
|
|
77
|
+
// Check for IP whitelisting
|
|
78
|
+
const hasIPWhitelist = annotations['nginx.ingress.kubernetes.io/whitelist-source-range'] ||
|
|
79
|
+
annotations['alb.ingress.kubernetes.io/inbound-cidrs'];
|
|
80
|
+
// Check for TLS
|
|
81
|
+
const hasTLS = spec?.tls && Array.isArray(spec.tls) && spec.tls.length > 0;
|
|
82
|
+
const issues = [];
|
|
83
|
+
if (!hasAuth && !hasIPWhitelist) {
|
|
84
|
+
issues.push('no authentication');
|
|
85
|
+
}
|
|
86
|
+
if (!hasTLS) {
|
|
87
|
+
issues.push('no TLS');
|
|
88
|
+
}
|
|
89
|
+
if (issues.length > 0) {
|
|
90
|
+
return {
|
|
91
|
+
severity: 'high',
|
|
92
|
+
message: `Unrestricted ingress detected in ${(0, parser_1.getResourceIdentifier)(resource)}: ${issues.join(', ')}`,
|
|
93
|
+
suggestion: 'Add authentication (OAuth, basic auth), IP whitelisting, and TLS to ingress resources.',
|
|
94
|
+
category: 'kubernetes-unrestricted-ingress',
|
|
95
|
+
cvssScore: 7.5,
|
|
96
|
+
exploitLikelihood: 'high',
|
|
97
|
+
impact: 'unauthorized-access',
|
|
98
|
+
owasp: 'A07:2021',
|
|
99
|
+
cwe: 'CWE-306',
|
|
100
|
+
attackVector: {
|
|
101
|
+
description: 'Unrestricted ingress exposes internal services to the internet without authentication or encryption.',
|
|
102
|
+
exploitExample: 'Public ingress with no auth → Attacker discovers endpoint → Direct access to internal service → Data breach',
|
|
103
|
+
realWorldImpact: [
|
|
104
|
+
'Unauthenticated public access',
|
|
105
|
+
'Exposure of internal services',
|
|
106
|
+
'No transport encryption (if no TLS)',
|
|
107
|
+
'Man-in-the-middle attacks',
|
|
108
|
+
],
|
|
109
|
+
},
|
|
110
|
+
remediation: {
|
|
111
|
+
before: `apiVersion: networking.k8s.io/v1\nkind: Ingress\nmetadata:\n name: public-api\nspec:\n rules:\n - host: api.example.com`,
|
|
112
|
+
after: `apiVersion: networking.k8s.io/v1\nkind: Ingress\nmetadata:\n name: public-api\n annotations:\n nginx.ingress.kubernetes.io/auth-type: basic\n nginx.ingress.kubernetes.io/auth-secret: basic-auth\n cert-manager.io/cluster-issuer: letsencrypt-prod\nspec:\n tls:\n - hosts:\n - api.example.com\n secretName: api-tls\n rules:\n - host: api.example.com`,
|
|
113
|
+
explanation: 'Add authentication (OAuth2, basic auth), TLS certificates, and optionally IP whitelisting for sensitive endpoints.',
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Check #20: Public LoadBalancer Services (Medium - CVSS 6.0)
|
|
121
|
+
* Detects LoadBalancer services without source IP restrictions
|
|
122
|
+
*/
|
|
123
|
+
function checkPublicLoadBalancer(resource) {
|
|
124
|
+
if (resource.kind !== 'Service') {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
const spec = resource.spec;
|
|
128
|
+
const type = spec?.type;
|
|
129
|
+
if (type !== 'LoadBalancer') {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
// Check for loadBalancerSourceRanges (IP whitelisting)
|
|
133
|
+
const sourceRanges = spec?.loadBalancerSourceRanges || [];
|
|
134
|
+
const hasIPRestrictions = sourceRanges.length > 0;
|
|
135
|
+
// Check for internal load balancer annotations (cloud-specific)
|
|
136
|
+
const annotations = resource.metadata.annotations || {};
|
|
137
|
+
const isInternal = annotations['service.beta.kubernetes.io/aws-load-balancer-internal'] === 'true' ||
|
|
138
|
+
annotations['cloud.google.com/load-balancer-type'] === 'Internal' ||
|
|
139
|
+
annotations['service.beta.kubernetes.io/azure-load-balancer-internal'] === 'true';
|
|
140
|
+
if (!hasIPRestrictions && !isInternal) {
|
|
141
|
+
return {
|
|
142
|
+
severity: 'medium',
|
|
143
|
+
message: `Public LoadBalancer service ${(0, parser_1.getResourceIdentifier)(resource)} without IP restrictions`,
|
|
144
|
+
suggestion: 'Add loadBalancerSourceRanges to restrict access or use internal load balancer annotations.',
|
|
145
|
+
category: 'kubernetes-public-loadbalancer',
|
|
146
|
+
cvssScore: 6.0,
|
|
147
|
+
exploitLikelihood: 'medium',
|
|
148
|
+
impact: 'network-exposure',
|
|
149
|
+
owasp: 'A05:2021',
|
|
150
|
+
cwe: 'CWE-284',
|
|
151
|
+
attackVector: {
|
|
152
|
+
description: 'Public LoadBalancers without IP restrictions expose services to the entire internet.',
|
|
153
|
+
exploitExample: 'LoadBalancer with public IP → No source IP filtering → Attacker scans and finds service → Exploits application vulnerabilities',
|
|
154
|
+
realWorldImpact: [
|
|
155
|
+
'Service exposed to entire internet',
|
|
156
|
+
'No IP-based access control',
|
|
157
|
+
'Increased attack surface',
|
|
158
|
+
'DDoS attack target',
|
|
159
|
+
],
|
|
160
|
+
},
|
|
161
|
+
remediation: {
|
|
162
|
+
before: `apiVersion: v1\nkind: Service\nmetadata:\n name: web-service\nspec:\n type: LoadBalancer\n ports:\n - port: 80`,
|
|
163
|
+
after: `apiVersion: v1\nkind: Service\nmetadata:\n name: web-service\n annotations:\n # Option 1: Make it internal (recommended for most services)\n service.beta.kubernetes.io/aws-load-balancer-internal: "true"\nspec:\n type: LoadBalancer\n # Option 2: Restrict source IPs if public access needed\n loadBalancerSourceRanges:\n - "203.0.113.0/24" # Your office IP range\n ports:\n - port: 80`,
|
|
164
|
+
explanation: 'Use internal load balancers for internal services, or add loadBalancerSourceRanges to whitelist specific IP ranges.',
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Run all network security checks on a resource
|
|
172
|
+
*/
|
|
173
|
+
function runNetworkSecurityChecks(resource) {
|
|
174
|
+
const vulnerabilities = [];
|
|
175
|
+
const checks = [checkMissingNetworkPolicies, checkUnrestrictedIngress, checkPublicLoadBalancer];
|
|
176
|
+
for (const check of checks) {
|
|
177
|
+
const vuln = check(resource);
|
|
178
|
+
if (vuln) {
|
|
179
|
+
vulnerabilities.push(vuln);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return vulnerabilities;
|
|
183
|
+
}
|
|
184
|
+
//# sourceMappingURL=network-security.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network-security.js","sourceRoot":"","sources":["../../../../../../../../src/lib/analyzers/kubernetes/checks/network-security.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;AAWH,kEAyCC;AAMD,4DA8DC;AAMD,0DAqDC;AAKD,4DAaC;AAjMD,sCAAkD;AAElD;;;;GAIG;AACH,SAAgB,2BAA2B,CACzC,QAA4B;IAE5B,gGAAgG;IAChG,2EAA2E;IAC3E,IAAI,QAAQ,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAChC,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAW,CAAC;QAClC,MAAM,IAAI,GAAG,IAAI,EAAE,IAAI,IAAI,WAAW,CAAC;QAEvC,sDAAsD;QACtD,IAAI,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YAChD,OAAO;gBACL,QAAQ,EAAE,QAAQ;gBAClB,OAAO,EAAE,kBAAkB,IAAA,8BAAqB,EAAC,QAAQ,CAAC,oCAAoC;gBAC9F,UAAU,EAAE,oHAAoH;gBAChI,QAAQ,EAAE,mCAAmC;gBAC7C,SAAS,EAAE,GAAG;gBACd,iBAAiB,EAAE,QAAQ;gBAC3B,MAAM,EAAE,kBAAkB;gBAC1B,KAAK,EAAE,UAAU;gBACjB,GAAG,EAAE,SAAS;gBACd,YAAY,EAAE;oBACZ,WAAW,EAAE,+GAA+G;oBAC5H,cAAc,EAAE,4GAA4G;oBAC5H,eA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C7B,CAAC;IACH,CAAC;IAED,OAAO,eAAe,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kubernetes Pod Security Checks
|
|
3
|
+
*
|
|
4
|
+
* WR3 Week 6: 8 Critical/High Severity Pod Security Checks
|
|
5
|
+
* - Privileged containers
|
|
6
|
+
* - Host namespace access (network, PID, IPC)
|
|
7
|
+
* - Root user containers
|
|
8
|
+
* - Writable root filesystem
|
|
9
|
+
* - Dangerous capabilities
|
|
10
|
+
* - Host path volumes
|
|
11
|
+
*
|
|
12
|
+
* Created: February 5, 2026
|
|
13
|
+
*/
|
|
14
|
+
import { SecurityVulnerability } from '../../types';
|
|
15
|
+
import type { KubernetesResource } from '../types';
|
|
16
|
+
/**
|
|
17
|
+
* Check #1: Privileged Containers (Critical - CVSS 9.0)
|
|
18
|
+
* Detects containers running with privileged: true
|
|
19
|
+
*/
|
|
20
|
+
export declare function checkPrivilegedContainers(resource: KubernetesResource): SecurityVulnerability | null;
|
|
21
|
+
/**
|
|
22
|
+
* Check #2: Host Network Access (Critical - CVSS 9.0)
|
|
23
|
+
* Detects pods using hostNetwork: true
|
|
24
|
+
*/
|
|
25
|
+
export declare function checkHostNetwork(resource: KubernetesResource): SecurityVulnerability | null;
|
|
26
|
+
/**
|
|
27
|
+
* Check #3: Host PID Namespace (Critical - CVSS 9.0)
|
|
28
|
+
* Detects pods using hostPID: true
|
|
29
|
+
*/
|
|
30
|
+
export declare function checkHostPID(resource: KubernetesResource): SecurityVulnerability | null;
|
|
31
|
+
/**
|
|
32
|
+
* Check #4: Host IPC Namespace (Critical - CVSS 9.0)
|
|
33
|
+
* Detects pods using hostIPC: true
|
|
34
|
+
*/
|
|
35
|
+
export declare function checkHostIPC(resource: KubernetesResource): SecurityVulnerability | null;
|
|
36
|
+
/**
|
|
37
|
+
* Check #5: Root User Containers (High - CVSS 8.0)
|
|
38
|
+
* Detects containers running as root (runAsNonRoot not set)
|
|
39
|
+
*/
|
|
40
|
+
export declare function checkRootUser(resource: KubernetesResource): SecurityVulnerability | null;
|
|
41
|
+
/**
|
|
42
|
+
* Check #6: Writable Root Filesystem (Medium - CVSS 6.0)
|
|
43
|
+
* Detects containers without readOnlyRootFilesystem
|
|
44
|
+
*/
|
|
45
|
+
export declare function checkWritableRootFilesystem(resource: KubernetesResource): SecurityVulnerability | null;
|
|
46
|
+
/**
|
|
47
|
+
* Check #7: Dangerous Capabilities (High - CVSS 8.5)
|
|
48
|
+
* Detects containers with dangerous Linux capabilities
|
|
49
|
+
*/
|
|
50
|
+
export declare function checkDangerousCapabilities(resource: KubernetesResource): SecurityVulnerability | null;
|
|
51
|
+
/**
|
|
52
|
+
* Check #8: Host Path Volumes (High - CVSS 7.5)
|
|
53
|
+
* Detects pods mounting host filesystem paths
|
|
54
|
+
*/
|
|
55
|
+
export declare function checkHostPathVolumes(resource: KubernetesResource): SecurityVulnerability | null;
|
|
56
|
+
/**
|
|
57
|
+
* Run all pod security checks on a resource
|
|
58
|
+
*/
|
|
59
|
+
export declare function runPodSecurityChecks(resource: KubernetesResource): SecurityVulnerability[];
|
|
60
|
+
//# sourceMappingURL=pod-security.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pod-security.d.ts","sourceRoot":"","sources":["../../../../../../../../src/lib/analyzers/kubernetes/checks/pod-security.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,KAAK,EAAE,kBAAkB,EAAuC,MAAM,UAAU,CAAC;AAIxF;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,kBAAkB,GAAG,qBAAqB,GAAG,IAAI,CA+CpG;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,kBAAkB,GAAG,qBAAqB,GAAG,IAAI,CAkC3F;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,kBAAkB,GAAG,qBAAqB,GAAG,IAAI,CAkCvF;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,kBAAkB,GAAG,qBAAqB,GAAG,IAAI,CAkCvF;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,kBAAkB,GAAG,qBAAqB,GAAG,IAAI,CA0DxF;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,kBAAkB,GAAG,qBAAqB,GAAG,IAAI,CA8CtG;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,QAAQ,EAAE,kBAAkB,GAAG,qBAAqB,GAAG,IAAI,CAqDrG;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,kBAAkB,GAAG,qBAAqB,GAAG,IAAI,CA8C/F;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,kBAAkB,GAAG,qBAAqB,EAAE,CAsB1F"}
|
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Kubernetes Pod Security Checks
|
|
4
|
+
*
|
|
5
|
+
* WR3 Week 6: 8 Critical/High Severity Pod Security Checks
|
|
6
|
+
* - Privileged containers
|
|
7
|
+
* - Host namespace access (network, PID, IPC)
|
|
8
|
+
* - Root user containers
|
|
9
|
+
* - Writable root filesystem
|
|
10
|
+
* - Dangerous capabilities
|
|
11
|
+
* - Host path volumes
|
|
12
|
+
*
|
|
13
|
+
* Created: February 5, 2026
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.checkPrivilegedContainers = checkPrivilegedContainers;
|
|
17
|
+
exports.checkHostNetwork = checkHostNetwork;
|
|
18
|
+
exports.checkHostPID = checkHostPID;
|
|
19
|
+
exports.checkHostIPC = checkHostIPC;
|
|
20
|
+
exports.checkRootUser = checkRootUser;
|
|
21
|
+
exports.checkWritableRootFilesystem = checkWritableRootFilesystem;
|
|
22
|
+
exports.checkDangerousCapabilities = checkDangerousCapabilities;
|
|
23
|
+
exports.checkHostPathVolumes = checkHostPathVolumes;
|
|
24
|
+
exports.runPodSecurityChecks = runPodSecurityChecks;
|
|
25
|
+
const parser_1 = require("../parser");
|
|
26
|
+
const types_1 = require("../types");
|
|
27
|
+
/**
|
|
28
|
+
* Check #1: Privileged Containers (Critical - CVSS 9.0)
|
|
29
|
+
* Detects containers running with privileged: true
|
|
30
|
+
*/
|
|
31
|
+
function checkPrivilegedContainers(resource) {
|
|
32
|
+
const podSpec = (0, parser_1.getPodSpec)(resource);
|
|
33
|
+
if (!podSpec)
|
|
34
|
+
return null;
|
|
35
|
+
const privilegedContainers = [];
|
|
36
|
+
const containers = [
|
|
37
|
+
...(podSpec.containers || []),
|
|
38
|
+
...(podSpec.initContainers || []),
|
|
39
|
+
];
|
|
40
|
+
for (const container of containers) {
|
|
41
|
+
if (container.securityContext?.privileged === true) {
|
|
42
|
+
privilegedContainers.push(container.name);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (privilegedContainers.length > 0) {
|
|
46
|
+
return {
|
|
47
|
+
severity: 'critical',
|
|
48
|
+
message: `Privileged container detected: ${privilegedContainers.join(', ')} in ${(0, parser_1.getResourceIdentifier)(resource)}`,
|
|
49
|
+
suggestion: 'Remove privileged: true from securityContext. Privileged containers have unrestricted access to host resources.',
|
|
50
|
+
category: 'kubernetes-privileged-container',
|
|
51
|
+
cvssScore: 9.0,
|
|
52
|
+
exploitLikelihood: 'high',
|
|
53
|
+
impact: 'privilege-escalation',
|
|
54
|
+
owasp: 'A01:2021',
|
|
55
|
+
cwe: 'CWE-250',
|
|
56
|
+
attackVector: {
|
|
57
|
+
description: 'Privileged containers can bypass all security restrictions and access host kernel features',
|
|
58
|
+
exploitExample: 'Attacker gains container access → Escalates to host root via privileged mode → Full cluster compromise',
|
|
59
|
+
realWorldImpact: [
|
|
60
|
+
'Complete host system compromise',
|
|
61
|
+
'Kernel module loading',
|
|
62
|
+
'Access to all host devices',
|
|
63
|
+
'Container breakout to host',
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
remediation: {
|
|
67
|
+
before: 'securityContext:\n privileged: true',
|
|
68
|
+
after: 'securityContext:\n privileged: false\n # Or remove this line entirely',
|
|
69
|
+
explanation: 'Run containers without privileged mode. Use specific capabilities instead if needed.',
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Check #2: Host Network Access (Critical - CVSS 9.0)
|
|
77
|
+
* Detects pods using hostNetwork: true
|
|
78
|
+
*/
|
|
79
|
+
function checkHostNetwork(resource) {
|
|
80
|
+
const podSpec = (0, parser_1.getPodSpec)(resource);
|
|
81
|
+
if (!podSpec)
|
|
82
|
+
return null;
|
|
83
|
+
if (podSpec.hostNetwork === true) {
|
|
84
|
+
return {
|
|
85
|
+
severity: 'critical',
|
|
86
|
+
message: `Host network access enabled in ${(0, parser_1.getResourceIdentifier)(resource)}`,
|
|
87
|
+
suggestion: 'Remove hostNetwork: true. Pods using host network can intercept and manipulate all network traffic.',
|
|
88
|
+
category: 'kubernetes-host-network',
|
|
89
|
+
cvssScore: 9.0,
|
|
90
|
+
exploitLikelihood: 'high',
|
|
91
|
+
impact: 'privilege-escalation',
|
|
92
|
+
owasp: 'A01:2021',
|
|
93
|
+
cwe: 'CWE-250',
|
|
94
|
+
attackVector: {
|
|
95
|
+
description: 'Pods with hostNetwork access can sniff traffic, bind to privileged ports, and bypass network policies',
|
|
96
|
+
exploitExample: 'Attacker compromises pod → Binds to port 22 → Intercepts SSH traffic → Steals credentials',
|
|
97
|
+
realWorldImpact: [
|
|
98
|
+
'Network traffic interception',
|
|
99
|
+
'Bypass network policies',
|
|
100
|
+
'Access to host services (kubelet API)',
|
|
101
|
+
'Privileged port binding (< 1024)',
|
|
102
|
+
],
|
|
103
|
+
},
|
|
104
|
+
remediation: {
|
|
105
|
+
before: 'spec:\n hostNetwork: true',
|
|
106
|
+
after: 'spec:\n # Remove hostNetwork or set to false\n hostNetwork: false',
|
|
107
|
+
explanation: 'Use standard pod networking with Services for connectivity.',
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Check #3: Host PID Namespace (Critical - CVSS 9.0)
|
|
115
|
+
* Detects pods using hostPID: true
|
|
116
|
+
*/
|
|
117
|
+
function checkHostPID(resource) {
|
|
118
|
+
const podSpec = (0, parser_1.getPodSpec)(resource);
|
|
119
|
+
if (!podSpec)
|
|
120
|
+
return null;
|
|
121
|
+
if (podSpec.hostPID === true) {
|
|
122
|
+
return {
|
|
123
|
+
severity: 'critical',
|
|
124
|
+
message: `Host PID namespace enabled in ${(0, parser_1.getResourceIdentifier)(resource)}`,
|
|
125
|
+
suggestion: 'Remove hostPID: true. Pods can see and interact with all host processes.',
|
|
126
|
+
category: 'kubernetes-host-pid',
|
|
127
|
+
cvssScore: 9.0,
|
|
128
|
+
exploitLikelihood: 'high',
|
|
129
|
+
impact: 'privilege-escalation',
|
|
130
|
+
owasp: 'A01:2021',
|
|
131
|
+
cwe: 'CWE-250',
|
|
132
|
+
attackVector: {
|
|
133
|
+
description: 'Pods with hostPID can view all host processes, kill critical services, or inject into host processes',
|
|
134
|
+
exploitExample: 'Attacker accesses pod → Views host processes (ps aux) → Kills kubelet → Node becomes unavailable',
|
|
135
|
+
realWorldImpact: [
|
|
136
|
+
'View all host processes',
|
|
137
|
+
'Kill critical system processes',
|
|
138
|
+
'Process injection attacks',
|
|
139
|
+
'Denial of service',
|
|
140
|
+
],
|
|
141
|
+
},
|
|
142
|
+
remediation: {
|
|
143
|
+
before: 'spec:\n hostPID: true',
|
|
144
|
+
after: 'spec:\n # Remove hostPID or set to false\n hostPID: false',
|
|
145
|
+
explanation: 'Use isolated PID namespaces for process separation.',
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Check #4: Host IPC Namespace (Critical - CVSS 9.0)
|
|
153
|
+
* Detects pods using hostIPC: true
|
|
154
|
+
*/
|
|
155
|
+
function checkHostIPC(resource) {
|
|
156
|
+
const podSpec = (0, parser_1.getPodSpec)(resource);
|
|
157
|
+
if (!podSpec)
|
|
158
|
+
return null;
|
|
159
|
+
if (podSpec.hostIPC === true) {
|
|
160
|
+
return {
|
|
161
|
+
severity: 'critical',
|
|
162
|
+
message: `Host IPC namespace enabled in ${(0, parser_1.getResourceIdentifier)(resource)}`,
|
|
163
|
+
suggestion: 'Remove hostIPC: true. Pods can access host inter-process communication.',
|
|
164
|
+
category: 'kubernetes-host-ipc',
|
|
165
|
+
cvssScore: 9.0,
|
|
166
|
+
exploitLikelihood: 'high',
|
|
167
|
+
impact: 'privilege-escalation',
|
|
168
|
+
owasp: 'A01:2021',
|
|
169
|
+
cwe: 'CWE-250',
|
|
170
|
+
attackVector: {
|
|
171
|
+
description: 'Pods with hostIPC can access shared memory, semaphores, and message queues on the host',
|
|
172
|
+
exploitExample: 'Attacker accesses pod → Reads shared memory → Extracts sensitive data from host processes',
|
|
173
|
+
realWorldImpact: [
|
|
174
|
+
'Access to shared memory segments',
|
|
175
|
+
'Semaphore manipulation',
|
|
176
|
+
'Message queue interception',
|
|
177
|
+
'Data exfiltration from host',
|
|
178
|
+
],
|
|
179
|
+
},
|
|
180
|
+
remediation: {
|
|
181
|
+
before: 'spec:\n hostIPC: true',
|
|
182
|
+
after: 'spec:\n # Remove hostIPC or set to false\n hostIPC: false',
|
|
183
|
+
explanation: 'Use standard IPC mechanisms within pod namespace.',
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Check #5: Root User Containers (High - CVSS 8.0)
|
|
191
|
+
* Detects containers running as root (runAsNonRoot not set)
|
|
192
|
+
*/
|
|
193
|
+
function checkRootUser(resource) {
|
|
194
|
+
const podSpec = (0, parser_1.getPodSpec)(resource);
|
|
195
|
+
if (!podSpec)
|
|
196
|
+
return null;
|
|
197
|
+
const rootContainers = [];
|
|
198
|
+
const containers = [
|
|
199
|
+
...(podSpec.containers || []),
|
|
200
|
+
...(podSpec.initContainers || []),
|
|
201
|
+
];
|
|
202
|
+
for (const container of containers) {
|
|
203
|
+
const containerSC = container.securityContext;
|
|
204
|
+
const podSC = podSpec.securityContext;
|
|
205
|
+
// Check if runAsNonRoot is explicitly set to true at either level
|
|
206
|
+
const containerEnforcesNonRoot = containerSC?.runAsNonRoot === true;
|
|
207
|
+
const podEnforcesNonRoot = podSC?.runAsNonRoot === true;
|
|
208
|
+
// If neither enforces non-root, container might run as root
|
|
209
|
+
if (!containerEnforcesNonRoot && !podEnforcesNonRoot) {
|
|
210
|
+
// Additionally check if runAsUser is set to non-zero
|
|
211
|
+
const runAsUser = containerSC?.runAsUser ?? podSC?.runAsUser;
|
|
212
|
+
if (runAsUser === undefined || runAsUser === 0) {
|
|
213
|
+
rootContainers.push(container.name);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (rootContainers.length > 0) {
|
|
218
|
+
return {
|
|
219
|
+
severity: 'high',
|
|
220
|
+
message: `Containers may run as root user: ${rootContainers.join(', ')} in ${(0, parser_1.getResourceIdentifier)(resource)}`,
|
|
221
|
+
suggestion: 'Set securityContext.runAsNonRoot: true or specify runAsUser > 0 to prevent root execution.',
|
|
222
|
+
category: 'kubernetes-root-user',
|
|
223
|
+
cvssScore: 8.0,
|
|
224
|
+
exploitLikelihood: 'high',
|
|
225
|
+
impact: 'privilege-escalation',
|
|
226
|
+
owasp: 'A01:2021',
|
|
227
|
+
cwe: 'CWE-250',
|
|
228
|
+
attackVector: {
|
|
229
|
+
description: 'Containers running as root have elevated privileges that can be exploited for container breakout',
|
|
230
|
+
exploitExample: 'Attacker exploits vulnerability in root container → Mounts host filesystem → Gains host access',
|
|
231
|
+
realWorldImpact: [
|
|
232
|
+
'Increased blast radius of vulnerabilities',
|
|
233
|
+
'Potential container escape',
|
|
234
|
+
'File system modifications',
|
|
235
|
+
'Process privilege escalation',
|
|
236
|
+
],
|
|
237
|
+
},
|
|
238
|
+
remediation: {
|
|
239
|
+
before: 'securityContext: {}',
|
|
240
|
+
after: 'securityContext:\n runAsNonRoot: true\n runAsUser: 1000\n runAsGroup: 1000',
|
|
241
|
+
explanation: 'Always run containers as non-root users for defense in depth.',
|
|
242
|
+
},
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Check #6: Writable Root Filesystem (Medium - CVSS 6.0)
|
|
249
|
+
* Detects containers without readOnlyRootFilesystem
|
|
250
|
+
*/
|
|
251
|
+
function checkWritableRootFilesystem(resource) {
|
|
252
|
+
const podSpec = (0, parser_1.getPodSpec)(resource);
|
|
253
|
+
if (!podSpec)
|
|
254
|
+
return null;
|
|
255
|
+
const writableContainers = [];
|
|
256
|
+
const containers = [
|
|
257
|
+
...(podSpec.containers || []),
|
|
258
|
+
...(podSpec.initContainers || []),
|
|
259
|
+
];
|
|
260
|
+
for (const container of containers) {
|
|
261
|
+
if (container.securityContext?.readOnlyRootFilesystem !== true) {
|
|
262
|
+
writableContainers.push(container.name);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
if (writableContainers.length > 0) {
|
|
266
|
+
return {
|
|
267
|
+
severity: 'medium',
|
|
268
|
+
message: `Writable root filesystem in containers: ${writableContainers.join(', ')} in ${(0, parser_1.getResourceIdentifier)(resource)}`,
|
|
269
|
+
suggestion: 'Set securityContext.readOnlyRootFilesystem: true and use volume mounts for writable directories.',
|
|
270
|
+
category: 'kubernetes-writable-root-fs',
|
|
271
|
+
cvssScore: 6.0,
|
|
272
|
+
exploitLikelihood: 'medium',
|
|
273
|
+
impact: 'info-disclosure',
|
|
274
|
+
owasp: 'A05:2021',
|
|
275
|
+
cwe: 'CWE-732',
|
|
276
|
+
attackVector: {
|
|
277
|
+
description: 'Writable filesystems allow attackers to modify binaries, install backdoors, or persist malware',
|
|
278
|
+
exploitExample: 'Attacker gains access → Modifies /bin/bash → Creates backdoor → Persists after restart',
|
|
279
|
+
realWorldImpact: [
|
|
280
|
+
'Malware persistence',
|
|
281
|
+
'Binary modification',
|
|
282
|
+
'Log tampering',
|
|
283
|
+
'Backdoor installation',
|
|
284
|
+
],
|
|
285
|
+
},
|
|
286
|
+
remediation: {
|
|
287
|
+
before: 'securityContext: {}',
|
|
288
|
+
after: 'securityContext:\n readOnlyRootFilesystem: true\nvolumeMounts:\n - name: tmp\n mountPath: /tmp',
|
|
289
|
+
explanation: 'Use read-only root filesystem with explicit volume mounts for directories that need writes (e.g., /tmp).',
|
|
290
|
+
},
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
return null;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Check #7: Dangerous Capabilities (High - CVSS 8.5)
|
|
297
|
+
* Detects containers with dangerous Linux capabilities
|
|
298
|
+
*/
|
|
299
|
+
function checkDangerousCapabilities(resource) {
|
|
300
|
+
const podSpec = (0, parser_1.getPodSpec)(resource);
|
|
301
|
+
if (!podSpec)
|
|
302
|
+
return null;
|
|
303
|
+
const dangerousContainers = [];
|
|
304
|
+
const containers = [
|
|
305
|
+
...(podSpec.containers || []),
|
|
306
|
+
...(podSpec.initContainers || []),
|
|
307
|
+
];
|
|
308
|
+
for (const container of containers) {
|
|
309
|
+
const addedCaps = container.securityContext?.capabilities?.add || [];
|
|
310
|
+
const dangerous = addedCaps.filter((cap) => types_1.DANGEROUS_CAPABILITIES.includes(cap));
|
|
311
|
+
if (dangerous.length > 0) {
|
|
312
|
+
dangerousContainers.push({ name: container.name, capabilities: dangerous });
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
if (dangerousContainers.length > 0) {
|
|
316
|
+
const details = dangerousContainers
|
|
317
|
+
.map(c => `${c.name} (${c.capabilities.join(', ')})`)
|
|
318
|
+
.join('; ');
|
|
319
|
+
return {
|
|
320
|
+
severity: 'high',
|
|
321
|
+
message: `Dangerous capabilities detected in ${(0, parser_1.getResourceIdentifier)(resource)}: ${details}`,
|
|
322
|
+
suggestion: 'Remove dangerous capabilities like SYS_ADMIN, NET_ADMIN, SYS_MODULE. Use minimal capabilities required.',
|
|
323
|
+
category: 'kubernetes-dangerous-capabilities',
|
|
324
|
+
cvssScore: 8.5,
|
|
325
|
+
exploitLikelihood: 'high',
|
|
326
|
+
impact: 'privilege-escalation',
|
|
327
|
+
owasp: 'A01:2021',
|
|
328
|
+
cwe: 'CWE-250',
|
|
329
|
+
attackVector: {
|
|
330
|
+
description: 'Dangerous capabilities grant kernel-level privileges that can be exploited for container breakout',
|
|
331
|
+
exploitExample: 'Container with SYS_ADMIN → Mounts host filesystem → Full host compromise',
|
|
332
|
+
realWorldImpact: [
|
|
333
|
+
'Kernel module loading (SYS_MODULE)',
|
|
334
|
+
'Network packet manipulation (NET_ADMIN)',
|
|
335
|
+
'Device access (SYS_RAWIO)',
|
|
336
|
+
'System administration (SYS_ADMIN)',
|
|
337
|
+
],
|
|
338
|
+
},
|
|
339
|
+
remediation: {
|
|
340
|
+
before: 'capabilities:\n add:\n - SYS_ADMIN\n - NET_ADMIN',
|
|
341
|
+
after: 'capabilities:\n drop:\n - ALL\n add:\n - NET_BIND_SERVICE # Only if needed',
|
|
342
|
+
explanation: 'Drop all capabilities by default, then add only the minimum required specific capabilities.',
|
|
343
|
+
},
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
return null;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Check #8: Host Path Volumes (High - CVSS 7.5)
|
|
350
|
+
* Detects pods mounting host filesystem paths
|
|
351
|
+
*/
|
|
352
|
+
function checkHostPathVolumes(resource) {
|
|
353
|
+
const podSpec = (0, parser_1.getPodSpec)(resource);
|
|
354
|
+
if (!podSpec)
|
|
355
|
+
return null;
|
|
356
|
+
const hostPathVolumes = [];
|
|
357
|
+
if (podSpec.volumes) {
|
|
358
|
+
for (const volume of podSpec.volumes) {
|
|
359
|
+
if (volume.hostPath) {
|
|
360
|
+
hostPathVolumes.push({ name: volume.name, path: volume.hostPath.path });
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
if (hostPathVolumes.length > 0) {
|
|
365
|
+
const details = hostPathVolumes.map(v => `${v.name} (${v.path})`).join(', ');
|
|
366
|
+
return {
|
|
367
|
+
severity: 'high',
|
|
368
|
+
message: `Host path volumes detected in ${(0, parser_1.getResourceIdentifier)(resource)}: ${details}`,
|
|
369
|
+
suggestion: 'Avoid hostPath volumes. Use PersistentVolumes, ConfigMaps, or Secrets instead.',
|
|
370
|
+
category: 'kubernetes-host-path-volume',
|
|
371
|
+
cvssScore: 7.5,
|
|
372
|
+
exploitLikelihood: 'high',
|
|
373
|
+
impact: 'data-breach',
|
|
374
|
+
owasp: 'A01:2021',
|
|
375
|
+
cwe: 'CWE-552',
|
|
376
|
+
attackVector: {
|
|
377
|
+
description: 'HostPath volumes expose host filesystem to containers, enabling data theft and modification',
|
|
378
|
+
exploitExample: 'Container mounts /etc → Modifies /etc/shadow → Creates backdoor user on host',
|
|
379
|
+
realWorldImpact: [
|
|
380
|
+
'Host filesystem access',
|
|
381
|
+
'Sensitive file exposure (/etc/shadow, SSH keys)',
|
|
382
|
+
'Host file modification',
|
|
383
|
+
'Credential theft',
|
|
384
|
+
],
|
|
385
|
+
},
|
|
386
|
+
remediation: {
|
|
387
|
+
before: 'volumes:\n - name: hostfs\n hostPath:\n path: /var/lib/docker',
|
|
388
|
+
after: 'volumes:\n - name: data\n persistentVolumeClaim:\n claimName: my-pvc',
|
|
389
|
+
explanation: 'Use PersistentVolumeClaims for storage instead of mounting host paths directly.',
|
|
390
|
+
},
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
return null;
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Run all pod security checks on a resource
|
|
397
|
+
*/
|
|
398
|
+
function runPodSecurityChecks(resource) {
|
|
399
|
+
const vulnerabilities = [];
|
|
400
|
+
const checks = [
|
|
401
|
+
checkPrivilegedContainers,
|
|
402
|
+
checkHostNetwork,
|
|
403
|
+
checkHostPID,
|
|
404
|
+
checkHostIPC,
|
|
405
|
+
checkRootUser,
|
|
406
|
+
checkWritableRootFilesystem,
|
|
407
|
+
checkDangerousCapabilities,
|
|
408
|
+
checkHostPathVolumes,
|
|
409
|
+
];
|
|
410
|
+
for (const check of checks) {
|
|
411
|
+
const vuln = check(resource);
|
|
412
|
+
if (vuln) {
|
|
413
|
+
vulnerabilities.push(vuln);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
return vulnerabilities;
|
|
417
|
+
}
|
|
418
|
+
//# sourceMappingURL=pod-security.js.map
|