示例#1
0
文件: audit.py 项目: anchore/anchore
def generate_reports(imagelist, showall=True, showdetails=True):
    ret = {}

    if showdetails:
        header = ['Image_Id', '*Type', 'Current_Tags', 'All_Tags', 'Is_Analyzed', 'Gate_Status', 'Size(bytes)', 'Counts', 'Base_Diffs']
    else:
        header = ['Image_Id', '*Type', 'Tags', 'Is_Analyzed', 'Gate_Status', 'Size(bytes)']

    for imageId in imagelist:
        isanalyzed = str(anchore_utils.is_image_analyzed(imageId))        
        ireport = anchore_utils.load_image_report(imageId)
        if ireport:
            usertype = str(ireport['meta']['usertype'])
            currtags = ','.join(ireport['anchore_current_tags'])
            alltags = ','.join(ireport['anchore_all_tags'])
        else:
            usertype = "None"
            try:
                idocker = contexts['docker_images'][imageId]
                currtags = ','.join(idocker['RepoTags'])
                alltags = currtags
            except:
                currtags = alltags = "N/A"

        if not showall and ((not usertype or usertype.lower() == 'none') and (not currtags and not alltags)):
            continue

        if ireport:
            baseId = str(ireport['familytree'][0])
            sizebytes = str(ireport['meta']['sizebytes'])
            shortId = str(ireport['meta']['shortId'])

        else:
            baseId = "N/A"
            sizebytes = "N/A"
            shortId = imageId[0:12]

        gates_eval_report = anchore_utils.load_gates_eval_report(imageId)
        record = {
            'image_report': ireport,
            'analysis_report': {},
            'gates_report': {},
            'gates_eval_report': gates_eval_report,
            'result': {
                'header':header,
                'rows': list()
            }
        }

        if showdetails: 
            record['analysis_report'] = anchore_utils.load_analysis_report(imageId)
            record['gates_report'] = anchore_utils.load_gates_report(imageId)

        
        gateaction = 'UNKNOWN'
        for g in gates_eval_report:
            if g['trigger'] == 'FINAL':
                gateaction = g['action']
                break

        if showdetails:
            try:
                pnum = str(len(anchore_utils.load_analysis_output(imageId, 'package_list', 'pkgs.all').keys()))
            except:
                pnum = "N/A"
            try:
                fnum = str(len(anchore_utils.load_analysis_output(imageId, 'file_list', 'files.all').keys()))
            except:
                fnum = "N/A"
            try:
                snum = str(len(anchore_utils.load_analysis_output(imageId, 'file_suids', 'files.suids').keys()))
            except:
                snum = "N/A"

            analysis_str = ' '.join(["PKGS="+pnum, "FILES="+fnum, "SUIDFILES="+snum])

            compare_str = "N/A"

            if imageId != baseId:
                diffdata = anchore_utils.diff_images(imageId, baseId)            
                record['base_compare_data'] = diffdata
                pnum = "N/A"
                if 'package_list' in diffdata and 'pkgs.all' in diffdata['package_list']:
                    for module_type in diffdata['package_list']['pkgs.all']:
                        pnum = str(len(diffdata['package_list']['pkgs.all'][module_type]))
                        break

                fnum = "N/A"
                if 'file_list' in diffdata and 'files.all' in diffdata['file_list']:
                    for module_type in diffdata['file_list']['files.all']:
                        fnum = str(len(diffdata['file_list']['files.all'][module_type]))

                snum = "N/A"
                if 'file_suids' in diffdata and 'files.suids' in diffdata['file_suids']:
                    for module_type in diffdata['file_suids']['files.suids']:
                        snum = str(len(diffdata['file_suids']['files.suids'][module_type]))

                compare_str = ' '.join(["PKGS="+pnum, "FILES="+fnum, "SUIDFILES="+snum])

            row = [ shortId, usertype, currtags, alltags, isanalyzed, gateaction, sizebytes, analysis_str, compare_str ]
        else:
            row = [ shortId, usertype, currtags, isanalyzed, gateaction, sizebytes]

        record['result']['rows'].append(row)

        ret[imageId] = record

    return ret
示例#2
0
    params = None

if not params:
    sys.exit(0)

outlist = list()

fullmatch = False
fullmatchpkgs = list()

submatch = False
submatchpkgs = list()

# do somthing
try:
    pkgdetail_data = anchore_utils.load_analysis_output(
        imgid, 'package_list', 'pkgs.allinfo')

    # try to load up non distro package types as well
    for ptype in ['npm', 'gem']:
        try:
            pkgdetail_data_extra = anchore_utils.load_analysis_output(
                imgid, 'package_list', 'pkgs.' + ptype + 's')
            for pkg in pkgdetail_data_extra.keys():
                pkgjson = json.loads(pkgdetail_data_extra[pkg])
                pkgkey = pkgjson['name'] + "(" + ptype + ")"
                pkgdetail_data[pkgkey] = pkgdetail_data_extra[pkg]
        except Exception as err:
            pass

    pkgdetail = {}
    pkglics = {}
示例#3
0
    def generate_reports(self):
        ret = {}
        for imageId in self.images:
            image = self.allimages[imageId]
            baseId = image.get_earliest_base()
            bimage = self.allimages[baseId]
            sizebytes = image.meta['sizebytes']

            image_report = image.get_image_report()
            analysis_report = image.get_analysis_report()
            gates_report = image.get_gates_report()
            gates_eval_report = image.get_gates_eval_report()

            record = {
                'image_report': image_report,
                'analysis_report': analysis_report,
                'gates_report': gates_report,
                'gates_eval_report': gates_eval_report,
                'result': {
                    'header': [
                        'Image_Id', 'Type', 'Current_Tags', 'All_Tags',
                        'Gate_Status', 'Size(bytes)', 'Counts', 'Base_Diffs'
                    ],
                    'rows':
                    list()
                }
            }

            shortId = image.meta['shortId']
            usertype = str(image.get_usertype())
            currtags = ','.join(image.get_alltags_current())
            alltags = ','.join(image.get_alltags_ever())

            gateaction = 'UNKNOWN'
            for g in gates_eval_report:
                if g['trigger'] == 'FINAL':
                    gateaction = g['action']
                    break

            try:
                pnum = str(
                    len(
                        anchore_utils.load_analysis_output(
                            image.meta['imageId'], 'package_list',
                            'pkgs.all').keys()))
            except:
                pnum = "N/A"
            try:
                fnum = str(
                    len(
                        anchore_utils.load_analysis_output(
                            image.meta['imageId'], 'file_list',
                            'files.all').keys()))
            except:
                fnum = "N/A"
            try:
                snum = str(
                    len(
                        anchore_utils.load_analysis_output(
                            image.meta['imageId'], 'file_suids',
                            'files.suids').keys()))
            except:
                fnum = "N/A"

            analysis_str = ' '.join(
                ["PKGS=" + pnum, "FILES=" + fnum, "SUIDFILES=" + snum])

            compare_str = "N/A"

            if image.meta['imageId'] != baseId:
                diffdata = anchore_utils.diff_images(image.meta['imageId'],
                                                     baseId)
                record['base_compare_data'] = diffdata
                pnum = "N/A"
                if 'package_list' in diffdata and 'pkgs.all' in diffdata[
                        'package_list']:
                    for module_type in diffdata['package_list']['pkgs.all']:
                        pnum = str(
                            len(diffdata['package_list']['pkgs.all']
                                [module_type]))
                        break

                fnum = "N/A"
                if 'file_list' in diffdata and 'files.all' in diffdata[
                        'file_list']:
                    for module_type in diffdata['file_list']['files.all']:
                        fnum = str(
                            len(diffdata['file_list']['files.all']
                                [module_type]))

                snum = "N/A"
                if 'file_suids' in diffdata and 'files.suids' in diffdata[
                        'file_suids']:
                    for module_type in diffdata['file_suids']['files.suids']:
                        snum = str(
                            len(diffdata['file_suids']['files.suids']
                                [module_type]))

                compare_str = ' '.join(
                    ["PKGS=" + pnum, "FILES=" + fnum, "SUIDFILES=" + snum])

            row = [
                shortId, usertype, currtags, alltags, gateaction, sizebytes,
                analysis_str, compare_str
            ]

            record['result']['rows'].append(row)

            ret[imageId] = record
        return ret
示例#4
0
def generate_reports(imagelist, showall=True, showdetails=True):
    ret = {}

    if showdetails:
        header = [
            'Image_Id', '*Type', 'Current_Tags', 'All_Tags', 'Is_Analyzed',
            'Gate_Status', 'Size(bytes)', 'Counts', 'Base_Diffs'
        ]
    else:
        header = [
            'Image_Id', '*Type', 'Tags', 'Is_Analyzed', 'Gate_Status',
            'Size(bytes)'
        ]

    for imageId in imagelist:
        isanalyzed = str(anchore_utils.is_image_analyzed(imageId))
        ireport = anchore_utils.load_image_report(imageId)
        if ireport:
            usertype = str(ireport['meta']['usertype'])
            currtags = ','.join(ireport['anchore_current_tags'])
            alltags = ','.join(ireport['anchore_all_tags'])
        else:
            usertype = "None"
            try:
                idocker = contexts['docker_images'][imageId]
                currtags = ','.join(idocker['RepoTags'])
                alltags = currtags
            except:
                currtags = alltags = "N/A"

        if not showall and ((not usertype or usertype.lower() == 'none') and
                            (not currtags and not alltags)):
            continue

        if ireport:
            baseId = str(ireport['familytree'][0])
            sizebytes = str(ireport['meta']['sizebytes'])
            shortId = str(ireport['meta']['shortId'])

        else:
            baseId = "N/A"
            sizebytes = "N/A"
            shortId = imageId[0:12]

        gates_eval_report = anchore_utils.load_gates_eval_report(imageId)
        record = {
            'image_report': ireport,
            'analysis_report': {},
            'gates_report': {},
            'gates_eval_report': gates_eval_report,
            'result': {
                'header': header,
                'rows': list()
            }
        }

        if showdetails:
            record['analysis_report'] = anchore_utils.load_analysis_report(
                imageId)
            record['gates_report'] = anchore_utils.load_gates_report(imageId)

        gateaction = 'UNKNOWN'
        for g in gates_eval_report:
            if g['trigger'] == 'FINAL':
                gateaction = g['action']
                break

        if showdetails:
            try:
                pnum = str(
                    len(
                        anchore_utils.load_analysis_output(
                            imageId, 'package_list', 'pkgs.all').keys()))
            except:
                pnum = "N/A"
            try:
                fnum = str(
                    len(
                        anchore_utils.load_analysis_output(
                            imageId, 'file_list', 'files.all').keys()))
            except:
                fnum = "N/A"
            try:
                snum = str(
                    len(
                        anchore_utils.load_analysis_output(
                            imageId, 'file_suids', 'files.suids').keys()))
            except:
                snum = "N/A"

            analysis_str = ' '.join(
                ["PKGS=" + pnum, "FILES=" + fnum, "SUIDFILES=" + snum])

            compare_str = "N/A"

            if imageId != baseId:
                diffdata = anchore_utils.diff_images(imageId, baseId)
                record['base_compare_data'] = diffdata
                pnum = "N/A"
                if 'package_list' in diffdata and 'pkgs.all' in diffdata[
                        'package_list']:
                    for module_type in diffdata['package_list']['pkgs.all']:
                        pnum = str(
                            len(diffdata['package_list']['pkgs.all']
                                [module_type]))
                        break

                fnum = "N/A"
                if 'file_list' in diffdata and 'files.all' in diffdata[
                        'file_list']:
                    for module_type in diffdata['file_list']['files.all']:
                        fnum = str(
                            len(diffdata['file_list']['files.all']
                                [module_type]))

                snum = "N/A"
                if 'file_suids' in diffdata and 'files.suids' in diffdata[
                        'file_suids']:
                    for module_type in diffdata['file_suids']['files.suids']:
                        snum = str(
                            len(diffdata['file_suids']['files.suids']
                                [module_type]))

                compare_str = ' '.join(
                    ["PKGS=" + pnum, "FILES=" + fnum, "SUIDFILES=" + snum])

            row = [
                shortId, usertype, currtags, alltags, isanalyzed, gateaction,
                sizebytes, analysis_str, compare_str
            ]
        else:
            row = [
                shortId, usertype, currtags, isanalyzed, gateaction, sizebytes
            ]

        record['result']['rows'].append(row)

        ret[imageId] = record

    return ret
示例#5
0
    params = None

if not params:
    sys.exit(0)

outlist = list()

fullmatch = False
fullmatchpkgs = list()

submatch = False
submatchpkgs = list()

# do somthing
try:
    pkgdetail_data = anchore_utils.load_analysis_output(imgid, 'package_list', 'pkgs.allinfo')

    # try to load up non distro package types as well
    for ptype in ['npm', 'gem']:
        try:
            pkgdetail_data_extra = anchore_utils.load_analysis_output(imgid, 'package_list', 'pkgs.'+ptype+'s')
            for pkg in pkgdetail_data_extra.keys():
                pkgjson = json.loads(pkgdetail_data_extra[pkg])
                pkgkey = pkgjson['name'] + "("+ptype+")"
                pkgdetail_data[pkgkey] = pkgdetail_data_extra[pkg]
        except Exception as err:
            pass

    pkgdetail = {}
    pkglics = {}
    for k in pkgdetail_data.keys():
示例#6
0
    def generate_reports(self):
        ret = {}
        for imageId in self.images:
            image = self.allimages[imageId]
            baseId = image.get_earliest_base()
            bimage = self.allimages[baseId]
            sizebytes = image.meta['sizebytes']

            image_report = image.get_image_report()
            analysis_report = image.get_analysis_report()
            gates_report = image.get_gates_report()
            gates_eval_report = image.get_gates_eval_report()

            record = {
                'image_report': image_report,
                'analysis_report': analysis_report,
                'gates_report': gates_report,
                'gates_eval_report': gates_eval_report,
                'result': {
                    'header':['Image_Id', 'Type', 'Current_Tags', 'All_Tags', 'Gate_Status', 'Size(bytes)', 'Counts', 'Base_Diffs'],
                    'rows': list()
                }
            }

            shortId = image.meta['shortId']
            usertype = str(image.get_usertype())
            currtags = ','.join(image.get_alltags_current())
            alltags = ','.join(image.get_alltags_ever())

            gateaction = 'UNKNOWN'
            for g in gates_eval_report:
                if g['trigger'] == 'FINAL':
                    gateaction = g['action']
                    break

            try:
                pnum = str(len(anchore_utils.load_analysis_output(image.meta['imageId'], 'package_list', 'pkgs.all').keys()))
            except:
                pnum = "N/A"
            try:
                fnum = str(len(anchore_utils.load_analysis_output(image.meta['imageId'], 'file_list', 'files.all').keys()))
            except:
                fnum = "N/A"
            try:
                snum = str(len(anchore_utils.load_analysis_output(image.meta['imageId'], 'file_suids', 'files.suids').keys()))
            except:
                fnum = "N/A"

            analysis_str = ' '.join(["PKGS="+pnum, "FILES="+fnum, "SUIDFILES="+snum])

            compare_str = "N/A"

            if image.meta['imageId'] != baseId:
                diffdata = anchore_utils.diff_images(image.meta['imageId'], baseId)            
                record['base_compare_data'] = diffdata
                pnum = "N/A"
                if 'package_list' in diffdata and 'pkgs.all' in diffdata['package_list']:
                    for module_type in diffdata['package_list']['pkgs.all']:
                        pnum = str(len(diffdata['package_list']['pkgs.all'][module_type]))
                        break

                fnum = "N/A"
                if 'file_list' in diffdata and 'files.all' in diffdata['file_list']:
                    for module_type in diffdata['file_list']['files.all']:
                        fnum = str(len(diffdata['file_list']['files.all'][module_type]))

                snum = "N/A"
                if 'file_suids' in diffdata and 'files.suids' in diffdata['file_suids']:
                    for module_type in diffdata['file_suids']['files.suids']:
                        snum = str(len(diffdata['file_suids']['files.suids'][module_type]))

                compare_str = ' '.join(["PKGS="+pnum, "FILES="+fnum, "SUIDFILES="+snum])

            row = [ shortId, usertype, currtags, alltags, gateaction, sizebytes, analysis_str, compare_str ]

            record['result']['rows'].append(row)

            ret[imageId] = record
        return ret