Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
En tant qu'administrateur de l'organisation, vous devez définir des règles auxquelles les développeurs doivent se conformer lors de l'application de l'infrastructure en tant que code. L'ensemble des règles de votre organisation est représenté sous forme d'une bibliothèque de règles. Cette page vous aide à créer un dépôt de règles centralisé et à ajouter des contraintes.
Avant de commencer
Vous devez disposer d'un dépôt Git vide pour stocker la bibliothèque de règles de votre organisation.
Vous devez configurer Git pour vous connecter de manière sécurisée. Par exemple, si votre dépôt git se trouve sur GitHub, vous pouvez suivre le processus décrit dans la section Se connecter à GitHub avec SSH.
Dupliquer l'exemple de bibliothèque
Google fournit un exemple de dépôt comprenant un ensemble de modèles de contrainte prédéfinis que vous pouvez modifier pour votre usage personnel.
Clonez l'exemple de dépôt de la bibliothèque de règles et dupliquez-le sur votre POLICY_LIBRARY_REPO:
git clone https://github.com/GoogleCloudPlatform/policy-library.git
cd policy-library
git remote set-url origin POLICY_LIBRARY_REPO
git push origin main
Examinez les modèles de contraintes disponibles dans policies/templates : ls policies/templates
Sélectionnez les modèles de contraintes que vous souhaitez utiliser. Pour cet exemple, choisissez gcp_storage_location_v1.yaml qui applique l'emplacement des buckets Cloud Storage.
Créez des fichiers YAML de contrainte correspondant à ces modèles sous policies/constraints.
Depuis votre copie locale du dépôt policy-library, validez et appliquez vos modifications à l'aide des commandes suivantes:
gitadd--all.gitcommit-m"Initial commit of policy library constraints"gitpush-uoriginmain
Structure de la bibliothèque
Un dépôt de bibliothèque de règles contient les répertoires suivants :
policies/ : ce répertoire contient deux sous-répertoires :
constraints/ : ce répertoire est initialement vide. Placez vos fichiers de contraintes ici.
templates/ : ce répertoire contient des modèles de contrainte prédéfinis.
validator/ : ce répertoire contient les fichiers .rego et les tests unitaires associés. Vous n'avez pas besoin de modifier ce répertoire, sauf si vous souhaitez modifier des modèles de contrainte existants ou en créer. L'exécution de make build intègre le contenu Rego dans les fichiers de modèle de contrainte correspondants.
Mises à jour périodiques
Vous devez extraire régulièrement les modifications du dépôt public qui peuvent contenir de nouveaux modèles et fichiers Rego.
La bibliothèque de règles contient un certain nombre de modèles de contraintes et un dossier samples avec des exemples de contraintes. Consultez la page Créer des contraintes Terraform ou Créer des contraintes CAI pour en savoir plus sur l'écriture et l'utilisation de contraintes et de modèles de contraintes.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/04 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/04 (UTC)."],[[["\u003cp\u003eThis page guides organization administrators on setting up a centralized policy repository, represented as a policy library, to define policies for developers using infrastructure as code.\u003c/p\u003e\n"],["\u003cp\u003eA pre-existing Git repository is required to store the policy library, and secure Git configuration is necessary for connection, which can be established by following the Github SSH process.\u003c/p\u003e\n"],["\u003cp\u003eA sample policy library from Google is provided, containing predefined constraint templates that can be duplicated, modified, and added to the organization's policy library.\u003c/p\u003e\n"],["\u003cp\u003eThe policy library repository has a specific structure with \u003ccode\u003epolicies/\u003c/code\u003e directory containing \u003ccode\u003econstraints/\u003c/code\u003e and \u003ccode\u003etemplates/\u003c/code\u003e subdirectories and a \u003ccode\u003evalidator/\u003c/code\u003e directory for Rego files, while periodic updates from the public repository should be made.\u003c/p\u003e\n"],["\u003cp\u003ePre-GA products and features from the provided content, such as this product, are available "as is" and may have limited support, as well as being subject to the Pre-GA Offerings Terms in the General Service Terms section.\u003c/p\u003e\n"]]],[],null,["# Create a policy library\n\n| **Preview**\n|\n|\n| This product or feature is subject to the \"Pre-GA Offerings Terms\" in the General Service Terms section\n| of the [Service Specific Terms](/terms/service-terms#1).\n|\n| Pre-GA products and features are available \"as is\" and might have limited support.\n|\n| For more information, see the\n| [launch stage descriptions](/products#product-launch-stages).\n\nAs an organization administrator, you need to define policies that developers adhere to when applying infrastructure as code. Your organization's set of policies is represented as a policy library. This page helps you create a centralized policy repository and add constraints.\n\nBefore you begin\n----------------\n\n- You need an empty Git repository for storing your organization's policy library.\n- You need to configure Git to connect securely. For example, if your git repository is on GitHub, you can follow the process outlined in [Connecting to GitHub with SSH](https://docs.github.com/en/authentication/connecting-to-github-with-ssh).\n\nDuplicate the sample library\n----------------------------\n\nGoogle provides a sample repository that includes a set of pre-defined constraint templates which you can modify for your personal use.\n\n1. Clone the policy library sample repository and duplicate it to your \u003cvar translate=\"no\"\u003ePOLICY_LIBRARY_REPO\u003c/var\u003e:\n\n ```\n git clone https://github.com/GoogleCloudPlatform/policy-library.git\n cd policy-library\n git remote set-url origin POLICY_LIBRARY_REPO\n git push origin main\n ```\n2. Examine the available constraint templates in `policies/templates`:\n `ls policies/templates`\n\n3. Select the constraint templates you want to use. For this example, choose `gcp_storage_location_v1.yaml`, which enforces location for Cloud Storage buckets.\n\n4. Create constraint YAML files corresponding to those templates under `policies/constraints`.\n\n5. From inside your local copy of the `policy-library` repository, use the following commands to commit and push your changes:\n\n git add --all .\n git commit -m \"Initial commit of policy library constraints\"\n git push -u origin main\n\n### Library structure\n\nA policy library repository contains the following directories:\n\n- `policies/` -- This directory contains two subdirectories:\n\n - `constraints/` -- This directory is initially empty. Place your constraint files here.\n - `templates/` -- This directory contains pre-defined constraint templates.\n- `validator/` -- This directory contains the `.rego` files and their associated unit tests. You don't need to touch this directory unless you intend to modify existing constraint templates or create new ones. Running `make build` inlines the Rego content in the corresponding constraint template files.\n\nPeriodic updates\n----------------\n\nPeriodically you should pull any changes from the public repository, which might contain new templates and Rego files. \n\n git remote add public https://github.com/GoogleCloudPlatform/policy-library.git\n git pull public main\n git push origin main\n\nNext steps\n----------\n\nThe policy library contains a number of constraint templates and a `samples`\nfolder with example constraints. Read\n[Create Terraform constraints](/docs/terraform/policy-validation/create-terraform-constraints)\nor\n[Create CAI constraints](/docs/terraform/policy-validation/create-cai-constraints)\nfor details on how to write and use constraint templates and constraints."]]