Datadog \u3067\u969c\u5bb3\u691c\u77e5\u3057\u305f\u3089 Slack \u3068 Backlog \u306b\u901a\u77e5\u3057\u3088\u3046<\/a><\/li>\n<\/ul>\nLambda<\/code> \u30d5\u30a1\u30f3\u30af\u30b7\u30e7\u30f3\u306f\u4e0b\u8a18\u306e\u3088\u3046\u306b\u3057\u305f\u3002<\/p>\nfrom datetime import datetime\nfrom logging import getLogger, INFO\nimport os\nfrom botocore.exceptions import ClientError\nimport boto3\nimport requests\n\nlogger = getLogger()\nlogger.setLevel(INFO)\n\n\ndef get_findings(detail):\n """Returns the image scan findings summary"""\n ecr = boto3.client('ecr')\n try:\n response = ecr.describe_images(\n repositoryName=detail['repository-name'],\n imageIds=[\n {'imageDigest': detail['image-digest']}\n ]\n )\n except ClientError as err:\n logger.error("Request failed: %s", err.response['Error']['Message'])\n else:\n return response['imageDetails'][0]\n\n\ndef create_backlog_issue(scan_result):\n """Create Backlog Issue"""\n company = os.environ['COMPANY']\n severity = 2\n region = 'ap-northeast-1'\n title = "ECR\u30a4\u30e1\u30fc\u30b8\u30b9\u30ad\u30e3\u30f3\u306b\u3066\u8106\u5f31\u6027\u304c\u691c\u51fa\u3055\u308c\u307e\u3057\u305f"\n url = f"https:\/\/{os.environ['BACKLOG_SPACE_ID']}.backlog.com\/api\/v2\/issues"\n repo = f"{scan_result['repositoryName']}:{scan_result['imageTags'][0]}"\n\n summary = scan_result['imageScanFindingsSummary']['findingSeverityCounts']\n complete_at = datetime.strftime(\n scan_result['imageScanFindingsSummary']['imageScanCompletedAt'],\n '%Y-%m-%d %H:%M:%S %Z'\n )\n source_update_at = datetime.strftime(\n scan_result['imageScanFindingsSummary']['vulnerabilitySourceUpdatedAt'],\n '%Y-%m-%d %H:%M:%S %Z'\n )\n result_url = f'''https:\/\/console.aws.amazon.com\/ecr\/repositories\/{\n scan_result['repositoryName']}\/image\/{\n scan_result['imageDigest']}\/scan-results?region={region}'''\n\n description = """\n\u4f1a\u793e\u540d: %s\n\u30a4\u30e1\u30fc\u30b8: %s\n\u30b9\u30ad\u30e3\u30f3\u5b8c\u4e86\u65e5\u6642: %s\n\u8106\u5f31\u6027\u60c5\u5831\u66f4\u65b0\u65e5\u6642: %s\n\u30b9\u30ad\u30e3\u30f3\u7d50\u679c: %s\n\nURL: %s\n """ % (company, repo, complete_at, source_update_at, summary, result_url)\n\n payload = {\n 'projectId' : os.environ['BACKLOG_PROJECT_ID'],\n 'issueTypeId' : os.environ['BACKLOG_ISSUE_TYPE_ID'],\n 'priorityId' : severity,\n 'summary' : title,\n 'description' : description,\n 'apiKey' : os.environ['BACKLOG_API_KEY']\n }\n response = requests.post(url, params=payload)\n return response.json()\n\n\ndef lambda_handler(event, context):\n """ECR Image Scan Findings to Backlog"""\n logger.info(event)\n response = 1\n scan_result = get_findings(event['detail'])\n\n # create backlog issue if 'CRITICAL' found\n counts = scan_result['imageScanFindingsSummary']['findingSeverityCounts']\n logger.info(counts)\n if 'CRITICAL' in counts:\n logger.info("CRITICAL found. Creating Backlog Issue.")\n response = create_backlog_issue(scan_result)\n\n return response<\/code><\/pre>\n\u203b \u74b0\u5883\u5909\u6570\u306b\u4e0b\u8a18\u306e\u5909\u6570\u8a2d\u5b9a\u3092\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u306e\u3067\u6ce8\u610f\u3002<\/p>\n
COMPANY
\nBACKLOG_SPACE_ID
\nBACKLOG_PROJECT_ID
\nBACKLOG_ISSUE_TYPE_ID
\nBACKLOG_API_KEY<\/p>\n
\u203b \u307e\u305f\u3001\u3053\u306e\u30d5\u30a1\u30f3\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001 requests<\/code> \u3092\u4f7f\u7528\u3057\u3066\u3044\u308b\u306e\u3067\u3001 Lambda Layer<\/code> \u306b requests<\/code> \u3092\u542b\u3081\u3066\u3084\u308b\u5fc5\u8981\u304c\u3042\u308b\u306e\u3067\u6ce8\u610f\u3002<\/p>\n$ mkdir python\n$ pip install -t .\/python boto3 requests\n$ zip -r boto3-1.10.28.zip python<\/code><\/pre>\n\u52d5\u4f5c\u78ba\u8a8d<\/h2>\n
\u8106\u5f31\u6027\u3092\u542b\u3093\u3060\u30a4\u30e1\u30fc\u30b8\u3092\u30d7\u30c3\u30b7\u30e5\u3057\u3066\u307f\u308b\u3068\u3001 \u7121\u4e8b Backlog<\/code> \u4e0a\u306b\u8ab2\u984c\u304c\u767b\u9332\u3055\u308c\u305f\u3002<\/p>\n<\/p>\n
\u4e0a\u8a18\u306e\u51e6\u7406\u3092\u7d44\u307f\u5408\u308f\u305b\u3066\u3001\u958b\u767a\u6642\u306b ECR<\/code> \u3078\u30d7\u30c3\u30b7\u30e5\u3059\u308b\u305f\u3073\u306b\u30b9\u30ad\u30e3\u30f3\u5b9f\u884c\u3001\u30b9\u30ad\u30e3\u30f3\u7d50\u679c\u3092 Slack<\/code> \u3078\u901a\u77e5\u3001\u3082\u3057\u8106\u5f31\u6027\u306e\u30ec\u30d9\u30eb\u306b CRITICAL<\/code> \u304c\u542b\u307e\u308c\u3066\u3044\u305f\u3089 Backlog<\/code> \u3078\u8ab2\u984c\u767b\u9332\u3059\u308b\u3001\u3068\u3044\u3046\u6d41\u308c\u304c\u3067\u304d\u308b\u3002
\n\u30ea\u30f3\u30af\u5148\u306e URL<\/code> \u3067\u30b9\u30ad\u30e3\u30f3\u7d50\u679c\u306e\u8a73\u7d30\u304c\u78ba\u8a8d\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u78ba\u8a8d\u304a\u3088\u3073\u5bfe\u5fdc\u3092\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3002<\/p>\n<\/p>\n","protected":false},"excerpt":{"rendered":"
2019\u5e7410\u6708\u306b Amazon ECR \u306e\u8106\u5f31\u6027\u306e\u30b9\u30ad\u30e3\u30f3\u6a5f\u80fd\u304c\u5b9f\u88c5\u3055\u308c\u305f\u3002 Announcing Image Scanning for Amazon ECR \u4eca\u56de\u306f\u3001\u4e0b\u8a18\u306e\u8a18\u4e8b\u3092\u53c2\u8003\u306b\u3001 ECR \u3078\u30a4\u30e1\u30fc\u30b8\u3092\u30d7\u30c3\u30b7\u30e5 ECR \u306e\u30a4\u30e1\u30fc\u30b8\u30b9\u30ad\u30e3\u30f3 \u30b9\u30ad\u30e3\u30f3\u5b9f\u884c\u3092\u30c8\u30ea\u30ac\u30fc\u306b Lambda \u3092\u5b9f\u884c\u3057\u3066 Slack \u901a\u77e5 \u3068\u3044\u3046\u6d41\u308c\u3067\u3084\u3063\u3066\u307f\u305f\u3002 \u3010\u53c2\u8003URL\u3011 Amazon ECR\u306e\u30a4\u30e1\u30fc\u30b8\u30b9\u30ad\u30e3\u30f3 […]<\/p>\n","protected":false},"author":3,"featured_media":684,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[13],"tags":[270,399],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/593"}],"collection":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/comments?post=593"}],"version-history":[{"count":1,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/593\/revisions"}],"predecessor-version":[{"id":3287,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/593\/revisions\/3287"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/media?parent=593"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/categories?post=593"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/tags?post=593"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}