סריקה ידנית של חבילות Go

במדריך למתחילים הזה נסביר איך לשלוף קובץ אימג' של קונטיינר, לסרוק אותו באופן ידני באמצעות On-Demand Scanning ולאחזר נקודות חולשה שזוהו בחבילות של מערכת ו-Go. כדי לבצע את השלבים במדריך הזה למתחילים, תשתמשו ב-Cloud Shell ובדוגמה של תמונת Alpine.

לפני שמתחילים

  1. נכנסים לחשבון Google Cloud . אם אתם משתמשים חדשים ב- Google Cloud, צרו חשבון כדי שתוכלו להעריך את הביצועים של המוצרים שלנו בתרחישים מהעולם האמיתי. לקוחות חדשים מקבלים בחינם גם קרדיט בשווי 300$ להרצה, לבדיקה ולפריסה של עומסי העבודה.
  2. 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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. 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 the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  5. 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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  6. Verify that billing is enabled for your Google Cloud project.

  7. 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 the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

הורדה וסריקה של תמונה

  1. פותחים את Cloud Shell בפרויקט.

    פתיחת Cloud Shell

    ייפתח חלון של Terminal עם כל הכלים שנדרשים כדי לפעול לפי המדריך הזה.

  2. משתמשים ב-Docker כדי למשוך את קובץ האימג' של הקונטיינר:

    docker pull golang:1.17.6-alpine
    
  3. מריצים את הסריקה:

    gcloud artifacts docker images scan golang:1.17.6-alpine --additional-package-types=GO
    

    הפעולה הזו מפעילה את תהליך הסריקה ומחזירה את שם הסריקה כשהיא מסתיימת:

    ✓ 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/849db1f8-2fb2-4559-9fe0-8720d8cd347c]
    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/f4adb1f8-20b2-4579-9fe0-8720d8cd347c
    response:
      '@type': type.googleapis.com/google.cloud.ondemandscanning.v1.AnalyzePackagesResponse
      scan: projects/my-project/locations/us/scans/a54f12b0-ca2d-4d93-8da5-5cf48e9e20ef
    
  4. משתמשים בשם הסריקה, בערך של scan מהפלט, כדי לאחזר את תוצאות הסריקה:

    gcloud artifacts docker images list-vulnerabilities \
    projects/my-project/locations/us/scans/a54f12b0-ca2d-4d93-8da5-5cf48e9e20ef
    

    הפלט מכיל רשימה של פגיעויות בחבילות Go, בספריית Go standard וב-Linux. התוויות הבאות מציינות את סוג הפגיעויות ב-Go:

    • packageType:GO_STDLIB. עוברים ל'פגיעויות בספרייה רגילה'. המשמעות היא שהפגיעות נמצאה בשרשרת הכלים של Go שמשמשת לבניית הקובץ הבינארי, או בספרייה הרגילה שמצורפת לשרשרת הכלים. פתרון אפשרי הוא לשדרג את כלי השרשור שלכם.

    • packageType:GO. עוברים אל package vulnerabilities (נקודות חולשה בחבילה). ההודעה הזו מציינת שהפגיעות נמצאה בחבילת צד שלישי. אפשר לנסות לשדרג את המודולים התלויים.

הסרת המשאבים

כדי לא לצבור חיובים לחשבון Google Cloud על המשאבים שבהם השתמשתם בדף הזה, פועלים לפי השלבים הבאים:

  1. במסוף Google Cloud , נכנסים לדף Manage resources.

    כניסה לדף Manage resources

  2. ברשימת הפרויקטים, בוחרים את הפרויקט שרוצים למחוק ולוחצים על Delete.
  3. כדי למחוק את הפרויקט, כותבים את מזהה הפרויקט בתיבת הדו-שיח ולוחצים על Shut down.

המאמרים הבאים