Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Como administrador de la organización, debes definir políticas que los desarrolladores cumplan cuando apliquen la infraestructura como código. El conjunto de políticas de tu organización se representa como una biblioteca de políticas. En esta página, se te ayudará a crear un repositorio de políticas centralizado y a agregar restricciones.
Antes de comenzar
Necesitas un repositorio de Git vacío para almacenar la biblioteca de políticas de tu organización.
Debes configurar Git para conectarte de forma segura. Por ejemplo, si tu repositorio de Git está en GitHub, puedes seguir el proceso descrito en Conéctate a GitHub con SSH.
Duplica la biblioteca de muestra
Google proporciona un repositorio de muestra que incluye un conjunto de plantillas de restricciones predefinidas que puedes modificar para tu uso personal.
Clona el repositorio de muestra de la biblioteca de políticas y duplicalo en tu 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
Examina las plantillas de restricciones disponibles en policies/templates: ls policies/templates
Selecciona las plantillas de restricciones que quieras usar. Para este ejemplo, elige gcp_storage_location_v1.yaml, que aplica la ubicación a los buckets de Cloud Storage.
Crea archivos YAML de restricción que correspondan a esas plantillas en policies/constraints.
Desde la copia local del repositorio policy-library, usa los siguientes comandos para confirmar y enviar los cambios:
gitadd--all.gitcommit-m"Initial commit of policy library constraints"gitpush-uoriginmain
Estructura de la biblioteca
Un repositorio de biblioteca de políticas contiene los siguientes directorios:
policies/: Este directorio contiene dos subdirectorios:
constraints/: Este directorio está inicialmente vacío. Coloca tus archivos de restricción aquí.
templates/: Este directorio contiene plantillas de restricciones predefinidas.
validator/: Este directorio contiene los archivos .rego y sus pruebas de unidades asociadas. No es necesario que toques este directorio, a menos que desees modificar las plantillas de restricciones existentes o crear nuevas. Si ejecutas make build, se intercala el contenido de Rego en los archivos de plantillas de restricciones correspondientes.
Actualizaciones periódicas
Debes extraer de forma periódica cualquier cambio del repositorio público que pueda contener plantillas nuevas y archivos de Rego.
La biblioteca de políticas contiene varias plantillas de restricciones y una carpeta samples con restricciones de ejemplo. Lee Crea restricciones de Terraform o Crea restricciones de CAI para obtener detalles sobre cómo escribir y usar restricciones y plantillas de restricciones.
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 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."]]