ה-On-Demand Scanning API מאפשר לסרוק תמונות שמאוחסנות באופן מקומי במחשב או מרחוק ב-Artifact Registry. אתם יכולים להשתמש בסריקה על פי דרישה כדי לסרוק תמונות בצינור העיבוד של CI/CD, במטרה לזהות נקודות חולשה במערכת ונקודות חולשה בחבילות Go, לפני שתחליטו אם לאחסן אותן במאגר. מידע על המחירים מופיע בדף המחירים.
בדף הזה מוסבר איך לסרוק ידנית קובצי אימג' של קונטיינרים כדי לזהות נקודות חולשה במערכת ובחבילות Go.
לפני שמתחילים
- נכנסים לחשבון 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
באמצעות מנהל הרכיבים של 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 הבאים בפרויקט:
- סוכן שירות לסריקת קונטיינרים (
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 golang:1.17.6-alpine ✓ 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: '2022-01-11T16:58:11.711487Z' resourceUri: golang:1.16.13-alpine 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 golang:1.17.6-alpine --async ✓ Scanning container image ✓ Locally extracting packages and versions from local container image ✓ Remotely initiating analysis of packages and versions Done. Check operation [projects/my-project/locations/us/operations/2e1a6b1f-16e5-4427-ac86-72c998a3dd16] for status. metadata: '@type': type.googleapis.com/google.cloud.ondemandscanning.v1.AnalyzePackagesMetadata createTime: '2022-01-11T16:58:11.711487Z' resourceUri: golang:1.16.13-alpine 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/my-project/locations/us/operations/2e1a6b1f-16e5-4427-ac86-72c998a3dd16 done: true metadata: '@type': type.googleapis.com/google.cloud.ondemandscanning.v1.AnalyzePackagesMetadata createTime: '2022-01-11T16:58:11.711487Z' resourceUri: golang:1.16.13-alpine 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הוא ערך מספרי.
לדוגמה:
createTime: '2022-01-11T16:58:11.972043Z'
kind: VULNERABILITY
name: projects/my-project/locations/us/occurrences/0c607d9b-aff4-4cde-86b7-e2c0a865aadd
noteName: projects/goog-vulnz/notes/CVE-2021-38297
resourceUri: golang:1.16.13-alpine
updateTime: '2022-01-11T16:58:11.972043Z'
vulnerability:
cvssScore: 7.5
effectiveSeverity: CRITICAL
longDescription: Go before 1.16.9 and 1.17.x before 1.17.2 has a Buffer Overflow
via large arguments in a function invocation from a WASM module, when GOARCH=wasm
GOOS=js is used.
packageIssue:
- affectedCpeUri: cpe:/o:alpine:alpine_linux:3.15
affectedPackage: go
affectedVersion:
fullName: 1.16.13
kind: NORMAL
name: 1.16.13
effectiveSeverity: CRITICAL
fixedCpeUri: cpe:/o:alpine:alpine_linux:3.15
fixedPackage: go
fixedVersion:
fullName: 1.17.2
kind: NORMAL
name: 1.17.2
packageType: GO_STDLIB
relatedUrls:
- label: More Info
url: https://security-tracker.debian.org/tracker/CVE-2021-38297
- label: More Info
url: https://access.redhat.com/security/cve/CVE-2021-38297
- label: More Info
url: https://nvd.nist.gov/vuln/detail/CVE-2021-38297
severity: HIGH
shortDescription: CVE-2021-38297
הפלט של הפקודה הזו הוא רשימה של מקרים בפורמט Grafeas. במקרה הזה, מוצגת נקודת חולשה אחת ברמת סיכון גבוהה שנמצאה בתמונה.
בסריקה על פי דרישה אפשר לזהות שני סוגים של נקודות חולשה בחבילות Go:
packageType:GO_STDLIB. נקודות חולשה בספרייה הרגילה של Go. המשמעות היא שהפגיעות נמצאה בשרשרת הכלים של Go ששימשה לבניית הקובץ הבינארי, או בספרייה הרגילה שמצורפת לשרשרת הכלים. פתרון אפשרי הוא לשדרג את כלי השרשור שלכם.
packageType:GO. נקודות חולשה בחבילות Go. הקוד הזה מציין שהחולשה נמצאה בחבילה של צד שלישי. אפשר לנסות לשדרג את המודולים התלויים.
תוצאות הסריקה זמינות למשך 48 שעות אחרי השלמת פעולת הסריקה.
המאמרים הבאים
- שימוש ב-On-Demand Scanning API בצינור Cloud Build.
- משתמשים ב-Artifact Analysis כדי לסרוק ולעדכן באופן רציף את נתוני נקודות החולשה של התמונות שמאוחסנות ב-Artifact Registry.