Skip to content

Commit f543474

Browse files
authored
Added support on privileged containers #9
1 parent cce2bae commit f543474

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

KubiScan.py

+25-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from argparse import ArgumentParser
22
import engine.utils
3+
import engine.privleged_containers
34
from prettytable import PrettyTable
45
from engine.priority import Priority
56
from misc.colours import *
@@ -305,6 +306,26 @@ def print_pods_with_access_secret_via_environment(namespace=None):
305306

306307
print_table_aligned_left(t)
307308

309+
def parse_security_context(security_context):
310+
context = ''
311+
if security_context:
312+
dict = security_context.to_dict()
313+
for key in dict.keys():
314+
if dict[key] is not None:
315+
context += '{0}: {1}\n'.format(key, dict[key])
316+
return context
317+
318+
def print_privileged_containers(namespace=None):
319+
print("+---------------------+")
320+
print("|Privileged Containers|")
321+
t = PrettyTable(['Pod', 'Namespace', 'Pod Security Context', 'Container', 'Container Security Context'])
322+
pods = engine.privleged_containers.get_privileged_containers(namespace)
323+
for pod in pods:
324+
for container in pod.spec.containers:
325+
t.add_row([pod.metadata.name, pod.metadata.namespace, parse_security_context(pod.spec.security_context), container.name, parse_security_context(container.security_context)])
326+
327+
print_table_aligned_left(t)
328+
308329
def print_join_token():
309330
import os
310331
from api.api_client import running_in_docker_container
@@ -356,7 +377,7 @@ def print_logo():
356377
-osssssssssssssssssssssssssssss-
357378
`/ssssssssssssssssssssssssss/`
358379
359-
KubiScan version 1.1
380+
KubiScan version 1.2
360381
Author: Eviatar Gerzi
361382
'''
362383
print(logo)
@@ -398,7 +419,7 @@ def main():
398419
'Use the -d\--deep switch to read the tokens from the current running containers', required=False)
399420
opt.add_argument('-d', '--deep', action='store_true', help='Works only with -rp\--risky-pods switch. If this is specified, it will execute each pod to get its token.\n'
400421
'Without it, it will read the pod mounted service account secret from the ETCD, it less reliable but much faster.', required=False)
401-
422+
opt.add_argument('-pp', '--privleged-pods', action='store_true', help='Get all privileged Pods\Containers.', required=False)
402423
opt.add_argument('-a', '--all', action='store_true',help='Get all risky Roles\ClusterRoles, RoleBindings\ClusterRoleBindings, users and pods\containers', required=False)
403424

404425
opt.add_argument('-jt', '--join-token', action='store_true', help='Get join token for the cluster. OpenSsl must be installed + kubeadm', required=False)
@@ -498,6 +519,8 @@ def main():
498519
print_all_risky_containers(priority=args.priority, namespace=args.namespace, read_token_from_container=args.deep)
499520
if args.all:
500521
print_all(days=args.less_than, priority=args.priority, read_token_from_container=args.deep)
522+
elif args.privleged_pods:
523+
print_privileged_containers(namespace=args.namespace)
501524
elif args.join_token:
502525
print_join_token()
503526
elif args.pods_secrets_volume:

0 commit comments

Comments
 (0)