Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Lorsque vous utilisez des clés API dans vos applications, assurez-vous qu'elles sont protégées lors du stockage et de la transmission. L'exposition publique de vos clés API peut entraîner des frais inattendus sur votre compte ou un accès non autorisé à vos données.
Pour contribuer à la sécurité de vos clés API, appliquez les bonnes pratiques suivantes.
Ajouter des restrictions de clés API à votre clé
En ajoutant des restrictions, vous pouvez limiter les modalités d'utilisation d'une clé API, réduisant ainsi l'impact d'une clé API compromise.
Supprimer les clés API inutiles pour réduire l'exposition aux attaques
Conservez uniquement les clés API que vous utilisez actuellement pour réduire au maximum votre surface d'attaque.
Supprimer et recréer régulièrement vos clés API
Vous devez créer périodiquement des clés API, mettre à jour vos applications pour qu'elles utilisent les nouvelles clés API et supprimer les anciennes.
Ne pas inclure de clés API dans le code client et ne pas effectuer de commit dans des dépôts de code
Les clés API codées en dur dans le code source ou stockées dans un dépôt peuvent être interceptées ou volées par des acteurs malveillants. Le client doit transmettre les requêtes au serveur, qui peut ajouter les identifiants et émettre la requête. Si vous devez stocker la clé côté client, utilisez un système de gestion des secrets pour la protéger.
Implémenter une surveillance et une journalisation efficaces
Envisager une méthode plus sécurisée pour autoriser l'accès
Pour savoir comment choisir une méthode d'authentification, consultez la section Méthodes d'authentification.
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 2024/12/24 (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 2024/12/24 (UTC)."],[[["\u003cp\u003eSecure API keys by implementing best practices during storage and transmission to prevent unauthorized access or unexpected charges.\u003c/p\u003e\n"],["\u003cp\u003eRestrict API key usage to minimize the impact of compromised keys, using the provided resources for more information on restrictions.\u003c/p\u003e\n"],["\u003cp\u003eAvoid including API keys in URLs as query parameters, instead opting for the \u003ccode\u003ex-goog-api-key\u003c/code\u003e HTML parameter or client libraries.\u003c/p\u003e\n"],["\u003cp\u003ePeriodically rotate API keys and delete old ones, while deleting any keys that are not in use to minimize potential exposure.\u003c/p\u003e\n"],["\u003cp\u003eNever include API keys directly in client code or code repositories, instead leveraging server-side logic, and implement monitoring to detect any unauthorized usage.\u003c/p\u003e\n"]]],[],null,["When you use API keys in your applications, ensure that they are kept secure\nduring both storage and transmission. Publicly exposing your API keys can lead\nto unexpected charges on your account or unauthorized access to your data. To\nhelp keep your API keys secure, implement the following best practices.\n\nAdd API key restrictions to your key\n\nBy adding restrictions, you can limit the ways an API key can be used, reducing\nthe impact of a compromised API key.\n\nFor more information, see\n[Apply API key restrictions](/docs/authentication/api-keys#api_key_restrictions).\n\nAvoid using query parameters to provide your API key to Google APIs\n\nProviding your API key to APIs as a query parameter includes your API key in the\nURL, exposing your key to theft through URL scans. Use the\n[`x-goog-api-key` HTTP header](/docs/authentication/api-keys-use#using-with-rest)\nor a [client library](/docs/authentication/api-keys-use#using-with-client-libs)\ninstead.\n\nDelete unneeded API keys to minimize exposure to attacks\n\nRetain only the API keys you are actively using to keep your attack surface as\nsmall as possible.\n\nDon't include API keys in client code or commit them to code repositories\n\nAPI keys hardcoded in the source code or stored in a repository are open to\ninterception or theft by bad actors. The client should pass requests to the\nserver, which can add the credential and issue the request.\n\nDon't use API keys bound to service accounts in production\n\nAPI keys bound to service accounts are designed to accelerate the initial\nexperience for developers exploring Google Cloud APIs. Don't use them in\nproduction environments. Instead,\n[plan to migrate to more secure alternatives](#consider-alternatives) such as\n[Identity and Access Management (IAM)](/iam/docs/grant-role-console) policies and\n[short-lived service account credentials](/iam/docs/service-account-creds#short-lived-credentials),\nfollowing least-privilege security practices.\n\nHere's why you should migrate from using an API key bound to a service account\nto more secure practices as soon as possible:\n\n- API keys are sent alongside requests. This makes it more likely that the key\n might be exposed or logged.\n\n- API keys are bearer credentials. This means that if someone steals an API key\n that's bound to a service account, they can use it to authenticate as that\n service account and access the same resources that service account can.\n\n- API keys bound to service accounts obscure the identity of the end user in\n audit logs. To track the actions of individual users, make sure each user has\n their own set of credentials.\n\nImplement strong monitoring and logging\n\nMonitoring API usage can help alert you to unauthorized usage. For more\ninformation, see\n[Cloud Monitoring overview](/monitoring/docs/monitoring-overview) and\n[Cloud Logging overview](/logging/docs/overview).\n\nIsolate API keys\n\nProvide each team member with their own API key for each application. This can\nhelp control access, provide an audit trail, and reduce the impact of a\ncompromised API key.\n\nRotate your API keys periodically\n\nPeriodically create new API keys, update your applications to use the new API\nkeys, and delete the old keys.\n\nFor more information, see\n[Rotate an API key](/docs/authentication/api-keys#rotate).\n\nConsider a more secure method of authorizing access\n\nFor help with choosing an authentication method, see\n[Authentication methods](/docs/authentication)."]]