ה-On-Demand Scanning API מאפשר לסרוק תמונות שמאוחסנות באופן מקומי במחשב או מרחוק ב-Artifact Registry. כך תוכלו לשלוט בצורה מדויקת בקונטיינרים שאתם רוצים לסרוק כדי לזהות פגיעויות. אתם יכולים להשתמש בסריקה לפי דרישה כדי לסרוק תמונות בצינור עיבוד הנתונים של CI/CD לפני שתחליטו אם לאחסן אותן במאגר. מידע על המחירים מופיע בדף המחירים.
בדף הזה מוסבר איך לסרוק ידנית תמונות של קונטיינרים באמצעות סריקה לפי דרישה.
לפני שמתחילים
- נכנסים לחשבון Google Cloud . אם אתם משתמשים חדשים ב- Google Cloud, צרו חשבון כדי שתוכלו להעריך את הביצועים של המוצרים שלנו בתרחישים מהעולם האמיתי. לקוחות חדשים מקבלים בחינם גם קרדיט בשווי 300$ להרצה, לבדיקה ולפריסה של עומסי העבודה.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the On-Demand Scanning API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
התקינו את ה-CLI של Google Cloud.
-
אם אתם משתמשים בספק זהויות חיצוני (IdP), קודם אתם צריכים להיכנס ל-CLI של gcloud באמצעות המאגר המאוחד לניהול זהויות.
-
כדי לאתחל את ה-CLI של gcloud, הריצו את הפקודה הבאה:
gcloud init -
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the On-Demand Scanning API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
התקינו את ה-CLI של Google Cloud.
-
אם אתם משתמשים בספק זהויות חיצוני (IdP), קודם אתם צריכים להיכנס ל-CLI של gcloud באמצעות המאגר המאוחד לניהול זהויות.
-
כדי לאתחל את ה-CLI של gcloud, הריצו את הפקודה הבאה:
gcloud init -
מוסיפים את הרכיב local-extract להתקנה של Google Cloud CLI
באמצעות Component Manager של Google Cloud CLI
בפעם הראשונה שמריצים את פקודת הסריקה, מנהל הרכיבים יציג בקשה להתקנת הרכיבים הנדרשים.
שימוש במנהל החבילות של המערכת
-
ל-Debian/Ubuntu:
sudo apt install google-cloud-sdk-local-extract
-
ב-Red Hat/Fedora/CentOS:
sudo dnf install google-cloud-sdk-local-extract
אפשרות אחרת היא להחליף את
dnfב-yumבפקודה הקודמת.
-
ל-Debian/Ubuntu:
- מקצים את תפקיד ה-IAM On-Demand Scanning Admin למשתמש או לחשבון השירות שבהם תשתמשו עם On-Demand Scanning. אם אתם משתמשים בחשבון שמוגדר כבעלים של הפרויקט כדי להריץ את הסריקות, אתם יכולים לדלג על השלב הזה.
סריקה של קובץ אימג' של קונטיינר
סריקה מקומית:
gcloud artifacts docker images scan IMAGE_URI \ [--location=(us,europe,asia)] [--async]אם התמונה נמצאת במחשב, צריך להשתמש באחד מהפורמטים הבאים עבור התג IMAGE_URI:
REPOSITORY:TAGREPOSITORY
סריקה מרחוק:
gcloud artifacts docker images scan IMAGE_URI \ --remote [--location=(us,europe,asia)] [--async]אם התמונה נמצאת במיקום מרוחק, צריך להשתמש באחד מהפורמטים הבאים עבור התג IMAGE_URI:
HOSTNAME/PROJECT_ID/REPOSITORY_ID/IMAGE_ID@sha256:HASHHOSTNAME/PROJECT_ID/REPOSITORY_ID/IMAGE_ID:HASHHOSTNAME/PROJECT_ID/REPOSITORY_ID/IMAGE_IDHOSTNAME/PROJECT_ID/IMAGE_ID@sha256:HASHHOSTNAME/PROJECT_ID/IMAGE_ID:HASHHOSTNAME/PROJECT_ID/IMAGE_ID
בתמונות ב-Artifact Registry, הקובץ IMAGE_URI חייב לכלול את
REPOSITORY_ID.
גם בסריקות מקומיות וגם בסריקות מרחוק, אפשר להשתמש בדגלים האופציונליים הבאים:
--locationהוא דגל לבחירה ידנית של מספר האזורים שבהם מתבצעת הסריקה. בחירה בהגדרה של מספר אזורים שקרובה למיקום הפיזי שלכם מצמצמת את זמן האחזור. המיקומים הזמינים הם:us, europeו-asia. מיקום ברירת המחדל הואus.
--asyncהוא דגל להפעלת תהליך הסריקה באופן אסינכרוני. אם לא תציינו את הדגל הזה, המסוף ייחסם עד שתהליך הסריקה יושלם.
סריקה סינכרונית
בדוגמה הבאה מוצג הפלט של סריקה סינכרונית, בלי הדגל --async:
$ gcloud artifacts docker images scan ubuntu:latest ✓ Scanning container image ✓ Locally extracting packages and versions from local container image ✓ Remotely initiating analysis of packages and versions ✓ Waiting for analysis operation to complete [projects/my-project/locations/us/operations/87d2e137-1d1c-4790-8e5e-daf6c96ae7d7] Done. done: true metadata: '@type': type.googleapis.com/google.cloud.ondemandscanning.v1.AnalyzePackagesMetadata createTime: '2021-01-05T23:03:04.185261Z' resourceUri: ubuntu:latest name: projects/my-project/locations/us/operations/87d2e137-1d1c-4790-8e5e-daf6c96ae7d7 response: '@type': type.googleapis.com/google.cloud.ondemandscanning.v1.AnalyzePackagesResponse scan: projects/my-project/locations/us/scans/2fe2bfb8-f0c5-4dd6-a8c8-38961869767a
משתמשים בשם הסריקה כדי לאחזר את תוצאות נקודות החולשה.
שם הסריקה הוא הערך של scan בשורה האחרונה של הודעת הפלט.
סריקה אסינכרונית
בדוגמה הבאה מוצג הפלט של סריקה אסינכרונית:
$ gcloud artifacts docker images scan ubuntu:latest --async ✓ Scanning container image ✓ Locally extracting packages and versions from local container image ✓ Remotely initiating analysis of packages and versions Done. Check operation [projects/cloud-project/locations/us/operations/2e1a6b1f-16e5-4427-ac86-72c998a3dd16] for status. metadata: '@type': type.googleapis.com/google.cloud.ondemandscanning.v1.AnalyzePackagesMetadata createTime: '2021-01-05T23:04:54.393510Z' resourceUri: ubuntu:latest name: projects/my-project/locations/us/operations/2e1a6b1f-16e5-4427-ac86-72c998a3dd16
הפעולה הזו מפעילה פעולה ממושכת ומחזירה את המזהה שלה בלי לחסום את הטרמינל. כדי לבדוק את הפעולה, צריך להשתמש במזהה הפעולה, הערך של name בשורה האחרונה של הודעת הפלט.
דגימה של פעולה ממושכת
משתמשים במזהה הפעולה, מהפלט של פקודת הסריקה האסינכרונית, כדי לבדוק את סטטוס הפעולה.
gcloud artifacts docker images get-operation LRO_ID
כאשר LRO_ID הוא מזהה הפעולה הממושכת.
בהמשך לדוגמה שבקטע סריקה אסינכרונית, כדי לבדוק את סטטוס הפעולה:
$ gcloud artifacts docker images get-operation \ projects/cloud-project/locations/us/operations/2e1a6b1f-16e5-4427-ac86-72c998a3dd16 done: true metadata: '@type': type.googleapis.com/google.cloud.ondemandscanning.v1.AnalyzePackagesMetadata createTime: '2021-01-05T23:04:54.393510Z' resourceUri: ubuntu:latest name: projects/my-project/locations/us/operations/2e1a6b1f-16e5-4427-ac86-72c998a3dd16 response: '@type': type.googleapis.com/google.cloud.ondemandscanning.v1.AnalyzePackagesResponse scan: projects/my-project/locations/us/scans/2fe2bfb8-f0c5-4dd6-a8c8-38961869767a
אם הפלט כולל את השורה done: true, פעולת הסריקה הושלמה. משתמשים בשם הסריקה כדי לאחזר את תוצאות הפגיעות. השם הוא הערך של scan בשורה האחרונה של הודעת הפלט.
אחזור תוצאות הסריקה
כדי לאחזר את תוצאות הסריקה אחרי שהסריקה מסתיימת, משתמשים בפקודה הבאה:
gcloud artifacts docker images list-vulnerabilities SCAN_NAME [--limit=X]
כאשר:
- SCAN_NAME הוא שם הסריקה. אפשר למצוא אותו בתחתית הפלט כשבודקים את הפעולה הממושכת, אחרי שהסריקה מסתיימת.
-
--limit=Xהוא דגל אופציונלי שמגביל את מספר המקרים שמוצגים בפלט. Xהוא ערך מספרי.
לדוגמה:
gcloud artifacts docker images list-vulnerabilities \
projects/my-project/locations/us/scans/2fe2bfb8-f0c5-4dd6-a8c8-38961869767a
createTime: '2021-01-05T23:05:42.956227Z'
kind: VULNERABILITY
name: projects/my-project/locations/us/occurrences/f82a1efd-a261-4973-acbd-f9854d8b8135
noteName: projects/goog-vulnz/notes/CVE-2018-1000654
resourceUri: ubuntu:latest
updateTime: '2021-01-05T23:05:42.956227Z'
vulnerability:
cvssScore: 7.1
cvssv3:
attackComplexity: ATTACK_COMPLEXITY_LOW
attackVector: ATTACK_VECTOR_NETWORK
availabilityImpact: IMPACT_HIGH
baseScore: 7.2
confidentialityImpact: IMPACT_HIGH
exploitabilityScore: 1.2
impactScore: 5.9
integrityImpact: IMPACT_HIGH
privilegesRequired: PRIVILEGES_REQUIRED_HIGH
scope: SCOPE_UNCHANGED
userInteraction: USER_INTERACTION_NONE
effectiveSeverity: MEDIUM
הפלט של הפקודה הזו הוא רשימה של מקרים בפורמט Grafeas. במקרה הזה, מוצגת נקודת חולשה ברמת חומרה בינונית שנמצאה בתמונה.
תוצאות הסריקה זמינות למשך 48 שעות אחרי שהסריקה מסתיימת.
המאמרים הבאים
- שימוש ב-On-Demand Scanning API בצינור Cloud Build.
- משתמשים ב-Artifact Analysis כדי לסרוק ולעדכן באופן רציף את נתוני נקודות החולשה של התמונות שמאוחסנות ב-Artifact Registry.