Best Practices für die Verwaltung von API-Schlüsseln
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Wenn Sie API-Schlüssel in Ihren Anwendungen verwenden, achten Sie darauf, dass sie sowohl beim Speichern als auch bei der Übertragung sicher sind. Wenn Sie Ihre API-Schlüssel öffentlich freigeben, kann dies zu unerwarteten Kosten in Ihrem Konto oder zu unbefugtem Zugriff auf Ihre Daten führen.
Beachten Sie die folgenden Best Practices, um die Sicherheit Ihrer API-Schlüssel zu wahren.
Fügen Sie Ihrem Schlüssel API-Schlüsseleinschränkungen hinzu.
Durch Hinzufügen von Einschränkungen können Sie die Verwendung eines API-Schlüssels einschränken und so die Auswirkungen eines manipulierten API-Schlüssels reduzieren.
Löschen Sie nicht benötigte API-Schlüssel, um das Angriffsrisiko zu minimieren
Behalten Sie nur die API-Schlüssel bei, die Sie derzeit verwenden, um Ihre Angriffsfläche so klein wie möglich zu halten.
API-Schlüssel regelmäßig löschen und neu erstellen
Sie sollten regelmäßig neue API-Schlüssel erstellen, die alten Schlüssel löschen und Ihre Anwendungen zur Verwendung der neuen API-Schlüssel aktualisieren.
API-Schlüssel nicht in Clientcode einfügen oder in Code-Repositories sichern
API-Schlüssel, die im Quellcode hartcodiert oder in einem Repository gespeichert sind, können von böswilligen Akteuren abgefangen oder gestohlen werden. Der Client sollte Anfragen an den Server weiterleiten, der die Anmeldedaten hinzufügen und die Anfrage senden kann. Wenn Sie den Schlüssel clientseitig speichern müssen, verwenden Sie ein Secret-Management-System, um den Schlüssel sicher aufzubewahren.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2024-12-22 (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)."]]