ה-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, if it is not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
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, if it is not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
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. אם אתם משתמשים בחשבון שמוגדר כבעלים של הפרויקט כדי להריץ את הסריקות, אתם יכולים לדלג על השלב הזה.
התפקידים הנדרשים
כדי לקבל את ההרשאות שדרושות להצגת תוצאות הסריקה של חבילות, צריך לבקש מהאדמין להקצות לכם את תפקידי ה-IAM הבאים בפרויקט:
- סוכן שירות Container Scanner (
roles/containerscanning.ServiceAgent) - Container Analysis Occurrences Viewer (
roles/containeranalysis.occurrences.viewer) - צפייה בהערות של Container Analysis (
roles/containeranalysis.notes.viewer) - קריאה ב-Artifact Registry (
roles/artifactregistry.reader)
להסבר על מתן תפקידים, ראו איך מנהלים את הגישה ברמת הפרויקט, התיקייה והארגון.
יכול להיות שאפשר לקבל את ההרשאות הנדרשות גם באמצעות תפקידים בהתאמה אישית או תפקידים מוגדרים מראש.
סריקה של קובץ אימג' של קונטיינר
סריקה מקומית:
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.