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

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

  • cloudbuild.googleapis.com/BitbucketServerConfig
  • cloudbuild.googleapis.com/Build
  • cloudbuild.googleapis.com/BuildTrigger
  • cloudbuild.googleapis.com/Connection
  • cloudbuild.googleapis.com/GithubEnterpriseConfig
  • cloudbuild.googleapis.com/Repository
  • cloudbuild.googleapis.com/WorkerPool

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

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

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

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

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

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

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

  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. התקינו את ה-CLI של Google Cloud.

  5. אם אתם משתמשים בספק זהויות חיצוני (IdP), קודם אתם צריכים להיכנס ל-CLI של gcloud באמצעות המאגר המאוחד לניהול זהויות.

  6. כדי לאתחל את ה-CLI של gcloud, הריצו את הפקודה הבאה:

    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. התקינו את ה-CLI של Google Cloud.

  10. אם אתם משתמשים בספק זהויות חיצוני (IdP), קודם אתם צריכים להיכנס ל-CLI של gcloud באמצעות המאגר המאוחד לניהול זהויות.

  11. כדי לאתחל את ה-CLI של gcloud, הריצו את הפקודה הבאה:

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

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

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

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

משאבים נתמכים ב-Cloud Build

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

משאב שדה
cloudbuild.googleapis.com/BitbucketServerConfig resource.apiKey
resource.hostUri
resource.name
resource.peeredNetwork
resource.peeredNetworkIpRange
resource.secrets.adminAccessTokenVersionName
resource.secrets.readAccessTokenVersionName
resource.secrets.webhookSecretVersionName
resource.sslCa
resource.username
cloudbuild.googleapis.com/Build resource.artifacts.goModules.modulePath
resource.artifacts.goModules.moduleVersion
resource.artifacts.goModules.repositoryLocation
resource.artifacts.goModules.repositoryName
resource.artifacts.goModules.repositoryProjectId
resource.artifacts.goModules.sourcePath
resource.artifacts.images
resource.artifacts.mavenArtifacts.artifactId
resource.artifacts.mavenArtifacts.groupId
resource.artifacts.mavenArtifacts.path
resource.artifacts.mavenArtifacts.repository
resource.artifacts.mavenArtifacts.version
resource.artifacts.npmPackages.packagePath
resource.artifacts.npmPackages.repository
resource.artifacts.objects.location
resource.artifacts.objects.paths
resource.artifacts.pythonPackages.paths
resource.artifacts.pythonPackages.repository
resource.availableSecrets.inline.envMap
resource.availableSecrets.inline.kmsKeyName
resource.availableSecrets.secretManager.env
resource.availableSecrets.secretManager.versionName
resource.dependencies.empty
resource.dependencies.gitSource.depth
resource.dependencies.gitSource.destPath
resource.dependencies.gitSource.recurseSubmodules
resource.dependencies.gitSource.repository.developerConnect
resource.dependencies.gitSource.repository.url
resource.dependencies.gitSource.revision
resource.gitConfig.http.proxySecretVersionName
resource.images
resource.logsBucket
resource.options.automapSubstitutions
resource.options.defaultLogsBucketBehavior
resource.options.diskSizeGb
resource.options.dynamicSubstitutions
resource.options.enableStructuredLogging
resource.options.env
resource.options.logging
resource.options.logStreamingOption
resource.options.machineType
resource.options.pool.name
resource.options.pubsubTopic
resource.options.requestedVerifyOption
resource.options.secretEnv
resource.options.sourceProvenanceHash
resource.options.substitutionOption
resource.options.volumes.name
resource.options.volumes.path
resource.queueTtl
resource.secrets.kmsKeyName
resource.secrets.secretEnv
resource.serviceAccount
resource.source.connectedRepository.dir
resource.source.connectedRepository.repository
resource.source.connectedRepository.revision
resource.source.developerConnectConfig.dir
resource.source.developerConnectConfig.gitRepositoryLink
resource.source.developerConnectConfig.revision
resource.source.gitSource.dir
resource.source.gitSource.revision
resource.source.gitSource.url
resource.source.repoSource.branchName
resource.source.repoSource.commitSha
resource.source.repoSource.dir
resource.source.repoSource.invertRegex
resource.source.repoSource.projectId
resource.source.repoSource.repoName
resource.source.repoSource.substitutions
resource.source.repoSource.tagName
resource.source.storageSource.bucket
resource.source.storageSource.generation
resource.source.storageSource.object
resource.source.storageSource.sourceFetcher
resource.source.storageSourceManifest.bucket
resource.source.storageSourceManifest.generation
resource.source.storageSourceManifest.object
resource.steps.allowExitCodes
resource.steps.allowFailure
resource.steps.args
resource.steps.automapSubstitutions
resource.steps.dir
resource.steps.entrypoint
resource.steps.env
resource.steps.id
resource.steps.name
resource.steps.script
resource.steps.secretEnv
resource.steps.timeout
resource.steps.volumes.name
resource.steps.volumes.path
resource.steps.waitFor
resource.substitutions
resource.tags
resource.timeout
cloudbuild.googleapis.com/BuildTrigger resource.approvalConfig.approvalRequired
resource.autodetect
resource.bitbucketServerTriggerConfig.bitbucketServerConfigResource
resource.bitbucketServerTriggerConfig.projectKey
resource.bitbucketServerTriggerConfig.pullRequest.branch
resource.bitbucketServerTriggerConfig.pullRequest.commentControl
resource.bitbucketServerTriggerConfig.pullRequest.invertRegex
resource.bitbucketServerTriggerConfig.push.branch
resource.bitbucketServerTriggerConfig.push.invertRegex
resource.bitbucketServerTriggerConfig.push.tag
resource.bitbucketServerTriggerConfig.repoSlug
resource.build.artifacts.images
resource.build.artifacts.mavenArtifacts.artifactId
resource.build.artifacts.mavenArtifacts.groupId
resource.build.artifacts.mavenArtifacts.path
resource.build.artifacts.mavenArtifacts.repository
resource.build.artifacts.mavenArtifacts.version
resource.build.artifacts.npmPackages.packagePath
resource.build.artifacts.npmPackages.repository
resource.build.artifacts.objects.location
resource.build.artifacts.objects.paths
resource.build.artifacts.pythonPackages.paths
resource.build.artifacts.pythonPackages.repository
resource.build.availableSecrets.inline.envMap
resource.build.availableSecrets.inline.kmsKeyName
resource.build.availableSecrets.secretManager.env
resource.build.availableSecrets.secretManager.versionName
resource.build.dependencies.empty
resource.build.dependencies.gitSource.depth
resource.build.dependencies.gitSource.destPath
resource.build.dependencies.gitSource.recurseSubmodules
resource.build.dependencies.gitSource.repository.developerConnect
resource.build.dependencies.gitSource.repository.url
resource.build.dependencies.gitSource.revision
resource.build.gitConfig.http.proxySecretVersionName
resource.build.images
resource.build.logsBucket
resource.build.options.automapSubstitutions
resource.build.options.defaultLogsBucketBehavior
resource.build.options.diskSizeGb
resource.build.options.dynamicSubstitutions
resource.build.options.env
resource.build.options.logging
resource.build.options.logStreamingOption
resource.build.options.machineType
resource.build.options.pool.name
resource.build.options.requestedVerifyOption
resource.build.options.secretEnv
resource.build.options.sourceProvenanceHash
resource.build.options.substitutionOption
resource.build.options.volumes.name
resource.build.options.volumes.path
resource.build.queueTtl
resource.build.secrets.kmsKeyName
resource.build.secrets.secretEnv
resource.build.serviceAccount
resource.build.source.connectedRepository.dir
resource.build.source.connectedRepository.repository
resource.build.source.connectedRepository.revision
resource.build.source.developerConnectConfig.dir
resource.build.source.developerConnectConfig.gitRepositoryLink
resource.build.source.developerConnectConfig.revision
resource.build.source.gitSource.dir
resource.build.source.gitSource.revision
resource.build.source.gitSource.url
resource.build.source.repoSource.branchName
resource.build.source.repoSource.commitSha
resource.build.source.repoSource.dir
resource.build.source.repoSource.invertRegex
resource.build.source.repoSource.projectId
resource.build.source.repoSource.repoName
resource.build.source.repoSource.substitutions
resource.build.source.repoSource.tagName
resource.build.source.storageSource.bucket
resource.build.source.storageSource.generation
resource.build.source.storageSource.object
resource.build.source.storageSource.sourceFetcher
resource.build.source.storageSourceManifest.bucket
resource.build.source.storageSourceManifest.generation
resource.build.source.storageSourceManifest.object
resource.build.steps.allowExitCodes
resource.build.steps.allowFailure
resource.build.steps.args
resource.build.steps.automapSubstitutions
resource.build.steps.dir
resource.build.steps.entrypoint
resource.build.steps.env
resource.build.steps.id
resource.build.steps.name
resource.build.steps.script
resource.build.steps.secretEnv
resource.build.steps.timeout
resource.build.steps.volumes.name
resource.build.steps.volumes.path
resource.build.steps.waitFor
resource.build.substitutions
resource.build.tags
resource.build.timeout
resource.description
resource.disabled
resource.eventType
resource.filename
resource.filter
resource.gitFileSource.bitbucketServerConfig
resource.gitFileSource.githubEnterpriseConfig
resource.gitFileSource.path
resource.gitFileSource.repository
resource.gitFileSource.repoType
resource.gitFileSource.revision
resource.gitFileSource.uri
resource.github.enterpriseConfigResourceName
resource.github.name
resource.github.owner
resource.github.pullRequest.branch
resource.github.pullRequest.commentControl
resource.github.pullRequest.invertRegex
resource.github.push.branch
resource.github.push.invertRegex
resource.github.push.tag
resource.gitlabEnterpriseEventsConfig.gitlabConfigResource
resource.gitlabEnterpriseEventsConfig.projectNamespace
resource.gitlabEnterpriseEventsConfig.pullRequest.branch
resource.gitlabEnterpriseEventsConfig.pullRequest.commentControl
resource.gitlabEnterpriseEventsConfig.pullRequest.invertRegex
resource.gitlabEnterpriseEventsConfig.push.branch
resource.gitlabEnterpriseEventsConfig.push.invertRegex
resource.gitlabEnterpriseEventsConfig.push.tag
resource.ignoredFiles
resource.includeBuildLogs
resource.includedFiles
resource.name
resource.pubsubConfig.serviceAccountEmail
resource.pubsubConfig.topic
resource.repositoryEventConfig.pullRequest.branch
resource.repositoryEventConfig.pullRequest.commentControl
resource.repositoryEventConfig.pullRequest.invertRegex
resource.repositoryEventConfig.push.branch
resource.repositoryEventConfig.push.invertRegex
resource.repositoryEventConfig.push.tag
resource.repositoryEventConfig.repository
resource.resourceName
resource.serviceAccount
resource.sourceToBuild.bitbucketServerConfig
resource.sourceToBuild.githubEnterpriseConfig
resource.sourceToBuild.ref
resource.sourceToBuild.repository
resource.sourceToBuild.repoType
resource.sourceToBuild.uri
resource.substitutions
resource.tags
resource.triggerTemplate.branchName
resource.triggerTemplate.commitSha
resource.triggerTemplate.dir
resource.triggerTemplate.invertRegex
resource.triggerTemplate.projectId
resource.triggerTemplate.repoName
resource.triggerTemplate.substitutions
resource.triggerTemplate.tagName
resource.webhookConfig.secret
cloudbuild.googleapis.com/Connection resource.annotations
resource.bitbucketCloudConfig.authorizerCredential.userTokenSecretVersion
resource.bitbucketCloudConfig.readAuthorizerCredential.userTokenSecretVersion
resource.bitbucketCloudConfig.webhookSecretSecretVersion
resource.bitbucketCloudConfig.workspace
resource.bitbucketDataCenterConfig.authorizerCredential.userTokenSecretVersion
resource.bitbucketDataCenterConfig.hostUri
resource.bitbucketDataCenterConfig.readAuthorizerCredential.userTokenSecretVersion
resource.bitbucketDataCenterConfig.serviceDirectoryConfig.service
resource.bitbucketDataCenterConfig.sslCa
resource.bitbucketDataCenterConfig.webhookSecretSecretVersion
resource.disabled
resource.githubConfig.appInstallationId
resource.githubConfig.authorizerCredential.oauthTokenSecretVersion
resource.githubEnterpriseConfig.apiKey
resource.githubEnterpriseConfig.appId
resource.githubEnterpriseConfig.appInstallationId
resource.githubEnterpriseConfig.appSlug
resource.githubEnterpriseConfig.authorizerCredential.oauthTokenSecretVersion
resource.githubEnterpriseConfig.hostUri
resource.githubEnterpriseConfig.oauthClientIdSecretVersion
resource.githubEnterpriseConfig.oauthSecretSecretVersion
resource.githubEnterpriseConfig.privateKeySecretVersion
resource.githubEnterpriseConfig.serviceDirectoryConfig.service
resource.githubEnterpriseConfig.sslCa
resource.githubEnterpriseConfig.webhookSecretSecretVersion
resource.gitlabConfig.authorizerCredential.userTokenSecretVersion
resource.gitlabConfig.hostUri
resource.gitlabConfig.readAuthorizerCredential.userTokenSecretVersion
resource.gitlabConfig.serviceDirectoryConfig.service
resource.gitlabConfig.sslCa
resource.gitlabConfig.webhookSecretSecretVersion
resource.name
cloudbuild.googleapis.com/GithubEnterpriseConfig resource.appId
resource.displayName
resource.hostUrl
resource.name
resource.peeredNetwork
resource.secrets.oauthClientIdVersionName
resource.secrets.oauthSecretVersionName
resource.secrets.privateKeyVersionName
resource.secrets.webhookSecretVersionName
resource.sslCa
resource.webhookKey
cloudbuild.googleapis.com/Repository resource.annotations
resource.name
resource.remoteUri
cloudbuild.googleapis.com/WorkerPool resource.annotations
resource.displayName
resource.privatePoolV1Config.networkConfig.egressOption
resource.privatePoolV1Config.networkConfig.peeredNetwork
resource.privatePoolV1Config.networkConfig.peeredNetworkIpRange
resource.privatePoolV1Config.privateServiceConnect.networkAttachment
resource.privatePoolV1Config.privateServiceConnect.publicIpAddressDisabled
resource.privatePoolV1Config.privateServiceConnect.routeAllTraffic
resource.privatePoolV1Config.workerConfig.diskSizeGb
resource.privatePoolV1Config.workerConfig.machineType

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

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

המסוף

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

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

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

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

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

    הפעולה allow (אישור) אומרת שהפעולה ליצירה או לעדכון של המשאב מותרת רק אם התנאי מחזיר את הערך true. כל מקרה אחר, מלבד אלה שמפורטים במפורש בתנאי, נחסם.

  13. לוחצים על יצירת אילוץ.
  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.enableCloudBuildPubsubTrigger. השדה הזה יכול להכיל עד 70 תווים, לא כולל הקידומת (custom.) – לדוגמה, organizations/123456789/customConstraints/custom. אל תכללו פרטים אישיים מזהים (PII) או נתונים רגישים במזהה האילוץ, כי הם עלולים להיחשף בהודעות שגיאה.
    • RESOURCE_NAME: השם מוגדר במלואו של המשאב Google Cloudשמכיל את האובייקט והשדה שרוצים להגביל. לדוגמה: cloudbuild.googleapis.com/BuildTrigger. רוב סוגי המשאבים תומכים בעד 20 אילוצים מותאמים אישית. אם תנסו ליצור עוד אילוצים בהתאמה אישית, הפעולה תיכשל.
    • methodTypes: שיטות ה-REST שבהן האילוץ נאכף. הערך יכול להיות CREATE או גם CREATE וגם UPDATE. אם אוכפים את האילוץ באמצעות השיטה UPDATE על משאב שמפר את האילוץ, שינויים במשאב הזה נחסמים על ידי מדיניות הארגון, אלא אם השינוי פותר את ההפרה.
    • כדי לראות את השיטות הנתמכות לכל שירות, מחפשים את השירות ב שירותים שתומכים באילוצים בהתאמה אישית.

    • CONDITION: תנאי CEL שנכתב על סמך ייצוג של משאב שירות נתמך. השדה הזה יכול להכיל עד 1,000 תווים. לדוגמה: resource.pubsubConfig != null && resource.pubsubConfig.topic.contains('cloud-build').
    • מידע נוסף על המשאבים שאפשר לכתוב תנאים לגביהם זמין במאמר משאבים נתמכים.

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

      הפעולה deny (דחייה) פירושה שאם התנאי מחזיר את הערך 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 , נכנסים לדף מדיניות הארגון.

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

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

gcloud

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

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

    • PROJECT_ID: הפרויקט שבו רוצים לאכוף את האילוץ.
    • CONSTRAINT_NAME: השם שהגדרתם לאילוץ המותאם אישית. לדוגמה, custom.enableCloudBuildPubsubTrigger.
  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 דקות לפני שהמדיניות תיכנס לתוקף.

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

בדוגמה הבאה נוצרים אילוץ ומדיניות מותאמים אישית שמאפשרים ליצור טריגר לפיתוח גרסת Build רק אם הטריגר הוא מסוג Pub/Sub ומאזין לנושאים שמכילים את המחרומתו cloud-build.

לפני שמתחילים, חשוב לוודא שהתנאים הבאים מתקיימים:

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

יצירת האילוץ

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

  1. יוצרים את קובץ ה-YAML הבא ושומרים אותו בשם constraint-enforce-vulnerabilityAssessmentTitle.yaml:

    name: organizations/ORGANIZATION_ID/customConstraints/custom.enableCloudBuildPubsubTrigger
    resourceTypes:
    - cloudbuild.googleapis.com/BuildTrigger
    methodTypes:
    - CREATE
    condition:  "resource.pubsubConfig != null && resource.pubsubConfig.topic.contains('cloud-build')"
    actionType: ALLOW
    displayName: Requires Pub/Sub triggers to contain "cloud-build" in the topic name.
    description: Pub/Sub triggers must contain "cloud-build" in the topic name.
    

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

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

    gcloud org-policies set-custom-constraint ~/constraint-enforce-vulnerabilityAssessmentTitle
    
  3. מוודאים שהאילוץ קיים:

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

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

    CUSTOM_CONSTRAINT                                          ACTION_TYPE  METHOD_TYPES   RESOURCE_TYPES                           DISPLAY_NAME
    custom.enableCloudBuildPubsubTrigger                       DENY         CREATE         cloudbuild.googleapis.com/BuildTrigger   Enable creating Pub/Sub trigger that listens on topics that contain "cloud-build".
    ...
    

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

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

  1. שומרים את הקובץ הבא בשם policy-enforce-enableCloudBuildPubsubTrigger.yaml:

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

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

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

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

    gcloud org-policies list --project=PROJECT_ID
    

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

    CONSTRAINT                                     LIST_POLICY    BOOLEAN_POLICY    ETAG
    custom.enforceEnableCloudBuildPubsubTrigger    -              SET               COCsm5QGENiXi2E=
    

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

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

כדי לבדוק את המדיניות:

  1. יוצרים נושא Pub/Sub שלא כולל את cloud-build במזהה הנושא.

  2. יוצרים טריגר Pub/Sub לנושא הזה.

    הפלט שיתקבל:

    Operation denied by custom org policies: ["customConstraints/custom.enableCloudBuildPubsubTrigger": "Pub/Sub triggers must contain "cloud-build" in the topic name."]
    

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

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

תיאור תחביר של אילוצים
תהליכי ה-build חייבים להשתמש ב-cloudbuild.yaml כקובץ הגדרות ה-build.
    actionType: ALLOW
    condition: "resource.source.storageSource.object.endsWith('cloudbuild.yaml')"
    description: All builds must use cloudbuild.yaml as the build configuration file.
    displayName: Enforce cloudbuild.yaml as the build config file name.
    methodTypes:
      - CREATE
    name: organizations/ORGANIZATION_ID/customConstraints/custom.enforceCloudBuildFileName
    resourceTypes:
      - cloudbuild.googleapis.com/Build
    
טריגרים של Build חייבים להשתמש במאגר מאושר
    actionType: ALLOW
    condition: "resource.repoSource.repoName == 'projects/PROJECT_ID/repos/approved-app-repo'"
    description: All Cloud Build Triggers must use the approved-app-repo repository.
    displayName: Enforce approved repository for build triggers
    methodTypes:
      - CREATE
    name: organizations/ORGANIZATION_ID/customConstraints/custom.enforceCloudBuildFileName
    resourceTypes:
      - cloudbuild.googleapis.com/BuildTrigger
    

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