Authentifier et configurer l'accès à l'API dans une station de travail
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Ce document explique comment authentifier et configurer l'accès aux API dans une station de travail.
Pour en savoir plus sur l' Google Cloud authentification, consultez la présentation de l'authentification.
S'authentifier en tant qu'utilisateur avec Google Cloud CLI
Après avoir lancé Cloud Workstations, vous pouvez accéder aux services Google Cloud et à l'API à l'aide de vos comptes utilisateur via la CLI gcloud.
Ouvrez un terminal dans votre poste de travail. La façon dont vous ouvrez une fenêtre de terminal dépend de l'IDE que vous utilisez.
Par exemple, si vous utilisez l'éditeur de base de Cloud Workstations, ouvrez un terminal en sélectionnant Terminal>Nouveau terminal ou en appuyant sur Ctrl+Maj+`.
Authentifiez-vous à l'aide de la commande suivante:
gcloud auth login --no-launch-browser
Suivez les instructions fournies par la commande pour vous authentifier auprès de Google Cloud.
Spécifiez l' Google Cloud ID de votre projet avec la commande suivante:
gcloud config set project PROJECT_ID
Activez les identifiants par défaut de l'application pour pouvoir appeler les services Google Cloud .
gcloud auth application-default login
Vos identifiants de la CLI gcloud sont désormais enregistrés et disponibles lorsque vous utilisez votre station de travail lors de sessions ultérieures.
Émettre une requête HTTP vers une station de travail
Pour envoyer une requête HTTP à une station de travail, vous avez besoin d'un jeton d'accès pour un compte disposant du rôle Utilisateur des stations de travail Cloud sur cette station de travail:
Ajoutez un en-tête HTTP nommé Authorization avec la valeur Bearer $TOKEN.
Se connecter à la station de travail dans votre navigateur
L'ouverture de l'URL de votre poste de travail dans votre navigateur s'authentifie automatiquement via une redirection vers le serveur de la station de travail et récupère un jeton d'accès généré par la méthode d'API generateAccessToken. Vous êtes alors redirigé vers votre station de travail et un cookie d'authentification valide pour votre session de station de travail actuelle est défini.
Pour ignorer cette redirection, utilisez le paramètre d'URL _workstationAccessToken:
Ouvrez l'URL de votre station de travail dans le navigateur et ajoutez un paramètre d'URL au format suivant : _workstationAccessToken=TOKEN.
Cela définit un cookie d'authentification dans votre navigateur qui autorise l'accès à votre session de poste de travail actuelle. Ignorer la redirection peut être utile lorsque l'accès au serveur de la station de travail est bloqué par des stratégies réseau ou lorsque des iFrames sont utilisés pour afficher la station de travail sur d'autres sites.
Emprunter l'identité d'un compte de service
Si les règles de sécurité de votre organisation empêchent les comptes utilisateur de disposer des autorisations requises, vous pouvez également usurper l'identité d'un compte de service. Pour usurper l'identité du
compte de service spécifié dans la configuration de votre station de travail, vous pouvez spécifier le champ
Champs d'application du compte de service.
Lorsque spécifié, les utilisateurs des stations de travail dans cette configuration doivent disposer de l'autorisation iam.serviceAccounts.actAs sur le compte de service. Pour en savoir plus sur la spécification de champs d'application pour le compte de service, consultez la section Champs d'application d'accès.
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/04 (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/04 (UTC)."],[],[],null,["This document describes how to authenticate and set up API access within a\nworkstation.\nFor general information about Google Cloud authentication, see the\n[authentication overview](/docs/authentication).\n\nAuthenticate as a user with Google Cloud CLI\n\n\nAfter you launch Cloud Workstations, you can access Google Cloud services and the API using\nyour user accounts through the `gcloud` CLI.\n\n1. Open a terminal in your workstation. The way you open a terminal window depends on the [IDE that you're using](/workstations/docs/preconfigured-ides). For example, if you're using the Cloud Workstations base editor, open a terminal by selecting **Terminal** \\\u003e **New Terminal** , or by pressing \u003ckbd\u003eControl+Shift+`\u003c/kbd\u003e.\n2. Authenticate with the following command: \n\n ```\n gcloud auth login --no-launch-browser\n ```\n3. Follow the instructions provided by the command to authenticate to Google Cloud.\n4. Specify your Google Cloud project ID with the following command: \n\n ```\n gcloud config set project PROJECT_ID\n ```\n5. Enable Application Default Credentials to allow you to call Google Cloud services. \n\n ```\n gcloud auth application-default login\n ```\n6. Your `gcloud` CLI credentials are now saved and available when you use your workstation in future sessions.\n\nIssue an HTTP request to a workstation\n\nTo issue an HTTP request to a workstation, you need an access token for\nan account that has the [Cloud Workstations User](/workstations/docs/access-control#workstations-user)\nrole on that workstation:\n\n1. Generate an access token using the [generateAccessToken](/workstations/docs/reference/rest/v1/projects.locations.workstationClusters.workstationConfigs.workstations/generateAccessToken) API method.\n2. Add an HTTP header named `Authorization` with the value `Bearer $TOKEN`.\n\n| **Note:** Once generated, the access token is valid for the expiration time of the token and cannot be revoked.\n\nConnect to the workstation in your browser\n\nOpening your workstation URL in your browser automatically authenticates\nthrough a redirect to the workstations server, and retrieves an access\ntoken generated by the\n[generateAccessToken](/workstations/docs/reference/rest/v1/projects.locations.workstationClusters.workstationConfigs.workstations/generateAccessToken)\nAPI method. This redirects back to your workstation and sets an\nauthentication cookie that is valid for your current workstation session.\n\nTo skip this redirect, use the `_workstationAccessToken` URL\nparameter:\n\n1. Generate an access token using the [generateAccessToken](/workstations/docs/reference/rest/v1/projects.locations.workstationClusters.workstationConfigs.workstations/generateAccessToken) API method.\n2. Open your workstation URL in the browser and append a URL parameter with the following form: `_workstationAccessToken=`\u003cvar translate=\"no\"\u003eTOKEN\u003c/var\u003e.\n\nThis sets an authentication cookie in your browser that allows access for\nyour current workstation session. Skipping the redirect can be helpful\nwhen access to the workstation server is blocked by network policies, or\nwhen using iframes to display the workstation in other sites.\n\nImpersonate a service account\n\n\nIf your organization's security policies prevent user accounts from having the required\npermissions, you can also impersonate a service account. To impersonate the\n[service account](/workstations/docs/reference/rest/v1/projects.locations.workstationClusters.workstationConfigs#GceInstance.FIELDS.service_account) specified on your workstation configuration, you can specify the\n[service account scopes](/workstations/docs/reference/rest/v1/projects.locations.workstationClusters.workstationConfigs#GceInstance.FIELDS.service_account_scopes) field.\n\n```\n gcloud workstations configs create CONFIG \\\n --cluster=CLUSTER \\\n --region=REGION \\\n --project=PROJECT \\\n --service-account=SERVICE_ACCOUNT \\\n --service-account-scopes=https://www.googleapis.com/auth/cloud-platform\n \n```\nWhen specified, users of workstations under this configuration must have `iam.serviceAccounts.actAs` permission on the service account. For more information on specifying scopes for the service account, see [Access scopes](/compute/docs/access/service-accounts#accesscopesiam).\n\n\u003cbr /\u003e\n\nWhat's next\n\n- Learn more about [SSH support](/workstations/docs/ssh-support).\n- See a list of [workstation configuration parameters](/workstations/docs/customize-development-environment).\n- [Access control with Identity and Access Management](/workstations/docs/access-control) and Cloud Workstations"]]