Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Auf dieser Seite finden Sie Anleitungen zu gängigen Aufgaben der IAM-Authentifizierungsfunktion für Memorystore for Redis Cluster. Weitere Informationen zu dieser Funktion finden Sie unter IAM-Authentifizierung.
Instanz mit IAM-Authentifizierung erstellen
Wenn Sie eine Memorystore for Redis Cluster-Instanz erstellen möchten, die die IAM-Authentifizierung verwendet, führen Sie den Befehl create aus:
INSTANCE_ID ist die ID der Memorystore for Redis Cluster-Instanz, die Sie erstellen. Die Instanz-ID muss 1 bis 63 Zeichen lang sein und darf nur Kleinbuchstaben, Ziffern oder Bindestriche enthalten. Er muss mit einem Kleinbuchstaben beginnen und mit einem Kleinbuchstaben oder einer Ziffer enden.
REGION_ID ist die Region, in der sich die Instanz befinden soll.
NETWORK ist das Netzwerk, das zum Erstellen der Instanz verwendet wurde. Er muss das Format projects/NETWORK_PROJECT_ID/global/networks/NETWORK_ID haben. Die hier verwendete Netzwerk-ID muss mit der Netzwerk-ID übereinstimmen, die von der Richtlinie für Dienstverbindungen verwendet wird. Andernfalls schlägt der Vorgang create fehl. Weitere Informationen finden Sie unter Netzwerk.
NODE_TYPE ist der von Ihnen ausgewählte Knotentyp. Zulässige Werte:
redis-shared-core-nano
redis-standard-small
redis-highmem-medium
redis-highmem-xlarge
SHARD_COUNT bestimmt die Anzahl der Shards in Ihrer Instanz. Die Anzahl der Shards bestimmt die Gesamtspeicherkapazität für das Speichern von Clusterdaten. Weitere Informationen zur Clusterspezifikation finden Sie unter Cluster- und Knotenspezifikation.
Berechtigungen für die IAM-Authentifizierung erteilen
Um IAM-Zugriff zu gewähren, weisen Sie dem Hauptkonto die Rolle roles/redis.dbConnectionUser zu. Folgen Sie dazu der Anleitung zum Zuweisen von IAM-Rollen.
Wenn Sie einem Hauptkonto die Rolle roles/redis.dbConnectionUser zuweisen, kann es standardmäßig auf alle Instanzen in Ihrem Projekt zugreifen.
Eingeschränkte IAM-Administratorrolle für eine Instanz erstellen
Möglicherweise möchten Sie eine Rolle erstellen, mit der IAM-Berechtigungen für Instanzverbindungen geändert werden können, ohne dass vollständiger IAM-Administratorzugriff gewährt wird. Dazu können Sie einen eingeschränkten IAM-Administrator für die Rolle roles/redis.dbConnectionUser` erstellen. Weitere Informationen finden Sie unter Eingeschränkte IAM-Administratoren erstellen.
Verbindung zu einer Instanz herstellen, die die IAM-Authentifizierung verwendet
Wenn Sie noch keine Compute Engine-VM haben, die dasselbe autorisierte Netzwerk wie Ihr Redis-Cluster verwendet, erstellen Sie eine VM und stellen Sie eine Verbindung zu ihr her: Folgen Sie dazu der Kurzanleitung: Linux-VM verwenden.
Installieren Sie redis-cli auf der Compute Engine-VM. Führen Sie dazu den folgenden Befehl im Compute Engine-SSH-Terminal aus:
sudo apt-get install redis-tools
Führen Sie den folgenden Befehl aus, um ein Zugriffstoken für Ihren IAM-Nutzer abzurufen:
gcloud auth print-access-token
Stellen Sie eine Verbindung zum Discovery-Endpunkt Ihrer Instanz her:
redis-cli -h NETWORK_ADDRESS -p PORT -a ACCESS_TOKEN -c
Ersetzen Sie Folgendes:
NETWORK_ADDRESS ist die Netzwerkadresse der Instanz. Informationen zum Aufrufen der Netzwerkadresse finden Sie unter Instanzinformationen ansehen.
PORT ist die Portnummer der Instanz. Informationen zum Aufrufen der Portnummer finden Sie unter Instanzinformationen ansehen.
ACCESS_TOKEN ist das IAM-Zugriffstoken, das in den vorherigen Schritten abgerufen wurde.
Führen Sie den Befehl CLUSTER SHARDS aus, um die Clustertopologie aufzurufen. Notieren Sie sich eine der IP-Adressen und Portnummern des Knotens.
Verwenden Sie den folgenden Befehl, um redis-cli zur Authentifizierung und Verbindung mit Ihrem Knoten zu verwenden:
redis-cli -h NODE_IP_ADDRESS -p NODE_PORT -a ACCESS_TOKEN -c
Ersetzen Sie Folgendes:
NODE_IP_ADDRESS: die IP-Adresse des Knotens, die Sie im vorherigen Schritt ermittelt haben
NODE_PORT: die Portnummer des Knotens, die Sie im vorherigen Schritt ermittelt haben
ACCESS_TOKEN: Das IAM-Zugriffstoken, das Sie in den vorherigen Schritten abgerufen haben.
Führen Sie einen Redis-Befehl SET und GET aus, um zu prüfen, ob eine authentifizierte Verbindung zu Ihrem Knoten hergestellt wurde.
Löschen Sie die Compute Engine-VM, mit der Sie eine Verbindung zum Redis-Cluster hergestellt haben. Dadurch vermeiden Sie, dass Ihrem Cloud-Rechnungskonto Gebühren berechnet werden.
Codebeispiel für die Verbindung zu einer Instanz, die die IAM-Authentifizierung verwendet
Codebeispiel für die Authentifizierung Ihrer Anwendung mit beliebten Clientbibliotheken. Außerdem erfahren Sie, wie Sie dieses Codebeispiel verwenden, um eine Verbindung zu einer Instanz herzustellen, die die IAM-Authentifizierung verwendet.
Fehlermeldungen bei der IAM-Authentifizierung beheben
Fehlermeldung
Empfohlene Maßnahmen
Beschreibung
-WRONGPASS invalid username-password pair or user is disabled
Prüfen Sie den Nutzernamen und das Zugriffstoken, die dem Memorystore for Redis Cluster-Server bereitgestellt wurden.
Der angegebene Nutzername oder das angegebene Zugriffstoken ist ungültig. „default“ ist der einzige unterstützte Nutzername. Wenn Ihre Anwendung bereits den Standardnutzernamen verwendet, prüfen Sie, ob das Zugriffstoken abgelaufen ist und ob es gemäß der Anleitung unter Verbindung zu einer Instanz herstellen, die die IAM-Authentifizierung verwendet abgerufen wurde. Es kann einige Minuten dauern, bis IAM-Berechtigungen wirksam werden, wenn sie vor Kurzem geändert wurden.
-NOAUTH Authentication required
Prüfen Sie, ob die Anwendung so konfiguriert ist, dass sie ein IAM-Zugriffstoken für den Memorystore for Redis-Cluster-Server bereitstellt.
-ERR (ERR_IAM_EXHAUSTED) Memorystore IAM authentication backend quota exceeded. See https://cloud.google.com/memorystore/docs/cluster/manage-iam-auth#error_messages.
Mit exponentiellem Backoff wiederholen.
Das IAM-Backend ist überlastet und hat dem Memorystore for Redis Cluster-Server einen Fehler vom Typ „Kontingent überschritten“ zurückgegeben. Anwendungen sollten versuchen, diesen Fehler mit exponentiellem Backoff zu wiederholen, um weitere Verbindungsfehler zu vermeiden.
-ERR (ERR_IAM_OTHER) Memorystore IAM authentication backend error. See https://cloud.google.com/memorystore/docs/cluster/manage-iam-auth#error_messages.
Mit exponentiellem Backoff wiederholen.
Das IAM-Backend hat einen vorübergehenden Fehler an den Memorystore for Redis Cluster-Server zurückgegeben. Anwendungen sollten versuchen, diesen Fehler mit exponentiellem Backoff zu wiederholen, um weitere Verbindungsfehler zu vermeiden.
[[["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: 2025-09-04 (UTC)."],[],[],null,["# Manage IAM authentication\n\nThis page provides instructions on common tasks for the IAM\nauthentication feature for Memorystore for Redis Cluster. For more details on the feature,\nsee [About IAM authentication](/memorystore/docs/cluster/about-iam-auth).\n\nCreate an instance with IAM authentication\n------------------------------------------\n\nTo create a Memorystore for Redis Cluster instance that uses IAM\nauthentication, run the `create` command: \n\n```\ngcloud redis clusters create INSTANCE_ID --region=REGION_ID --network=NETWORK --node-type=NODE_TYPE --shard-count=SHARD_COUNT --auth-mode=iam-auth\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eINSTANCE_ID\u003c/var\u003e is the ID of the Memorystore for Redis Cluster instance you're\n creating. Your instance ID must be 1 to 63 characters and use only lowercase\n letters, numbers, or hyphens. It must start with a lowercase letter and end with\n a lowercase letter or number.\n\n- \u003cvar translate=\"no\"\u003eREGION_ID\u003c/var\u003e is the region where you want the instance placed.\n\n | **Note:** You can only create instances in the [supported regions](/memorystore/docs/cluster/locations) for Memorystore for Redis Cluster. Not all of the regions currently supported by Memorystore for Redis are available for Memorystore for Redis Cluster. The `gcloud redis regions list` commands shows supported regions for Memorystore for Redis, not Memorystore for Redis Cluster.\n- \u003cvar translate=\"no\"\u003eNETWORK\u003c/var\u003e is the network used to create your instance. It must use\n the format: `projects/NETWORK_PROJECT_ID/global/networks/NETWORK_ID`. The\n network ID used here must match the network ID used by the service connection\n policy. Otherwise, the `create` operation fails. For more details, see\n [Networking](/memorystore/docs/cluster/networking).\n\n- \u003cvar translate=\"no\"\u003eNODE_TYPE\u003c/var\u003e is your chosen node type. Accepted values are:\n\n - `redis-shared-core-nano`\n - `redis-standard-small`\n - `redis-highmem-medium`\n - `redis-highmem-xlarge`\n\n | **Caution** : We recommend that you use the `redis-shared-core-nano` node type for development or testing purposes only. If you run Memorystore for Redis Cluster in a production environment, then we recommend using the `redis-standard-small`, `redis-highmem-medium`, or `redis-highmem-xlarge` node types. For more information about these node types, see [Choose a node type](/memorystore/docs/cluster/cluster-node-specification#choose_a_node_type).\n- \u003cvar translate=\"no\"\u003eSHARD_COUNT\u003c/var\u003e determines the number of shards in your\n instance. Shard count determines the total memory capacity for storing\n cluster data. To see more details about cluster specification, see [Cluster and node specification](/memorystore/docs/cluster/cluster-node-specification).\n\nGrant permissions for IAM authentication\n----------------------------------------\n\nTo grant an IAM access, grant the principal the\n`roles/redis.dbConnectionUser` role using the [Grant IAM role instructions](/iam/docs/grant-role-console#grant_an_iam_role).\n\nBy default, granting a principal the `roles/redis.dbConnectionUser` role allows\nthe principal to access all instances in your project.\n| **Note:** For instructions on limiting user access on a per-instance basis, see [Grant access to a group of resources based on resource name prefixes](/iam/docs/configuring-resource-based-access#resource-name-instance). When granting limited access for your instance, use the `resource.name` attribute and the following format for the instance name - `projects/PROJECT/locations/REGION/clusters/INSTANCE_NAME`.\n\n### Create a limited IAM admin role for an instance\n\nYou might want to create a role that can modify instance connection\nIAM permissions without granting full IAM admin\naccess. This can be done by creating a limited IAM admin for the\n`roles/redis.dbConnectionUser`\\` role. For more details, visit [Create limited IAM admins](/iam/docs/setting-limits-on-granting-roles#limited-admins-example).\n\nConnect to an instance that uses IAM authentication\n---------------------------------------------------\n\n1. If you don't already have a Compute Engine VM that uses the same\n authorized network as your Redis cluster, create one and connect to it by\n following [Quickstart Using a Linux VM](/compute/docs/create-linux-vm-instance).\n\n2. For your project, enable the Cloud Platform API scope. For more\n information about enabling this access scope, see\n [Attach the service account and update the access scope](/compute/docs/instances/change-service-account#changeserviceaccountandscopes). For more information\n about best practices for this scope, see\n [Scopes best practice](/compute/docs/access/service-accounts#scopes_best_practice).\n\n3. For your project, enable the Memorystore for Redis API.\n\n [Memorystore for Redis API](https://console.cloud.google.com/apis/library/redis.googleapis.com)\n\n \u003cbr /\u003e\n\n4. Install redis-cli on the Compute Engine VM by running the following\n command from the Compute Engine SSH terminal:\n\n ```\n sudo apt-get install redis-tools\n ```\n5. Run the following command to get an access token for your IAM\n user:\n\n ```\n gcloud auth print-access-token\n ```\n | **Note:** Access tokens will expire in one hour. For more information, see [IAM access token timeframe](/memorystore/docs/cluster/about-iam-auth#iam_access_token_time_frame).\n6. Connect to your instance's discovery endpoint:\n\n ```\n redis-cli -h NETWORK_ADDRESS -p PORT -a ACCESS_TOKEN -c\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eNETWORK_ADDRESS\u003c/var\u003e is the instance's network address. To view the\n network address, see [View instance information](/memorystore/docs/cluster/view-instance-information).\n\n - \u003cvar translate=\"no\"\u003ePORT\u003c/var\u003e is the instances port number. To view the port number, see\n [View instance information](/memorystore/docs/cluster/view-instance-information).\n\n - \u003cvar translate=\"no\"\u003eACCESS_TOKEN\u003c/var\u003e is the IAM access token retrieved in previous\n steps.\n\n | **Note:** Authenticated connections are valid for 12 hours. For more information, see [IAMaccess token time frame](/memorystore/docs/cluster/about-iam-auth#iam_access_token_time_frame).\n7. Run the `CLUSTER SHARDS` command to view your cluster topology. Take a note\n of one of the node's IP addresses and port numbers.\n\n8. To use `redis-cli` to authenticate and connect to your node, use the\n following command:\n\n ```\n redis-cli -h NODE_IP_ADDRESS -p NODE_PORT -a ACCESS_TOKEN -c\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eNODE_IP_ADDRESS\u003c/var\u003e: the node's IP address that you found in the previous step\n - \u003cvar translate=\"no\"\u003eNODE_PORT\u003c/var\u003e: the node's port number that you found in the previous step\n - \u003cvar translate=\"no\"\u003eACCESS_TOKEN\u003c/var\u003e: the IAM access token that you retrieved in previous steps\n\n | **Note:** Authenticated connections are valid for 12 hours. For more information, see [IAM access token time frame](/memorystore/docs/cluster/about-iam-auth#iam_access_token_time_frame).\n9. To verify that you have an authenticated connection to your node, run a Redis\n `SET` and `GET` command.\n\n10. [Delete the Compute Engine VM](/compute/docs/create-linux-vm-instance#clean-up)\n that you used to connect to the Redis cluster. This helps you avoid incurring\n charges to your Cloud Billing account.\n\nAutomate access token retrieval\n-------------------------------\n\n| **Note:**We strongly recommend that you automate access\n| token retrieval in your application. Because of the short lifetime of an access\n| token, it's difficult to hardcode the token.\n|\n| For a code sample that shows how you can authenticate your application by using\n| popular client libraries, see [IAM\n| authentication client library code sample](/memorystore/docs/cluster/client-library-connection#iam_authentication_client_library_code_sample).\n\n1. **(Optional)** If you haven't already, create a service account for your application (see [Creating and managing a service account](/iam/docs/creating-managing-service-accounts)).\n\n ```\n gcloud iam service-accounts create SA_NAME \\\n --description=\"DESCRIPTION\" \\\n --display-name=\"DISPLAY_NAME\"\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eSA_NAME\u003c/var\u003e is the name of the service account.\n - \u003cvar translate=\"no\"\u003eDESCRIPTION\u003c/var\u003e is an optional description of the service account.\n - \u003cvar translate=\"no\"\u003eDISPLAY_NAME\u003c/var\u003e is a service account name to display in the Google Cloud console.\n2. Grant your service account `redis.dbConnectionUser` permission on your\n project.\n\n ```\n gcloud projects add-iam-policy-binding PROJECT_ID \\\n --member=\"serviceAccount:SA_NAME@PROJECT_ID.iam.gserviceaccount.com\" \\\n --role=\"ROLE_NAME\"\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: the project ID\n - \u003cvar translate=\"no\"\u003eSA_NAME\u003c/var\u003e: the name of the service account\n - \u003cvar translate=\"no\"\u003eROLE_NAME\u003c/var\u003e: a role name, such as `redis.dbConnectionUser`\n3. [Authenticate your application](#connect_to_an_instance_that_uses_iam_authentication) as the given service account. For more\n information, see [Service accounts](/docs/authentication#service-accounts).\n\nCode sample for connecting to an instance that uses IAM authentication\n----------------------------------------------------------------------\n\nYou can view a [code sample](/memorystore/docs/cluster/client-library-connection#iam_authentication_client_library_code_sample) that\nshows you how you can authenticate your\napplication by using popular client libraries. In addition, you can see how to\nuse this code sample to connect to an instance that uses IAM authentication.\n\nTroubleshooting error messages with IAM authentication\n------------------------------------------------------"]]