אתם יכולים לספק מטא-נתונים משלכם ל-Artifact Analysis כדי לענות על צורך עסקי ספציפי. לדוגמה, ארגון שמספק ניהול אבטחה עבור קובצי Docker של הלקוחות שלו יכול להשתמש ב-Artifact Analysis כדי לאחסן ולאחזר מטא-נתונים שקשורים לאבטחה של התמונות האלה.
בשלבים הבאים מוסבר איך לספק מטא-נתונים של אימות לתמונות באמצעות Artifact Analysis API. אפשר להשתמש באותן הוראות כדי לאחסן ולשלוף כל סוג של מטא-נתונים שנתמך על ידי Artifact Analysis.
לפני שמתחילים
- נכנסים לחשבון 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.
Enable the Container Analysis 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.
Enable the Container Analysis 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 - כך מגדירים בקרת גישה למטא-נתונים בפרויקט. אפשר לדלג על השלב הזה אם אתם צורכים מטא-נתונים רק ממופעים שנוצרו על ידי סריקת קונטיינרים של Artifact Analysis.
יצירת הערות ומופעים לפרויקטים
בקטע הזה מוסבר איך ליצור הערות ומופעים. בדוגמה הזו נשתמש בסוג ATTESTATION.
כספק, אתם יוצרים הערה בפרויקט שלכם לכל אישור, ויוצרים מופע בפרויקט של הלקוח למופע של האישור הזה.
יצירת הערות
כדי ליצור הערה ולהקצות לה מזהה הערה:
API
יוצרים קובץ בשם
note.jsonעם תיאור ופרטים של האישור. הקוד הבא מציג קובץnote.jsonלדוגמה:{ "shortDescription": "A brief Description of the note", "longDescription": "A longer description of the note", "kind": "ATTESTATION", "attestation": { "hint": { "humanReadableName": "my-attestation-authority" } } }מידע נוסף על ייצוג JSON של ההערות מופיע במאמרי העזרה של Notes API.
מריצים את פקודת ה-Curl הבאה כדי ליצור הערה:
curl -v -H "Content-Type: application/json" -H \ "Authorization: Bearer $(gcloud auth print-access-token)" \ https://containeranalysis.googleapis.com/v1/projects/PROVIDER_PROJECT_ID/notes?note_id=NOTE_ID -d @note.jsonכאשר:
- PROVIDER_PROJECT_ID הוא מזהה הפרויקט.
- NOTE_ID מציין מזהה לפתק. מחרוזת באורך של עד 100 תווים.
Java
מידע על התקנת ספריית הלקוח של Artifact Analysis ושימוש בה מופיע במאמר ספריות הלקוח של Artifact Analysis. מידע נוסף מופיע במאמרי העזרה של Artifact Analysis Java API.
כדי לבצע אימות ב-Artifact Analysis, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.
import com.google.cloud.devtools.containeranalysis.v1.ContainerAnalysisClient;
import io.grafeas.v1.GrafeasClient;
import io.grafeas.v1.Note;
import io.grafeas.v1.ProjectName;
import io.grafeas.v1.Version;
import io.grafeas.v1.AttestationNote;
import java.io.IOException;
import java.lang.InterruptedException;
public class CreateNote {
// Creates and returns a new Note
public static Note createNote(String noteId, String projectId)
throws IOException, InterruptedException {
// String noteId = "my-note";
// String projectId = "my-project-id";
final String projectName = ProjectName.format(projectId);
Note newNote =
Note.newBuilder()
// Associate the Note with the metadata type
// https://docs.cloud.google.com/artifact-registry/docs/analysis
// Here, we use the type "attestation"
.setAttestation(
AttestationNote.newBuilder()
.setHint(
AttestationNote.Hint.newBuilder()
.setHumanReadableName("my-attestation-authority")))
.build();
// Initialize client that will be used to send requests. After completing all of your requests,
// call the "close" method on the client to safely clean up any remaining background resources.
GrafeasClient client = ContainerAnalysisClient.create().getGrafeasClient();
Note result = client.createNote(projectName, noteId, newNote);
return result;
}
}
המשך
מידע על התקנת ספריית הלקוח של Artifact Analysis ושימוש בה מופיע במאמר ספריות הלקוח של Artifact Analysis. מידע נוסף מופיע במאמרי העזרה של Artifact Analysis Go API.
כדי לבצע אימות ב-Artifact Analysis, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.
import (
"context"
"fmt"
containeranalysis "cloud.google.com/go/containeranalysis/apiv1"
grafeaspb "google.golang.org/genproto/googleapis/grafeas/v1"
)
// createNote creates and returns a new attestation Note.
func createNote(noteID, projectID string) (*grafeaspb.Note, error) {
ctx := context.Background()
client, err := containeranalysis.NewClient(ctx)
if err != nil {
return nil, fmt.Errorf("NewClient: %w", err)
}
defer client.Close()
projectName := fmt.Sprintf("projects/%s", projectID)
req := &grafeaspb.CreateNoteRequest{
Parent: projectName,
NoteId: noteID,
Note: &grafeaspb.Note{
Type: &grafeaspb.Note_Attestation{
Attestation: &grafeaspb.AttestationNote{
Hint: &grafeaspb.AttestationNote_Hint{
HumanReadableName: "my-attestation-authority",
},
},
},
},
}
return client.GetGrafeasClient().CreateNote(ctx, req)
}
Node.js
מידע על התקנת ספריית הלקוח של Artifact Analysis ושימוש בה מופיע במאמר ספריות הלקוח של Artifact Analysis. מידע נוסף מופיע במאמרי העזרה של ה-API של Artifact Analysis Node.js.
כדי לבצע אימות ב-Artifact Analysis, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.
/**
* TODO(developer): Uncomment these variables before running the sample
*/
// const projectId = 'your-project-id', // Your Google Cloud Project ID
// const noteId = 'my-note-id' // Id of the note
// Import the library and create a client
const {ContainerAnalysisClient} = require('@google-cloud/containeranalysis');
const client = new ContainerAnalysisClient();
// Construct request
// Associate the Note with a metadata type
// https://docs.cloud.google.com/artifact-registry/docs/analysis
// Here, we use the type "attestation"
const formattedParent = client.getGrafeasClient().projectPath(projectId);
// Creates and returns a new Note
const [note] = await client.getGrafeasClient().createNote({
parent: formattedParent,
noteId: noteId,
note: {
attestation: {
hint: {
humanReadableName: 'my-attestation-authority',
},
},
},
});
console.log(`Note ${note.name} created.`);
Ruby
מידע על התקנת ספריית הלקוח של Artifact Analysis ושימוש בה מופיע במאמר ספריות הלקוח של Artifact Analysis. מידע נוסף מופיע במאמרי העזרה של Artifact Analysis Ruby API.
כדי לבצע אימות ב-Artifact Analysis, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.
# note_id = "A user-specified identifier for the note"
# project_id = "Your Google Cloud project ID"
require "google/cloud/container_analysis"
# Initialize the client
client = Google::Cloud::ContainerAnalysis.container_analysis.grafeas_client
parent = client.project_path project: project_id
note = {
attestation: {
hint: {
human_readable_name: "attestation-authority"
}
}
}
response = client.create_note parent: parent, note_id: note_id, note: note
puts response.name
Python
מידע על התקנת ספריית הלקוח של Artifact Analysis ושימוש בה מופיע במאמר ספריות הלקוח של Artifact Analysis. מידע נוסף מופיע במאמרי העזרה של Artifact Analysis Python API.
כדי לבצע אימות ב-Artifact Analysis, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.
from google.cloud.devtools import containeranalysis_v1
from grafeas.grafeas_v1 import types, Version
def create_note(note_id: str, project_id: str) -> types.grafeas.Note:
"""Creates and returns a new attestation note."""
# note_id = 'my-note'
# project_id = 'my-gcp-project'
client = containeranalysis_v1.ContainerAnalysisClient()
grafeas_client = client.get_grafeas_client()
project_name = f"projects/{project_id}"
note = {
"attestation": {
"hint": {
"human_readable_name": "attestation-authority",
}
}
}
response = grafeas_client.create_note(
parent=project_name, note_id=note_id, note=note
)
return response
יצירת מופעים של ההערות
כדי ליצור מופעים של פתק:
API
יוצרים קובץ בשם
occurrence.jsonעם תיאור ופרטים של האישור. הקוד הבא מציג קובץoccurrence.jsonלדוגמה:{ "resourceUri": "your-resource-uri-here", "noteName": "projects/your-note-project/notes/your-note-id", "kind": "ATTESTATION", "attestation": { "serializedPayload": "eW91ci1wYXlsb2FkLWhlcmU=", "signatures": [ { "publicKeyId": "your-key-id-here", "signature": "eW91ci1zaWduYXR1cmUtaGVyZQ==" } ] } }מידע נוסף על ייצוג JSON של ההערות מופיע במאמרי העזרה של Notes API.
מריצים את פקודת ה-curl הבאה כדי ליצור מופע:
curl -v -H "Content-Type: application/json" -H \ "Authorization: Bearer $(gcloud auth print-access-token)" \ https://containeranalysis.googleapis.com/v1/projects/PROVIDER_PROJECT_ID/occurrences/ -d @occurrence.jsonכאשר:
- PROVIDER_PROJECT_ID הוא מזהה הפרויקט.
- NOTE_ID מציין מזהה לפתק. מחרוזת באורך של עד 100 תווים.
Java
מידע על התקנת ספריית הלקוח של Artifact Analysis ושימוש בה מופיע במאמר ספריות הלקוח של Artifact Analysis. מידע נוסף מופיע במאמרי העזרה של Artifact Analysis Java API.
כדי לבצע אימות ב-Artifact Analysis, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.
import com.google.cloud.devtools.containeranalysis.v1.ContainerAnalysisClient;
import com.google.protobuf.ByteString;
import io.grafeas.v1.AttestationOccurrence;
import io.grafeas.v1.GrafeasClient;
import io.grafeas.v1.NoteName;
import io.grafeas.v1.Occurrence;
import io.grafeas.v1.ProjectName;
import io.grafeas.v1.Signature;
import java.io.IOException;
public class CreateOccurrence {
// Creates and returns a new attestation Occurrence associated with an existing Note
public static Occurrence createOccurrence(
String resourceUrl, String noteId, String occProjectId, String noteProjectId)
throws IOException {
// String resourceUrl = "https://gcr.io/project/image@sha256:123";
// String noteId = "my-note";
// String occProjectId = "my-project-id";
// String noteProjectId = "my-project-id";
final NoteName noteName = NoteName.of(noteProjectId, noteId);
final String occProjectName = ProjectName.format(occProjectId);
Occurrence newOcc =
Occurrence.newBuilder()
.setNoteName(noteName.toString())
.setResourceUri(resourceUrl)
.setAttestation(
AttestationOccurrence.newBuilder()
.setSerializedPayload(ByteString.copyFrom("your-payload-here", "UTF-8"))
.addSignatures(
Signature.newBuilder()
.setPublicKeyId("your-key-id-here")
.setSignature(ByteString.copyFrom("your-signature-here", "UTF-8"))))
.build();
// Initialize client that will be used to send requests. After completing all of your requests,
// call the "close" method on the client to safely clean up any remaining background
// resources.
GrafeasClient client = ContainerAnalysisClient.create().getGrafeasClient();
Occurrence result = client.createOccurrence(occProjectName, newOcc);
return result;
}
}
המשך
מידע על התקנת ספריית הלקוח של Artifact Analysis ושימוש בה מופיע במאמר ספריות הלקוח של Artifact Analysis. מידע נוסף מופיע במאמרי העזרה של Artifact Analysis Go API.
כדי לבצע אימות ב-Artifact Analysis, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.
import (
"context"
"fmt"
containeranalysis "cloud.google.com/go/containeranalysis/apiv1"
grafeaspb "google.golang.org/genproto/googleapis/grafeas/v1"
)
// createsOccurrence creates and returns a new Occurrence of a previously created attestation note.
// Use this style of URL when you use Google Artifact Registry.
// resourceURL := "https://LOCATION-docker.pkg.dev/my-project/my-repo/my-image"
// noteID := "my-note"
ctx := context.Background()
client, err := containeranalysis.NewClient(ctx)
if err != nil {
return nil, fmt.Errorf("NewClient: %w", err)
}
defer client.Close()
req := &grafeaspb.CreateOccurrenceRequest{
Parent: fmt.Sprintf("projects/%s", occProjectID),
Occurrence: &grafeaspb.Occurrence{
NoteName: fmt.Sprintf("projects/%s/notes/%s", noteProjectID, noteID),
// Attach the occurrence to the associated resource uri.
ResourceUri: resourceURL,
// Details about the attestation can be added here.
Details: &grafeaspb.Occurrence_Attestation{
Attestation: &grafeaspb.AttestationOccurrence{
SerializedPayload: []byte("..."),
Signatures: []*grafeaspb.Signature{
{
PublicKeyId: "...",
Signature: []byte("..."),
},
},
},
},
},
}
return client.GetGrafeasClient().CreateOccurrence(ctx, req)
}
Node.js
מידע על התקנת ספריית הלקוח של Artifact Analysis ושימוש בה מופיע במאמר ספריות הלקוח של Artifact Analysis. מידע נוסף מופיע במאמרי העזרה של ה-API של Artifact Analysis Node.js.
כדי לבצע אימות ב-Artifact Analysis, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.
/**
* TODO(developer): Uncomment these variables before running the sample
*/
// const noteProjectId = 'your-project-id', // Your Google Cloud Project ID
// const noteId = 'my-note-id', // Id of the note
// const occurrenceProjectId = 'your-project-id', // The Google Cloud Project ID of the occurrence
// If you are using Google Artifact Registry
// const imageUrl = 'https://LOCATION-docker.pkg.dev/my-project/my-repo/my-image:123' // Image to attach metadata to
// Import the library and create a client
const {ContainerAnalysisClient} = require('@google-cloud/containeranalysis');
const client = new ContainerAnalysisClient();
// Construct request
const formattedParent = client
.getGrafeasClient()
.projectPath(occurrenceProjectId);
const formattedNote = client
.getGrafeasClient()
.notePath(noteProjectId, noteId);
// Creates and returns a new Occurrence associated with an existing Note
const [occurrence] = await client.getGrafeasClient().createOccurrence({
parent: formattedParent,
occurrence: {
noteName: formattedNote,
resourceUri: imageUrl,
attestation: {
serializedPayload: Buffer.from('your-payload-here').toString('base64'),
signatures: [
{
publicKeyId: 'your-key-id-here',
signature: Buffer.from('your-signature-here').toString('base64'),
},
],
},
},
});
console.log(`Occurrence created ${occurrence.name}.`);
return occurrence;
Ruby
מידע על התקנת ספריית הלקוח של Artifact Analysis ושימוש בה מופיע במאמר ספריות הלקוח של Artifact Analysis. מידע נוסף מופיע במאמרי העזרה של Artifact Analysis Ruby API.
כדי לבצע אימות ב-Artifact Analysis, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.
# note_id = "A user-specified identifier for the note"
# project_id = "Your Google Cloud project ID"
# note_project = "The project that contains the note"
# occurrence_project = "The project that contains the occurrence"
require "google/cloud/container_analysis"
require "base64"
# Initialize the client
client = Google::Cloud::ContainerAnalysis.container_analysis.grafeas_client
note_path = client.note_path project: note_project, note: note_id
project_path = client.project_path project: occurrence_project
occurrence = {
note_name: note_path,
resource_uri: resource_url,
attestation: {
serialized_payload: Base64.encode64("your-payload-here"),
signatures: [
{
public_key_id: "your-key-id-here",
signature: Base64.encode64("your-signature-here")
}
]
}
}
response = client.create_occurrence parent: project_path, occurrence: occurrence
puts response.name
Python
מידע על התקנת ספריית הלקוח של Artifact Analysis ושימוש בה מופיע במאמר ספריות הלקוח של Artifact Analysis. מידע נוסף מופיע במאמרי העזרה של Artifact Analysis Python API.
כדי לבצע אימות ב-Artifact Analysis, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.
import base64
from google.cloud.devtools import containeranalysis_v1
from grafeas.grafeas_v1 import types
def create_occurrence(
resource_url: str, note_id: str, occurrence_project: str, note_project: str
) -> types.grafeas.Occurrence:
"""Creates and returns a new occurrence of a previously
created attestation note."""
# note_id = 'my-note'
# project_id = 'my-gcp-project'
client = containeranalysis_v1.ContainerAnalysisClient()
grafeas_client = client.get_grafeas_client()
formatted_note = f"projects/{note_project}/notes/{note_id}"
formatted_project = f"projects/{occurrence_project}"
occurrence = {
"note_name": formatted_note,
"resource_uri": resource_url,
"attestation": {
"serialized_payload": base64.b64encode(b"your-payload-here").decode("utf-8"),
"signatures": [
{
"public_key_id": "your-key-id-here",
"signature": base64.b64encode(b"your-signature-here").decode("utf-8"),
}
],
},
}
return grafeas_client.create_occurrence(
parent=formatted_project, occurrence=occurrence
)
הצגת כל המקרים של הערה ספציפית
אתם יכולים לראות את כל המקרים של אישור ספציפי בפרויקטים של הלקוח באמצעות notes.occurrences.list().
API
כדי להציג את כל המופעים של הערה, שולחים בקשת GET באופן הבא:
GET https://containeranalysis.googleapis.com/v1/projects/PROJECT_ID/notes/NOTE_ID/occurrences
פרטים נוספים זמינים בנקודת קצה ל-API של projects.notes.occurrences.list.
Java
מידע על התקנת ספריית הלקוח של Artifact Analysis ושימוש בה מופיע במאמר ספריות הלקוח של Artifact Analysis. מידע נוסף מופיע במאמרי העזרה של Artifact Analysis Java API.
כדי לבצע אימות ב-Artifact Analysis, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.
Go
מידע על התקנת ספריית הלקוח של Artifact Analysis ושימוש בה מופיע במאמר ספריות הלקוח של Artifact Analysis. מידע נוסף מופיע במאמרי העזרה של Artifact Analysis Go API.
כדי לבצע אימות ב-Artifact Analysis, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.
Node.js
מידע על התקנת ספריית הלקוח של Artifact Analysis ושימוש בה מופיע במאמר ספריות הלקוח של Artifact Analysis. מידע נוסף מופיע במאמרי העזרה של Artifact Analysis Node.js API.
כדי לבצע אימות ב-Artifact Analysis, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.
Ruby
מידע על התקנת ספריית הלקוח של Artifact Analysis ושימוש בה מופיע במאמר ספריות הלקוח של Artifact Analysis. מידע נוסף מופיע במאמרי העזרה של Artifact Analysis Ruby API.
כדי לבצע אימות ב-Artifact Analysis, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.
Python
מידע על התקנת ספריית הלקוח של Artifact Analysis ושימוש בה מופיע במאמר ספריות הלקוח של Artifact Analysis. מידע נוסף מופיע במאמרי העזרה של Artifact Analysis Python API.
כדי לבצע אימות ב-Artifact Analysis, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.
המאמרים הבאים
הוראות להצגה ולסינון של הערות ומופעים של נקודות חולשה בקובצי אימג' של קונטיינרים מפורטות במאמר הצגת מופעים של נקודות חולשה.
הוראות להגדרת התראות מופיעות במאמר התראות Pub/Sub.