אתם יכולים לחפש מדיניות הרשאות של IAM במשאבים שלכם בפרויקט, בתיקייה או בארגון, ולסנן את התוצאות שמתקבלות באמצעות שאילתה.
לפני שמתחילים
מפעילים את Cloud Asset Inventory API בפרויקט שממנו מריצים את הפקודות של מאגר משאבי ענן.
מוודאים שלחשבון שלכם יש את התפקיד המתאים כדי להפעיל את Cloud Asset Inventory API. בקטע הרשאות מפורטות ההרשאות הספציפיות לכל סוג קריאה.
יצירת שאילתה
לפני שיוצרים שאילתה, כדאי להתחיל בבקשת חיפוש שלא מציינת שאילתה. משתמשים בשדות ובערכים מהתגובה המלאה כדי ליצור שאילתה באמצעות תחביר שאילתת החיפוש, ומצמצמים אותה עד שמתקבלות התוצאות הרצויות.
השדות שאפשר להשתמש בהם בשאילתה מפורטים במסמכי העזרה של IamPolicySearchResult.
כשיוצרים שאילתה, חשוב לזכור את המגבלות הבאות:
השדה
policyהוא אובייקט בתצוגת עץ, ולכן אפשר להשתמש בו רק עם האופרטור:.אי אפשר לחפש את כל סוגי הנכסים. כדי לבדוק אם שירות מסוים לא זמין בממשקי ה-API לחיפוש, אפשר לעיין בסוגי המשאבים.
אפשר להשתמש גם בשדות הנוספים הבאים כדי להגביל את התוצאות לסוגים מסוימים של חשבונות משתמשים, הרשאות או תפקידים:
| שדה | תיאור |
|---|---|
memberTypes |
מכיל אחד מסוגי חשבונות המשתמשים הבאים ב-IAM:
דוגמהmemberTypes=user |
policy.role.permissions |
מכיל הרשאות IAM ספציפיות. דוגמהpolicy.role.permissions=storage.buckets.create |
roles |
מכיל תפקידי IAM ספציפיים. דוגמהroles=roles/storage.objectAdmin |
חיפוש במדיניות ההרשאות של IAM
לפני שיוצרים שאילתה, כדאי להתחיל בבקשת חיפוש שלא מציינת שאילתה. משתמשים בשדות ובערכים מהתגובה המלאה כדי ליצור שאילתה באמצעות תחביר שאילתת החיפוש, ומצמצמים אותה עד שמתקבלות התוצאות הרצויות.
המסוף
כדי לחפש מטא-נתונים של מדיניות הרשאות ב-IAM:
-
נכנסים לדף Asset Inventory במסוף Google Cloud .
- עוברים לפרויקט, לתיקייה או לארגון שרוצים לחפש בהם.
- לוחצים על הכרטיסייה מדיניות IAM.
-
כדי לחפש כללי מדיניות הרשאה, מזינים שאילתה בשדה Filter. במאמר תחביר של שאילתות חיפוש מוסבר איך לכתוב שאילתת חיפוש.
כדי להקל על יצירת שאילתות, אתם יכולים ללחוץ על שדה הסינון כדי להציג ולהוסיף את שדות החיפוש הזמינים לשאילתה.
אחרי שמבצעים חיפוש, מדיניות ההרשאה שתואמת לשאילתה מופיעה בטבלה Results. לוחצים לחיצה כפולה על השאילתה כדי לערוך אותה, או משתמשים בחלונית סינון תוצאות כדי להחיל הגדרות קבועות מראש של שאילתות או להגביל את תוצאות החיפוש לפי קריטריונים ספציפיים.
כדי לראות את השאילתה כפקודה של Google Cloud CLI, לוחצים על View query.
כדי לייצא את התוצאות, לוחצים על הורדת CSV.
gcloud
gcloud asset search-all-iam-policies \ --scope=SCOPE_PATH \ --query="QUERY" \ --asset-types=ASSET_TYPE_1,ASSET_TYPE_2,... \ --order-by="ORDER_BY"
מספקים את הערכים הבאים:
-
SCOPE_PATH: משתמשים באחד מהערכים הבאים:-
projects/PROJECT_ID, כאשרPROJECT_IDהוא מזהה הפרויקט שבו נמצאים הנכסים עם כללי מדיניות ההרשאה של IAM שרוצים לחפש. -
projects/PROJECT_NUMBER, כאשרPROJECT_NUMBERהוא מספר הפרויקט שיש בו נכסים עם כללי מדיניות הרשאה של IAM שרוצים לחפש.איך מוצאים את Google Cloud מספר הפרויקט
מסוףGoogle Cloud
כדי למצוא את מספר הפרויקט ב- Google Cloud :
-
נכנסים לדף Welcome במסוף Google Cloud .
- לוחצים על תיבת הרשימה switcher בסרגל התפריטים.
-
בוחרים את הארגון מתיבת הרשימה ומחפשים את שם הפרויקט. שם הפרויקט, מספר הפרויקט ומזהה הפרויקט מופיעים ליד הכותרת Welcome.
מוצגים עד 4,000 משאבים. אם הפרויקט שחיפשתם לא מופיע, נכנסים לדף Manage resources ומסננים את הרשימה לפי שם הפרויקט.
CLI של gcloud
כדי לאחזר את מספר הפרויקט, משתמשים בפקודה הבאה: Google Cloud
gcloud projects describe PROJECT_ID --format="value(projectNumber)"
-
-
folders/FOLDER_ID, כאשרFOLDER_IDהוא המזהה של התיקייה שיש בה נכסים עם כללי מדיניות הרשאה ב-IAM שרוצים לחפש.איך מוצאים את המזהה של תיקיית Google Cloud
מסוףGoogle Cloud
כדי למצוא את המזהה של תיקיית Google Cloud :
-
נכנסים למסוף Google Cloud .
- לוחצים על תיבת הרשימה switcher בסרגל התפריטים.
- בוחרים את הארגון שלכם בתיבת הרשימה.
- מחפשים את שם התיקייה. מזהה התיקייה מוצג לצד שם התיקייה.
CLI של gcloud
כדי לאחזר את המזהה של תיקייה ברמת הארגון, מריצים את הפקודה הבאה: Google Cloud
gcloud resource-manager folders list \ --organization=$(gcloud organizations describe ORGANIZATION_NAME \ --format="value(name.segment(1))") \ --filter='"DISPLAY_NAME":"TOP_LEVEL_FOLDER_NAME"' \ --format="value(ID)"
כאשר TOP_LEVEL_FOLDER_NAME הוא התאמה חלקית או מלאה של מחרוזת לשם התיקייה. מסירים את הדגל
--formatכדי לראות מידע נוסף על התיקיות שנמצאו.הפקודה הקודמת לא מחזירה את המזהים של תיקיות משנה בתוך תיקיות. כדי לעשות את זה, מריצים את הפקודה הבאה באמצעות המזהה של התיקייה ברמה העליונה:
gcloud resource-manager folders list --folder=FOLDER_ID
-
-
organizations/ORGANIZATION_ID, כאשרORGANIZATION_IDהוא המזהה של הארגון שיש לו נכסים עם כללי מדיניות ההרשאה של IAM שרוצים לחפש.איך מוצאים את המזהה של ארגון ב- Google Cloud
מסוףGoogle Cloud
כדי למצוא את המזהה של ארגון ב- Google Cloud :
-
נכנסים למסוף Google Cloud .
- לוחצים על תיבת הרשימה switcher בסרגל התפריטים.
- בוחרים את הארגון שלכם בתיבת הרשימה.
- לוחצים על הכרטיסייה הכול. מזהה הארגון מופיע לצד שם הארגון.
CLI של gcloud
כדי לאחזר את המזהה של ארגון ב- Google Cloud , משתמשים בפקודה הבאה:
gcloud organizations describe ORGANIZATION_NAME --format="value(name.segment(1))"
-
-
-
QUERY: אופציונלי. ביטוי השאילתה. אם לא צוין ערך או שהערך ריק, החיפוש יתבצע בכל המשאבים בהיקף שצוין. כדי ללמוד איך לכתוב שאילתת חיפוש, קראו את המאמר תחביר של שאילתת חיפוש. -
ASSET_TYPE_#: אופציונלי. רשימה מופרדת בפסיקים של סוגי נכסים שניתן לחפש. יש תמיכה בביטויים רגולריים שתואמים ל-RE2. אם הביטוי הרגולרי לא תואם לאף סוג נכס נתמך, תוחזר שגיאתINVALID_ARGUMENT. אם לא מציינים את--asset-types, מוחזרים כל סוגי הנכסים. -
ORDER_BY: אופציונלי. רשימה מופרדת בפסיקים של שדות שמציינים את סדר המיון של התוצאות. ברירת המחדל מוגדרת לסדר עולה. כדי לציין סדר יורד, מוסיפיםDESCאחרי שם השדה. ב מאמרי העזרה מופיעה רשימה של שדות שאפשר למיין לפיהם.
אפשר להשתמש בדגלים --format ו---flatten כדי לעצב את הפלט של ה-CLI של gcloud.
כל האפשרויות מפורטות במדריך העזר ל-CLI של gcloud.
דוגמה
מריצים את הפקודה הבאה כדי לקבל רשימה של כל המכונות של Compute Engine (compute.googleapis.com/Instance) בפרויקט my-project, עם מדיניות הרשאות של IAM שמקשרת אותן למשתמש alex@example.com. התוצאות מוצגות בסדר יורד לפי משאב (resource DESC).
gcloud asset search-all-iam-policies \ --scope=projects/my-project \ --query="policy:\"user:alex@example.com\"" \ --asset-types=compute.googleapis.com/Instance \ --order-by="resource DESC"
דוגמה לתשובה
---
assetType: compute.googleapis.com/Instance
folders:
- folders/0000000000000
organization: organizations/0000000000000
policy:
bindings:
- members:
- user:alex@example.com
role: roles/compute.viewer
- members:
- user:alex@example.com
role: roles/editor
- members:
- user:alex@example.com
role: roles/owner
project: projects/0000000000000
resource: //compute.googleapis.com/projects/my-project/zones/us-central1-a/instances/debian
REST
ה-method של ה-HTTP וכתובת ה-URL:
POST https://cloudasset.googleapis.com/v1/SCOPE_PATH:searchAllIamPolicies
תוכן בקשת JSON:
{ "query": "QUERY", "assetTypes": [ "ASSET_TYPE_1", "ASSET_TYPE_2", "..." ], "orderBy": "ORDER_BY", "pageSize": "PAGE_SIZE", "pageToken": "PAGE_TOKEN" }
מספקים את הערכים הבאים:
-
SCOPE_PATH: משתמשים באחד מהערכים הבאים:-
projects/PROJECT_ID, כאשרPROJECT_IDהוא מזהה הפרויקט שבו נמצאים הנכסים עם כללי מדיניות ההרשאה של IAM שרוצים לחפש. -
projects/PROJECT_NUMBER, כאשרPROJECT_NUMBERהוא מספר הפרויקט שיש בו נכסים עם כללי מדיניות הרשאה של IAM שרוצים לחפש.איך מוצאים את Google Cloud מספר הפרויקט
מסוףGoogle Cloud
כדי למצוא את מספר הפרויקט ב- Google Cloud :
-
נכנסים לדף Welcome במסוף Google Cloud .
- לוחצים על תיבת הרשימה switcher בסרגל התפריטים.
-
בוחרים את הארגון מתיבת הרשימה ומחפשים את שם הפרויקט. שם הפרויקט, מספר הפרויקט ומזהה הפרויקט מופיעים ליד הכותרת Welcome.
מוצגים עד 4,000 משאבים. אם הפרויקט שחיפשתם לא מופיע, נכנסים לדף Manage resources ומסננים את הרשימה לפי שם הפרויקט.
CLI של gcloud
כדי לאחזר את מספר הפרויקט, משתמשים בפקודה הבאה: Google Cloud
gcloud projects describe PROJECT_ID --format="value(projectNumber)"
-
-
folders/FOLDER_ID, כאשרFOLDER_IDהוא המזהה של התיקייה שכוללת נכסים עם מדיניות ההרשאות של IAM שרוצים לחפש.איך מוצאים את המזהה של תיקיית Google Cloud
מסוףGoogle Cloud
כדי למצוא את המזהה של תיקיית Google Cloud :
-
נכנסים למסוף Google Cloud .
- לוחצים על תיבת הרשימה switcher בסרגל התפריטים.
- בוחרים את הארגון שלכם בתיבת הרשימה.
- מחפשים את שם התיקייה. מזהה התיקייה מוצג לצד שם התיקייה.
CLI של gcloud
כדי לאחזר את המזהה של תיקייה ברמת הארגון, מריצים את הפקודה הבאה: Google Cloud
gcloud resource-manager folders list \ --organization=$(gcloud organizations describe ORGANIZATION_NAME \ --format="value(name.segment(1))") \ --filter='"DISPLAY_NAME":"TOP_LEVEL_FOLDER_NAME"' \ --format="value(ID)"
כאשר TOP_LEVEL_FOLDER_NAME הוא התאמה חלקית או מלאה של מחרוזת לשם התיקייה. מסירים את הדגל
--formatכדי לראות מידע נוסף על התיקיות שנמצאו.הפקודה הקודמת לא מחזירה את המזהים של תיקיות משנה בתוך תיקיות. כדי לעשות את זה, מריצים את הפקודה הבאה באמצעות המזהה של התיקייה ברמה העליונה:
gcloud resource-manager folders list --folder=FOLDER_ID
-
-
organizations/ORGANIZATION_ID, כאשרORGANIZATION_IDהוא המזהה של הארגון שיש לו נכסים עם כללי מדיניות ההרשאה של IAM שרוצים לחפש.איך מוצאים את המזהה של ארגון ב- Google Cloud
מסוףGoogle Cloud
כדי למצוא את המזהה של ארגון ב- Google Cloud :
-
נכנסים למסוף Google Cloud .
- לוחצים על תיבת הרשימה switcher בסרגל התפריטים.
- בוחרים את הארגון שלכם בתיבת הרשימה.
- לוחצים על הכרטיסייה הכול. מזהה הארגון מופיע לצד שם הארגון.
CLI של gcloud
כדי לאחזר את המזהה של ארגון ב- Google Cloud , משתמשים בפקודה הבאה:
gcloud organizations describe ORGANIZATION_NAME --format="value(name.segment(1))"
-
-
-
QUERY: אופציונלי. ביטוי השאילתה. אם לא צוין ערך או שהערך ריק, החיפוש יתבצע בכל המשאבים בהיקף שצוין. כדי ללמוד איך לכתוב שאילתת חיפוש, קראו את המאמר תחביר של שאילתת חיפוש. -
ASSET_TYPE_#: אופציונלי. מערך של סוגי נכסים שניתן לחפש. יש תמיכה בביטויים רגולריים שתואמים ל-RE2. אם הביטוי הרגולרי לא תואם לאף סוג נכס נתמך, תוחזר שגיאתINVALID_ARGUMENT. אם לא מציינים אתassetTypes, מוחזרים כל סוגי הנכסים. -
ORDER_BY: אופציונלי. רשימה מופרדת בפסיקים של שדות שמציינים את סדר המיון של התוצאות. ברירת המחדל מוגדרת לסדר עולה. כדי לציין סדר יורד, מוסיפיםDESCאחרי שם השדה. ב מאמרי העזרה מופיעה רשימה של שדות שאפשר למיין לפיהם. -
PAGE_SIZE: אופציונלי. מספר התוצאות שיוצגו בכל דף. המספר המקסימלי הוא 500. אם הערך מוגדר כ-0או כערך שלילי, נבחרת ברירת מחדל מתאימה. מוחזרnextPageTokenכדי לאחזר את התוצאות הבאות. -
PAGE_TOKEN: אופציונלי. תשובות ארוכות לבקשות מחולקות לכמה דפים. אם לא מציינים אתpageToken, מוצג הדף הראשון. כדי לקרוא לדפים הבאים, אפשר להשתמש ב-nextPageTokenשל התגובה הקודמת בתור הערך שלpageToken.
כל האפשרויות מפורטות במאמר העזרה בנושא REST.
דוגמאות לפקודות
מריצים אחת מהפקודות הבאות כדי לקבל רשימה של כל המכונות של Compute Engine (compute.googleapis.com/Instance) בפרויקט my-project עם מדיניות הרשאות של IAM שמקשרת אותן למשתמש alex@example.com. התוצאות מוצגות בסדר יורד לפי משאב (resource DESC).
Curl (Linux, macOS או Cloud Shell)
curl -X POST \ -H "X-HTTP-Method-Override: GET" \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d '{ "query": "policy:\"user:alex@example.com\"", "assetTypes": ["compute.googleapis.com/Instance"], "orderBy": "resource DESC" }' \ https://cloudasset.googleapis.com/v1/projects/my-project:searchAllIamPolicies
PowerShell (Windows)
$cred = gcloud auth print-access-token $headers = @{ "X-HTTP-Method-Override" = "GET"; "Authorization" = "Bearer $cred" } $body = @" { "query": "policy:\"user:alex@example.com\"", "assetTypes": ["compute.googleapis.com/Instance"], "orderBy": "resource DESC" } "@ Invoke-WebRequest ` -Method POST ` -Headers $headers ` -ContentType: "application/json; charset=utf-8" ` -Body $body ` -Uri "https://cloudasset.googleapis.com/v1/projects/my-project:searchAllIamPolicies" | Select-Object -Expand Content
דוגמה לתשובה
{ "resource": "//compute.googleapis.com/projects/my-project/zones/us-central1-a/instances/debian", "project": "projects/0000000000000", "policy": { "bindings": [ { "role": "roles/compute.viewer", "members": [ "user:alex@example.com" ] }, { "role": "roles/editor", "members": [ "user:alex@example.com" ] }, { "role": "roles/owner", "members": [ "user:alex@example.com" ] } ] }, "assetType": "compute.googleapis.com/Instance", "folders": [ "folders/0000000000000" ], "organization": "organizations/0000000000000" }
C#
מידע על התקנת ספריית הלקוח של מאגר משאבי ענן והשימוש בה מופיע במאמר ספריות הלקוח של מאגר משאבי ענן.
כדי לבצע אימות במאגר משאבי ענן, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.
המשך
מידע על התקנת ספריית הלקוח של מאגר משאבי ענן והשימוש בה מופיע במאמר ספריות הלקוח של מאגר משאבי ענן.
כדי לבצע אימות במאגר משאבי ענן, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.
Java
מידע על התקנת ספריית הלקוח של מאגר משאבי ענן והשימוש בה מופיע במאמר ספריות הלקוח של מאגר משאבי ענן.
כדי לבצע אימות במאגר משאבי ענן, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.
Node.js
מידע על התקנת ספריית הלקוח של מאגר משאבי ענן והשימוש בה מופיע במאמר ספריות הלקוח של מאגר משאבי ענן.
כדי לבצע אימות במאגר משאבי ענן, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.
PHP
מידע על התקנת ספריית הלקוח של מאגר משאבי ענן והשימוש בה מופיע במאמר ספריות הלקוח של מאגר משאבי ענן.
כדי לבצע אימות במאגר משאבי ענן, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.
Python
מידע על התקנת ספריית הלקוח של מאגר משאבי ענן והשימוש בה מופיע במאמר ספריות הלקוח של מאגר משאבי ענן.
כדי לבצע אימות במאגר משאבי ענן, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.
Ruby
מידע על התקנת ספריית הלקוח של מאגר משאבי ענן והשימוש בה מופיע במאמר ספריות הלקוח של מאגר משאבי ענן.
כדי לבצע אימות במאגר משאבי ענן, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.
דוגמאות נוספות לחיפוש
דוגמאות הקוד הבאות מציגות שאילתות חיפוש ספציפיות ל-gcloud ול-REST, כדי לעזור לכם ליצור חיפושים משלכם.
משאבים עם מדיניות הרשאות של IAM
בדוגמה הבאה אפשר לראות איך מחפשים את כל המשאבים עם מדיניות ההרשאות של IAM בפרויקט my-project.
gcloud
gcloud asset search-all-iam-policies \ --scope=projects/my-project \ --flatten="policy.bindings[].members[]" \ --format="table(resource, policy.bindings.role, policy.bindings.members)"
REST
ה-method של ה-HTTP וכתובת ה-URL:
GET https://cloudasset.googleapis.com/v1/projects/my-project:searchAllIamPolicies
דוגמאות לפקודות
Curl (Linux, macOS או Cloud Shell)
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ https://cloudasset.googleapis.com/v1/projects/my-project:searchAllIamPolicies
PowerShell (Windows)
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://cloudasset.googleapis.com/v1/projects/my-project:searchAllIamPolicies" | Select-Object -Expand Content
משאבים עם שם ועם מדיניות הרשאות של IAM
בדוגמה הבאה אפשר לראות איך מחפשים את כל המשאבים שהשם שלהם מכיל את המחרוזת example ויש להם כללי מדיניות הרשאה ב-IAM.
gcloud
gcloud asset search-all-iam-policies \ --scope=projects/my-project \ --query="resource:example"
REST
ה-method של ה-HTTP וכתובת ה-URL:
POST https://cloudasset.googleapis.com/v1/projects/my-project:searchAllIamPolicies
תוכן בקשת JSON:
{ "pageSize": 1, "query": "resource:example" }
דוגמאות לפקודות
Curl (Linux, macOS או Cloud Shell)
curl -X POST \ -H "X-HTTP-Method-Override: GET" \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d '{ "pageSize": 1, "query": "resource:example" }' \ https://cloudasset.googleapis.com/v1/projects/my-project:searchAllIamPolicies
PowerShell (Windows)
$cred = gcloud auth print-access-token $headers = @{ "X-HTTP-Method-Override" = "GET"; "Authorization" = "Bearer $cred" } $body = @" { "pageSize": 1, "query": "resource:example" } "@ Invoke-WebRequest ` -Method POST ` -Headers $headers ` -ContentType: "application/json; charset=utf-8" ` -Body $body ` -Uri "https://cloudasset.googleapis.com/v1/projects/my-project:searchAllIamPolicies" | Select-Object -Expand Content
כללי מדיניות הרשאות של IAM בפרויקטים, בתיקיות ובארגונים
בדוגמה הבאה מוסבר איך לחפש את כל כללי מדיניות ההרשאות של IAM בכל הפרויקטים והתיקיות בארגון עם המזהה my-organization-id.
איך מוצאים את המזהה של ארגון ב- Google Cloud
מסוףGoogle Cloud
כדי למצוא את המזהה של ארגון ב- Google Cloud :
-
נכנסים למסוף Google Cloud .
- לוחצים על תיבת הרשימה switcher בסרגל התפריטים.
- בוחרים את הארגון שלכם בתיבת הרשימה.
- לוחצים על הכרטיסייה הכול. מזהה הארגון מופיע לצד שם הארגון.
CLI של gcloud
כדי לאחזר את המזהה של ארגון ב- Google Cloud , משתמשים בפקודה הבאה:
gcloud organizations describe ORGANIZATION_NAME --format="value(name.segment(1))"
gcloud
gcloud asset search-all-iam-policies \ --scope=organizations/my-organization-id \ --asset-types=cloudresourcemanager.*
REST
ה-method של ה-HTTP וכתובת ה-URL:
POST https://cloudasset.googleapis.com/v1/organizations/my-organization-id:searchAllIamPolicies
תוכן בקשת JSON:
{ "assetTypes": "cloudresourcemanager.*", "pageSize": 1, }
דוגמאות לפקודות
Curl (Linux, macOS או Cloud Shell)
curl -X POST \ -H "X-HTTP-Method-Override: GET" \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d '{ "assetTypes": "cloudresourcemanager.*", "pageSize": 1, }' \ https://cloudasset.googleapis.com/v1/organizations/my-organization-id:searchAllIamPolicies
PowerShell (Windows)
$cred = gcloud auth print-access-token $headers = @{ "X-HTTP-Method-Override" = "GET"; "Authorization" = "Bearer $cred" } $body = @" { "assetTypes": "cloudresourcemanager.*", "pageSize": 1, } "@ Invoke-WebRequest ` -Method POST ` -Headers $headers ` -ContentType: "application/json; charset=utf-8" ` -Body $body ` -Uri "https://cloudasset.googleapis.com/v1/organizations/my-organization-id:searchAllIamPolicies" | Select-Object -Expand Content
בעלים בפרויקט
בדוגמה הבאה מוסבר איך לחפש חשבונות משתמשים עם התפקיד "בעלים" (roles/owner) בפרויקט my-project.
הבקשה הזו מחזירה רק חשבונות משתמשים שקיבלו את התפקיד "בעלים" בפרויקט. הוא לא כולל חשבונות משתמשים שירשו את התפקיד "בעלים" באמצעות ירושה של מדיניות.
gcloud
gcloud asset search-all-iam-policies \ --scope=projects/my-project \ --query="roles:roles/owner" \ --asset-types=cloudresourcemanager.* \ --flatten="policy.bindings[].members[]" \ --format="table(policy.bindings.members)"
REST
ה-method של ה-HTTP וכתובת ה-URL:
POST https://cloudasset.googleapis.com/v1/projects/my-project:searchAllIamPolicies
תוכן בקשת JSON:
{ "assetTypes": "cloudresourcemanager.*", "pageSize": 1, "query": "roles:roles/owner" }
דוגמאות לפקודות
Curl (Linux, macOS או Cloud Shell)
curl -X POST \ -H "X-HTTP-Method-Override: GET" \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d '{ "assetTypes": "cloudresourcemanager.*", "pageSize": 1, "query": "roles:roles/owner" }' \ https://cloudasset.googleapis.com/v1/projects/my-project:searchAllIamPolicies
PowerShell (Windows)
$cred = gcloud auth print-access-token $headers = @{ "X-HTTP-Method-Override" = "GET"; "Authorization" = "Bearer $cred" } $body = @" { "assetTypes": "cloudresourcemanager.*", "pageSize": 1, "query": "roles:roles/owner" } "@ Invoke-WebRequest ` -Method POST ` -Headers $headers ` -ContentType: "application/json; charset=utf-8" ` -Body $body ` -Uri "https://cloudasset.googleapis.com/v1/projects/my-project:searchAllIamPolicies" | Select-Object -Expand Content
פרויקטים שבהם לחשבון משתמש יש את תפקיד הבעלים
בדוגמה הבאה מוסבר איך לחפש פרויקטים שבהם למשתמש alex@example.com יש את התפקיד "בעלים" (roles/owner), בארגון עם המזהה my-organization-id.
הבקשה הזו מחזירה רק את הפרויקטים שבהם הוקצה למשתמש alex@example.com התפקיד "בעלים". הוא לא כולל פרויקטים שבהם alex@example.com ירש את התפקיד "בעלים".
איך מוצאים את המזהה של ארגון ב- Google Cloud
מסוףGoogle Cloud
כדי למצוא את המזהה של ארגון ב- Google Cloud :
-
נכנסים למסוף Google Cloud .
- לוחצים על תיבת הרשימה switcher בסרגל התפריטים.
- בוחרים את הארגון שלכם בתיבת הרשימה.
- לוחצים על הכרטיסייה הכול. מזהה הארגון מופיע לצד שם הארגון.
CLI של gcloud
כדי לאחזר את המזהה של ארגון ב- Google Cloud , משתמשים בפקודה הבאה:
gcloud organizations describe ORGANIZATION_NAME --format="value(name.segment(1))"
gcloud
gcloud asset search-all-iam-policies \ --scope=organizations/my-organization-id \ --query="policy:(roles/owner alex@example.com)" \ --asset-types=cloudresourcemanager.googleapis.com/Project \ --format="table(resource)"
REST
ה-method של ה-HTTP וכתובת ה-URL:
POST https://cloudasset.googleapis.com/v1/organizations/my-organization-id:searchAllIamPolicies
תוכן בקשת JSON:
{ "assetTypes": "cloudresourcemanager.googleapis.com/Project", "pageSize": 1, "query": "policy:(roles/owner alex@example.com)" }
דוגמאות לפקודות
Curl (Linux, macOS או Cloud Shell)
curl -X POST \ -H "X-HTTP-Method-Override: GET" \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d '{ "assetTypes": "cloudresourcemanager.googleapis.com/Project", "pageSize": 1, "query": "policy:(roles/owner alex@example.com)" }' \ https://cloudasset.googleapis.com/v1/organizations/my-organization-id:searchAllIamPolicies
PowerShell (Windows)
$cred = gcloud auth print-access-token $headers = @{ "X-HTTP-Method-Override" = "GET"; "Authorization" = "Bearer $cred" } $body = @" { "assetTypes": "cloudresourcemanager.googleapis.com/Project", "pageSize": 1, "query": "policy:(roles/owner alex@example.com)" } "@ Invoke-WebRequest ` -Method POST ` -Headers $headers ` -ContentType: "application/json; charset=utf-8" ` -Body $body ` -Uri "https://cloudasset.googleapis.com/v1/organizations/my-organization-id:searchAllIamPolicies" | Select-Object -Expand Content
תפקידים של חשבון משתמש בפרויקט
בדוגמה הבאה אפשר לראות איך מחפשים את התפקידים של alex@example.com בפרויקט my-project.
הבקשה הזו מחזירה רק את התפקידים שניתנו ל-alex@example.com בפרויקט. היא לא כוללת תפקידים ש-alex@example.com קיבל באמצעות ירושה של מדיניות.
gcloud
gcloud asset search-all-iam-policies \ --scope=projects/my-project \ --query="policy:alex@example.com" \ --asset-types=cloudresourcemanager.googleapis.com/Project \ --flatten="policy.bindings[]" \ --format="table(policy.bindings.role)"
REST
ה-method של ה-HTTP וכתובת ה-URL:
POST https://cloudasset.googleapis.com/v1/projects/my-project:searchAllIamPolicies
תוכן בקשת JSON:
{ "assetTypes": "cloudresourcemanager.googleapis.com/Project", "pageSize": 1, "query": "policy:alex@example.com" }
דוגמאות לפקודות
Curl (Linux, macOS או Cloud Shell)
curl -X POST \ -H "X-HTTP-Method-Override: GET" \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d '{ "assetTypes": "cloudresourcemanager.googleapis.com/Project", "pageSize": 1, "query": "policy:alex@example.com" }' \ https://cloudasset.googleapis.com/v1/projects/my-project:searchAllIamPolicies
PowerShell (Windows)
$cred = gcloud auth print-access-token $headers = @{ "X-HTTP-Method-Override" = "GET"; "Authorization" = "Bearer $cred" } $body = @" { "assetTypes": "cloudresourcemanager.googleapis.com/Project", "pageSize": 1, "query": "policy:alex@example.com" } "@ Invoke-WebRequest ` -Method POST ` -Headers $headers ` -ContentType: "application/json; charset=utf-8" ` -Body $body ` -Uri "https://cloudasset.googleapis.com/v1/projects/my-project:searchAllIamPolicies" | Select-Object -Expand Content
הרשאות שיש לחשבון משתמש בפרויקט
בדוגמה הבאה אפשר לראות איך מחפשים את ההרשאות שיש ל-alex@example.com בפרויקט my-project.
הבקשה הזו מחזירה רק את ההרשאות שיש ל-alex@example.com בפרויקט. היא לא כוללת הרשאות ש-alex@example.com קיבל בירושה באמצעות מדיניות שעברה בירושה.
gcloud
gcloud asset search-all-iam-policies \ --scope=projects/my-project \ --query="policy:alex@example.com policy.role.permissions:\"\"" \ --asset-types=cloudresourcemanager.* \ --format="default(explanation.matchedPermissions)"
REST
ה-method של ה-HTTP וכתובת ה-URL:
POST https://cloudasset.googleapis.com/v1/projects/my-project:searchAllIamPolicies
תוכן בקשת JSON:
{ "assetTypes": "cloudresourcemanager.*", "pageSize": 1, "query": "policy:alex@example.com policy.role.permissions:\"\"" }
דוגמאות לפקודות
Curl (Linux, macOS או Cloud Shell)
curl -X POST \ -H "X-HTTP-Method-Override: GET" \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d '{ "assetTypes": "cloudresourcemanager.*", "pageSize": 1, "query": "policy:alex@example.com policy.role.permissions:\"\"" }' \ https://cloudasset.googleapis.com/v1/projects/my-project:searchAllIamPolicies
PowerShell (Windows)
$cred = gcloud auth print-access-token $headers = @{ "X-HTTP-Method-Override" = "GET"; "Authorization" = "Bearer $cred" } $body = @" { "assetTypes": "cloudresourcemanager.*", "pageSize": 1, "query": "policy:alex@example.com policy.role.permissions:\"\"" } "@ Invoke-WebRequest ` -Method POST ` -Headers $headers ` -ContentType: "application/json; charset=utf-8" ` -Body $body ` -Uri "https://cloudasset.googleapis.com/v1/projects/my-project:searchAllIamPolicies" | Select-Object -Expand Content
חשבונות משתמשים שיכולים לגשת לקטגוריות של Cloud Storage
בדוגמה הבאה מוסבר איך לחפש חשבונות משתמשים שיכולים לגשת לקטגוריות של Cloud Storage בפרויקט my-project.
gcloud
gcloud asset search-all-iam-policies \ --scope=projects/my-project \ --query="policy.role.permissions:storage.buckets" \ --asset-types=cloudresourcemanager.* \ --flatten="policy.bindings[].members[]" \ --format="table(policy.bindings.members)"
REST
ה-method של ה-HTTP וכתובת ה-URL:
POST https://cloudasset.googleapis.com/v1/projects/my-project:searchAllIamPolicies
תוכן בקשת JSON:
{ "assetTypes": "cloudresourcemanager.*", "pageSize": 1, "query": "policy.role.permissions:storage.buckets" }
דוגמאות לפקודות
Curl (Linux, macOS או Cloud Shell)
curl -X POST \ -H "X-HTTP-Method-Override: GET" \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d '{ "assetTypes": "cloudresourcemanager.*", "pageSize": 1, "query": "policy.role.permissions:storage.buckets" }' \ https://cloudasset.googleapis.com/v1/projects/my-project:searchAllIamPolicies
PowerShell (Windows)
$cred = gcloud auth print-access-token $headers = @{ "X-HTTP-Method-Override" = "GET"; "Authorization" = "Bearer $cred" } $body = @" { "assetTypes": "cloudresourcemanager.*", "pageSize": 1, "query": "policy.role.permissions:storage.buckets" } "@ Invoke-WebRequest ` -Method POST ` -Headers $headers ` -ContentType: "application/json; charset=utf-8" ` -Body $body ` -Uri "https://cloudasset.googleapis.com/v1/projects/my-project:searchAllIamPolicies" | Select-Object -Expand Content
חשבונות שירות עם תפקיד בעלים
בדוגמה הבאה מוסבר איך לחפש חשבונות שירות עם התפקיד 'בעלים' (roles/owner) בארגון עם המזהה my-organization-id. אתם יכולים להשתמש בשאילתה הזו כדי לצמצם את פרופיל הסיכון.
איך מוצאים את המזהה של ארגון ב- Google Cloud
מסוףGoogle Cloud
כדי למצוא את המזהה של ארגון ב- Google Cloud :
-
נכנסים למסוף Google Cloud .
- לוחצים על תיבת הרשימה switcher בסרגל התפריטים.
- בוחרים את הארגון שלכם בתיבת הרשימה.
- לוחצים על הכרטיסייה הכול. מזהה הארגון מופיע לצד שם הארגון.
CLI של gcloud
כדי לאחזר את המזהה של ארגון ב- Google Cloud , משתמשים בפקודה הבאה:
gcloud organizations describe ORGANIZATION_NAME --format="value(name.segment(1))"
gcloud
בדוגמה הזו נעשה שימוש בפקודה `grep`, שזמינה ב-Cloud Shell ובמערכות הפעלה דמויות Unix.
gcloud asset search-all-iam-policies \ --scope=organizations/my-organization-id \ --query="policy:(roles/owner serviceAccount)" \ --flatten="policy.bindings[].members[]" \ --format="table(resource.segment(3):label=RESOURCE_TYPE, resource.basename():label=RESOURCE, policy.bindings.members)" | grep serviceAccount
REST
ה-method של ה-HTTP וכתובת ה-URL:
POST https://cloudasset.googleapis.com/v1/organizations/my-organization-id:searchAllIamPolicies
תוכן בקשת JSON:
{ "pageSize": 1, "query": "policy:(roles/owner serviceAccount)" }
דוגמאות לפקודות
Curl (Linux, macOS או Cloud Shell)
curl -X POST \ -H "X-HTTP-Method-Override: GET" \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d '{ "pageSize": 1, "query": "policy:(roles/owner serviceAccount)" }' \ https://cloudasset.googleapis.com/v1/organizations/my-organization-id:searchAllIamPolicies
PowerShell (Windows)
$cred = gcloud auth print-access-token $headers = @{ "X-HTTP-Method-Override" = "GET"; "Authorization" = "Bearer $cred" } $body = @" { "pageSize": 1, "query": "policy:(roles/owner serviceAccount)" } "@ Invoke-WebRequest ` -Method POST ` -Headers $headers ` -ContentType: "application/json; charset=utf-8" ` -Body $body ` -Uri "https://cloudasset.googleapis.com/v1/organizations/my-organization-id:searchAllIamPolicies" | Select-Object -Expand Content
משאבים עם תפקידים שהוקצו לדומיין
בדוגמה הבאה אפשר לראות איך מחפשים משאבים עם תפקידים שהוקצו לדומיין example.com, בארגון עם המזהה my-organization-id.
איך מוצאים את המזהה של ארגון ב- Google Cloud
מסוףGoogle Cloud
כדי למצוא את המזהה של ארגון ב- Google Cloud :
-
נכנסים למסוף Google Cloud .
- לוחצים על תיבת הרשימה switcher בסרגל התפריטים.
- בוחרים את הארגון שלכם בתיבת הרשימה.
- לוחצים על הכרטיסייה הכול. מזהה הארגון מופיע לצד שם הארגון.
CLI של gcloud
כדי לאחזר את המזהה של ארגון ב- Google Cloud , משתמשים בפקודה הבאה:
gcloud organizations describe ORGANIZATION_NAME --format="value(name.segment(1))"
gcloud
gcloud asset search-all-iam-policies \ --scope=organizations/my-organization-id \ --query="policy:\"domain:example.com\"" \ --flatten="policy.bindings[]" \ --format="table(resource, policy.bindings.role)"
REST
ה-method של ה-HTTP וכתובת ה-URL:
POST https://cloudasset.googleapis.com/v1/organizations/my-organization-id:searchAllIamPolicies
תוכן בקשת JSON:
{ "pageSize": 1, "query": "policy:\"domain:DOMAIN_NAME\"" }
דוגמאות לפקודות
Curl (Linux, macOS או Cloud Shell)
curl -X POST \ -H "X-HTTP-Method-Override: GET" \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d '{ "pageSize": 1, "query": "policy:\"domain:DOMAIN_NAME\"" }' \ https://cloudasset.googleapis.com/v1/organizations/my-organization-id:searchAllIamPolicies
PowerShell (Windows)
$cred = gcloud auth print-access-token $headers = @{ "X-HTTP-Method-Override" = "GET"; "Authorization" = "Bearer $cred" } $body = @" { "pageSize": 1, "query": "policy:\"domain:DOMAIN_NAME\"" } "@ Invoke-WebRequest ` -Method POST ` -Headers $headers ` -ContentType: "application/json; charset=utf-8" ` -Body $body ` -Uri "https://cloudasset.googleapis.com/v1/organizations/my-organization-id:searchAllIamPolicies" | Select-Object -Expand Content
משאבים עם תפקידים שניתנו לציבור
בדוגמה הבאה אפשר לראות איך מחפשים משאבים עם תפקידים שניתנו לציבור, בארגון עם המזהה my-organization-id.
איך מוצאים את המזהה של ארגון ב- Google Cloud
מסוףGoogle Cloud
כדי למצוא את המזהה של ארגון ב- Google Cloud :
-
נכנסים למסוף Google Cloud .
- לוחצים על תיבת הרשימה switcher בסרגל התפריטים.
- בוחרים את הארגון שלכם בתיבת הרשימה.
- לוחצים על הכרטיסייה הכול. מזהה הארגון מופיע לצד שם הארגון.
CLI של gcloud
כדי לאחזר את המזהה של ארגון ב- Google Cloud , משתמשים בפקודה הבאה:
gcloud organizations describe ORGANIZATION_NAME --format="value(name.segment(1))"
gcloud
gcloud asset search-all-iam-policies \ --scope=organizations/my-organization-id \ --query="memberTypes:(allUsers OR allAuthenticatedUsers)" \ --format="table(resource)"
REST
ה-method של ה-HTTP וכתובת ה-URL:
POST https://cloudasset.googleapis.com/v1/organizations/my-organization-id:searchAllIamPolicies
תוכן בקשת JSON:
{ "pageSize": 1, "query": "memberTypes:(allUsers OR allAuthenticatedUsers)" }
דוגמאות לפקודות
Curl (Linux, macOS או Cloud Shell)
curl -X POST \ -H "X-HTTP-Method-Override: GET" \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d '{ "pageSize": 1, "query": "memberTypes:(allUsers OR allAuthenticatedUsers)" }' \ https://cloudasset.googleapis.com/v1/organizations/my-organization-id:searchAllIamPolicies
PowerShell (Windows)
$cred = gcloud auth print-access-token $headers = @{ "X-HTTP-Method-Override" = "GET"; "Authorization" = "Bearer $cred" } $body = @" { "pageSize": 1, "query": "memberTypes:(allUsers OR allAuthenticatedUsers)" } "@ Invoke-WebRequest ` -Method POST ` -Headers $headers ` -ContentType: "application/json; charset=utf-8" ` -Body $body ` -Uri "https://cloudasset.googleapis.com/v1/organizations/my-organization-id:searchAllIamPolicies" | Select-Object -Expand Content
חשבונות משתמשים שיכולים לשנות את מדיניות ההרשאות של IAM בארגון
בדוגמה הבאה אפשר לראות איך לחפש חשבונות משתמשים שיכולים לשנות את מדיניות ההרשאות של IAM בארגון עם המזהה my-organization-id.
איך מוצאים את המזהה של ארגון ב- Google Cloud
מסוףGoogle Cloud
כדי למצוא את המזהה של ארגון ב- Google Cloud :
-
נכנסים למסוף Google Cloud .
- לוחצים על תיבת הרשימה switcher בסרגל התפריטים.
- בוחרים את הארגון שלכם בתיבת הרשימה.
- לוחצים על הכרטיסייה הכול. מזהה הארגון מופיע לצד שם הארגון.
CLI של gcloud
כדי לאחזר את המזהה של ארגון ב- Google Cloud , משתמשים בפקודה הבאה:
gcloud organizations describe ORGANIZATION_NAME --format="value(name.segment(1))"
gcloud
gcloud asset search-all-iam-policies \ --scope=organizations/my-organization-id \ --query="policy.role.permissions:(resourcemanager.organizations.setIamPolicy OR resourcemanager.folders.setIamPolicy OR resourcemanager.projects.setIamPolicy)" \ --format="json(resource, policy.bindings, explanation.matchedPermissions)"
REST
ה-method של ה-HTTP וכתובת ה-URL:
POST https://cloudasset.googleapis.com/v1/organizations/my-organization-id:searchAllIamPolicies
תוכן בקשת JSON:
{ "pageSize": 1, "query": "policy.role.permissions:(resourcemanager.organizations.setIamPolicy OR resourcemanager.folders.setIamPolicy OR resourcemanager.projects.setIamPolicy)" }
דוגמאות לפקודות
Curl (Linux, macOS או Cloud Shell)
curl -X POST \ -H "X-HTTP-Method-Override: GET" \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d '{ "pageSize": 1, "query": "policy.role.permissions:(resourcemanager.organizations.setIamPolicy OR resourcemanager.folders.setIamPolicy OR resourcemanager.projects.setIamPolicy)" }' \ https://cloudasset.googleapis.com/v1/organizations/my-organization-id:searchAllIamPolicies
PowerShell (Windows)
$cred = gcloud auth print-access-token $headers = @{ "X-HTTP-Method-Override" = "GET"; "Authorization" = "Bearer $cred" } $body = @" { "pageSize": 1, "query": "policy.role.permissions:(resourcemanager.organizations.setIamPolicy OR resourcemanager.folders.setIamPolicy OR resourcemanager.projects.setIamPolicy)" } "@ Invoke-WebRequest ` -Method POST ` -Headers $headers ` -ContentType: "application/json; charset=utf-8" ` -Body $body ` -Uri "https://cloudasset.googleapis.com/v1/organizations/my-organization-id:searchAllIamPolicies" | Select-Object -Expand Content