יצירת אילוצים מותאמים אישית של מדיניות הארגון

בדף הזה מוסבר איך להשתמש באילוצים בהתאמה אישית של שירות מדיניות הארגון כדי להגביל פעולות ספציפיות במשאבים הבאים של Google Cloud :

  • dataform.googleapis.com/CompilationResult
  • dataform.googleapis.com/Folder
  • dataform.googleapis.com/ReleaseConfig
  • dataform.googleapis.com/Repository
  • dataform.googleapis.com/TeamFolder
  • dataform.googleapis.com/WorkflowConfig
  • dataform.googleapis.com/WorkflowInvocation
  • dataform.googleapis.com/Workspace

מידע נוסף על מדיניות הארגון בהתאמה אישית

מידע על כללי מדיניות ואילוצים של הארגון

Google Cloud שירות מדיניות הארגון נותן לכם שליטה מרוכזת ופרוגרמטית על המשאבים של הארגון. אדמינים של מדיניות הארגון יכולים להגדיר מדיניות ארגונית, שהיא קבוצה של הגבלות שנקראות אילוצים. האילוצים האלה חלים על משאביGoogle Cloud ועל הצאצאים של המשאבים האלה בGoogle Cloud היררכיית המשאבים. אפשר לאכוף את מדיניות הארגון ברמת הארגון, התיקייה או הפרויקט.

מדיניות הארגון מספקת אילוצים מנוהלים מובְנים לשירותים שונים של Google Cloud . עם זאת, אם אתם רוצים שליטה מפורטת יותר בהתאמה אישית על השדות הספציפיים שמוגבלים במדיניות הארגון, אתם יכולים גם ליצור אילוצים בהתאמה אישית ולהשתמש בהם במדיניות הארגון.

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

כברירת מחדל, כללי המדיניות של הארגון עוברים בירושה לצאצאים של המשאבים שעליהם אתם אוכפים את המדיניות. לדוגמה, אם אוכפים מדיניות בתיקייה, Google Cloud אוכף את המדיניות בכל הפרויקטים שבתיקייה. למידע נוסף על ההתנהגות הזו ואיך לשנות אותה, קראו את המאמר כללי הערכה של היררכיה.

יתרונות

אתם יכולים להשתמש במדיניות ארגון בהתאמה אישית כדי לאשר או לדחות ערכים ספציפיים של משאבי Dataform. לדוגמה, אם בקשה ליצור או לעדכן משאב dataform.googleapis.com/Repository לא עוברת את האימות של האילוץ המותאם אישית שהוגדר במדיניות הארגון, הבקשה נכשלת ומוחזרת שגיאה למבצע הקריאה החוזרת.

השימוש במדיניות ארגונית בהתאמה אישית מוסיף עוד שכבה של אבטחה, תאימות ופיקוח. לדוגמה, אתם יכולים להגדיר כללי מדיניות שמאפשרים ליצור משאבים רק באזור מסוים, או שאוסרים על שימוש במאגרי Git מרוחקים מחוץ לארגון.

מגבלות

כמו כל האילוצים של מדיניות הארגון, שינויים במדיניות לא חלים רטרואקטיבית על משאבים קיימים:

  • מדיניות חדשה לא משפיעה על משאבים קיימים.
  • אם משנים את המדיניות, משאב קיים נשאר תקין, אלא אם משנים את המשאב מערך תואם לערך לא תואם באמצעות מסוףGoogle Cloud או RPC.

לפני שאוכפים מדיניות חדשה, מומלץ לוודא שכל המשאבים הקיימים תואמים למדיניות. כדי לבדוק אילו משאבים קיימים לא יעמדו בדרישות אחרי אכיפת מדיניות הארגון, אתם יכולים להשתמש בסימולטור המדיניות של הארגון.

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

  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. Install the Google Cloud CLI.

  5. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  6. To initialize the gcloud CLI, run the following command:

    gcloud init
  7. 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

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

  9. Install the Google Cloud CLI.

  10. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  11. To initialize the gcloud CLI, run the following command:

    gcloud init
  12. חשוב לוודא שאתם יודעים מהו מזהה הארגון שלכם.

התפקידים הנדרשים

כדי לקבל את ההרשאות שדרושות לניהול מדיניות ארגונית בהתאמה אישית, צריך לבקש מהאדמין להקצות לכם את התפקיד אדמין של מדיניות ארגונית (roles/orgpolicy.policyAdmin) ב-IAM במשאב הארגון. כדי לקרוא הסבר על מתן תפקידים, ראו איך מנהלים את הגישה ברמת הפרויקט, התיקייה והארגון.

יכול להיות שאפשר לקבל את ההרשאות הנדרשות גם באמצעות תפקידים בהתאמה אישית או תפקידים מוגדרים מראש.

משאבים נתמכים ב-Dataform

בטבלה הבאה מפורטים המשאבים של Dataform שאפשר להפנות אליהם באילוצים בהתאמה אישית.

משאב שדה
dataform.googleapis.com/CompilationResult resource.codeCompilationConfig.assertionSchema
resource.codeCompilationConfig.builtinAssertionNamePrefix
resource.codeCompilationConfig.databaseSuffix
resource.codeCompilationConfig.defaultDatabase
resource.codeCompilationConfig.defaultLocation
resource.codeCompilationConfig.defaultNotebookRuntimeOptions.aiPlatformNotebookRuntimeTemplate
resource.codeCompilationConfig.defaultNotebookRuntimeOptions.gcsOutputBucket
resource.codeCompilationConfig.defaultSchema
resource.codeCompilationConfig.schemaSuffix
resource.codeCompilationConfig.tablePrefix
resource.codeCompilationConfig.vars
resource.gitCommitish
resource.releaseConfig
resource.workspace
dataform.googleapis.com/Folder resource.containingFolder
resource.displayName
dataform.googleapis.com/ReleaseConfig resource.codeCompilationConfig.assertionSchema
resource.codeCompilationConfig.builtinAssertionNamePrefix
resource.codeCompilationConfig.databaseSuffix
resource.codeCompilationConfig.defaultDatabase
resource.codeCompilationConfig.defaultLocation
resource.codeCompilationConfig.defaultNotebookRuntimeOptions.aiPlatformNotebookRuntimeTemplate
resource.codeCompilationConfig.defaultNotebookRuntimeOptions.gcsOutputBucket
resource.codeCompilationConfig.defaultSchema
resource.codeCompilationConfig.schemaSuffix
resource.codeCompilationConfig.tablePrefix
resource.codeCompilationConfig.vars
resource.cronSchedule
resource.disabled
resource.gitCommitish
resource.name
resource.releaseCompilationResult
resource.timeZone
dataform.googleapis.com/Repository resource.containingFolder
resource.displayName
resource.gitRemoteSettings.authenticationTokenSecretVersion
resource.gitRemoteSettings.defaultBranch
resource.gitRemoteSettings.sshAuthenticationConfig.hostPublicKey
resource.gitRemoteSettings.sshAuthenticationConfig.userPrivateKeySecretVersion
resource.gitRemoteSettings.url
resource.kmsKeyName
resource.name
resource.npmrcEnvironmentVariablesSecretVersion
resource.serviceAccount
resource.setAuthenticatedUserAdmin
resource.workspaceCompilationOverrides.defaultDatabase
resource.workspaceCompilationOverrides.schemaSuffix
resource.workspaceCompilationOverrides.tablePrefix
dataform.googleapis.com/TeamFolder resource.displayName
dataform.googleapis.com/WorkflowConfig resource.cronSchedule
resource.disabled
resource.invocationConfig.endUserAuthConfig.oauthConfig.additionalOauthScopes
resource.invocationConfig.executionMode
resource.invocationConfig.fullyRefreshIncrementalTablesEnabled
resource.invocationConfig.includedTags
resource.invocationConfig.includedTargets.database
resource.invocationConfig.includedTargets.name
resource.invocationConfig.includedTargets.schema
resource.invocationConfig.queryPriority
resource.invocationConfig.serviceAccount
resource.invocationConfig.transitiveDependenciesIncluded
resource.invocationConfig.transitiveDependentsIncluded
resource.name
resource.releaseConfig
resource.timeZone
resource.workflowTriggerConfig.condition
resource.workflowTriggerConfig.maxWaitDuration
resource.workflowTriggerConfig.minExecutionDuration
resource.workflowTriggerConfig.workflowTriggers.tableUpdateTrigger.table.database
resource.workflowTriggerConfig.workflowTriggers.tableUpdateTrigger.table.name
resource.workflowTriggerConfig.workflowTriggers.tableUpdateTrigger.table.schema
dataform.googleapis.com/WorkflowInvocation resource.compilationResult
resource.invocationConfig.endUserAuthConfig.oauthConfig.additionalOauthScopes
resource.invocationConfig.executionMode
resource.invocationConfig.fullyRefreshIncrementalTablesEnabled
resource.invocationConfig.includedTags
resource.invocationConfig.includedTargets.database
resource.invocationConfig.includedTargets.name
resource.invocationConfig.includedTargets.schema
resource.invocationConfig.queryPriority
resource.invocationConfig.serviceAccount
resource.invocationConfig.transitiveDependenciesIncluded
resource.invocationConfig.transitiveDependentsIncluded
resource.workflowConfig
dataform.googleapis.com/Workspace resource.name

הגדרת אילוץ בהתאמה אישית

אילוץ בהתאמה אישית מוגדר בקובץ YAML לפי המשאבים, השיטות, התנאים והפעולות שנתמכים בשירות שבו אתם אוכפים את מדיניות הארגון. התנאים של האילוצים המותאמים אישית מוגדרים באמצעות Common Expression Language (CEL). בקטע CEL במאמר יצירה וניהול של אילוצים בהתאמה אישית מוסבר איך ליצור תנאים באילוצים בהתאמה אישית באמצעות CEL.

המסוף

כדי ליצור אילוץ בהתאמה אישית:

  1. במסוף Google Cloud , נכנסים לדף מדיניות הארגון.

    כניסה לדף Organization policies

  2. בכלי לבחירת פרויקטים, בוחרים את הפרויקט שרוצים להגדיר לו את מדיניות הארגון.
  3. לוחצים על Custom constraint.
  4. בתיבה Display name, מזינים שם לאילוץ שיהיה קריא לאנשים. השם הזה מופיע בהודעות שגיאה ואפשר להשתמש בו לזיהוי ולניפוי באגים. אל תשתמשו בפרטים אישיים מזהים (PII) או במידע רגיש בשמות לתצוגה, כי השם הזה עלול להיחשף בהודעות שגיאה. השדה הזה יכול להכיל עד 200 תווים.
  5. בתיבה Constraint ID, מזינים את המזהה שרוצים לתת לאילוץ החדש בהתאמה אישית. אילוץ בהתאמה אישית יכול להכיל רק אותיות (כולל אותיות רישיות וקטנות) או מספרים, לדוגמה custom.restrictRepositoryLocation. השדה הזה יכול להכיל עד 70 תווים, לא כולל הקידומת (custom.), לדוגמה, organizations/123456789/customConstraints/custom. אל תכללו פרטים אישיים מזהים (PII) או מידע רגיש במזהה האילוץ, כי הם עלולים להיחשף בהודעות שגיאה.
  6. בתיבה Description, מזינים תיאור קריא לאנשים של האילוץ. התיאור הזה משמש כהודעת שגיאה כשיש הפרה של המדיניות. ציינו פרטים על הסיבה להפרת המדיניות ואיך לפתור את הבעיה. אל תכללו פרטים אישיים מזהים (PII) או מידע רגיש בתיאור, כי הם עלולים להיחשף בהודעות שגיאה. השדה הזה יכול להכיל עד 2,000 תווים.
  7. בתיבה Resource type, בוחרים את השם של משאב ה- Google Cloud REST שמכיל את האובייקט והשדה שרוצים להגביל, לדוגמה container.googleapis.com/NodePool. רוב סוגי המשאבים תומכים בעד 20 אילוצים בהתאמה אישית. אם תנסו ליצור יותר אילוצים בהתאמה אישית, הפעולה תיכשל.
  8. בקטע Enforcement method, בוחרים אם לאכוף את האילוץ על שיטת REST CREATE או על השיטות CREATE ו-UPDATE. אם אוכפים את האילוץ באמצעות השיטה UPDATE במשאב שמפר את האילוץ, מדיניות הארגון חוסמת את השינויים במשאב הזה, אלא אם השינוי פותר את ההפרה.
  9. כדי לראות את השיטות הנתמכות לכל שירות, חפשו את השירות במאמר שירותים שתומכים באילוצים בהתאמה אישית.

  10. כדי להגדיר תנאי, לוחצים על עריכת התנאי.
    1. בחלונית Add condition, יוצרים תנאי CEL שמתייחס למשאב שירות נתמך, לדוגמה resource.management.autoUpgrade == false. השדה הזה יכול להכיל עד 1,000 תווים. לפרטים על השימוש ב-CEL, קראו את המאמר Common Expression Language. מידע נוסף על משאבי השירות שבהם אפשר להשתמש באילוצים מותאמים אישית מופיע במאמר שירותים שנתמכים באילוצים מותאמים אישית.
    2. לוחצים על Save.
  11. בקטע Action, בוחרים אם לאשר או לדחות את השיטה שנבדקה אם התנאי מתקיים.
  12. פעולת הדחייה פירושה שהפעולה ליצירה או לעדכון של המשאב נחסמת אם התנאי מתקיים.

    פעולת ההרשאה מאפשרת ליצור או לעדכן את המשאב רק אם התנאי מתקיים. כל מקרה אחר, מלבד אלה שרשומים במפורש בתנאי, נחסם.

  13. לוחצים על Create constraint.
  14. אחרי שמזינים ערך בכל שדה, הגדרת ה-YAML המקבילה לאילוץ המותאם אישית הזה מופיעה בצד שמאל.

gcloud

  1. כדי ליצור אילוץ בהתאמה אישית, יוצרים קובץ YAML בפורמט הבא:
  2. name: organizations/ORGANIZATION_ID/customConstraints/CONSTRAINT_NAME
    resourceTypes: RESOURCE_NAME
    methodTypes:
      - CREATE
    - UPDATE
    condition: "CONDITION" actionType: ACTION displayName: DISPLAY_NAME description: DESCRIPTION

    מחליפים את מה שכתוב בשדות הבאים:

    • ‫ORGANIZATION_ID: מזהה הארגון, למשל 123456789.
    • ‫CONSTRAINT_NAME: השם שרוצים לתת לאילוץ החדש בהתאמה אישית. אילוץ בהתאמה אישית יכול להכיל רק אותיות (כולל אותיות רישיות וקטנות) או מספרים, לדוגמה, custom.restrictRepositoryLocation. השדה הזה יכול להכיל עד 70 תווים, לא כולל הקידומת (custom.) – לדוגמה, organizations/123456789/customConstraints/custom. אל תכללו פרטים אישיים מזהים (PII) או מידע רגיש במזהה האילוץ, כי הם עלולים להיחשף בהודעות שגיאה.
    • ‫RESOURCE_NAME: השם המלא של המשאב ב- Google Cloudשמכיל את האובייקט והשדה שרוצים להגביל. לדוגמה, dataform.googleapis.com/Repository. רוב סוגי המשאבים תומכים בעד 20 אילוצים בהתאמה אישית. אם תנסו ליצור יותר אילוצים בהתאמה אישית, הפעולה תיכשל.
    • ‫methodTypes: שיטות ה-REST שעליהן נאכף האילוץ. יכול להיות CREATE או גם CREATE וגם UPDATE. אם אוכפים את האילוץ באמצעות השיטה UPDATE במשאב שמפר את האילוץ, מדיניות הארגון חוסמת את השינויים במשאב הזה, אלא אם השינוי פותר את ההפרה.
    • כדי לראות את השיטות הנתמכות בכל שירות, חפשו את השירות במאמר שירותים שתומכים באילוצים בהתאמה אישית.

    • ‫CONDITION: תנאי CEL שנכתב כנגד ייצוג של משאב שירות נתמך. השדה הזה יכול להכיל עד 1,000 תווים. לדוגמה, "resource.name.contains('/locations/us-central1/')".
    • למידע נוסף על המשאבים הזמינים לכתיבת תנאים, ראו משאבים נתמכים.

    • ‫ACTION: הפעולה שצריך לבצע אם התנאי condition מתקיים. הערכים האפשריים הם ALLOW ו-DENY.
    • הפעולה allow פירושה שאם התנאי מקבל את הערך true, מותר ליצור או לעדכן את המשאב. זה גם אומר שכל מקרה אחר, מלבד המקרה שמופיע במפורש בתנאי, חסום.

      פעולת הדחייה פירושה שאם התנאי מקבל את הערך True, הפעולה ליצירה או לעדכון של המשאב נחסמת.

    • ‫DISPLAY_NAME: שם קריא לאנשים של האילוץ. השם הזה מופיע בהודעות שגיאה ואפשר להשתמש בו לזיהוי ולניפוי באגים. אל תשתמשו בפרטים אישיים מזהים (PII) או במידע רגיש בשמות המוצגים, כי השם הזה עלול להיחשף בהודעות שגיאה. השדה הזה יכול להכיל עד 200 תווים.
    • ‫DESCRIPTION: תיאור ידידותי למשתמש של האילוץ, שיוצג כהודעת שגיאה במקרה של הפרת המדיניות. השדה הזה יכול להכיל עד 2,000 תווים.
  3. אחרי שיוצרים את קובץ ה-YAML לאילוץ חדש בהתאמה אישית, צריך להגדיר אותו כדי שיהיה זמין למדיניות הארגון. כדי להגדיר אילוץ בהתאמה אישית, משתמשים בפקודה gcloud org-policies set-custom-constraint:
  4. gcloud org-policies set-custom-constraint CONSTRAINT_PATH

    מחליפים את CONSTRAINT_PATH בנתיב המלא לקובץ האילוץ בהתאמה אישית. לדוגמה, /home/user/customconstraint.yaml.

    בסיום הפעולה, האילוצים המותאמים אישית יהיו זמינים כמדיניות ארגונית ברשימת Google Cloud המדיניות הארגונית.

  5. כדי לוודא שהאילוץ המותאם אישית קיים, משתמשים בפקודה gcloud org-policies list-custom-constraints:
  6. gcloud org-policies list-custom-constraints --organization=ORGANIZATION_ID

    מחליפים את ORGANIZATION_ID במזהה של משאב הארגון.

    למידע נוסף, קראו את המאמר הצגת מדיניות הארגון.

אכיפה של מדיניות ארגונית בהתאמה אישית

כדי לאכוף אילוץ, אפשר ליצור מדיניות ארגון שמפנה אליו, ואז להחיל את מדיניות הארגון על משאב ב- Google Cloud .

המסוף

  1. במסוף Google Cloud , נכנסים לדף מדיניות הארגון.

    כניסה לדף Organization policies

  2. בכלי לבחירת פרויקטים, בוחרים את הפרויקט שרוצים להגדיר לו את מדיניות הארגון.
  3. ברשימה שבדף מדיניות הארגון, בוחרים את האילוץ כדי להציג את הדף Policy details של אותו אילוץ.
  4. כדי להגדיר את מדיניות הארגון למשאב הזה, לוחצים על ניהול המדיניות.
  5. בדף עריכת המדיניות, בוחרים באפשרות במקום המדיניות של המשאב הראשי.
  6. לוחצים על Add a rule.
  7. בקטע Enforcement, בוחרים אם לאכוף את מדיניות הארגון או לא.
  8. אופציונלי: כדי להוסיף תנאי למדיניות הארגון שמבוסס על תג, לוחצים על Add condition. שימו לב: אם מוסיפים כלל מותנה למדיניות הארגון, צריך להוסיף לפחות כלל אחד לא מותנה, אחרת אי אפשר לשמור את המדיניות. למידע נוסף, קראו את המאמר הגדרת ההיקף של מדיניות הארגון באמצעות תגים.
  9. לוחצים על Test changes כדי לדמות את ההשפעה של מדיניות הארגון. מידע נוסף זמין במאמר בדיקת שינויים במדיניות הארגון באמצעות סימולטור המדיניות.
  10. כדי לאכוף את מדיניות הארגון במצב פרימטר לבדיקות, לוחצים על הגדרת המדיניות להרצת בדיקה. למידע נוסף, קראו את המאמר בדיקת כללי מדיניות של הארגון.
  11. אחרי שמוודאים שמדיניות הארגון במצב פרימטר לבדיקות פועלת כמו שצריך, לוחצים על Set policy כדי להגדיר את המדיניות הפעילה.

gcloud

  1. כדי ליצור מדיניות ארגונית עם כללים בוליאניים, יוצרים קובץ YAML של מדיניות שמפנה לאילוץ:
  2. name: projects/PROJECT_ID/policies/CONSTRAINT_NAME
    spec:
      rules:
      - enforce: true
    
    dryRunSpec:
      rules:
      - enforce: true

    מחליפים את מה שכתוב בשדות הבאים:

    • ‫PROJECT_ID: הפרויקט שבו רוצים לאכוף את האילוץ.
    • ‫CONSTRAINT_NAME: השם שהגדרתם לאילוץ המותאם אישית. לדוגמה, custom.restrictRepositoryLocation.
  3. כדי לאכוף את מדיניות הארגון במצב פרימטר לבדיקות, מריצים את הפקודה הבאה עם הדגל dryRunSpec:
  4. gcloud org-policies set-policy POLICY_PATH --update-mask=dryRunSpec

    מחליפים את POLICY_PATH בנתיב המלא לקובץ ה-YAML של מדיניות הארגון. המדיניות תיכנס לתוקף תוך 15 דקות לכל היותר.

  5. אחרי שמוודאים שמדיניות הארגון במצב פרימטר לבדיקות פועלת כמו שצריך, מגדירים את המדיניות הפעילה באמצעות הפקודה org-policies set-policy והדגל spec:
  6. gcloud org-policies set-policy POLICY_PATH --update-mask=spec

    מחליפים את POLICY_PATH בנתיב המלא לקובץ ה-YAML של מדיניות הארגון. המדיניות תיכנס לתוקף תוך 15 דקות לכל היותר.

בדיקת מדיניות הארגון בהתאמה אישית

בדוגמה הבאה נוצרים אילוץ ומדיניות בהתאמה אישית, שדורשים שכל משאבי dataform.googleapis.com/Repository ייווצרו באזור מסוים.

לפני שמתחילים, צריך:

  • מזהה הארגון שלך
  • מזהה פרויקט

יצירת האילוץ

כדי ליצור אילוץ בהתאמה אישית:

  1. שומרים את הקובץ הבא בשם constraint-restrict-repository-location.yaml:

    name: organizations/ORGANIZATION_ID/customConstraints/custom.restrictRepositoryLocation
    resourceTypes:
    - dataform.googleapis.com/Repository
    methodTypes:
    - CREATE
    - UPDATE
    condition: "resource.name.contains('/locations/us-central1/')"
    actionType: ALLOW
    displayName: Only us-central1 region is allowed.
    description: All resources must be created in the us-central1 region.
    

    מחליפים את ORGANIZATION_ID במזהה הארגון.

    הקובץ הזה מגדיר אילוץ שבו כל פעולת יצירה או עדכון במשאב dataform.googleapis.com/Repository מותרת רק אם האזור שנבחר למשאב הוא us-central1.

  2. מחילים את האילוץ:

    gcloud org-policies set-custom-constraint ~/constraint-restrict-repository-location.yaml
    
  3. מוודאים שהאילוץ קיים:

    gcloud org-policies list-custom-constraints --organization=ORGANIZATION_ID
    

    הפלט אמור להיראות כך:

    CUSTOM_CONSTRAINT                       ACTION_TYPE  METHOD_TYPES   RESOURCE_TYPES                     DISPLAY_NAME
    custom.restrictRepositoryLocation       ALLOW        CREATE,UPDATE  dataform.googleapis.com/Repository Only us-central1 region is allowed.
    ...
    

יצירת המדיניות

עכשיו יוצרים מדיניות ומחילים אותה על האילוץ המותאם אישית שיצרתם.

  1. שומרים את הקובץ הבא בשם policy-restrict-repository-location.yaml:

    name: projects/PROJECT_ID/policies/custom.restrictRepositoryLocation
    spec:
      rules:
      - enforce: true
    

    מחליפים את PROJECT_ID במזהה הפרויקט.

  2. מחילים את המדיניות:

    gcloud org-policies set-policy ~/policy-restrict-repository-location.yaml
    
  3. מוודאים שהמדיניות קיימת:

    gcloud org-policies list --project=PROJECT_ID
    

    הפלט אמור להיראות כך:

    CONSTRAINT                           LIST_POLICY    BOOLEAN_POLICY    ETAG
    custom.restrictRepositoryLocation    -              SET               ETAG
    

אחרי שמחילים את המדיניות, ממתינים כשתי דקות עד ש- Google Cloud יתחיל לאכוף את המדיניות.

בדיקת המדיניות

כדי ליצור משאב dataform.googleapis.com/Repository בפרויקט, פועלים לפי השלבים במאמר יצירת מאגר. בוחרים אזור שונה מהאזור שציינתם באילוץ בהתאמה אישית.

הפלט שיתקבל:

Operation denied by custom org policies: ["customConstraints/custom.restrictRepositoryLocation": "All resources must be created in the us-central1 region."]

דוגמאות למדיניות ארגונית בהתאמה אישית לתרחישים נפוצים

בטבלה הבאה מופיעות דוגמאות לתחביר של כמה אילוצים נפוצים בהתאמה אישית.

תיאור תחביר של אילוצים
כל המשאבים צריכים להיווצר באזור us-central1.
    name: organizations/ORGANIZATION_ID/customConstraints/custom.restrictRepositoryLocation
    resourceTypes:
    - dataform.googleapis.com/Repository
    methodTypes:
    - CREATE
    - UPDATE
    condition: "resource.name.contains('/locations/us-central1/')"
    actionType: ALLOW
    displayName: Only us-central1 region is allowed.
    description: All resources must be created in the us-central1 region.
    
אפשר להגדיר Git מרוחק רק כדי להתחבר באמצעות HTTPS למאגרים בארגון Google ב-GitHub.
    name: organizations/ORGANIZATION_ID/customConstraints/custom.restrictGitRemote
    resourceTypes:
    - dataform.googleapis.com/Repository
    methodTypes:
    - CREATE
    - UPDATE
    condition: |-
      resource.gitRemoteSettings.url == ""
      || resource.gitRemoteSettings.url.startsWith('https://github.com/google/')
    actionType: ALLOW
    displayName:  Only allow the https://github.com/google/ Git remote.
    description: Only allow configuration of a Git remote to connect using HTTPS to repositories in the Google organization on GitHub.
    
אי אפשר להגדיר פרטי כניסה של משתמשי קצה בהגדרות של תהליכי עבודה.
    name: organizations/ORGANIZATION_ID/customConstraints/custom.disableWorkflowConfigEuc
    resourceTypes:
    - dataform.googleapis.com/WorkflowConfig
    methodTypes:
    - CREATE
    - UPDATE
    condition: "has(resource.invocationConfig.endUserAuthConfig)"
    actionType: DENY
    displayName: Disallow end user credentials in workflow configurations
    description: Disallow using end user credentials to configure scheduled workflow runs.
    
לא לאפשר הפעלת קריאות לתהליכי עבודה באמצעות פרטי כניסה של משתמשי קצה.
    name: organizations/ORGANIZATION_ID/customConstraints/custom.disableWorkflowInvocationEuc
    resourceTypes:
    - dataform.googleapis.com/WorkflowInvocation
    methodTypes:
    - CREATE
    condition: "has(resource.invocationConfig.endUserAuthConfig)"
    actionType: DENY
    displayName: Disallow end user credentials in workflow invocations
    description: Disallow executing workflows using end user credentials.
    

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