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

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

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

  3. Install the Google Cloud CLI.

  4. Configure the gcloud CLI to use your federated identity.

    For more information, see Sign in to the gcloud CLI with your federated identity.

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

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

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

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

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

משאבים נתמכים ב-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 , נכנסים לדף מדיניות הארגון.

    כניסה לדף Organization policies

  2. בכלי לבחירת פרויקטים, בוחרים את הפרויקט שרוצים להגדיר לו את מדיניות הארגון.
  3. לוחצים על Custom constraint.
  4. בתיבה Display name, מזינים שם לאילוץ שיהיה קריא לאנשים. השם הזה מופיע בהודעות שגיאה ואפשר להשתמש בו לזיהוי ולניפוי באגים. אל תשתמשו בפרטים אישיים מזהים (PII) או במידע רגיש בשמות לתצוגה, כי השם הזה עלול להיחשף בהודעות שגיאה. השדה הזה יכול להכיל עד 200 תווים.
  5. בתיבה Constraint ID, מזינים את המזהה שרוצים לתת לאילוץ החדש בהתאמה אישית. אילוץ בהתאמה אישית יכול להכיל רק אותיות (כולל אותיות רישיות וקטנות) או מספרים, לדוגמה custom.enableCloudBuildPubsubTrigger. השדה הזה יכול להכיל עד 70 תווים, לא כולל הקידומת (custom.), לדוגמה, organizations/123456789/customConstraints/custom. אל תכללו פרטים אישיים מזהים או מידע רגיש במזהה האילוץ, כי הם עלולים להיחשף בהודעות שגיאה.
  6. בתיבה Description, מזינים תיאור של האילוץ שקריא לאנשים. התיאור הזה משמש כהודעת שגיאה כשהמדיניות מופרת. ציינו פרטים על הסיבה להפרת המדיניות ואיך לפתור את הבעיה. אל תכללו פרטים אישיים מזהים או מידע רגיש בתיאור, כי הם עלולים להיחשף בהודעות שגיאה. השדה הזה יכול להכיל עד 2,000 תווים.
  7. בתיבה Resource type, בוחרים את השם של משאב ה- Google Cloud REST שמכיל את האובייקט והשדה שרוצים להגביל, לדוגמה container.googleapis.com/Cluster. רוב סוגי המשאבים תומכים בעד 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. פעולת הדחייה פירושה שהפעולה ליצירה או לעדכון של המשאב נחסמת אם התנאי מקבל את הערך true.

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

  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.enableCloudBuildPubsubTrigger. השדה הזה יכול להכיל עד 70 תווים, לא כולל הקידומת (custom.) – לדוגמה, organizations/123456789/customConstraints/custom. אל תכללו פרטים אישיים מזהים או מידע רגיש במזהה האילוץ, כי הם עלולים להיחשף בהודעות שגיאה.
    • ‫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, מותר ליצור או לעדכן את המשאב. זה גם אומר שכל מקרה אחר, מלבד המקרה שמופיע במפורש בתנאי, חסום.

      פעולת הדחייה פירושה שאם התנאי מקבל את הערך 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. לוחצים על בדיקת השינויים כדי לדמות את ההשפעה של מדיניות הארגון. למידע נוסף, קראו את המאמר בדיקת שינויים במדיניות הארגון באמצעות סימולטור המדיניות.
  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.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."]
    

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

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

תיאור תחביר של אילוצים
ה-builds צריכים להשתמש ב-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
    

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