The gcp:kms/cryptoKeyIAMBinding:CryptoKeyIAMBinding resource, part of the Pulumi GCP provider, manages IAM access to KMS crypto keys by controlling which identities can perform encryption, decryption, or key management operations. This guide focuses on three capabilities: authoritative role bindings with multiple members, time-based access with IAM Conditions, and non-authoritative single-member grants.
KMS IAM resources reference existing crypto keys and assume Google Cloud identities are already provisioned. The examples are intentionally small. Combine them with your own key ring and crypto key resources.
Grant a role to multiple members
When managing encryption keys, you often need to grant the same role to multiple users or service accounts at once.
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const cryptoKey = new gcp.kms.CryptoKeyIAMBinding("crypto_key", {
cryptoKeyId: key.id,
role: "roles/cloudkms.cryptoKeyEncrypter",
members: ["user:jane@example.com"],
});
import pulumi
import pulumi_gcp as gcp
crypto_key = gcp.kms.CryptoKeyIAMBinding("crypto_key",
crypto_key_id=key["id"],
role="roles/cloudkms.cryptoKeyEncrypter",
members=["user:jane@example.com"])
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/kms"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := kms.NewCryptoKeyIAMBinding(ctx, "crypto_key", &kms.CryptoKeyIAMBindingArgs{
CryptoKeyId: pulumi.Any(key.Id),
Role: pulumi.String("roles/cloudkms.cryptoKeyEncrypter"),
Members: pulumi.StringArray{
pulumi.String("user:jane@example.com"),
},
})
if err != nil {
return err
}
return nil
})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;
return await Deployment.RunAsync(() =>
{
var cryptoKey = new Gcp.Kms.CryptoKeyIAMBinding("crypto_key", new()
{
CryptoKeyId = key.Id,
Role = "roles/cloudkms.cryptoKeyEncrypter",
Members = new[]
{
"user:jane@example.com",
},
});
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.kms.CryptoKeyIAMBinding;
import com.pulumi.gcp.kms.CryptoKeyIAMBindingArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var cryptoKey = new CryptoKeyIAMBinding("cryptoKey", CryptoKeyIAMBindingArgs.builder()
.cryptoKeyId(key.id())
.role("roles/cloudkms.cryptoKeyEncrypter")
.members("user:jane@example.com")
.build());
}
}
resources:
cryptoKey:
type: gcp:kms:CryptoKeyIAMBinding
name: crypto_key
properties:
cryptoKeyId: ${key.id}
role: roles/cloudkms.cryptoKeyEncrypter
members:
- user:jane@example.com
The CryptoKeyIAMBinding resource is authoritative for the specified role: it replaces all members for that role while preserving other roles on the key. The cryptoKeyId references your crypto key, role specifies the permission level (like roles/cloudkms.cryptoKeyEncrypter), and members lists all identities that should have this role. If you later remove a member from the list, they lose access on the next deployment.
Add time-based access with IAM Conditions
Temporary access grants expire automatically when you attach IAM Conditions to bindings, useful for contractor access or time-limited delegations.
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const cryptoKey = new gcp.kms.CryptoKeyIAMBinding("crypto_key", {
cryptoKeyId: key.id,
role: "roles/cloudkms.cryptoKeyEncrypter",
members: ["user:jane@example.com"],
condition: {
title: "expires_after_2019_12_31",
description: "Expiring at midnight of 2019-12-31",
expression: "request.time < timestamp(\"2020-01-01T00:00:00Z\")",
},
});
import pulumi
import pulumi_gcp as gcp
crypto_key = gcp.kms.CryptoKeyIAMBinding("crypto_key",
crypto_key_id=key["id"],
role="roles/cloudkms.cryptoKeyEncrypter",
members=["user:jane@example.com"],
condition={
"title": "expires_after_2019_12_31",
"description": "Expiring at midnight of 2019-12-31",
"expression": "request.time < timestamp(\"2020-01-01T00:00:00Z\")",
})
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/kms"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := kms.NewCryptoKeyIAMBinding(ctx, "crypto_key", &kms.CryptoKeyIAMBindingArgs{
CryptoKeyId: pulumi.Any(key.Id),
Role: pulumi.String("roles/cloudkms.cryptoKeyEncrypter"),
Members: pulumi.StringArray{
pulumi.String("user:jane@example.com"),
},
Condition: &kms.CryptoKeyIAMBindingConditionArgs{
Title: pulumi.String("expires_after_2019_12_31"),
Description: pulumi.String("Expiring at midnight of 2019-12-31"),
Expression: pulumi.String("request.time < timestamp(\"2020-01-01T00:00:00Z\")"),
},
})
if err != nil {
return err
}
return nil
})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;
return await Deployment.RunAsync(() =>
{
var cryptoKey = new Gcp.Kms.CryptoKeyIAMBinding("crypto_key", new()
{
CryptoKeyId = key.Id,
Role = "roles/cloudkms.cryptoKeyEncrypter",
Members = new[]
{
"user:jane@example.com",
},
Condition = new Gcp.Kms.Inputs.CryptoKeyIAMBindingConditionArgs
{
Title = "expires_after_2019_12_31",
Description = "Expiring at midnight of 2019-12-31",
Expression = "request.time < timestamp(\"2020-01-01T00:00:00Z\")",
},
});
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.kms.CryptoKeyIAMBinding;
import com.pulumi.gcp.kms.CryptoKeyIAMBindingArgs;
import com.pulumi.gcp.kms.inputs.CryptoKeyIAMBindingConditionArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var cryptoKey = new CryptoKeyIAMBinding("cryptoKey", CryptoKeyIAMBindingArgs.builder()
.cryptoKeyId(key.id())
.role("roles/cloudkms.cryptoKeyEncrypter")
.members("user:jane@example.com")
.condition(CryptoKeyIAMBindingConditionArgs.builder()
.title("expires_after_2019_12_31")
.description("Expiring at midnight of 2019-12-31")
.expression("request.time < timestamp(\"2020-01-01T00:00:00Z\")")
.build())
.build());
}
}
resources:
cryptoKey:
type: gcp:kms:CryptoKeyIAMBinding
name: crypto_key
properties:
cryptoKeyId: ${key.id}
role: roles/cloudkms.cryptoKeyEncrypter
members:
- user:jane@example.com
condition:
title: expires_after_2019_12_31
description: Expiring at midnight of 2019-12-31
expression: request.time < timestamp("2020-01-01T00:00:00Z")
The condition block adds temporal constraints to the binding. The expression uses CEL (Common Expression Language) to define when access is valid; here, request.time < timestamp("2020-01-01T00:00:00Z") grants access until midnight on December 31, 2019. The title and description document the condition’s purpose. When the timestamp passes, Google Cloud automatically denies requests even though the binding still exists.
Add a single member to a role
When you need to grant access to one additional user without affecting existing members, use CryptoKeyIAMMember for non-authoritative grants.
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const cryptoKey = new gcp.kms.CryptoKeyIAMMember("crypto_key", {
cryptoKeyId: key.id,
role: "roles/cloudkms.cryptoKeyEncrypter",
member: "user:jane@example.com",
});
import pulumi
import pulumi_gcp as gcp
crypto_key = gcp.kms.CryptoKeyIAMMember("crypto_key",
crypto_key_id=key["id"],
role="roles/cloudkms.cryptoKeyEncrypter",
member="user:jane@example.com")
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/kms"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := kms.NewCryptoKeyIAMMember(ctx, "crypto_key", &kms.CryptoKeyIAMMemberArgs{
CryptoKeyId: pulumi.Any(key.Id),
Role: pulumi.String("roles/cloudkms.cryptoKeyEncrypter"),
Member: pulumi.String("user:jane@example.com"),
})
if err != nil {
return err
}
return nil
})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;
return await Deployment.RunAsync(() =>
{
var cryptoKey = new Gcp.Kms.CryptoKeyIAMMember("crypto_key", new()
{
CryptoKeyId = key.Id,
Role = "roles/cloudkms.cryptoKeyEncrypter",
Member = "user:jane@example.com",
});
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.kms.CryptoKeyIAMMember;
import com.pulumi.gcp.kms.CryptoKeyIAMMemberArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var cryptoKey = new CryptoKeyIAMMember("cryptoKey", CryptoKeyIAMMemberArgs.builder()
.cryptoKeyId(key.id())
.role("roles/cloudkms.cryptoKeyEncrypter")
.member("user:jane@example.com")
.build());
}
}
resources:
cryptoKey:
type: gcp:kms:CryptoKeyIAMMember
name: crypto_key
properties:
cryptoKeyId: ${key.id}
role: roles/cloudkms.cryptoKeyEncrypter
member: user:jane@example.com
Unlike CryptoKeyIAMBinding, CryptoKeyIAMMember adds a single member to a role without replacing existing members. The member property takes one identity (note the singular form, not an array). This resource can coexist with other CryptoKeyIAMMember resources for the same role, and with CryptoKeyIAMBinding resources for different roles. It cannot coexist with CryptoKeyIAMPolicy, which replaces the entire policy.
Beyond these examples
These snippets focus on specific IAM binding features: role-based access control, IAM Conditions for time-based access, and authoritative vs non-authoritative member management. They’re intentionally minimal rather than full key management solutions.
The examples reference pre-existing infrastructure such as KMS crypto keys (referenced by cryptoKeyId) and Google Cloud users, service accounts, or groups. They focus on configuring access rather than provisioning the keys themselves.
To keep things focused, common IAM patterns are omitted, including:
- Full policy replacement (CryptoKeyIAMPolicy)
- Custom role definitions
- Audit logging configuration
- Key ring and crypto key creation
These omissions are intentional: the goal is to illustrate how each IAM binding feature is wired, not provide drop-in key management modules. See the CryptoKeyIAMBinding resource reference for all available configuration options.
Let's manage GCP KMS Crypto Key IAM Permissions
Get started with Pulumi Cloud, then follow our quick setup guide to deploy this infrastructure.
Try Pulumi Cloud for FREEFrequently Asked Questions
Resource Selection & Conflicts
CryptoKeyIAMPolicy is authoritative and replaces the entire IAM policy. CryptoKeyIAMBinding is authoritative for a specific role, preserving other roles. CryptoKeyIAMMember is non-authoritative, adding individual members while preserving existing ones.CryptoKeyIAMPolicy cannot be used with CryptoKeyIAMBinding or CryptoKeyIAMMember as they will conflict over policy management.Configuration & Identity Management
allUsers, allAuthenticatedUsers, user:{email}, serviceAccount:{email}, group:{email}, or domain:{domain}.[projects|organizations]/{parent-name}/roles/{role-name}.{location}/{key_ring}/{crypto_key} and the provider’s project setting will be used as a fallback.IAM Conditions & Advanced Features
condition property with title, description, and expression fields. For example, set expression to request.time < timestamp("2020-01-01T00:00:00Z") for time-based expiration.Immutability & Lifecycle
cryptoKeyId, role, and condition properties are immutable and require resource replacement if changed.