Learn Configuring Access and Security (GCP ACE) with Interactive Flashcards
Master key concepts in Configuring Access and Security through our interactive flashcard system. Click on each card to reveal detailed explanations and enhance your understanding.
Viewing IAM policies
IAM (Identity and Access Management) policies in Google Cloud define who has what type of access to which resources. Viewing these policies is essential for auditing, troubleshooting, and maintaining security compliance in your cloud environment.
To view IAM policies, you can use the Google Cloud Console, gcloud CLI, or the REST API. In the Console, navigate to 'IAM & Admin' from the main menu, then select 'IAM' to see all members and their assigned roles for the current project. You can switch between projects, folders, or organization levels to view policies at different hierarchy levels.
Using gcloud CLI, the command 'gcloud projects get-iam-policy PROJECT_ID' retrieves the IAM policy for a specific project. For organizations, use 'gcloud organizations get-iam-policy ORG_ID', and for folders, use 'gcloud resource-manager folders get-iam-policy FOLDER_ID'. Adding '--format=json' or '--format=yaml' outputs the policy in your preferred format.
IAM policies consist of bindings that connect members (users, service accounts, groups) to roles. When viewing policies, you'll see role assignments like 'roles/editor' or 'roles/viewer' mapped to identities such as 'user:example@gmail.com' or 'serviceAccount:sa@project.iam.gserviceaccount.com'.
The Policy Analyzer tool provides advanced capabilities for understanding effective permissions. It helps answer questions like 'Who can access this resource?' or 'What resources can this user access?' This is particularly useful for complex environments with inherited permissions.
For individual resources like Cloud Storage buckets or Compute Engine instances, you can view resource-level IAM policies through their respective console pages or using resource-specific gcloud commands like 'gcloud storage buckets get-iam-policy BUCKET_NAME'.
Regularly reviewing IAM policies helps ensure the principle of least privilege is maintained, identifying overly permissive access or unused permissions that could pose security risks.
Creating IAM policies
IAM (Identity and Access Management) policies in Google Cloud are fundamental components for controlling access to cloud resources. These policies define who can do what on which resources, following the principle of least privilege.
An IAM policy consists of bindings that connect members (users, groups, service accounts, or domains) to specific roles. Each binding grants a set of permissions to the specified members for particular resources.
To create IAM policies, you can use several methods:
1. **Google Cloud Console**: Navigate to IAM & Admin, select the project, and click 'Grant Access' to add members and assign roles through a visual interface.
2. **gcloud CLI**: Use commands like 'gcloud projects add-iam-policy-binding' to programmatically assign roles. For example: gcloud projects add-iam-policy-binding PROJECT_ID --member='user:email@example.com' --role='roles/viewer'
3. **Terraform or Infrastructure as Code**: Define policies declaratively for version control and automated deployments.
4. **REST API**: Make HTTP requests to the Resource Manager API for policy management.
Key concepts when creating policies:
- **Roles**: Collections of permissions (Primitive, Predefined, or Custom roles)
- **Members**: Identities receiving access (user:, serviceAccount:, group:, domain:)
- **Conditions**: Optional expressions that further restrict when bindings apply
- **Resource Hierarchy**: Policies inherit from organization to folder to project to resource level
Best practices include:
- Using predefined roles when possible
- Creating custom roles for specific permission requirements
- Implementing conditional access for time-based or attribute-based restrictions
- Regularly auditing policies using Policy Analyzer
- Avoiding primitive roles (Owner, Editor, Viewer) in production environments
Policy changes are eventually consistent, meaning updates may take a short time to propagate across all systems. Always test policy changes in non-production environments first to ensure proper access configuration.
Managing IAM role types
Identity and Access Management (IAM) in Google Cloud provides granular control over who can access resources and what actions they can perform. Understanding the three types of IAM roles is essential for effective security management.
**Basic Roles (Primitive Roles)**
These are the original roles that existed before Cloud IAM was introduced. They include Owner, Editor, and Viewer. Owner has full administrative access including managing roles and permissions. Editor can modify resources but cannot manage access. Viewer has read-only access to resources. Basic roles are broad and grant permissions across all services in a project, making them less suitable for production environments where granular control is needed.
**Predefined Roles**
Google Cloud provides hundreds of predefined roles that offer more granular access to specific services. Examples include roles/compute.instanceAdmin for managing Compute Engine instances, roles/storage.objectViewer for reading Cloud Storage objects, and roles/bigquery.dataEditor for modifying BigQuery datasets. These roles follow the principle of least privilege by granting only the permissions necessary for specific tasks.
**Custom Roles**
When predefined roles do not meet your requirements, you can create custom roles with specific permissions tailored to your organizational needs. Custom roles can be created at the organization or project level. They allow you to combine individual permissions to match exact job functions. However, custom roles require ongoing maintenance as new permissions become available.
**Best Practices**
Always prefer predefined roles over basic roles for tighter security. Use custom roles when predefined options are insufficient. Regularly audit role assignments using IAM recommender to identify overly permissive access. Apply roles at the appropriate resource hierarchy level - organization, folder, project, or individual resource. Grant roles to groups rather than individual users for easier management and scalability.
Basic IAM roles
Basic IAM roles in Google Cloud Platform are predefined roles that provide broad permissions across all resources within a project. These roles were the original access control mechanism before more granular options became available.
There are three fundamental Basic IAM roles:
1. **Owner (roles/owner)**: This role grants full administrative access to all resources. Owners can manage roles and permissions for team members, set up billing, and have complete control over the project. They can add or remove members and delete the entire project.
2. **Editor (roles/editor)**: Editors have read and write access to most resources. They can create, modify, and delete resources within the project. However, they cannot manage IAM policies or handle billing settings. This role is suitable for developers who need to deploy and manage applications.
3. **Viewer (roles/viewer)**: This role provides read-only access to resources. Viewers can see existing resources and their configurations but cannot make any modifications. This is ideal for auditors or team members who need visibility for monitoring purposes.
Key considerations when using Basic roles:
- **Security concerns**: Basic roles grant extensive permissions, which may violate the principle of least privilege. For production environments, predefined or custom roles are recommended.
- **Inheritance**: Basic roles assigned at the organization or folder level are inherited by all child resources, including projects and individual resources.
- **Billing implications**: Only Owners can configure billing accounts and manage payment settings.
Best practices suggest limiting the use of Basic roles and instead leveraging predefined roles that offer more granular permissions tailored to specific services. This approach enhances security by ensuring users only have access to what they need for their specific tasks. Custom roles can also be created when predefined options do not meet requirements.
Predefined IAM roles
Predefined IAM roles in Google Cloud Platform are curated sets of permissions that Google creates and maintains to help organizations implement access control efficiently. These roles are designed around common job functions and use cases, making it easier for Cloud Engineers to assign appropriate access levels to users, groups, and service accounts.
Unlike primitive roles (Owner, Editor, Viewer) which apply broad permissions across all resources, predefined roles follow the principle of least privilege by granting specific permissions for particular services. For example, the 'Compute Instance Admin' role provides permissions to manage virtual machine instances but does not include access to other services like Cloud Storage or BigQuery.
Predefined roles are organized by service and typically follow a naming convention: roles/[service].[role]. Common examples include:
- roles/compute.networkAdmin: Manages networking resources except firewall rules and SSL certificates
- roles/storage.objectViewer: Allows reading objects in Cloud Storage buckets
- roles/pubsub.publisher: Grants ability to publish messages to Pub/Sub topics
- roles/cloudsql.client: Provides connectivity access to Cloud SQL instances
These roles are particularly valuable because Google maintains them, automatically updating permissions when new features are released. This reduces administrative overhead compared to creating and maintaining custom roles.
When configuring access, Cloud Engineers should first identify the predefined role that most closely matches the required job function. If a predefined role grants more permissions than necessary, consider using a custom role instead. Predefined roles can be assigned at various resource hierarchy levels including organization, folder, project, or individual resource level.
Best practices include regularly auditing role assignments, using groups rather than individual users for role assignment, and combining multiple predefined roles when a single role does not provide the exact permissions needed. This approach ensures secure, manageable, and scalable access control across your Google Cloud environment.
Custom IAM roles
Custom IAM roles in Google Cloud Platform allow organizations to create tailored permission sets that align precisely with their security requirements and the principle of least privilege. Unlike predefined roles provided by Google, custom roles enable administrators to define exactly which permissions a user, service account, or group should have.
When working with custom roles, you can create them at either the organization level or project level. Organization-level custom roles can be granted across any project within that organization, while project-level custom roles are limited to that specific project.
To create a custom role, you need the iam.roles.create permission, typically available through the Role Administrator role. You can create custom roles using the Google Cloud Console, gcloud CLI, or the IAM API. When defining a custom role, you specify a role ID, title, description, launch stage (ALPHA, BETA, GA, or DISABLED), and the list of permissions to include.
Custom roles support several launch stages that help manage their lifecycle. The DISABLED stage is particularly useful when you want to temporarily revoke access granted by a role across all members.
There are some limitations to consider. Certain permissions cannot be included in custom roles, and you cannot use custom roles at the folder level. Additionally, each organization and project has a limit of 300 custom roles.
Best practices for custom roles include starting with a predefined role as a template and removing unnecessary permissions, regularly auditing custom roles to ensure they remain appropriate, and using meaningful naming conventions for easy identification.
To manage custom roles effectively, you can use gcloud commands such as gcloud iam roles create for creation, gcloud iam roles update for modifications, and gcloud iam roles delete for removal. Custom roles provide granular control over access management, making them essential for organizations with specific compliance or security needs that predefined roles cannot satisfy.
Defining custom IAM roles
Custom IAM roles in Google Cloud Platform allow you to create tailored permission sets that align precisely with your organization's security requirements. Unlike predefined roles, custom roles give you granular control over which permissions to include, following the principle of least privilege.
To define a custom IAM role, you need to understand several key components. First, you must specify a role ID, which is a unique identifier within your project or organization. Second, you provide a title and description that help administrators understand the role's purpose. Third, and most importantly, you select the specific permissions to include from Google Cloud's extensive permissions catalog.
Custom roles can be created at two levels: project level or organization level. Organization-level custom roles can be granted across all projects within that organization, while project-level roles are limited to that specific project.
You can create custom roles using the Google Cloud Console, gcloud CLI, or the IAM API. When using gcloud, the command follows this pattern: gcloud iam roles create [ROLE_ID] --project=[PROJECT_ID] --permissions=[PERMISSIONS_LIST] --title=[TITLE] --description=[DESCRIPTION].
There are important considerations when working with custom roles. Some permissions cannot be used in custom roles, and certain permissions are only available at specific resource levels. You should also be aware that custom roles have launch stages: ALPHA, BETA, GA, DISABLED, and EAP, which indicate their maturity level.
Best practices include starting with a predefined role that closely matches your needs, then adding or removing permissions as necessary. Regular auditing of custom roles ensures they remain aligned with security policies. Additionally, maintaining documentation about why each custom role was created helps with governance and compliance requirements.
Custom roles support up to 3,000 permissions per role and have quotas limiting how many custom roles you can create per project or organization.
Creating service accounts
Service accounts are special Google Cloud accounts that belong to applications or virtual machines rather than individual users. They enable workloads to authenticate and access Google Cloud resources securely without human intervention.
To create a service account, you can use the Google Cloud Console, gcloud CLI, or APIs. In the Console, navigate to IAM & Admin > Service Accounts, click 'Create Service Account', provide a name and description, then assign appropriate IAM roles.
Using gcloud CLI, execute: gcloud iam service-accounts create [SA-NAME] --description="[DESCRIPTION]" --display-name="[DISPLAY-NAME]"
Service accounts have unique email addresses formatted as: [SA-NAME]@[PROJECT-ID].iam.gserviceaccount.com
There are three types of service accounts:
1. User-managed service accounts - Created by users for specific application needs
2. Default service accounts - Automatically created when certain APIs are enabled (like Compute Engine or App Engine)
3. Google-managed service accounts - Created and managed by Google for internal processes
After creation, you must grant the service account appropriate IAM roles to access resources. Follow the principle of least privilege by assigning only necessary permissions.
For authentication, service accounts can use:
- Service account keys (JSON or P12 format) - Should be managed carefully and rotated regularly
- Workload Identity Federation - Allows external identities to impersonate service accounts
- Attached service accounts - VMs and other resources can use attached service accounts
Best practices include:
- Avoid using default service accounts for production workloads
- Create dedicated service accounts for each application
- Regularly audit and rotate service account keys
- Use Cloud IAM Conditions for fine-grained access control
- Monitor service account usage through Cloud Audit Logs
Service accounts are fundamental for securing automated processes and maintaining proper access control in Google Cloud environments.
Using service accounts in IAM policies
Service accounts in Google Cloud are special accounts used by applications, virtual machines, and services to authenticate and authorize access to Google Cloud resources. Unlike user accounts, service accounts are not tied to individuals but represent non-human identities that perform automated tasks.
When configuring access and security, service accounts play a crucial role in IAM policies. Each service account has a unique email address format: service-account-name@project-id.iam.gserviceaccount.com. You can assign IAM roles to service accounts just like you would for user accounts.
There are three types of service accounts: default service accounts (created automatically for certain services), user-managed service accounts (created by users for specific purposes), and Google-managed service accounts (created and managed by Google).
To use service accounts in IAM policies, you grant them appropriate roles at various levels - organization, folder, project, or resource level. For example, granting a service account the Storage Object Viewer role on a Cloud Storage bucket allows applications using that service account to read objects from the bucket.
Best practices for using service accounts include: following the principle of least privilege by granting minimal necessary permissions, rotating service account keys regularly when using key-based authentication, using workload identity federation to avoid managing keys, and auditing service account usage through Cloud Audit Logs.
Service accounts can also be impersonated by users or other service accounts when granted the Service Account User or Service Account Token Creator roles. This allows temporary assumption of service account permissions for specific tasks.
You can manage service accounts through the Cloud Console, gcloud CLI, or Cloud IAM API. Monitoring service account activity helps identify unused accounts or excessive permissions that should be revoked to maintain security posture across your cloud environment.
Service accounts with minimum permissions
Service accounts with minimum permissions is a critical security concept in Google Cloud Platform (GCP) that follows the principle of least privilege. This principle states that any identity should only have the exact permissions necessary to perform its intended tasks, nothing more.
A service account is a special type of Google account that belongs to an application or virtual machine rather than an individual user. These accounts are used to authenticate and authorize automated processes, applications, and compute resources when they need to interact with GCP services and APIs.
When configuring service accounts with minimum permissions, you should first identify the specific tasks the service account needs to perform. Then, assign only the predefined roles or custom roles that contain precisely those permissions. For example, if a service account only needs to read objects from Cloud Storage, assign the Storage Object Viewer role rather than the broader Storage Admin role.
Best practices for implementing minimum permissions include creating separate service accounts for different applications or functions instead of sharing one account across multiple services. You should regularly audit service account permissions using IAM recommender, which analyzes usage patterns and suggests removing unused permissions.
Custom roles are particularly useful when predefined roles grant more access than required. You can create a custom role containing only the specific permissions your workload needs. Additionally, use service account impersonation carefully and limit which identities can act as service accounts.
Avoid granting primitive roles like Owner, Editor, or Viewer to service accounts as these provide overly broad access. Instead, prefer granular predefined roles or custom roles tailored to your specific use case.
Implementing minimum permissions reduces the potential blast radius if a service account is compromised, limits accidental modifications to resources, and helps maintain compliance with security standards and organizational policies. Regular reviews and updates to service account permissions ensure they remain aligned with actual operational requirements.
Assigning service accounts to resources
Service accounts in Google Cloud are special accounts used by applications, virtual machines, and other resources to authenticate and interact with Google Cloud APIs. Unlike user accounts, service accounts are designed for non-human entities and provide a secure way to manage permissions programmatically.
When assigning service accounts to resources, you establish an identity that the resource uses to access other Google Cloud services. This is fundamental for implementing the principle of least privilege, where each resource receives only the permissions necessary for its function.
To assign a service account to a Compute Engine VM instance, you can specify it during creation using the Console, gcloud CLI, or API. Using gcloud, the command includes the --service-account flag followed by the service account email. For existing instances, you must stop the VM before changing its service account.
For GKE workloads, you can use Workload Identity to link Kubernetes service accounts to Google Cloud service accounts, enabling pods to authenticate securely. This approach is preferred over storing service account keys.
Cloud Functions, Cloud Run, and App Engine services also support custom service account assignment. During deployment, you specify which service account the service should use for authentication when calling other APIs.
Key considerations when assigning service accounts include:
1. Access Scopes - For Compute Engine, you can limit OAuth scopes even if the service account has broader IAM permissions
2. Default Service Accounts - Google Cloud creates default service accounts automatically, but creating custom ones with specific permissions is recommended for production
3. Cross-Project Access - Service accounts can be granted permissions in other projects, enabling secure cross-project resource access
4. Impersonation - Users or other service accounts can impersonate a service account if granted the Service Account Token Creator role
Properly configuring service account assignments ensures your resources can securely communicate while maintaining strong access controls and auditability across your cloud environment.
Managing IAM permissions of a service account
Managing IAM permissions for service accounts in Google Cloud is a critical aspect of configuring access and security. Service accounts are special accounts used by applications, virtual machines, and other workloads to authenticate and access Google Cloud resources.
To manage IAM permissions for service accounts, you work with three key concepts: roles, bindings, and policies. Roles define a collection of permissions that determine what actions can be performed on resources. You can assign predefined roles like Service Account User, Service Account Admin, or Service Account Token Creator, or create custom roles for specific needs.
There are two perspectives when managing service account permissions. First, you control what the service account itself can do by granting it roles on various resources. For example, giving a service account the Storage Object Viewer role allows it to read objects in Cloud Storage buckets. Second, you control who can use or manage the service account by granting users roles on the service account resource.
You can manage these permissions through the Google Cloud Console, gcloud CLI, or the IAM API. Using gcloud, commands like 'gcloud projects add-iam-policy-binding' and 'gcloud iam service-accounts add-iam-policy-binding' are commonly used.
Best practices include following the principle of least privilege, granting only necessary permissions. Avoid using primitive roles like Owner or Editor for service accounts. Instead, use more granular predefined or custom roles. Regularly audit service account permissions using Cloud Asset Inventory or IAM Recommender.
Service account impersonation allows users or other service accounts to act as a target service account when they have the Service Account Token Creator role. This provides flexible access patterns while maintaining security controls.
Key management is also essential. You can create and rotate service account keys, though using attached service accounts or Workload Identity Federation is preferred over managing key files manually.
Managing service account impersonation
Service account impersonation in Google Cloud allows a principal (user or service account) to act as another service account, effectively assuming its identity and permissions. This is a powerful security feature that enables controlled delegation of privileges without sharing service account keys.
To configure service account impersonation, you need to grant the 'Service Account Token Creator' role (roles/iam.serviceAccountTokenCreator) to the principal who needs to impersonate the target service account. This role allows the creation of access tokens, ID tokens, and signing of blobs on behalf of the service account.
The impersonation process works through a chain of trust. When a user or service account impersonates another service account, they can generate short-lived credentials that expire automatically. This approach is more secure than downloading and storing service account keys, which pose security risks if compromised.
To implement impersonation using the gcloud CLI, you can use the --impersonate-service-account flag with your commands. For example: gcloud compute instances list --impersonate-service-account=sa@project.iam.gserviceaccount.com
You can also set impersonation as a default configuration property using: gcloud config set auth/impersonate_service_account [SERVICE_ACCOUNT_EMAIL]
Best practices for managing service account impersonation include: limiting who can impersonate service accounts by carefully granting the Token Creator role, using impersonation chains only when necessary (maximum of one delegation hop is recommended), monitoring impersonation activities through Cloud Audit Logs, and following the principle of least privilege when assigning permissions to service accounts.
Service account impersonation is particularly useful for scenarios like local development testing, cross-project access, and administrative tasks where temporary elevated privileges are needed. It provides an audit trail showing which principal performed actions while impersonating, enhancing security visibility and compliance tracking.
Creating short-lived service account credentials
Short-lived service account credentials in Google Cloud provide temporary access tokens that enhance security by limiting the window of potential misuse. Unlike long-lived service account keys, these credentials automatically expire after a specified duration, typically ranging from a few minutes to several hours.
To create short-lived credentials, you primarily use the IAM Service Account Credentials API. There are three main types of short-lived credentials:
1. **Access Tokens**: Generated using the generateAccessToken method, these OAuth 2.0 tokens allow applications to authenticate as a service account. The maximum lifetime is 3600 seconds (1 hour) by default, extendable to 12 hours with proper configuration.
2. **ID Tokens**: Created via the generateIdToken method, these JWT tokens are used for authenticating to services that accept OIDC tokens, such as Cloud Run or Cloud Functions.
3. **Self-Signed JWTs and Blobs**: The signJwt and signBlob methods allow signing arbitrary data using the service account's private key.
To implement short-lived credentials, the calling identity needs the Service Account Token Creator role (roles/iam.serviceAccountTokenCreator) on the target service account. This enables secure delegation where one identity can act as another service account temporarily.
The process typically involves:
- Enabling the IAM Credentials API
- Granting appropriate permissions to the caller
- Making API calls or using client libraries to generate tokens
- Using the returned credential before expiration
Benefits include reduced risk from credential compromise, better audit trails, elimination of key rotation complexity, and compliance with security best practices. Short-lived credentials are particularly valuable in automated workflows, cross-project access scenarios, and when implementing the principle of least privilege.
Google Cloud client libraries and tools like gcloud can automatically manage these credentials, making implementation straightforward while maintaining robust security posture.
Managing short-lived service account credentials
Short-lived service account credentials in Google Cloud are temporary credentials that provide enhanced security compared to persistent service account keys. As a Cloud Engineer, understanding how to manage these credentials is essential for maintaining secure access to GCP resources.
Short-lived credentials are generated using the Service Account Credentials API and typically expire within a limited timeframe, usually ranging from a few minutes to a maximum of 12 hours. This approach significantly reduces security risks because even if credentials are compromised, they become invalid after expiration.
There are three main types of short-lived credentials:
1. **Access Tokens**: OAuth 2.0 tokens that authenticate API requests. These are obtained through the generateAccessToken method and are valid for up to one hour by default.
2. **ID Tokens**: OpenID Connect tokens used for identity verification when accessing services that require authentication. Generated using the generateIdToken method.
3. **Self-signed JWTs and Blobs**: Used for custom authentication scenarios where you need signed data for verification purposes.
To generate short-lived credentials, a principal must have the Service Account Token Creator role (roles/iam.serviceAccountTokenCreator) on the target service account. This role grants permission to impersonate the service account and create tokens on its behalf.
Best practices for managing short-lived credentials include:
- Prefer short-lived credentials over downloaded service account keys
- Set appropriate token lifetimes based on your use case
- Use Workload Identity Federation for external workloads to obtain tokens through identity providers
- Implement proper IAM bindings to control who can generate tokens
- Monitor token creation using Cloud Audit Logs
Organizations can also set constraints using Organization Policies to limit maximum token lifetimes, ensuring compliance with security requirements. This approach aligns with the principle of least privilege and reduces the attack surface for potential security breaches.
Using service accounts with GKE applications
Service accounts are essential for securing GKE applications by providing identity and access management for workloads running in Kubernetes clusters. In Google Cloud, service accounts enable pods to authenticate and interact with Google Cloud APIs securely.
There are two primary approaches for using service accounts with GKE applications:
1. **Node Service Account**: By default, GKE nodes use a service account that all pods on that node inherit. This approach is simpler but less secure since all workloads share the same permissions. You can specify a custom service account when creating a node pool using the --service-account flag.
2. **Workload Identity**: This is the recommended approach for GKE. Workload Identity allows Kubernetes service accounts to act as Google Cloud service accounts. You create a binding between a Kubernetes service account and a Google Cloud service account, enabling fine-grained access control per workload.
To configure Workload Identity:
- Enable Workload Identity on your GKE cluster
- Create a Google Cloud service account with required IAM permissions
- Create a Kubernetes service account in your namespace
- Add an IAM policy binding between both service accounts
- Annotate the Kubernetes service account with the Google Cloud service account email
- Configure pods to use the Kubernetes service account
Best practices include:
- Follow the principle of least privilege when assigning roles
- Use separate service accounts for different applications
- Avoid using the default Compute Engine service account
- Regularly audit service account permissions
- Enable Workload Identity Federation for enhanced security
Service accounts can also be used for pulling container images from private Container Registry or Artifact Registry repositories. The node service account needs the storage.objectViewer role to access these registries.
Proper service account configuration ensures your GKE applications can securely access Google Cloud resources while maintaining isolation between different workloads and adhering to security best practices.