On-Demand Scanning API memungkinkan Anda memindai image yang disimpan secara lokal di komputer, atau dari jarak jauh di Artifact Registry. Anda dapat menggunakan Pemindaian On-Demand untuk memindai image di pipeline CI/CD, untuk kerentanan sistem dan kerentanan paket Java (Maven) sebelum memutuskan apakah akan menyimpannya di registry atau tidak. Lihat halaman Harga untuk mengetahui informasi harga.
Halaman ini menjelaskan cara memindai image container secara manual untuk mendeteksi kerentanan sistem dan kerentanan paket Maven.
Sebelum memulai
- Login ke akun Google Cloud Anda. Jika Anda baru menggunakan Google Cloud, buat akun untuk mengevaluasi performa produk kami dalam skenario dunia nyata. Pelanggan baru juga mendapatkan kredit gratis senilai $300 untuk menjalankan, menguji, dan men-deploy workload.
-
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 -
Menambahkan komponen local-extract ke penginstalan Google Cloud CLI Anda
Menggunakan Component Manager Google Cloud CLI
Pengelola komponen akan meminta Anda menginstal komponen yang diperlukan saat pertama kali Anda menjalankan perintah pemindaian.
Menggunakan pengelola paket sistem Anda
-
Untuk Debian/Ubuntu:
sudo apt install google-cloud-sdk-local-extract
-
Untuk Red Hat/Fedora/CentOS:
sudo dnf install google-cloud-sdk-local-extract
Atau, Anda dapat mengganti
dnfdenganyumdalam perintah sebelumnya.
-
Untuk Debian/Ubuntu:
- Berikan peran IAM On-Demand Scanning Admin kepada pengguna atau akun layanan yang akan Anda gunakan dengan On-Demand Scanning. Jika Anda menggunakan akun pemilik project untuk menjalankan pemindaian, Anda dapat melewati langkah ini.
Peran yang diperlukan
Untuk mendapatkan izin yang Anda perlukan untuk Melihat hasil pemindaian paket, minta administrator untuk memberi Anda peran IAM berikut pada project:
- Agen Layanan Pemindai Kontainer (
roles/containerscanning.ServiceAgent) - Container Analysis Occurrences Viewer (
roles/containeranalysis.occurrences.viewer) - Container Analysis Notes Viewer (
roles/containeranalysis.notes.viewer) - Pembaca Artifact Registry (
roles/artifactregistry.reader)
Untuk mengetahui informasi selengkapnya tentang pemberian peran, lihat Mengelola akses ke project, folder, dan organisasi.
Anda mungkin juga bisa mendapatkan izin yang diperlukan melalui peran khusus atau peran bawaan lainnya.
Memindai image container
Pemindaian lokal:
gcloud artifacts docker images scan IMAGE_URI \ [--location=(us,europe,asia)] [--async]Untuk gambar lokal, gunakan salah satu format berikut untuk IMAGE_URI:
REPOSITORY:TAGREPOSITORY
Pemindaian jarak jauh:
gcloud artifacts docker images scan IMAGE_URI \ --remote [--location=(us,europe,asia)] [--async]Untuk image jarak jauh, gunakan salah satu format berikut untuk 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
Untuk image di Artifact Registry, IMAGE_URI harus menyertakan
REPOSITORY_ID.
Untuk pemindaian lokal dan jarak jauh, Anda dapat menggunakan flag opsional berikut:
--locationadalah tanda opsional untuk memilih multi-region secara manual tempat pemindaian dilakukan. Memilih multi-region yang lebih dekat dengan lokasi fisik Anda akan meminimalkan latensi. Lokasi yang tersedia adalah:us,europe, danasia. Lokasi defaultnya adalahus.--asyncadalah tanda opsional untuk menjalankan proses pemindaian secara asinkron. Jika Anda menghilangkan flag ini, terminal Anda akan diblokir hingga proses pemindaian selesai.
Pemindaian sinkron
Contoh berikut menunjukkan output pemindaian sinkron, tanpa flag --async:
$ gcloud artifacts docker images scan jenkins:2.60.3-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: '2021-01-05T23:03:04.185261Z' resourceUri: jenkins:2.60.3-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
Gunakan nama pemindaian untuk mengambil hasil kerentanan. Dalam contoh, nama pemindaian adalah nilai scan di baris terakhir pesan output.
Pemindaian asinkron
Contoh berikut menunjukkan output dari melakukan pemindaian asinkron:
$ gcloud artifacts docker images scan jenkins:2.60.3-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/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: jenkins:2.60.3-alpine name: projects/my-project/locations/us/operations/2e1a6b1f-16e5-4427-ac86-72c998a3dd16
Tindakan ini meluncurkan operasi yang berjalan lama dan menampilkan ID-nya tanpa memblokir terminal Anda. Gunakan ID operasi, nilai name di baris terakhir pesan output, untuk melakukan polling pada operasi.
Jajak pendapat untuk menjalankan operasi yang berjalan lama
Gunakan ID operasi dari output perintah pemindaian asinkron untuk memeriksa status operasi:
gcloud artifacts docker images get-operation LRO_ID
Dengan LRO_ID sebagai ID operasi yang berjalan lama.
Melanjutkan contoh bagian pemindaian asinkron, untuk memeriksa status operasi:
$ 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: jenkins:2.60.3-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
Jika output menyertakan baris done: true, operasi pemindaian telah selesai. Gunakan nama pemindaian untuk mengambil hasil kerentanan.
Nama pemindaian adalah nilai scan di baris terakhir pesan output.
Mengambil hasil pemindaian
Untuk mengambil hasil pemindaian setelah operasi pemindaian selesai, gunakan perintah berikut:
gcloud artifacts docker images list-vulnerabilities SCAN_NAME [--limit=X]
Dengan:
SCAN_NAME adalah nama pemindaian. Anda dapat menemukannya di baris terakhir output saat Anda menjalankan pemindaian sinkron atau memeriksa operasi yang berjalan lama, setelah pemindaian selesai.
--limit=Xadalah tanda opsional yang membatasi jumlah kemunculan yang ditampilkan dalam output.Xadalah nilai numerik.
Contoh:
createTime: '2021-06-29T17:01:18.819477Z'
kind: VULNERABILITY
name: projects/my-project/locations/us/occurrences/06305977-f557-4772-8586-4260684291d3
noteName: projects/my-project/notes/CVE-2014-0114
resourceUri: jenkins:2.60.3-alpine
updateTime: '2021-06-29T17:01:18.819477Z'
vulnerability:
cvssScore: 4.3
effectiveSeverity: MEDIUM
longDescription: http/conn/ssl/SSLConnectionSocketFactory.java in ...
packageIssue:
- affectedCpeUri: cpe:/o:alpine:alpine_linux:3.13
affectedPackage: org.apache.httpcomponents:httpclient
affectedVersion:
fullName: 4.0.2
kind: NORMAL
name: 4.0.2
effectiveSeverity: MEDIUM
fixedCpeUri: cpe:/o:alpine:alpine_linux:3.13
fixedPackage: org.apache.httpcomponents:httpclient
fixedVersion:
fullName: 4.3.6
kind: NORMAL
name: 4.3.6
packageType: MAVEN
relatedUrls:
- label: More Info
url: https://security-tracker.debian.org/tracker/CVE-2015-5262
severity: MEDIUM
shortDescription: CVE-2015-5262
Output dari perintah ini adalah
daftar kemunculan dalam format Grafeas. Dalam
kasus ini, kerentanan tingkat sedang yang ditemukan dalam image adalah satu. Kerentanan paket Maven berisi kolom packageType:MAVEN.
Hasil pemindaian tersedia selama 48 jam setelah operasi pemindaian selesai.
Langkah berikutnya
- Gunakan On-Demand Scanning API di pipeline Cloud Build Anda.
- Gunakan Artifact Analysis untuk memindai dan terus memperbarui informasi kerentanan untuk image Anda yang disimpan di Artifact Registry.