Connect Google Cloud (GCP)
A Mayadyn connection to Google Cloud works in one project, as one service account. There are two ways to connect:
- Keyless (recommended): Workload Identity Federation. Your project
trusts Mayadyn’s OpenID issuer (
https://id.mayadyn.com) for this one connection, and lets that identity act as your service account. Mayadyn stores no key. - Service account key. You download a JSON key and give it to Mayadyn, which stores it encrypted.
Both need the Compute Engine API enabled in the project.
Keyless: connect a GCP project
Section titled “Keyless: connect a GCP project”What you need
Section titled “What you need”- The project ID (e.g.
acme-prod) and the project number (digits, shown on the project’s dashboard). - A service account in the project for Mayadyn to act as, e.g.
mayadyn@acme-prod.iam.gserviceaccount.com. Create one under IAM & Admin → Service accounts if you do not have one. Do not create a key for it. - Names for a Workload Identity pool and provider, each 4 to 32
lowercase letters, digits or dashes (e.g.
mayadynandmayadyn-oidc). You choose them now; the trust steps create them. gcloudwith rights to create Workload Identity pools and to change IAM policies in the project.- The
adminscope in Mayadyn.
Step 1: create the connection
Section titled “Step 1: create the connection”The Workload Identity provider field is the full name of the provider the steps will create:
projects/<project number>/locations/global/workloadIdentityPools/<pool>/providers/<provider>Console
- Open Cloud accounts and choose Connect account.
- Pick Google Cloud, enter a Name (e.g.
gcp-dammam) and the Default region (e.g.me-central2). - Keep Keyless. Enter Project ID, Workload Identity provider and Service account.
- Choose Connect account. The Trust steps dialog opens.
CLI
cat > gcp-keyless.json <<'EOF'{"type": "mayadyn_federated", "project_id": "acme-prod", "workload_provider": "projects/123456789012/locations/global/workloadIdentityPools/mayadyn/providers/mayadyn-oidc", "service_account": "mayadyn@acme-prod.iam.gserviceaccount.com"}EOFmayadyn connections add --provider gcp --name gcp-dammam --region me-central2 --credentials gcp-keyless.jsonmayadyn connections setup gcp-dammamOnly these four fields are accepted; anything else is refused.
The connection shows Needs fixing until you finish step 2. That is expected.
Step 2: run the trust steps in your project
Section titled “Step 2: run the trust steps in your project”The Trust steps dialog (or mayadyn connections setup <name>) shows the
Issuer, the Trusted subject, the Audience, and the exact
commands for your connection. They have this shape:
gcloud iam workload-identity-pools create <pool> --project=<project id> --location=global --display-name="Mayadyn"
gcloud iam workload-identity-pools providers create-oidc <provider> --project=<project id> --location=global --workload-identity-pool=<pool> --issuer-uri=https://id.mayadyn.com --allowed-audiences=//iam.googleapis.com/projects/<project number>/locations/global/workloadIdentityPools/<pool>/providers/<provider> --attribute-mapping="google.subject=assertion.sub" --attribute-condition="assertion.sub == 'mayadyn:<workspace id>:<connection id>'"
gcloud iam service-accounts add-iam-policy-binding <service account> --project=<project id> --role=roles/iam.workloadIdentityUser --member="principal://iam.googleapis.com/projects/<project number>/locations/global/workloadIdentityPools/<pool>/subject/mayadyn:<workspace id>:<connection id>"
gcloud projects add-iam-policy-binding <project id> --member=serviceAccount:<service account> --role=roles/compute.instanceAdmin.v1Then choose Check on the connection (or mayadyn connections verify <name>). It should turn Working.
Notes the steps come with:
- The pool and provider must be in the project whose number is in
workload_provider. - Your first machine also needs
roles/compute.networkAdminandroles/compute.securityAdminon the service account, because Mayadyn creates themayadynnetwork and its firewall rules. You may remove them afterwards. - Only the subject
mayadyn:<workspace id>:<connection id>is trusted. No other Mayadyn workspace or connection can use this trust.
What each step does
Section titled “What each step does”| Step | Effect |
|---|---|
| Create the pool | A container for external identities in your project. |
| Create the OIDC provider | Trusts tokens from https://id.mayadyn.com, only with this connection’s audience, and only when the token’s subject is this connection’s subject. |
workloadIdentityUser binding |
Lets that one subject act as your service account. |
compute.instanceAdmin.v1 binding |
Lets the service account manage Compute Engine instances in the project. |
Mayadyn’s tokens for this trust are short-lived and are created only when Mayadyn opens this connection.
Roles the service account needs
Section titled “Roles the service account needs”| Role | When |
|---|---|
roles/compute.instanceAdmin.v1 |
Always. |
roles/compute.networkAdmin |
The first time (creates the mayadyn network). |
roles/compute.securityAdmin |
The first time (creates the firewall rules). |
Revoke access
Section titled “Revoke access”Delete the provider, or remove the roles/iam.workloadIdentityUser binding
for the subject. Google then refuses Mayadyn’s tokens, and the connection
fails its checks with auth_failed: “The project’s Workload Identity trust
for this connection is missing, changed or was removed.”
Errors you may see
Section titled “Errors you may see”| Code | Meaning | Fix |
|---|---|---|
auth_failed |
Google did not accept Mayadyn’s token: the pool, provider, audience, condition or binding is missing or different. | Run mayadyn connections setup <name> (or Trust steps), apply the steps, then check again. |
permission_denied |
The service account lacks a role, or the Compute Engine API is off. | Grant roles/compute.instanceAdmin.v1 (and networkAdmin/securityAdmin for first use), and enable the Compute Engine API. |
invalid_input |
A field has the wrong shape, or the project cannot use the default region. | Fix the value. The message lists the regions the project can use. |
Service account key: connect with a stored key
Section titled “Service account key: connect with a stored key”Step 1: create a key
Section titled “Step 1: create a key”- Create a service account in the project (or pick one).
- Grant it
roles/compute.instanceAdmin.v1, plusroles/compute.networkAdminandroles/compute.securityAdminfor the first machine. - Create a JSON key: IAM → Service accounts → Keys → Create JSON key.
Step 2: create the connection
Section titled “Step 2: create the connection”Console: Cloud accounts → Connect account → Google Cloud, pick Stored key, and paste the whole file into Service account key (JSON).
CLI:
mayadyn connections add --provider gcp --name gcp-dammam --region me-central2 --credentials key.jsonUse the key file exactly as Google issued it. A key whose token_uri is not
https://oauth2.googleapis.com/token, or whose universe is not
googleapis.com, is refused.
Credentials are encrypted and never shown again. Every use is recorded in the audit log (“Used account credentials”).
Errors you may see
Section titled “Errors you may see”| Code | Hint Mayadyn gives |
|---|---|
auth_failed |
“The service account key is invalid or was deleted; create a new key.” |
permission_denied |
“Grant the service account roles/compute.instanceAdmin.v1 (and networkAdmin/securityAdmin for first use), and enable the Compute Engine API.” |
invalid_input |
“Create a key for a service account (IAM → Service accounts → Keys → JSON) and send the whole file.” |
Switch to keyless later
Section titled “Switch to keyless later”Use Replace credentials with keyless values for the same project, run the trust steps, check, then delete the service account key in Google Cloud. See Replace credentials.
Regions and zones
Section titled “Regions and zones”The console offers these GCP regions first: me-central2 (Dammam),
me-central1 (Doha), europe-west3 (Frankfurt), europe-west2 (London),
us-east4 (Ashburn), us-central1 (Iowa). Other regions work if your
project can use them.
GCP machines live in zones. When you give a region (me-central2), Mayadyn
uses its -a zone (me-central2-a). Give a zone (me-central2-b) to use
that zone.