Esempio n. 1
0
 def get_varlog_mounters(self):
     logging.debug("accessing /pods manually on ProveVarLogMount")
     pods = json.loads(
         self.event.session.get(self.base_path + KubeletHandlers.PODS.value,
                                verify=False).text)["items"]
     for pod in pods:
         volume = VarLogMountHunter(ExposedPodsHandler(
             pods=pods)).has_write_mount_to(pod, "/var/log")
         if volume:
             yield pod, volume
Esempio n. 2
0
 def get_varlog_mounters(self):
     logger.debug("accessing /pods manually on ProveVarLogMount")
     pods = self.event.session.get(
         self.base_path + KubeletHandlers.PODS.value,
         verify=False,
         timeout=config.network_timeout).json()["items"]
     for pod in pods:
         volume = VarLogMountHunter(ExposedPodsHandler(
             pods=pods)).has_write_mount_to(pod, "/var/log")
         if volume:
             yield pod, volume
Esempio n. 3
0
def test_AzureSpnHunter():
    e = ExposedPodsHandler(pods=[])
    pod_template = '{{"items":[ {{"apiVersion":"v1","kind":"Pod","metadata":{{"name":"etc","namespace":"default"}},"spec":{{"containers":[{{"command":["sleep","99999"],"image":"ubuntu","name":"test","volumeMounts":[{{"mountPath":"/mp","name":"v"}}]}}],"volumes":[{{"hostPath":{{"path":"{}"}},"name":"v"}}]}}}} ]}}'

    bad_paths = [
        "/", "/etc", "/etc/", "/etc/kubernetes", "/etc/kubernetes/azure.json"
    ]
    good_paths = ["/yo", "/etc/yo", "/etc/kubernetes/yo.json"]

    for p in bad_paths:
        e.pods = json.loads(pod_template.format(p))["items"]
        h = AzureSpnHunter(e)
        c = h.get_key_container()
        assert c

    for p in good_paths:
        e.pods = json.loads(pod_template.format(p))["items"]
        h = AzureSpnHunter(e)
        c = h.get_key_container()
        assert c == None

    pod_no_volume_mounts = '{"items":[ {"apiVersion":"v1","kind":"Pod","metadata":{"name":"etc","namespace":"default"},"spec":{"containers":[{"command":["sleep","99999"],"image":"ubuntu","name":"test"}],"volumes":[{"hostPath":{"path":"/whatever"},"name":"v"}]}} ]}'
    e.pods = json.loads(pod_no_volume_mounts)["items"]
    h = AzureSpnHunter(e)
    c = h.get_key_container()
    assert c == None

    pod_no_volumes = '{"items":[ {"apiVersion":"v1","kind":"Pod","metadata":{"name":"etc","namespace":"default"},"spec":{"containers":[{"command":["sleep","99999"],"image":"ubuntu","name":"test"}]}} ]}'
    e.pods = json.loads(pod_no_volumes)["items"]
    h = AzureSpnHunter(e)
    c = h.get_key_container()
    assert c == None

    pod_other_volume = '{"items":[ {"apiVersion":"v1","kind":"Pod","metadata":{"name":"etc","namespace":"default"},"spec":{"containers":[{"command":["sleep","99999"],"image":"ubuntu","name":"test","volumeMounts":[{"mountPath":"/mp","name":"v"}]}],"volumes":[{"emptyDir":{},"name":"v"}]}} ]}'
    e.pods = json.loads(pod_other_volume)["items"]
    h = AzureSpnHunter(e)
    c = h.get_key_container()
    assert c == None