Pour obtenir les autorisations requises pour mettre à jour les règles de filtrage des adresses IP sur un bucket, demandez à votre administrateur de vous accorder le rôle Administrateur de l'espace de stockage (roles/storage.admin) sur le bucket. Ce rôle contient les autorisations requises pour mettre à jour les règles de filtrage des adresses IP des buckets.
Pour afficher les autorisations exactes requises, développez la section Autorisations requises :
Autorisations requises
storage.buckets.update
storage.buckets.setIpFilter
Vous pouvez également obtenir ces autorisations avec des rôles personnalisés. Vous pouvez également obtenir ces autorisations avec d'autres rôles prédéfinis. Pour connaître les rôles et les autorisations associées, consultez la page Rôles IAM pour Cloud Storage.
Créer ou mettre à jour des règles de filtrage des adresses IP sur un bucket existant
gcloud
Vérifiez que la version 526.0.0 ou ultérieure de Google Cloud CLI est installée :
gcloud version | head -n1
Si vous avez installé une version antérieure de gcloud CLI, mettez-la à jour :
gcloud components update --version=526.0.0
Créez un fichier JSON qui définit les règles pour les requêtes entrantes. Pour obtenir des exemples et des informations sur la façon de structurer les règles de filtrage des adresses IP des buckets, consultez Configurations de filtrage des adresses IP des buckets.
MODE correspond au mode de configuration du filtrage des adresses IP du bucket. Les valeurs valides sont Enabled et Disabled. Lorsque la valeur est définie sur Enabled, les règles de filtrage des adresses IP sont appliquées à un bucket. Toute requête entrante vers le bucket est évaluée par rapport à ces règles. Lorsque ce paramètre est défini sur Disabled, toutes les requêtes entrantes sont autorisées à accéder au bucket.
RANGE_CIDR est une plage d'adresses IPv4 ou IPv6 de réseau public autorisée à accéder au bucket. Vous pouvez saisir une ou plusieurs plages d'adresses sous forme de liste.
PROJECT_ID est l'ID du projet dans lequel se trouve le réseau cloud privé virtuel (VPC). Pour configurer plusieurs réseaux VPC, vous devez spécifier le projet dans lequel se trouve chaque réseau.
NETWORK_NAME est le nom du réseau VPC autorisé à accéder au bucket. Pour configurer plusieurs réseaux VPC, vous devez spécifier un nom pour chacun d'eux.
ALLOW_CROSS_ORG_VPCS est une valeur booléenne qui indique s'il faut autoriser les réseaux VPC définis dans vpcNetworkSources à provenir d'une autre organisation. Ce champ est facultatif. Si la valeur est définie sur true, la requête autorise les réseaux VPC inter-organisations. Si la valeur est définie sur false, la requête limite les réseaux VPC à la même organisation que le bucket. Si aucune valeur n'est spécifiée, la valeur par défaut est false. Ce champ ne s'applique que si vpcNetworkSources n'est pas vide.
ALLOW_ALL_SERVICE_AGENT_ACCESS est une valeur booléenne qui indique s'il faut autoriser les agents de service à accéder au bucket, quelle que soit la configuration du filtre d'adresse IP. Si la valeur est true, d'autres servicestruepeuvent utiliser des agents de service pour accéder au bucket sans validation basée sur l'adresse IP. Google Cloud
Pour mettre à jour les règles de filtrage des adresses IP du bucket, exécutez la commande gcloud alpha storage
buckets update dans votre environnement de développement :
MODE correspond à l'état de la configuration du filtre d'adresses IP. Les valeurs valides sont Enabled et Disabled. Lorsque la valeur est définie sur Enabled, les règles de filtrage des adresses IP sont appliquées à un bucket, et toutes les requêtes entrantes adressées à ce bucket sont évaluées par rapport à ces règles. Lorsque la valeur est définie sur Disabled, toutes les requêtes entrantes peuvent accéder au bucket et à ses données sans aucune évaluation.
RANGE_CIDR est une plage d'adresses IPv4 ou IPv6 de réseau public autorisée à accéder au bucket. Vous pouvez saisir une ou plusieurs plages d'adresses sous forme de liste.
PROJECT_ID est l'ID du projet dans lequel se trouve le réseau VPC. Pour configurer plusieurs réseaux VPC, vous devez spécifier le projet dans lequel se trouve chaque réseau.
NETWORK_NAME est le nom du réseau VPC autorisé à accéder au bucket. Pour configurer plusieurs réseaux VPC, vous devez spécifier un nom pour chacun d'eux.
ALLOW_ALL_SERVICE_AGENT_ACCESS est une valeur booléenne qui indique s'il faut autoriser les agents de service à accéder au bucket, quelle que soit la configuration du filtre d'adresse IP. Si la valeur est true, d'autres services Google Cloud peuvent utiliser des agents de service pour accéder au bucket sans validation basée sur l'adresse IP.
ALLOW_CROSS_ORG_VPCS est une valeur booléenne qui indique s'il faut autoriser les réseaux VPC définis dans la liste vpcNetworkSources à provenir d'une autre organisation. Ce champ est facultatif. Si la valeur est définie sur true, la requête autorise les réseaux VPC inter-organisations. Si la valeur est définie sur false, la requête limite les réseaux VPC à la même organisation que le bucket. Si aucune valeur n'est spécifiée, la valeur par défaut est false. Ce champ ne s'applique que si vpcNetworkSources n'est pas vide.
Si vous débutez sur Google Cloud, créez un compte pour évaluer les performances de Cloud Storage en conditions réelles. Les nouveaux clients bénéficient également de 300 $ de crédits gratuits pour exécuter, tester et déployer des charges de travail.
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/05 (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/05 (UTC)."],[],[],null,["# Create or update IP filtering rules on an existing bucket\n\nThis page describes how to create or update the [bucket IP filtering](/storage/docs/ip-filtering-overview) rules\non an existing bucket.\n\nRequired roles\n--------------\n\nTo get the required permissions for updating the IP filtering rules on a bucket,\nask your administrator to grant you the Storage Admin (`roles/storage.admin`)\nrole on the bucket. This role contains the permissions required to update bucket\nIP filtering rules.\n\nTo see the exact permissions that are required, expand the\n**Required permissions** section: \n\n#### Required permissions\n\n- `storage.buckets.update`\n- `storage.buckets.setIpFilter`\n\nYou can also get these permissions with [custom roles](/iam/docs/creating-custom-roles). You might be able to get these permissions with other predefined roles as well. To see which roles are associated with which permissions,\nrefer to [IAM roles for Cloud Storage](/iam/docs/understanding-roles).\n\nFor instructions on granting roles for projects, see [Manage access to\nprojects](/storage/docs/access-control/using-iam-permissions#bucket-iam).\n\nCreate or update IP filtering rules on an existing bucket\n---------------------------------------------------------\n\n### gcloud\n\n1. Verify that you have the Google Cloud CLI version 526.0.0 or later installed:\n\n gcloud version | head -n1\n\n2. If you have an earlier gcloud CLI version installed, update the version:\n\n gcloud components update --version=526.0.0\n\n3. Create a JSON file that defines rules for incoming requests. For\n examples and information about how to structure the bucket IP filtering\n rules, see [Bucket IP filtering configurations](/storage/docs/create-ip-filter#ip-filtering-configurations).\n\n \u003cbr /\u003e\n\n ```json\n {\n \"mode\":\"\u003cvar translate=\"no\"\u003eMODE\u003c/var\u003e\",\n \"publicNetworkSource\":{\n \"allowedIpCidrRanges\":[\n \"\u003cvar translate=\"no\"\u003eRANGE_CIDR\u003c/var\u003e\",\n \"...\"\n ]\n },\n \"vpcNetworkSources\":[\n {\n \"network\":\"projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/global/networks/\u003cvar translate=\"no\"\u003eNETWORK_NAME\u003c/var\u003e\",\n \"allowedIpCidrRanges\":[\n \"\u003cvar translate=\"no\"\u003eRANGE_CIDR\u003c/var\u003e\",\n \"...\"\n ]\n },\n \"...\"\n ],\n \"allowCrossOrgVpcs\": ALLOW_CROSS_ORG_VPCS,\n \"allowAllServiceAgentAccess\": ALLOW_ALL_SERVICE_AGENT_ACCESS\n }\n \n ```\n\n \u003cbr /\u003e\n\n Where:\n - \u003cvar translate=\"no\"\u003eMODE\u003c/var\u003e is the mode of the bucket IP\n filtering configuration. Valid values are `Enabled`\n and `Disabled`. When set to `Enabled`, IP\n filtering rules are applied to a bucket. Any incoming request to\n the bucket is evaluated against these rules. When set to\n `Disabled`, all incoming requests are allowed to\n access the bucket.\n\n - \u003cvar translate=\"no\"\u003eRANGE_CIDR\u003c/var\u003e is a public network IPv4 or IPv6\n address range that's allowed to access the bucket. You can\n enter one or multiple address ranges as a list.\n\n - \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e is the project ID where\n the Virtual Private Cloud (VPC) network exists. To configure\n multiple VPC networks, you need to specify\n the project where each network is located.\n\n - \u003cvar translate=\"no\"\u003eNETWORK_NAME\u003c/var\u003e is the name of the\n VPC network that is allowed to access the\n bucket. To configure multiple VPC networks,\n you need to specify a name for each network.\n\n - \u003cvar translate=\"no\"\u003eALLOW_CROSS_ORG_VPCS\u003c/var\u003e is a boolean value\n that indicates whether to allow VPC networks\n that are defined in `vpcNetworkSources` to originate\n from a different organization. This field is optional. If set to `true`, the\n request allows cross-organizational VPC\n networks. If set to `false`, the request restricts\n the VPC networks to the same organization as the\n bucket. If not specified, the default value is\n `false`. This field applies only if `vpcNetworkSources` is not empty.\n\n - \u003cvar translate=\"no\"\u003eALLOW_ALL_SERVICE_AGENT_ACCESS\u003c/var\u003e is a\n boolean value that indicates whether to allow [service\n agents](/iam/docs/service-agents) to access the bucket,\n regardless of the IP filter configuration. If the value is\n `true`, other Google Cloud services can use\n service agents to access the bucket without IP-based validation.\n\n4. To update bucket IP filtering rules, run the [`gcloud alpha storage\n buckets update`](/sdk/gcloud/reference/alpha/storage/buckets/update) command in your development environment:\n\n ```\n gcloud alpha storage buckets update gs://BUCKET_NAME --ip-filter-file=IP_FILTER_CONFIG_FILE\n ```\n\n Where:\n - \u003cvar translate=\"no\"\u003eBUCKET_NAME\u003c/var\u003e is the name of your bucket. For example, `my-bucket`.\n - \u003cvar translate=\"no\"\u003eIP_FILTER_CONFIG_FILE\u003c/var\u003e is the JSON file created in the preceding step.\n\n### REST APIs\n\n### JSON API\n\n1. Have gcloud CLI [installed and initialized](/sdk/docs/install), which lets\n you generate an access token for the `Authorization` header.\n\n\n2.\n\n Create a JSON file that contains the settings for the bucket, which\n must include the `name` and the `ipFilter` configuration fields for the bucket. For examples and information about how to structure the bucket IP filtering rules, see [Bucket IP filtering configurations](/storage/docs/create-ip-filter#ip-filtering-configurations). \n\n ```json\n {\n \"ipFilter\":{\n \"mode\":\"\u003cvar translate=\"no\"\u003eMODE\u003c/var\u003e\",\n \"publicNetworkSource\":{\n \"allowedIpCidrRanges\":[\n \"\u003cvar translate=\"no\"\u003eRANGE_CIDR\u003c/var\u003e\",\n \"...\"\n ]\n },\n \"vpcNetworkSources\":[\n {\n \"network\":\"projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/global/networks/\u003cvar translate=\"no\"\u003eNETWORK_NAME\u003c/var\u003e\",\n \"allowedIpCidrRanges\":[\n \"\u003cvar translate=\"no\"\u003eRANGE_CIDR\u003c/var\u003e\",\n \"...\"\n ]\n },\n \"...\"\n ],\n \"allowCrossOrgVpcs\": ALLOW_CROSS_ORG_VPCS,\n \"allowAllServiceAgentAccess\": ALLOW_ALL_SERVICE_AGENT_ACCESS\n }\n }\n ```\n\n Where:\n - \u003cvar translate=\"no\"\u003eMODE\u003c/var\u003e is the state of the IP filter\n configuration. Valid values are `Enabled` and\n `Disabled`. When set to `Enabled`, IP\n filtering rules are applied to a bucket and all incoming\n requests to the bucket are evaluated against these rules. When\n set to `Disabled`, all incoming requests can access\n the bucket and its data without any evaluation.\n\n - \u003cvar translate=\"no\"\u003eRANGE_CIDR\u003c/var\u003e is a public network IPv4 or\n IPv6 address range that's allowed to access the bucket. You can\n enter one or multiple address ranges as a list.\n\n - \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e is the project ID where the\n VPC network exists. To configure multiple\n VPC networks, you need to specify the project\n where each network is located.\n\n - \u003cvar translate=\"no\"\u003eNETWORK_NAME\u003c/var\u003e is the name of the\n VPC network that is allowed to access the\n bucket. To configure multiple VPC networks, you\n need to specify a name for each network.\n\n - \u003cvar translate=\"no\"\u003eALLOW_ALL_SERVICE_AGENT_ACCESS\u003c/var\u003e is a\n boolean value that indicates whether to allow [service\n agents](/iam/docs/service-agents) to access the bucket,\n regardless of the IP filter configuration. If the value is\n `true`, other Google Cloud services can use\n service agents to access the bucket without IP-based validation.\n\n - \u003cvar translate=\"no\"\u003eALLOW_CROSS_ORG_VPCS\u003c/var\u003e is a boolean value that indicates whether to allow VPC networks that are defined in the `vpcNetworkSources` list to originate from a different organization. This field is optional. If set to `true`, the request allows cross-organizational VPC networks. If set to `false`, the request restricts the VPC networks to the same organization as the bucket. If not specified, the default value is `false`. This field applies only if `vpcNetworkSources` is not empty.\n\n3. Use [`cURL`](http://curl.haxx.se/) to call the [JSON API](/storage/docs/json_api) with a [PATCH bucket](/storage/docs/json_api/v1/buckets/patch) request:\n\n ```\n curl -X PATCH --data-binary @JSON_FILE_NAME \\\n -H \"Authorization: Bearer $(gcloud auth print-access-token)\" \\\n -H \"Content-Type: application/json\" \\\n \"https://storage.googleapis.com/storage/v1/b/BUCKET_NAME?project=PROJECT_IDENTIFIER\"\n ```\n\n Where:\n - \u003cvar translate=\"no\"\u003eJSON_FILE_NAME\u003c/var\u003e is name of the JSON file you created in the preceding step.\n - \u003cvar translate=\"no\"\u003eBUCKET_NAME\u003c/var\u003e is the name of your bucket.\n - \u003cvar translate=\"no\"\u003ePROJECT_IDENTIFIER\u003c/var\u003e is the ID or number of the project with which your bucket is associated. For example, `my-project`.\n\nWhat's next\n-----------\n\n- [List bucket IP filtering rules](/storage/docs/list-ip-filter).\n- [Disable bucket IP filtering rules](/storage/docs/disable-ip-filtering).\n\nTry it for yourself\n-------------------\n\n\nIf you're new to Google Cloud, create an account to evaluate how\nCloud Storage performs in real-world\nscenarios. New customers also get $300 in free credits to run, test, and\ndeploy workloads.\n[Try Cloud Storage free](https://console.cloud.google.com/freetrial)"]]