GCP-IAM
Manage identity and access control for Google Cloud Platform resources.
IT Services · GCP IAM
Details
| ID | GCP-IAM |
|---|---|
| Provider | |
| Category | IT Services |
| From Version | 6.0.0 |
| Docker Image | demisto/google-api-py3:1.0.0.10182333 |
| Supported Modules | Agentix XSIAM EDR Cortex Cloud Cloud Runtime Security |
README
GCP-IAM
Manage identity and access control for Google Cloud Platform resources.
This integration was integrated and tested with the following version of GCP-IAM API:
- Identity and Access Management API - v1 version.
- Cloud Resource Manager API - v3 version.
- Cloud Identity API - v1 version.
Configure GCP-IAM in Cortex
| Parameter | Required |
|---|---|
| Service Account Private Key file content (JSON). | True |
Commands
You can execute these commands from the CLI, as part of an automation, or in a playbook.
After you successfully execute a command, a DBot message appears in the War Room with the command details.
gcp-iam-projects-get
Lists project under the specified parent, or retrieves a specific project’’s information. One of the arguments: ‘‘parent’’ or ‘‘project_name’’ must be provided.
Base Command
gcp-iam-projects-get
Input
| Argument Name | Description | Required |
|---|---|---|
| project_name | A comma-separated list of project names to retrieve. For example, projects/415104041262. Leave empty to retrieve a list of projects under a specified parent resource. | Optional |
| limit | The maximum number of results to retrieve. Minimum value is 1. Maximum value is 100. Default is 50. | Optional |
| page | The page number of the results to retrieve. Minimum value is 1. Default is 1. | Optional |
| parent | The name of the parent resource to list projects under. For example, setting this field to ‘folders/1234’ would list all projects directly under that folder. | Optional |
| show_deleted | If true, projects that have been marked for deletion will also be retrieved. Possible values are: False, True. Default is False. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| GCPIAM.Project.createTime | Date | Project creation time. |
| GCPIAM.Project.displayName | String | Project display name. |
| GCPIAM.Project.name | String | The unique resource name of the project. |
| GCPIAM.Project.parent | String | The project parent resource. |
| GCPIAM.Project.projectId | String | The unique, user-assigned ID of the project. |
| GCPIAM.Project.state | String | The project lifecycle state. |
| GCPIAM.Project.updateTime | Date | The most recent time the project was modified. |
Command example
!gcp-iam-projects-get project_name="projects/project-name-1"
Context Example
{
"GCP": {
"IAM": {
"Project": {
"createTime": "2021-11-01T10:43:50.858000+00:00",
"displayName": "My First Project",
"etag": "SIVTMlYY9sE1j3K0iNDLcw==",
"name": "projects/project-name-1",
"parent": "organizations/xsoar-organization",
"projectId": "project-id-1",
"state": "ACTIVE",
"updateTime": "2021-11-01T10:43:53.026000+00:00"
}
}
}
}
Human Readable Output
Project projects/project-name-1 information
Name Parent Project Id Display Name Create Time Update Time projects/project-name-1 organizations/xsoar-organization project-id-1 My First Project 2021-11-01T10:43:50.858000+00:00 2021-11-01T10:43:53.026000+00:00
gcp-iam-project-iam-policy-get
Retrieves the IAM access control policy for the specified project.
Base Command
gcp-iam-project-iam-policy-get
Input
| Argument Name | Description | Required |
|---|---|---|
| project_name | The project name for which the policy is being requested. For example, projects/415104041262. | Required |
| limit | The maximum number of results to retrieve. Minimum value is 1. Default is 50. | Optional |
| page | The page number of the results to retrieve. Minimum value is 1. Default is 1. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| GCPIAM.Policy.bindings.members | String | The members who associate to the role. |
| GCPIAM.Policy.bindings.role | String | The role that is assigned to the list of members. |
| GCPIAM.Policy.name | String | The unique resource name of the project. Note that this output was added manually. |
Command Example
!gcp-iam-project-iam-policy-get project_name="projects/project-name-1" limit=2
Context Example
{
"GCP": {
"IAM": {
"Policy": {
"bindings": [
{
"members": [
"serviceAccount:service-account-1@project-id-1.iam.gserviceaccount.com"
],
"role": "roles/anthosidentityservice.serviceAgent"
},
{
"members": [
"group:poctest@xsoar.com",
"serviceAccount:service-account-2@project-id-1.iam.gserviceaccount.com"
],
"role": "roles/browser"
}
],
"etag": "BwXRnN60xqw=",
"name": "projects/project-name-1",
"version": 1
}
}
}
}
Human Readable Output
Project projects/project-name-1 IAM Policy List
Current page size: 2
Showing page 1 out of others that may exist.
Role Members roles/anthosidentityservice.serviceAgent serviceAccount:service-account-1@project-id-1.iam.gserviceaccount.com roles/browser group:poctest@xsoar.com,
serviceAccount:service-account-2@project-id-1.iam.gserviceaccount.com
gcp-iam-project-iam-permission-test
Returns permissions that a caller has on the specified project. The permission list can be obtained by running the ‘gcp-iam-testable-permission-list’ command.
Base Command
gcp-iam-project-iam-permission-test
Input
| Argument Name | Description | Required |
|---|---|---|
| project_name | The project name for which the permissions is being tested. For example, projects/415104041262. | Required |
| permissions | A comma-separated list of permissions names to validate for the resource. | Required |
Context Output
| Path | Type | Description |
|---|---|---|
| GCPIAM.Permission | String | The caller allowed permissions. |
Command Example
!gcp-iam-project-iam-permission-test project_name="projects/project-name-1" permissions="compute.instances.create,aiplatform.dataItems.create"
Context Example
{
"GCP": {
"IAM": {
"Permission": [
{
"name": "aiplatform.dataItems.create"
},
{
"name": "compute.instances.create"
}
]
}
}
}
Human Readable Output
Project projects/project-name-1 permissions
Name aiplatform.dataItems.create compute.instances.create
gcp-iam-project-iam-member-add
Adds members to the project policy.
Base Command
gcp-iam-project-iam-member-add
Input
| Argument Name | Description | Required |
|---|---|---|
| project_name | The resource for which the policy is being specified. For example, projects/415104041262. | Required |
| role | The name of the policy role. | Required |
| members | A comma-separated list of members to add to the policy. For example: user:mike@example.com, group:admins@example.com, domain:google.com, serviceAccount:my-project-id@xsoar.gserviceaccount.com. | Required |
Context Output
There is no context output for this command.
Command Example
!gcp-iam-project-iam-member-add project_name="projects/project-name-3" role="roles/browser" members="serviceAccount:service-account-2@project-id-1.iam.gserviceaccount.com"
Human Readable Output
Role roles/browser updated successfully.
gcp-iam-project-iam-member-remove
Removes members from the project policy.
Base Command
gcp-iam-project-iam-member-remove
Input
| Argument Name | Description | Required |
|---|---|---|
| project_name | The name of the project for which the policy is being specified. For example, projects/415104041262. | Required |
| role | The name of the policy role. | Required |
| members | A comma-separated list of members to remove from the policy. For example: user:mike@example.com, group:admins@example.com, domain:google.com, serviceAccount:my-project-id@xsoar.gserviceaccount.com. | Required |
Context Output
There is no context output for this command.
Command Example
!gcp-iam-project-iam-member-remove project_name="projects/project-name-3" role="roles/browser" members="serviceAccount:service-account-2@project-id-1.iam.gserviceaccount.com"
Human Readable Output
Role roles/browser updated successfully.
gcp-iam-project-iam-policy-set
Sets the IAM access control policy for the specified project. This operation will overwrite any existing policy.
Base Command
gcp-iam-project-iam-policy-set
Input
| Argument Name | Description | Required |
|---|---|---|
| project_name | The name of the project for which the policy is being specified. For example, projects/415104041262. | Required |
| policy | A comma-separated list of JSON policies objects. Every policy item consists of ‘role’ and ‘members’. For example: [ { “role”: “roles/resourcemanager.organizationViewer”, “members”: [ “user:eve@example.com” ] } ]. |
Required |
Context Output
| Path | Type | Description |
|---|---|---|
| GCPIAM.Policy.bindings.members | String | The members who associate to the role. |
| GCPIAM.Policy.bindings.role | String | The role that is assigned to the list of members. |
| GCPIAM.Policy.name | String | The unique resource name of the project. Note that this output was added manually. |
Command Example
!gcp-iam-project-iam-policy-set project_name="projects/project-name-3" policy=`{"role": "roles/owner", "members": ["group:poctest@xsoar.com", "serviceAccount:service-account-2@project-id-1.iam.gserviceaccount.com"]}, { "role": "roles/browser", "members": [ "group:poctest@xsoar.com" ] }`
Context Example
{
"GCP": {
"IAM": {
"Policy": {
"bindings": [
{
"members": [
"group:poctest@xsoar.com"
],
"role": "roles/browser"
},
{
"members": [
"group:poctest@xsoar.com",
"serviceAccount:service-account-2@project-id-1.iam.gserviceaccount.com"
],
"role": "roles/owner"
}
],
"etag": "BwXUDeggkiM=",
"name": "projects/project-name-3",
"version": 1
}
}
}
}
Human Readable Output
projects/project-name-3 IAM policy updated successfully
Role Members roles/browser group:poctest@xsoar.com roles/owner group:poctest@xsoar.com,
serviceAccount:service-account-2@project-id-1.iam.gserviceaccount.com
gcp-iam-project-iam-policy-create
Adds a new project IAM policy.
Base Command
gcp-iam-project-iam-policy-create
Input
| Argument Name | Description | Required |
|---|---|---|
| project_name | The name of the project for which the policy is being specified. For example, projects/415104041262. | Required |
| role | The name of the policy role. | Required |
| members | A comma-separated list of members associated with the role. For example: user:mike@example.com, group:admins@example.com, domain:google.com, serviceAccount:my-project-id@xsoar.gserviceaccount.com. | Required |
Context Output
There is no context output for this command.
Command Example
!gcp-iam-project-iam-policy-create project_name="projects/project-name-3" role="roles/anthosidentityservice.serviceAgent" members="serviceAccount:service-account-2@project-id-1.iam.gserviceaccount.com"
Human Readable Output
Role roles/anthosidentityservice.serviceAgent updated successfully.
gcp-iam-folders-get
Lists folders under the specified parent, or retrieves a specific folder information. One of the arguments: ‘‘parent’’ or ‘‘folder_name’’ must be provided.
Base Command
gcp-iam-folders-get
Input
| Argument Name | Description | Required |
|---|---|---|
| folder_name | A comma-separated list of folder names to retrieve. For example, folders/12342. Leave empty to retrieve a list of folders under a specified parent resource. | Optional |
| parent | The name of the parent resource to list folders under. For example, setting this field to ‘folders/1234’ would list all folder directly under that folder. | Optional |
| limit | The maximum number of results to retrieve. Minimum value is 1, maximum value is 100. Default is 50. | Optional |
| page | The page number of the results to retrieve. Minimum value is 1. Default is 1. | Optional |
| show_deleted | If true, folders that have been marked for deletion will also be retrieved. Possible values are: False, True. Default is False. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| GCPIAM.Folder.createTime | Date | Folder creation time. |
| GCPIAM.Folder.displayName | String | Folder display name. |
| GCPIAM.Folder.name | String | The unique resource name of the folder. |
| GCPIAM.Folder.parent | String | The folder parent resource. |
| GCPIAM.Folder.state | String | The folder lifecycle state. |
| GCPIAM.Folder.updateTime | Date | The most recent time the folder was modified. |
Command example
!gcp-iam-folders-get folder_name="folders/folder-name-1"
Context Example
{
"GCP": {
"IAM": {
"Folder": {
"createTime": "2021-12-20T09:16:57.801000+00:00",
"displayName": "integration folder",
"etag": "DNurvk2qbYsaHclxISf8AQ==",
"name": "folders/folder-name-1",
"parent": "organizations/xsoar-organization",
"state": "ACTIVE",
"updateTime": "2021-12-20T09:16:57.801000+00:00"
}
}
}
}
Human Readable Output
Folder folders/folder-name-1 information
Name Parent Display Name Create Time Update Time folders/folder-name-1 organizations/xsoar-organization integration folder 2021-12-20T09:16:57.801000+00:00 2021-12-20T09:16:57.801000+00:00
gcp-iam-folder-iam-policy-get
Retrieves the IAM access control policy for the specified folder.
Base Command
gcp-iam-folder-iam-policy-get
Input
| Argument Name | Description | Required |
|---|---|---|
| folder_name | The folder name for which the policy is being requested. For example, folders/12342. | Required |
| limit | The maximum number of results to retrieve. Minimum value is 1. Default is 50. | Optional |
| page | The page number of the results to retrieve. Minimum value is 1. Default is 1. | Optional |
| roles | A comma-separated list of roles. (Ex: “roles/bigquery.admin, roles/editor, roles/owner”). | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| GCPIAM.Policy.bindings.members | String | The members who associate to the role. |
| GCPIAM.Policy.bindings.role | String | The role that is assigned to the list of members. |
| GCPIAM.Policy.name | String | The unique resource name of the folder. Note that this output was added manually. |
Command Example
!gcp-iam-folder-iam-policy-get folder_name="folders/folder-name-3" limit=2
Context Example
{
"GCP": {
"IAM": {
"Policy": {
"bindings": [
{
"members": [
"group:poctest@xsoar.com",
"serviceAccount:service-account-2@project-id-1.iam.gserviceaccount.com"
],
"role": "organizations/xsoar-organization/roles/xsoar_demo_99"
},
{
"members": [
"user:user-1@xsoar.com"
],
"role": "roles/resourcemanager.folderAdmin"
}
],
"etag": "BwXUDa+Bs4c=",
"name": "folders/folder-name-3",
"version": 1
}
}
}
}
Human Readable Output
Folder folders/folder-name-3 IAM Policy List
Current page size: 2
Showing page 1 out of others that may exist.
Role Members organizations/xsoar-organization/roles/xsoar_demo_99 group:poctest@xsoar.com,
serviceAccount:service-account-2@project-id-1.iam.gserviceaccount.comroles/resourcemanager.folderAdmin user:user-1@xsoar.com
gcp-iam-folder-iam-permission-test
Returns permissions that a caller has on the specified folder. The permission list can be obtained by running the ‘gcp-iam-testable-permission-list’ command.
Base Command
gcp-iam-folder-iam-permission-test
Input
| Argument Name | Description | Required |
|---|---|---|
| folder_name | The folder name for which the permissions is being tested. For example, folders/12342. | Required |
| permissions | A comma-separated list of permission names to validate for the resource. | Required |
Context Output
| Path | Type | Description |
|---|---|---|
| GCPIAM.Permission | String | The caller allowed permissions. |
Command Example
!gcp-iam-folder-iam-permission-test folder_name="folders/folder-name-3" permissions="compute.instances.create,aiplatform.dataItems.create"
Context Example
{
"GCP": {
"IAM": {
"Permission": [
{
"name": "aiplatform.dataItems.create"
},
{
"name": "compute.instances.create"
}
]
}
}
}
Human Readable Output
Folder folders/folder-name-3 permissions
Name aiplatform.dataItems.create compute.instances.create
gcp-iam-folder-iam-member-add
Adds members to the folder policy.
Base Command
gcp-iam-folder-iam-member-add
Input
| Argument Name | Description | Required |
|---|---|---|
| folder_name | The resource for which the policy is being specified. For example, folders/12342. | Required |
| role | The name of the policy role. | Required |
| members | A comma-separated list of members to add to the policy. For example: user:mike@example.com, group:admins@example.com, domain:google.com, serviceAccount:my-project-id@xsoar.gserviceaccount.com. | Required |
Context Output
There is no context output for this command.
Command Example
!gcp-iam-folder-iam-member-add folder_name=folders/folder-name-3 role=roles/resourcemanager.folderEditor members=serviceAccount:service-account-2@project-id-1.iam.gserviceaccount.com,group:poctest@xsoar.com
Human Readable Output
Role roles/resourcemanager.folderEditor updated successfully.
gcp-iam-folder-iam-member-remove
Removes members from the folder policy.
Base Command
gcp-iam-folder-iam-member-remove
Input
| Argument Name | Description | Required |
|---|---|---|
| folder_name | The name of the folder for which the policy is being specified. For example, folders/12342. | Required |
| role | The name of the policy role. | Required |
| members | A comma-separated list of members to remove from the policy. For example: user:mike@example.com, group:admins@example.com, domain:google.com, serviceAccount:my-project-id@xsoar.gserviceaccount.com. | Required |
Context Output
There is no context output for this command.
Command Example
!gcp-iam-folder-iam-member-remove folder_name="folders/folder-name-3" role="roles/resourcemanager.folderEditor" members="serviceAccount:service-account-2@project-id-1.iam.gserviceaccount.com"
Human Readable Output
Role roles/resourcemanager.folderEditor updated successfully.
gcp-iam-folder-iam-policy-set
Sets the IAM access control policy for the specified folder. This operation will overwrite any existing policy.
Base Command
gcp-iam-folder-iam-policy-set
Input
| Argument Name | Description | Required |
|---|---|---|
| folder_name | The name of the folder for which the policy is being specified. For example, folders/12342. | Required |
| policy | A comma-separated list of JSON policies objects. Every policy item consists of ‘role’ and ‘members’. For example: [ { “role”: “roles/resourcemanager.organizationViewer”, “members”: [ “user:eve@example.com” ] } ]. |
Required |
Context Output
| Path | Type | Description |
|---|---|---|
| GCPIAM.Policy.bindings.members | String | The members who associate to the role. |
| GCPIAM.Policy.bindings.role | String | The role that is assigned to the list of members. |
| GCPIAM.Policy.name | String | The unique resource name of the folder. Note that this output was added manually. |
Command Example
!gcp-iam-folder-iam-policy-set folder_name="folders/folder-name-3" policy=`{"role": "roles/resourcemanager.folderAdmin","members": ["user:user-1@xsoar.com"]},{"role": "roles/resourcemanager.folderEditor","members": ["user:user-1@xsoar.com"]}`
Context Example
{
"GCP": {
"IAM": {
"Policy": {
"bindings": [
{
"members": [
"user:user-1@xsoar.com"
],
"role": "roles/resourcemanager.folderAdmin"
},
{
"members": [
"user:user-1@xsoar.com"
],
"role": "roles/resourcemanager.folderEditor"
}
],
"etag": "BwXUDa8IhW0=",
"name": "folders/folder-name-3",
"version": 1
}
}
}
}
Human Readable Output
folders/folder-name-3 IAM policy updated successfully
Role Members roles/resourcemanager.folderAdmin user:user-1@xsoar.com roles/resourcemanager.folderEditor user:user-1@xsoar.com
gcp-iam-folder-iam-policy-create
Adds a new folder IAM policy.
Base Command
gcp-iam-folder-iam-policy-create
Input
| Argument Name | Description | Required |
|---|---|---|
| folder_name | The name of the folder for which the policy is being specified. For example, folders/12342. | Required |
| role | The name of the policy role. | Required |
| members | A comma-separated list of members associated with the role. For example: user:mike@example.com, group:admins@example.com, domain:google.com, serviceAccount:my-project-id@xsoar.gserviceaccount.com. | Required |
Context Output
There is no context output for this command.
Command Example
!gcp-iam-folder-iam-policy-create folder_name="folders/folder-name-3" role="organizations/xsoar-organization/roles/xsoar_demo_99" members="serviceAccount:service-account-2@project-id-1.iam.gserviceaccount.com,group:poctest@xsoar.com"
Human Readable Output
Role organizations/xsoar-organization/roles/xsoar_demo_99 updated successfully.
gcp-iam-organizations-get
Lists organization resources that are visible to the caller, or retrieves an organization’s information.
Base Command
gcp-iam-organizations-get
Input
| Argument Name | Description | Required |
|---|---|---|
| limit | The maximum number of results to retrieve. Minimum value is 1. Default is 50. | Optional |
| page | The page number of the results to retrieve. Minimum value is 1. Default is 1. | Optional |
| organization_name | A comma-separated list of organization names to retrieve. For example, organizations/3456. Leave empty to retrieve a list of organizations that are visible to the caller. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| GCPIAM.Organization.createTime | Date | Organization creation time. |
| GCPIAM.Organization.directoryCustomerId | String | The G Suite / Workspace customer ID used in the Directory API. |
| GCPIAM.Organization.displayName | String | Organization display name. |
| GCPIAM.Organization.name | String | The unique resource name of the organization. |
| GCPIAM.Organization.state | String | The organization lifecycle state. |
| GCPIAM.Organization.updateTime | Date | The most recent time the organization was modified. |
Command example
!gcp-iam-organizations-get limit="50" page="1"
Context Example
{
"GCP": {
"IAM": {
"Organization": {
"createTime": "2021-11-01T10:32:53.855000+00:00",
"directoryCustomerId": "xsoar-customer-id",
"displayName": "xsoar.com",
"etag": "TdmlNua+ZCbmiXGBNzldeg==",
"name": "organizations/xsoar-organization",
"state": "ACTIVE",
"updateTime": "2021-11-01T10:32:53.855000+00:00"
}
}
}
}
Human Readable Output
Organizations List
Current page size: 50
Showing page 1 out of others that may exist.
Name Display Name Directory Customer Id Create Time Update Time organizations/xsoar-organization xsoar.com xsoar-customer-id 2021-11-01T10:32:53.855000+00:00 2021-11-01T10:32:53.855000+00:00
gcp-iam-organization-iam-policy-get
Retrieves the IAM access control policy for the specified organization.
Base Command
gcp-iam-organization-iam-policy-get
Input
| Argument Name | Description | Required |
|---|---|---|
| organization_name | The organization name for which the policy is being requested. For example, organizations/3456. | Required |
| limit | The maximum number of results to retrieve. Minimum value is 1. Default is 50. | Optional |
| page | The page number of the results to retrieve. Minimum value is 1. Default is 1. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| GCPIAM.Policy.bindings.members | String | The members who associate to the role. |
| GCPIAM.Policy.bindings.role | String | The role that is assigned to the list of members. |
| GCPIAM.Policy.name | String | The unique resource name of the organization. Note that this output was added manually. |
Command Example
!gcp-iam-organization-iam-policy-get organization_name="organizations/xsoar-organization" limit=2
Context Example
{
"GCP": {
"IAM": {
"Policy": {
"bindings": [
{
"members": [
"user:user-1@xsoar.com"
],
"role": "roles/bigquery.admin"
},
{
"members": [
"user:user-1@xsoar.com"
],
"role": "roles/bigquery.user"
}
],
"etag": "BwXUxBjIO70=",
"name": "organizations/xsoar-organization",
"version": 1
}
}
}
}
Human Readable Output
Organization organizations/xsoar-organization IAM Policy List
Current page size: 2
Showing page 1 out of others that may exist.
Role Members roles/bigquery.admin user:user-1@xsoar.com roles/bigquery.user user:user-1@xsoar.com
gcp-iam-organization-iam-permission-test
Returns permissions that a caller has on the specified organization. The permission list can be obtained by running the ‘gcp-iam-testable-permission-list’ command.
Base Command
gcp-iam-organization-iam-permission-test
Input
| Argument Name | Description | Required |
|---|---|---|
| organization_name | The organization name for which the permissions is being tested. For example, organizations/3456. | Required |
| permissions | A comma-separated list of permissions names to validate for the resource. | Required |
Context Output
| Path | Type | Description |
|---|---|---|
| GCPIAM.Permission | String | The caller allowed permissions. |
Command Example
!gcp-iam-organization-iam-permission-test organization_name="organizations/xsoar-organization" permissions="compute.instances.create,aiplatform.dataItems.create"
Context Example
{
"GCP": {
"IAM": {
"Permission": [
{
"name": "compute.instances.create"
},
{
"name": "aiplatform.dataItems.create"
}
]
}
}
}
Human Readable Output
Organization organizations/xsoar-organization permissions
Name compute.instances.create aiplatform.dataItems.create
gcp-iam-organization-iam-member-add
Adds members to the organization policy.
Base Command
gcp-iam-organization-iam-member-add
Input
| Argument Name | Description | Required |
|---|---|---|
| organization_name | The resource for which the policy is being specified. For example, organizations/3456. | Required |
| role | The name of the policy role. | Required |
| members | A comma-separated list of members ato add to the policy. For example: user:mike@example.com, group:admins@example.com, domain:google.com, serviceAccount:my-project-id@xsoar.gserviceaccount.com. | Required |
Context Output
There is no context output for this command.
Command Example
!gcp-iam-organization-iam-member-add organization_name="organizations/xsoar-organization" role="organizations/xsoar-organization/roles/xsoar_demo_70" members="user:user-1@xsoar.com"
Human Readable Output
Role organizations/xsoar-organization/roles/xsoar_demo_70 updated successfully.
gcp-iam-organization-iam-member-remove
Removes members from the organization policy.
Base Command
gcp-iam-organization-iam-member-remove
Input
| Argument Name | Description | Required |
|---|---|---|
| organization_name | The name of the organization for which the policy is being specified. For example, organizations/3456. | Required |
| role | The name of the policy role. | Required |
| members | A comma-separated list of members to remove from the policy. For example: user:mike@example.com, group:admins@example.com, domain:google.com, serviceAccount:my-project-id@xsoar.gserviceaccount.com. | Required |
Context Output
There is no context output for this command.
Command Example
!gcp-iam-organization-iam-member-remove organization_name="organizations/xsoar-organization" role="organizations/xsoar-organization/roles/xsoar_demo_70" members="user:user-1@xsoar.com"
Human Readable Output
Role organizations/xsoar-organization/roles/xsoar_demo_70 updated successfully.
gcp-iam-organization-iam-policy-set
Sets the IAM access control policy for the specified organization. This operation will overwrite any existing policy.
Base Command
gcp-iam-organization-iam-policy-set
Input
| Argument Name | Description | Required |
|---|---|---|
| organization_name | The name of the organization for which the policy is being specified. For example, organizations/3456. | Required |
| policy | A comma-separated list of JSON policies objects. Every policy item consists of ‘role’ and ‘members’. For example: [ { “role”: “roles/resourcemanager.organizationViewer”, “members”: [ “user:eve@example.com” ] } ]. |
Required |
Context Output
| Path | Type | Description |
|---|---|---|
| GCPIAM.Policy.bindings.members | String | The members who associate to the role. |
| GCPIAM.Policy.bindings.role | String | The role that is assigned to the list of members. |
| GCPIAM.Policy.name | String | The unique resource name of the organization. Note that this output was added manually. |
Command Example
!gcp-iam-organization-iam-policy-set organization_name="organizations/xsoar-organization" policy=` { "members": [ "user:user-1@xsoar.com" ], "role": "roles/bigquery.admin" }`
Context Example
{
"GCP": {
"IAM": {
"Policy": {
"bindings": [
{
"members": [
"user:user-1@xsoar.com"
],
"role": "roles/bigquery.admin"
}
],
"etag": "BwXUxBs/sN0=",
"name": "organizations/xsoar-organization",
"version": 1
}
}
}
}
Human Readable Output
organizations/xsoar-organization IAM policy updated successfully
Role Members roles/bigquery.admin user:user-1@xsoar.com
gcp-iam-organization-iam-policy-create
Adds a new organization IAM policy.
Base Command
gcp-iam-organization-iam-policy-create
Input
| Argument Name | Description | Required |
|---|---|---|
| organization_name | The name of the organization for which the policy is being specified. For example, organizations/3456. | Required |
| role | The name of the policy role. | Required |
| members | A comma-separated list of members associated with the role. For example: user:mike@example.com, group:admins@example.com, domain:google.com, serviceAccount:my-project-id@xsoar.gserviceaccount.com. | Required |
Context Output
There is no context output for this command.
Command Example
!gcp-iam-organization-iam-policy-create organization_name="organizations/xsoar-organization" role="organizations/xsoar-organization/roles/xsoar_demo_70" members="serviceAccount:service-account-2@project-id-1.iam.gserviceaccount.com,group:poctest@xsoar.com"
Human Readable Output
Role organizations/xsoar-organization/roles/xsoar_demo_70 updated successfully.
gcp-iam-group-create
Creates a new group. The end user making the request will be added as the initial owner of the group.
Base Command
gcp-iam-group-create
Input
| Argument Name | Description | Required |
|---|---|---|
| parent | The parent resource of the groups to create. Must be of the form identitysources/{identity_source_id} for external- identity-mapped groups or customers/{customer_id} for Google Groups. The customer_id must begin with “C” (for example, ‘C046psxkn’). Customer ID can be obtained by running the ‘gcp-iam-organizations-get’ command. The customer ID can be found in the ‘directoryCustomerId’ field. | Required |
| description | The description of the group. | Optional |
| display_name | The display name of the group. | Required |
| group_email_address | The group unique email address. There is no need to set up the email in the organization, the command will do this independently. | Required |
Context Output
| Path | Type | Description |
|---|---|---|
| GCPIAM.Group.createTime | Date | Group creation time. |
| GCPIAM.Group.displayName | String | The display name of the group |
| GCPIAM.Group.groupKey.id | String | The ID of the group. |
| GCPIAM.Group.name | String | The resource name of the group. |
| GCPIAM.Group.parent | String | The resource name of the entity under which this group resides in the Cloud Identity resource hierarchy. |
| GCPIAM.Group.updateTime | Date | The most recent time the group was modified. |
Command Example
!gcp-iam-group-create parent="customers/xsoar-customer-id" display_name="integration-test" group_email_address="xsoar-test-10@xsoar.com"
Context Example
{
"GCP": {
"IAM": {
"Group": {
"@type": "type.googleapis.com/google.apps.cloudidentity.groups.v1.Group",
"createTime": "2022-01-04T15:25:46.218759+00:00",
"displayName": "integration-test",
"groupKey": {
"id": "xsoar-test-10@xsoar.com"
},
"labels": {
"cloudidentity.googleapis.com/groups.discussion_forum": ""
},
"name": "group-4-name",
"parent": "customers/xsoar-customer-id",
"updateTime": "2022-01-04T15:25:46.218759+00:00"
}
}
}
}
Human Readable Output
Successfully Created Group “group-4-name”
Name Group Key Parent Display Name Create Time Update Time group-4-name id: xsoar-test-10@xsoar.com customers/xsoar-customer-id integration-test 2022-01-04T15:25:46.218759+00:00 2022-01-04T15:25:46.218759+00:00
gcp-iam-group-list
Lists groups that are visible to the caller.
Base Command
gcp-iam-group-list
Input
| Argument Name | Description | Required |
|---|---|---|
| parent | The parent resource of the groups to retrieve. This parameter is usually equal to the organization customer ID. For example customers/C01234. | Required |
| limit | The maximum number of results to retrieve. Minimum value is 1, maximum value is 500. Default is 50. | Optional |
| page | The page number of the results to retrieve. Minimum value is 1. Default is 1. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| GCPIAM.Group.displayName | String | The display name of the group. |
| GCPIAM.Group.groupKey.id | String | The ID of the group. |
| GCPIAM.Group.name | String | The resource name of the group. |
Command Example
!gcp-iam-group-list parent="customers/xsoar-customer-id" limit="2" page="1"
Context Example
{
"GCP": {
"IAM": {
"Group": [
{
"displayName": "integration-test",
"groupKey": {
"id": "xsoar-service-account-245@xsoar.com"
},
"name": "groups/group-5-name"
},
{
"displayName": "xsoar-api-test-2",
"groupKey": {
"id": "poctest1s2@xsoar.com"
},
"name": "groups/group-4-name"
}
]
}
}
}
Human Readable Output
Groups List
Current page size: 2
Showing page 1 out of others that may exist.
Name Group Key Display Name groups/group-5-name id: xsoar-service-account-245@xsoar.com integration-test groups/group-4-name id: poctest1s2@xsoar.com xsoar-api-test-2
gcp-iam-group-get
Retrieves a group information.
Base Command
gcp-iam-group-get
Input
| Argument Name | Description | Required |
|---|---|---|
| group_name | The name of the group to retrieve. Must be of the form groups/{group_id}. | Required |
Context Output
| Path | Type | Description |
|---|---|---|
| GCPIAM.Group.createTime | Date | Group creation time. |
| GCPIAM.Group.displayName | String | The display name of the group |
| GCPIAM.Group.groupKey.id | String | The ID of the group. |
| GCPIAM.Group.name | String | The resource name of the group. |
| GCPIAM.Group.parent | String | The resource name of the entity under which this group resides in the Cloud Identity resource hierarchy. |
| GCPIAM.Group.updateTime | Date | The most recent time the group was modified. |
Command Example
!gcp-iam-group-get group_name="groups/group-5-name"
Context Example
{
"GCP": {
"IAM": {
"Group": {
"createTime": "2021-12-14T12:33:04.648409+00:00",
"displayName": "integration-test",
"groupKey": {
"id": "xsoar-service-account-245@xsoar.com"
},
"labels": {
"cloudidentity.googleapis.com/groups.discussion_forum": ""
},
"name": "groups/group-5-name",
"parent": "customers/xsoar-customer-id",
"updateTime": "2021-12-14T12:33:04.648409+00:00"
}
}
}
}
Human Readable Output
Group information
Name Group Key Parent Display Name Create Time Update Time groups/group-5-name id: xsoar-service-account-245@xsoar.com customers/xsoar-customer-id integration-test 2021-12-14T12:33:04.648409+00:00 2021-12-14T12:33:04.648409+00:00
gcp-iam-group-delete
Deletes a group.
Base Command
gcp-iam-group-delete
Input
| Argument Name | Description | Required |
|---|---|---|
| group_name | The name of the group to delete. Must be of the form groups/{group_id}. | Required |
Context Output
There is no context output for this command.
Command Example
!gcp-iam-group-delete group_name="group-4-name"
Human Readable Output
Group group-4-name was successfully deleted.
gcp-iam-group-membership-create
Creates a group membership.
Base Command
gcp-iam-group-membership-create
Input
| Argument Name | Description | Required |
|---|---|---|
| groups_name | A comma-separated list of group names that will contain the membership. Every group name must be of the form groups/{group_id}. | Required |
| member_email | The email address of the member to add to the group. | Required |
| role | A comma-separated list of membership roles that apply to the membership. The ‘MEMBER’ role must be provided. Possible values are: OWNER, MANAGER, MEMBER. Default is MEMBER. | Required |
Context Output
| Path | Type | Description |
|---|---|---|
| GCPIAM.Membership.name | String | The resource name of the membership. |
| GCPIAM.Membership.preferredMemberKey.id | String | The member key ID. |
| GCPIAM.Membership.roles.name | String | The membership roles that apply to the membership. |
Command Example
!gcp-iam-group-membership-create groups_name="groups/group-5-name" member_email="user-1@xsoar.com" role="MEMBER"
Context Example
{
"GCP": {
"IAM": {
"Membership": {
"@type": "type.googleapis.com/google.apps.cloudidentity.groups.v1.Membership",
"name": "groups/group-5-name/memberships/membership-3",
"preferredMemberKey": {
"id": "user-1@xsoar.com"
},
"roles": [
{
"name": "MEMBER"
}
]
}
}
}
}
Human Readable Output
Membership information
Name Roles Preferred Member Key groups/group-5-name/memberships/membership-3 MEMBER user-1@xsoar.com
gcp-iam-group-membership-list
Lists the group memberships.
Base Command
gcp-iam-group-membership-list
Input
| Argument Name | Description | Required |
|---|---|---|
| group_name | The name of the group that contains the membership. Must be of the form groups/{group_id}. | Required |
| limit | The maximum number of results to retrieve. Minimum value is 1, maximum value is 500. Default is 50. | Optional |
| page | The page number of the results to retrieve. Minimum value is 1. Default is 1. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| GCPIAM.Membership.name | String | The resource name of the membership. |
| GCPIAM.Membership.preferredMemberKey.id | String | The member key ID. |
| GCPIAM.Membership.roles.name | String | The membership roles that apply to the membership. |
Command Example
!gcp-iam-group-membership-list group_name="groups/group-5-name" limit="2" page="1"
Context Example
{
"GCP": {
"IAM": {
"Membership": [
{
"name": "groups/group-5-name/memberships/membership-3",
"preferredMemberKey": {
"id": "user-1@xsoar.com"
},
"roles": [
{
"name": "MEMBER"
}
]
},
{
"name": "groups/group-5-name/memberships/membership-1",
"preferredMemberKey": {
"id": "user-2@xsoar.com"
},
"roles": [
{
"name": "MEMBER"
},
{
"name": "MANAGER"
}
]
}
]
}
}
}
Human Readable Output
Membership List
Current page size: 2
Showing page 1 out of others that may exist.
Name Roles Preferred Member Key groups/group-5-name/memberships/membership-3 MEMBER user-1@xsoar.com groups/group-5-name/memberships/membership-1 MEMBER,
MANAGERuser-2@xsoar.com
gcp-iam-group-membership-get
Retrieves group membership information.
Base Command
gcp-iam-group-membership-get
Input
| Argument Name | Description | Required |
|---|---|---|
| membership_name | The name of the group membership to retrieve. Must be of the form: groups/{group_id}/memberships/{membership_id}. | Required |
Context Output
| Path | Type | Description |
|---|---|---|
| GCPIAM.Membership.createTime | Date | The membership creation time. |
| GCPIAM.Membership.name | String | The resource name of the membership. |
| GCPIAM.Membership.preferredMemberKey.id | String | The member key ID. |
| GCPIAM.Membership.roles.name | String | The membership roles that apply to the membership. |
| GCPIAM.Membership.updateTime | Date | The most recent time the membership was modified. |
Command Example
!gcp-iam-group-membership-get membership_name="groups/group-5-name/memberships/membership-1"
Context Example
{
"GCP": {
"IAM": {
"Membership": {
"createTime": "2021-12-14T13:12:46.091080+00:00",
"name": "groups/group-5-name/memberships/membership-1",
"preferredMemberKey": {
"id": "user-2@xsoar.com"
},
"roles": [
{
"name": "MEMBER"
},
{
"name": "MANAGER"
}
],
"type": "USER",
"updateTime": "2021-12-14T13:12:46.091080+00:00"
}
}
}
}
Human Readable Output
Membership information
Name Roles Preferred Member Key groups/group-5-name/memberships/membership-1 MEMBER,
MANAGERuser-2@xsoar.com
gcp-iam-group-membership-role-add
Adds a group membership role.
Base Command
gcp-iam-group-membership-role-add
Input
| Argument Name | Description | Required |
|---|---|---|
| membership_name | The name of the group membership to update. Must be of the form: groups/{group_id}/memberships/{membership_id}. | Required |
| role | A comma-separated list of membership roles to add to the membership. Possible values are: MANAGER, OWNER. | Required |
Context Output
There is no context output for this command.
Command Example
!gcp-iam-group-membership-role-add membership_name="groups/group-5-name/memberships/membership-3" role="OWNER"
Human Readable Output
Membership groups/group-5-name/memberships/membership-3 updated successfully.
gcp-iam-group-membership-role-remove
Removes a group membership role.
Base Command
gcp-iam-group-membership-role-remove
Input
| Argument Name | Description | Required |
|---|---|---|
| membership_name | The resource name of the membership. Must be of the form: groups/{group_id}/memberships/{membership_id}. | Required |
| role | A comma-separated list of membership roles to remove from the membership. Possible values are: OWNER, MANAGER. | Required |
Context Output
There is no context output for this command.
Command Example
!gcp-iam-group-membership-role-remove membership_name="groups/group-5-name/memberships/membership-3" role="OWNER"
Human Readable Output
Membership groups/group-5-name/memberships/membership-3 updated successfully.
gcp-iam-group-membership-delete
Deletes a group membership.
Base Command
gcp-iam-group-membership-delete
Input
| Argument Name | Description | Required |
|---|---|---|
| membership_names | A comma-separated list of resource names of the memberships to delete. Must be of the form: groups/{group_id}/memberships/{membership_id}. | Required |
Context Output
There is no context output for this command.
Command Example
!gcp-iam-group-membership-delete membership_names=groups/group-5-name/memberships/membership-1
Human Readable Output
Membership groups/group-5-name/memberships/membership-1 deleted successfully.
gcp-iam-service-account-create
Creates a service account in project.
Base Command
gcp-iam-service-account-create
Input
| Argument Name | Description | Required |
|---|---|---|
| project_name | The name of the project associated with the service account. Must be of the form projects/{project_id}. | Required |
| service_account_id | The account ID that is used to generate the service account email address and a stable unique ID. It is unique within a project, must be 6-30 characters long, and match the regular expression [a-z]([-a-z0-9]*[a-z0-9]). |
Required |
| display_name | Human readable name for the created service account. | Optional |
| description | Human readable description for the created service account. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| GCPIAM.ServiceAccount.email | String | The email address of the service account. |
| GCPIAM.ServiceAccount.name | String | The resource name of the service account. |
| GCPIAM.ServiceAccount.oauth2ClientId | String | The OAuth 2.0 client ID for the service account. |
| GCPIAM.ServiceAccount.projectId | String | The ID of the project that owns the service account. |
| GCPIAM.ServiceAccount.uniqueId | String | The unique, stable numeric ID for the service account. |
| GCPIAM.ServiceAccount.disabled | Boolean | Indicates whether the service account is disabled. |
Command Example
!gcp-iam-service-account-create project_name="projects/project-name-3" service_account_id="integration-test-15" display_name="xsoar-service-account" description="XSOAR integration service-account"
Context Example
{
"GCP": {
"IAM": {
"ServiceAccount": {
"description": "XSOAR integration service-account",
"disabled": false,
"displayName": "xsoar-service-account",
"email": "integration-test-15@project-name-3.iam.gserviceaccount.com",
"etag": "MDEwMjE5MjA=",
"name": "projects/project-id-1/serviceAccounts/integration-test-15@project-name-3.iam.gserviceaccount.com",
"oauth2ClientId": "unique-id-5",
"projectId": "project-id-1",
"uniqueId": "unique-id-5"
}
}
}
}
Human Readable Output
Service account information
Name Display Name Description Project Id projects/project-id-1/serviceAccounts/integration-test-15@project-name-3.iam.gserviceaccount.com xsoar-service-account XSOAR integration service-account project-id-1
gcp-iam-service-account-update
Updates a service account.
Base Command
gcp-iam-service-account-update
Input
| Argument Name | Description | Required |
|---|---|---|
| service_account_name | The name of the service account to update. Must be of the form projects/{PROJECT_ID}/serviceAccounts/{ACCOUNT}. | Required |
| display_name | Human readable name for the updated service account. | Optional |
| description | Human readable description for the updated service account. | Optional |
| fields_to_update | A comma-separated list of names list of the fields to update. Possible values are: displayName, description. | Required |
Context Output
There is no context output for this command.
Command Example
!gcp-iam-service-account-update service_account_name="projects/project-id-1/serviceAccounts/integration-test-3@project-name-3.iam.gserviceaccount.com" display_name="xsoar-service-account" fields_to_update="displayName"
Human Readable Output
Service account projects/project-id-1/serviceAccounts/integration-test-3@project-name-3.iam.gserviceaccount.com updated successfully.
gcp-iam-service-accounts-get
Lists service accounts in project, or retrieves a specific service accounts information. One of the arguments: ‘‘service_account_name’’ or ‘‘project_name’’ must be provided.
Base Command
gcp-iam-service-accounts-get
Input
| Argument Name | Description | Required |
|---|---|---|
| service_account_name | A comma-separated list of service accounts names to retrieve in the following format: projects/{PROJECT_ID}/serviceAccounts/{ACCOUNT}. Leave empty to retrieve a list of service accounts under a specified project resource. | Optional |
| project_name | The name of the project associated with the service accounts to retrieve, for example: projects/my-project-123. | Optional |
| limit | The maximum number of results to retrieve. Minimum value is 1, maximum value is 100. Default is 50. | Optional |
| page | The page number of the results to retrieve. Minimum value is 1. Default is 1. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| GCPIAM.ServiceAccount.email | String | The email address of the service account. |
| GCPIAM.ServiceAccount.name | String | The resource name of the service account. |
| GCPIAM.ServiceAccount.oauth2ClientId | String | The OAuth 2.0 client ID for the service account. |
| GCPIAM.ServiceAccount.projectId | String | The ID of the project that owns the service account. |
| GCPIAM.ServiceAccount.uniqueId | String | The unique, stable numeric ID for the service account. |
| GCPIAM.ServiceAccount.disabled | Boolean | Indicates whether the service account is disabled. |
Command Example
!gcp-iam-service-accounts-get service_account_name="projects/project-id-1/serviceAccounts/integration-test-2@project-name-3.iam.gserviceaccount.com"
Context Example
{
"GCP": {
"IAM": {
"ServiceAccount": {
"description": "user-1-description",
"disabled": false,
"displayName": "user-1-display-name",
"email": "integration-test-2@project-name-3.iam.gserviceaccount.com",
"etag": "MDEwMjE5MjA=",
"name": "projects/project-id-1/serviceAccounts/integration-test-2@project-name-3.iam.gserviceaccount.com",
"oauth2ClientId": "unique-id-3",
"projectId": "project-id-1",
"uniqueId": "unique-id-3"
}
}
}
}
Human Readable Output
Service account information
Name Display Name Description Project Id projects/project-id-1/serviceAccounts/integration-test-2@project-name-3.iam.gserviceaccount.com user-1-display-name user-1-description project-id-1
gcp-iam-service-account-enable
Enables a project service account.
Base Command
gcp-iam-service-account-enable
Input
| Argument Name | Description | Required |
|---|---|---|
| service_account_name | A comma-separated list of names of service accounts to enable. Every resource name should be in the following format: projects/{PROJECT_ID}/serviceAccounts/{ACCOUNT}. | Required |
Context Output
There is no context output for this command.
Command Example
!gcp-iam-service-account-enable service_account_name="projects/xsoar-project-5/serviceAccounts/my-service-account@xsoar-project-5.iam.gserviceaccount.com"
Human Readable Output
Service account projects/xsoar-project-5/serviceAccounts/my-service-account@xsoar-project-5.iam.gserviceaccount.com updated successfully.
gcp-iam-service-account-disable
Disables a project service account.
Base Command
gcp-iam-service-account-disable
Input
| Argument Name | Description | Required |
|---|---|---|
| service_account_name | A comma-separated list of names of service accounts to disable. Every resource name should be in the following format: projects/{PROJECT_ID}/serviceAccounts/{ACCOUNT}. | Required |
Context Output
There is no context output for this command.
Command Example
!gcp-iam-service-account-disable service_account_name="projects/xsoar-project-5/serviceAccounts/my-service-account@xsoar-project-5.iam.gserviceaccount.com"
Human Readable Output
Service account projects/xsoar-project-5/serviceAccounts/my-service-account@xsoar-project-5.iam.gserviceaccount.com updated successfully.
gcp-iam-service-account-key-create
Creates a service account key. A service account can have up to 10 keys. Service account keys that you create don’t have an expiry date and stay valid until you delete them.
Base Command
gcp-iam-service-account-key-create
Input
| Argument Name | Description | Required |
|---|---|---|
| service_account_name | The name of the service account associated with the key. Must be of the form projects/{PROJECT_ID}/serviceAccounts/{ACCOUNT}. | Required |
| key_algorithm | The RSA key algorithm. Possible values are: KEY_ALG_RSA_1024, KEY_ALG_RSA_2048. Default is KEY_ALG_RSA_2048. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| GCPIAM.ServiceAccountKey.keyAlgorithm | String | Specifies the algorithm for the key. |
| GCPIAM.ServiceAccountKey.keyOrigin | String | Service account key origin provider. |
| GCPIAM.ServiceAccountKey.keyType | String | Indicates the resource managed type. |
| GCPIAM.ServiceAccountKey.name | String | The resource name of the service account key. |
| GCPIAM.ServiceAccountKey.privateKeyData | String | The encrypted private key data. |
| GCPIAM.ServiceAccountKey.privateKeyType | String | The output format for the private key. |
| GCPIAM.ServiceAccountKey.validAfterTime | Date | Indicates the time the key can be used after this timestamp. |
| GCPIAM.ServiceAccountKey.validBeforeTime | Date | Indicates the time the key can be used before this timestamp. |
| GCPIAM.ServiceAccountKey.disabled | Boolean | Indicates whether the service account key is disabled. |
Command Example
!gcp-iam-service-account-key-create service_account_name="projects/project-id-1/serviceAccounts/integration-test-15@project-name-3.iam.gserviceaccount.com" key_algorithm="KEY_ALG_RSA_1024"
Context Example
{
"GCP": {
"IAM": {
"ServiceAccountKey": {
"disabled": false,
"keyAlgorithm": "KEY_ALG_RSA_1024",
"keyOrigin": "GOOGLE_PROVIDED",
"keyType": "USER_MANAGED",
"name": "projects/project-id-1/serviceAccounts/integration-test-15@project-name-3.iam.gserviceaccount.com/keys/key-3",
"privateKeyData": "my-private-key-data",
"privateKeyType": "TYPE_GOOGLE_CREDENTIALS_FILE",
"validAfterTime": "2022-01-04T15:37:22+00:00",
"validBeforeTime": "9999-12-31T23:59:59+00:00"
}
}
}
}
Human Readable Output
Service account key information
Name Valid After Time Valid Before Time Disabled Key Type projects/project-id-1/serviceAccounts/integration-test-15@project-name-3.iam.gserviceaccount.com/keys/key-3 2022-01-04T15:37:22+00:00 9999-12-31T23:59:59+00:00 false USER_MANAGED
gcp-iam-service-account-keys-get
Lists service account keys, or retrieves a specific service account key information. One of the arguments: ‘‘service_account_name’’ or ‘‘key_name’’ must be provided.
Base Command
gcp-iam-service-account-keys-get
Input
| Argument Name | Description | Required |
|---|---|---|
| key_name | The resource name of the service account key to retrieve. The resource name should be in the following format: projects/{PROJECT_ID}/serviceAccounts/{ACCOUNT}/keys/{key}. Leave empty to retrieve a list of service account keys that are associated with the service account resource. | Optional |
| service_account_name | The name of the service account associated with the keys. Must be of the form projects/{PROJECT_ID}/serviceAccounts/{ACCOUNT}. | Optional |
| limit | The maximum number of results to retrieve. Minimum value is 1. Default is 50. | Optional |
| page | The page number of the results to retrieve. Minimum value is 1. Default is 1. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| GCPIAM.ServiceAccountKey.keyAlgorithm | String | Specifies the algorithm for the key. |
| GCPIAM.ServiceAccountKey.keyOrigin | String | Service account key origin provider. |
| GCPIAM.ServiceAccountKey.keyType | String | Indicates the resource managed type. |
| GCPIAM.ServiceAccountKey.name | String | The resource name of the service account key. |
| GCPIAM.ServiceAccountKey.validAfterTime | Date | Indicates the time the key can be used after this timestamp. |
| GCPIAM.ServiceAccountKey.validBeforeTime | Date | Indicates the time the key can be used before this timestamp. |
| GCPIAM.ServiceAccountKey.disabled | Boolean | Indicates whether the service account key is disabled. |
Command Example
!gcp-iam-service-account-keys-get service_account_name="projects/project-id-1/serviceAccounts/service-account-1@project-name-3.iam.gserviceaccount.com" limit="2" page="1"
Context Example
{
"GCP": {
"IAM": {
"ServiceAccountKey": [
{
"disabled": false,
"keyAlgorithm": "KEY_ALG_RSA_2048",
"keyOrigin": "GOOGLE_PROVIDED",
"keyType": "SYSTEM_MANAGED",
"name": "projects/project-id-1/serviceAccounts/service-account-1@project-name-3.iam.gserviceaccount.com/keys/key-1",
"validAfterTime": "2021-12-15T13:10:43+00:00",
"validBeforeTime": "2022-01-01T13:10:43+00:00"
},
{
"disabled": false,
"keyAlgorithm": "KEY_ALG_RSA_2048",
"keyOrigin": "GOOGLE_PROVIDED",
"keyType": "SYSTEM_MANAGED",
"name": "projects/project-id-1/serviceAccounts/service-account-1@project-name-3.iam.gserviceaccount.com/keys/key-2",
"validAfterTime": "2021-12-24T13:10:43+00:00",
"validBeforeTime": "2022-01-09T13:10:43+00:00"
}
]
}
}
}
Human Readable Output
Service Account Keys List
Current page size: 2
Showing page 1 out of others that may exist.
Name Valid After Time Valid Before Time Disabled Key Type projects/project-id-1/serviceAccounts/service-account-1@project-name-3.iam.gserviceaccount.com/keys/key-1 2021-12-15T13:10:43+00:00 2022-01-01T13:10:43+00:00 false SYSTEM_MANAGED projects/project-id-1/serviceAccounts/service-account-1@project-name-3.iam.gserviceaccount.com/keys/key-2 2021-12-24T13:10:43+00:00 2022-01-09T13:10:43+00:00 false SYSTEM_MANAGED
gcp-iam-service-account-key-enable
Enables a service account key.
Base Command
gcp-iam-service-account-key-enable
Input
| Argument Name | Description | Required |
|---|---|---|
| key_name | A comma-separated list of names of resource name of the service account key to enable. Every resource name should be in the following format: projects/{PROJECT_ID}/serviceAccounts/{ACCOUNT}/keys/{key}. | Required |
Context Output
There is no context output for this command.
Command Example
!gcp-iam-service-account-key-enable key_name="projects/project-id-1/serviceAccounts/service-account-1@project-name-3.iam.gserviceaccount.com/keys/key-3"
Human Readable Output
Service account key projects/project-id-1/serviceAccounts/service-account-1@project-name-3.iam.gserviceaccount.com/keys/key-3 updated successfully.
gcp-iam-service-account-key-disable
Disables a service account key.
Base Command
gcp-iam-service-account-key-disable
Input
| Argument Name | Description | Required |
|---|---|---|
| key_name | A comma-separated list of names of resource name of the service account key to disable. Every resource name should be in the following format: projects/{PROJECT_ID}/serviceAccounts/{ACCOUNT}/keys/{key}. | Required |
Context Output
There is no context output for this command.
Command Example
!gcp-iam-service-account-key-disable key_name="projects/project-id-1/serviceAccounts/service-account-1@project-name-3.iam.gserviceaccount.com/keys/key-3"
Human Readable Output
Service account key projects/project-id-1/serviceAccounts/service-account-1@project-name-3.iam.gserviceaccount.com/keys/key-3 updated successfully.
gcp-iam-service-account-key-delete
Deletes a service account key.
Base Command
gcp-iam-service-account-key-delete
Input
| Argument Name | Description | Required |
|---|---|---|
| key_name | A comma-separated list of names of resource name of the service account key to delete. Every resource name should be in the following format: projects/{PROJECT_ID}/serviceAccounts/{ACCOUNT}/keys/{key}. | Required |
Context Output
There is no context output for this command.
Command Example
!gcp-iam-service-account-key-delete key_name="projects/project-id-1/serviceAccounts/integration-test-15@project-name-3.iam.gserviceaccount.com/keys/key-3"
Human Readable Output
Service account key projects/project-id-1/serviceAccounts/integration-test-15@project-name-3.iam.gserviceaccount.com/keys/key-3 deleted successfully.
gcp-iam-organization-role-create
Creates a custom organization role.
Base Command
gcp-iam-organization-role-create
Input
| Argument Name | Description | Required |
|---|---|---|
| organization_name | The name of the organization that contains the custom role. For example organizations/1234567. | Required |
| role_id | The unique ID of the role to create. A role ID may contain alphanumeric characters, underscores (_), and periods (.). It must contain a minimum of 3 characters and a maximum of 64 characters. | Required |
| description | The description of the role to create. | Optional |
| title | The title of the role to create. | Optional |
| permissions | A comma-separated list of names of the permissions the role grants when bound in an IAM policy. | Optional |
| stage | The launch stage of the role. More information can be found here: https://cloud.google.com/iam/docs/reference/rest/v1/organizations.roles#rolelaunchstage. Possible values are: ALPHA, BETA, GA, DEPRECATED, DISABLED, EAP. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| GCPIAM.Role.name | String | The name of the role. |
Command Example
!gcp-iam-organization-role-create organization_name="organizations/xsoar-organization" role_id="xsoar_demo_60" stage=ALPHA description="Demo role" permissions=accessapproval.requests.approve,aiplatform.artifacts.get title="XSOAR Role"
Context Example
{
"GCP": {
"IAM": {
"Role": {
"deleted": false,
"description": "Demo role",
"etag": "BwXUw4jsavE=",
"includedPermissions": [
"accessapproval.requests.approve",
"aiplatform.artifacts.get"
],
"name": "organizations/xsoar-organization/roles/xsoar_demo_60",
"stage": "ALPHA",
"title": "XSOAR Role"
}
}
}
}
Human Readable Output
Role organizations/xsoar-organization/roles/xsoar_demo_60 information
Name Included Permissions Title Description organizations/xsoar-organization/roles/xsoar_demo_60 accessapproval.requests.approve,
aiplatform.artifacts.getXSOAR Role Demo role
gcp-iam-organization-role-update
Updates a custom organization role.
Base Command
gcp-iam-organization-role-update
Input
| Argument Name | Description | Required |
|---|---|---|
| role_name | The name of the role to update. Must be in the format of organizations/{ORGANIZATION_ID}/roles/{CUSTOM_ROLE_ID}. | Required |
| description | The updated description of the role. | Optional |
| title | The updated title of the role. | Optional |
| permissions | A comma-separated list of names of the permissions the role grants when bound in an IAM policy. Note that this command argument will replace the existing permissions. | Optional |
| fields_to_update | A comma-separated list of names of the fields to update. Possible values are: description, title, includedPermissions, stage. | Required |
| stage | The launch stage of the role. More information can be found here: https://cloud.google.com/iam/docs/reference/rest/v1/organizations.roles#rolelaunchstage. Possible values are: ALPHA, BETA, GA, DEPRECATED, DISABLED, EAP. | Optional |
Context Output
There is no context output for this command.
Command Example
!gcp-iam-organization-role-update role_name="organizations/xsoar-organization/roles/xsoar_demo_70" title="xsoar role 70" fields_to_update="title"
Human Readable Output
Role organizations/xsoar-organization/roles/xsoar_demo_70 updated successfully.
gcp-iam-organization-role-permission-add
Adds permissions to a custom organization role.
Base Command
gcp-iam-organization-role-permission-add
Input
| Argument Name | Description | Required |
|---|---|---|
| role_name | The resource name of the role. Must be in the format of organizations/{ORGANIZATION_ID}/roles/{CUSTOM_ROLE_ID}. | Required |
| permissions | A comma-separated list of names of the permissions to add to the role. | Required |
Context Output
There is no context output for this command.
Command Example
!gcp-iam-organization-role-permission-add role_name="organizations/xsoar-organization/roles/xsoar_demo_70" permissions="aiplatform.artifacts.get"
Human Readable Output
Role organizations/xsoar-organization/roles/xsoar_demo_70 updated successfully.
gcp-iam-organization-role-permission-remove
Removes permissions from a custom organization role.
Base Command
gcp-iam-organization-role-permission-remove
Input
| Argument Name | Description | Required |
|---|---|---|
| role_name | The resource name of the role. Must be in the format of organizations/{ORGANIZATION_ID}/roles/{CUSTOM_ROLE_ID}. | Required |
| permissions | A comma-separated list of names of the permissions to remove from the role. | Required |
Context Output
There is no context output for this command.
Command Example
!gcp-iam-organization-role-permission-remove role_name="organizations/xsoar-organization/roles/xsoar_demo_70" permissions="aiplatform.artifacts.get"
Human Readable Output
Role organizations/xsoar-organization/roles/xsoar_demo_70 updated successfully.
gcp-iam-organization-role-list
Lists the organization custom roles.
Base Command
gcp-iam-organization-role-list
Input
| Argument Name | Description | Required |
|---|---|---|
| organization_name | The name of the organization that contains the custom role. For example organizations/12345. | Required |
| include_permissions | Indicates whether to include permissions in the response. Possible values are: True, False. Default is True. | Optional |
| limit | The maximum number of results to retrieve. Minimum value is 1, maximum value is 1,000. Default is 50. | Optional |
| page | The page number of the results to retrieve. Minimum value is 1, maximum value is 1000. Default is 1. | Optional |
| show_deleted | If true, roles that have been deleted will also be retrieved. Possible values are: False, True. Default is False. | Optional |
| title_filter | Used to filter the retrieved roles by the rule title. The command will retrieve the rules that include the provided argument in their title. | Optional |
| permission_filter | A comma-separated list of role permissions. Used to filter the retrieved roles by their permissions. The command will retrieve the rules that include all the provided permissions in their permissions list. If the argument is provided, the command will include the role permissions in the output. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| GCPIAM.Role.name | String | The resource name of the role. |
Command Example
!gcp-iam-organization-role-list organization_name="organizations/xsoar-organization" include_permissions="True" limit="2" page="1"
Context Example
{
"GCP": {
"IAM": {
"Role": [
{
"deleted": false,
"description": "my first role",
"etag": "BwXUDfGzgu0=",
"includedPermissions": [
"accessapproval.requests.approve",
"aiplatform.artifacts.get"
],
"name": "organizations/xsoar-organization/roles/xsoar_demo_70",
"stage": "ALPHA",
"title": "xsoar role 70"
},
{
"deleted": false,
"etag": "BwXTfraB2FU=",
"includedPermissions": [],
"name": "organizations/xsoar-organization/roles/xsoar_demo_9",
"stage": "BETA"
}
]
}
}
}
Human Readable Output
Custom Organization Roles list
Current page size: 2
Showing page 1 out of others that may exist.
Name Included Permissions Title Description organizations/xsoar-organization/roles/xsoar_demo_70 accessapproval.requests.approve,
aiplatform.artifacts.getxsoar role 70 my first role organizations/xsoar-organization/roles/xsoar_demo_9
gcp-iam-organization-role-get
Retrieves an organization role information.
Base Command
gcp-iam-organization-role-get
Input
| Argument Name | Description | Required |
|---|---|---|
| role_name | A comma-separated list of organization roles to retrieve. Every role name should be in the following format: organizations/{ORGANIZATION_ID}/roles/{CUSTOM_ROLE_ID}. | Required |
Context Output
| Path | Type | Description |
|---|---|---|
| GCPIAM.Role.name | String | The resource name of the role. |
Command Example
!gcp-iam-organization-role-get role_name="organizations/xsoar-organization/roles/xsoar_demo_70"
Context Example
{
"GCP": {
"IAM": {
"Role": {
"deleted": false,
"description": "my first role",
"etag": "BwXUC+Mfa9M=",
"includedPermissions": [
"accessapproval.requests.approve",
"aiplatform.artifacts.get"
],
"name": "organizations/xsoar-organization/roles/xsoar_demo_70",
"stage": "ALPHA",
"title": "my demo role"
}
}
}
}
Human Readable Output
Role organizations/xsoar-organization/roles/xsoar_demo_70 information
Name Included Permissions Title Description organizations/xsoar-organization/roles/xsoar_demo_70 accessapproval.requests.approve,
aiplatform.artifacts.getmy demo role my first role
gcp-iam-organization-role-delete
Deletes a custom organization role.
Base Command
gcp-iam-organization-role-delete
Input
| Argument Name | Description | Required |
|---|---|---|
| role_name | A comma-separated list of organization roles to delete. Every role name should be in the following format: organizations/{ORGANIZATION_ID}/roles/{CUSTOM_ROLE_ID}. | Required |
Context Output
There is no context output for this command.
Command Example
!gcp-iam-organization-role-delete role_name="organizations/xsoar-organization/roles/xsoar_demo_60"
Human Readable Output
Role organizations/xsoar-organization/roles/xsoar_demo_60 deleted successfully.
gcp-iam-project-role-create
Creates a custom project role.
Base Command
gcp-iam-project-role-create
Input
| Argument Name | Description | Required |
|---|---|---|
| project_id | The ID of the project that contains the custom role. | Required |
| role_id | The unique ID of the role to create. A role ID may contain alphanumeric characters, underscores (_), and periods (.). It must contain a minimum of 3 characters and a maximum of 64 characters. | Required |
| description | The description of the role to create. | Optional |
| title | The title of the role to create. | Optional |
| permissions | A comma-separated list of names of the permissions the role grants when bound in an IAM policy. | Optional |
| stage | The launch stage of the role. More information can be found here: https://cloud.google.com/iam/docs/reference/rest/v1/organizations.roles#rolelaunchstage. Possible values are: ALPHA, BETA, GA, DEPRECATED, DISABLED, EAP. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| GCPIAM.Role.name | String | The name of the role. |
Command Example
!gcp-iam-project-role-create project_id="xsoar-project-5" role_id="xsoar_demo_role_1" description="My demo role" title="test xsoar platform" permissions="accessapproval.requests.approve,aiplatform.artifacts.get" stage="ALPHA"
Context Example
{
"GCP": {
"IAM": {
"Role": {
"deleted": false,
"description": "My demo role",
"etag": "BwXUw5Zrxew=",
"includedPermissions": [
"accessapproval.requests.approve",
"aiplatform.artifacts.get"
],
"name": "projects/xsoar-project-5/roles/xsoar_demo_role_1",
"stage": "ALPHA",
"title": "test xsoar platform"
}
}
}
}
Human Readable Output
Role projects/xsoar-project-5/roles/xsoar_demo_role_1 information
Name Included Permissions Title Description projects/xsoar-project-5/roles/xsoar_demo_role_1 accessapproval.requests.approve,
aiplatform.artifacts.gettest xsoar platform My demo role
gcp-iam-project-role-update
Updates a custom project role.
Base Command
gcp-iam-project-role-update
Input
| Argument Name | Description | Required |
|---|---|---|
| role_name | The name of the role to update. Must be in the format of projects/{PROJECT_ID}/roles/{CUSTOM_ROLE_ID}. . | Required |
| description | The updated description of the role. | Optional |
| title | The updated title of the role. | Optional |
| permissions | A comma-separated list of names of the permissions the role grants when bound in an IAM policy. Note that this command argument will replace the existing permissions. | Optional |
| stage | The launch stage of the role. More information can be found here: https://cloud.google.com/iam/docs/reference/rest/v1/organizations.roles#rolelaunchstage. Possible values are: ALPHA, BETA, GA, DEPRECATED, DISABLED, EAP. | Optional |
| fields_to_update | A comma-separated list of names of the fields to update. Possible values are: description, title, includedPermissions, stage. | Required |
Context Output
There is no context output for this command.
Command Example
!gcp-iam-project-role-update role_name="projects/xsoar-project-5/roles/test_xsoar_101" title="xsoar role update" permissions="accessapproval.requests.approve,aiplatform.artifacts.get" stage="BETA" fields_to_update="includedPermissions,title,stage"
Human Readable Output
Role projects/xsoar-project-5/roles/test_xsoar_101 updated successfully.
gcp-iam-project-role-permission-add
Adds permissions to a custom project role.
Base Command
gcp-iam-project-role-permission-add
Input
| Argument Name | Description | Required |
|---|---|---|
| role_name | The resource name of the role. Must be in the format of projects/{PROJECT_ID}/roles/{CUSTOM_ROLE_ID}. . | Required |
| permissions | A comma-separated list of names of the permissions to add to the role. | Required |
Context Output
There is no context output for this command.
Command Example
!gcp-iam-project-role-permission-add role_name="projects/xsoar-project-5/roles/test_xsoar_101" permissions="accessapproval.requests.approve,aiplatform.artifacts.get"
Human Readable Output
Role projects/xsoar-project-5/roles/test_xsoar_101 updated successfully.
gcp-iam-project-role-permission-remove
Removes permissions from the custom project role.
Base Command
gcp-iam-project-role-permission-remove
Input
| Argument Name | Description | Required |
|---|---|---|
| role_name | The resource name of the role. Must be in the format of projects/{PROJECT_ID}/roles/{CUSTOM_ROLE_ID}. . | Required |
| permissions | A comma-separated list of names of the permissions to remove from the role. | Required |
Context Output
There is no context output for this command.
Command Example
!gcp-iam-project-role-permission-remove role_name="projects/xsoar-project-5/roles/test_xsoar_101" permissions="aiplatform.artifacts.get"
Human Readable Output
Role projects/xsoar-project-5/roles/test_xsoar_101 updated successfully.
gcp-iam-project-role-list
Lists the project custom roles.
Base Command
gcp-iam-project-role-list
Input
| Argument Name | Description | Required |
|---|---|---|
| project_id | The ID of the project that contains the custom role. | Required |
| include_permissions | Indicates whether to include permissions in the response. Possible values are: True, False. Default is True. | Optional |
| limit | The maximum number of results to retrieve. Minimum value is 1, maximum value is 1,000. Default is 50. | Optional |
| page | The page number of the results to retrieve. Minimum value is 1. Default is 1. | Optional |
| show_deleted | If true, roles that have been deleted will also be retrieved. Possible values are: False, True. Default is False. | Optional |
| title_filter | Used to filter the retrieved roles by the rule title. The command will retrieve the rules that include the provided argument in their title. | Optional |
| permission_filter | A comma-separated list of role permissions. Used to filter the retrieved roles by their permissions. The command will retrieve the rules that include all the provided permissions in their permissions list. If the argument is provided, the command will include the role permissions in the output. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| GCPIAM.Role.name | String | The resource name of the role. |
Command Example
!gcp-iam-project-role-list project_id="xsoar-project-5" include_permissions="True" limit="2" page="1"
Context Example
{
"GCP": {
"IAM": {
"Role": [
{
"deleted": false,
"description": "my-description-1",
"etag": "BwXTknaCMm0=",
"includedPermissions": [
"accessapproval.requests.approve",
"aiplatform.artifacts.get"
],
"name": "projects/xsoar-project-5/roles/testRolePoc12112573",
"stage": "BETA",
"title": "xsoar role update"
},
{
"deleted": false,
"description": "my first role",
"etag": "BwXUDgTKKN0=",
"includedPermissions": [
"accessapproval.requests.approve"
],
"name": "projects/xsoar-project-5/roles/test_xsoar_101",
"stage": "BETA",
"title": "xsoar role update"
}
]
}
}
}
Human Readable Output
Custom Project Roles list
Current page size: 2
Showing page 1 out of others that may exist.
Name Included Permissions Title Description projects/xsoar-project-5/roles/testRolePoc12112573 accessapproval.requests.approve,
aiplatform.artifacts.getxsoar role update my-description-1 projects/xsoar-project-5/roles/test_xsoar_101 accessapproval.requests.approve xsoar role update my first role
gcp-iam-project-role-get
Retrieves a custom project role.
Base Command
gcp-iam-project-role-get
Input
| Argument Name | Description | Required |
|---|---|---|
| role_name | A comma-separated list of project roles to retrieve. Every role name should be in the following format: projects/{PROJECT_ID}/roles/{CUSTOM_ROLE_ID}. | Required |
Context Output
| Path | Type | Description |
|---|---|---|
| GCPIAM.Role.name | String |
Command Example
!gcp-iam-project-role-get role_name="projects/xsoar-project-5/roles/test_xsoar_101"
Context Example
{
"GCP": {
"IAM": {
"Role": {
"deleted": false,
"description": "my first role",
"etag": "BwXUDfNUGpM=",
"includedPermissions": [
"accessapproval.requests.approve",
"aiplatform.artifacts.get"
],
"name": "projects/xsoar-project-5/roles/test_xsoar_101",
"stage": "BETA",
"title": "xsoar role update"
}
}
}
}
Human Readable Output
Role projects/xsoar-project-5/roles/test_xsoar_101 information
Name Included Permissions Title Description projects/xsoar-project-5/roles/test_xsoar_101 accessapproval.requests.approve,
aiplatform.artifacts.getxsoar role update my first role
gcp-iam-project-role-delete
Deletes a custom project role.
Base Command
gcp-iam-project-role-delete
Input
| Argument Name | Description | Required |
|---|---|---|
| role_name | A comma-separated list of project role to delete. Every role name should be in the following format: projects/{PROJECT_ID}/roles/{CUSTOM_ROLE_ID}. | Required |
Context Output
There is no context output for this command.
Command Example
!gcp-iam-project-role-delete role_name="projects/xsoar-project-5/roles/xsoar_demo_role_1"
Human Readable Output
Role projects/xsoar-project-5/roles/xsoar_demo_role_1 deleted successfully.
gcp-iam-testable-permission-list
Lists every permission can be tested on a resource.
Base Command
gcp-iam-testable-permission-list
Input
| Argument Name | Description | Required |
|---|---|---|
| resource_name | The name of the resource to query from the list of testable permissions. For a project’s resource, provide “projects/project-ID”, and for organizations, provide “organizations/organization-ID”. | Required |
| limit | The maximum number of results to retrieve. Minimum value is 1, maximum value is 1,000. Default is 50. | Optional |
| page | The page number of the results to retrieve. Minimum value is 1. Default is 1. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| GCPIAM.Permission.name | String | The name of the permissions. |
| GCPIAM.Permission.stage | String | The current launch stage of the permission |
Command Example
!gcp-iam-testable-permission-list resource_name="organizations/xsoar-organization" limit="2"
Context Example
{
"GCP": {
"IAM": {
"Permission": [
{
"name": "accessapproval.requests.approve",
"stage": "BETA"
},
{
"name": "accessapproval.requests.dismiss",
"stage": "BETA"
}
]
}
}
}
Human Readable Output
organizations/xsoar-organization testable permissions list
Current page size: 2
Showing page 1 out of others that may exist.
Name Stage accessapproval.requests.approve BETA accessapproval.requests.dismiss BETA
gcp-iam-service-account-delete
Deletes a service account.
Base Command
gcp-iam-service-account-delete
Input
| Argument Name | Description | Required |
|---|---|---|
| service_account_name | A comma-separated list of names of service accounts to delete. Every resource name should be in the following format: projects/{PROJECT_ID}/serviceAccounts/{ACCOUNT}. | Required |
Context Output
There is no context output for this command.
Command Example
!gcp-iam-service-account-delete service_account_name="projects/project-id-1/serviceAccounts/integration-test-15@project-name-3.iam.gserviceaccount.com"
Human Readable Output
Service account projects/project-id-1/serviceAccounts/integration-test-15@project-name-3.iam.gserviceaccount.com deleted successfully.
gcp-iam-grantable-role-list
Lists roles that can be granted on a Google Cloud resource. A role is grantable if the IAM policy for the resource can contain bindings to the role.
Base Command
gcp-iam-grantable-role-list
Input
| Argument Name | Description | Required |
|---|---|---|
| resource_name | The resource name to query from the list of grantable roles. For a project’s resource, provide “projects/project-ID”, and for organizations, provide “organizations/organization-ID”. | Required |
| limit | The maximum number of results to retrieve. Minimum value is 1, maximum value is 1,000. Default is 50. | Optional |
| page | The page number of the results to retrieve. Minimum value is 1. Default is 1. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| GCPIAM.Role.name | String | The name of the role. |
Command Example
!gcp-iam-grantable-role-list resource_name="organizations/xsoar-organization" limit="2"
Context Example
{
"GCP": {
"IAM": {
"Roles": {
"description": "my first role",
"etag": "BwXUDfL1OlM=",
"name": "organizations/xsoar-organization/roles/xsoar_demo_70",
"title": "xsoar role 70"
}
}
}
}
Human Readable Output
organizations/xsoar-organization grantable roles list
Current page size: 2
Showing page 1 out of others that may exist.
Name Title Description organizations/xsoar-organization/roles/xsoar_demo_70 xsoar role 70 my first role
gcp-iam-role-get
Retrieves the GCP IAM predefined role information.
Base Command
gcp-iam-role-get
Input
| Argument Name | Description | Required |
|---|---|---|
| role_name | A comma-separated list of GCP IAM predefined roles to retrieve. Every role name should be in the following format: roles/{ROLE_NAME}. | Required |
Context Output
| Path | Type | Description |
|---|---|---|
| GCPIAM.Role.name | String | The resource name of the role. |
Command Example
!gcp-iam-role-get role_name="roles/accessapproval.viewer"
Context Example
{
"GCP": {
"IAM": {
"Role": {
"deleted": false,
"description": "Ability to view access approval requests and configuration",
"etag": "AA==",
"includedPermissions": [
"accessapproval.requests.get",
"accessapproval.requests.list",
"accessapproval.settings.get",
"resourcemanager.projects.get",
"resourcemanager.projects.list"
],
"name": "roles/accessapproval.viewer",
"stage": "BETA",
"title": "Access Approval Viewer"
}
}
}
}
Human Readable Output
Role roles/accessapproval.viewer information
Name Included Permissions Title Description roles/accessapproval.viewer accessapproval.requests.get,
accessapproval.requests.list,
accessapproval.settings.get,
resourcemanager.projects.get,
resourcemanager.projects.listAccess Approval Viewer Ability to view access approval requests and configuration
gcp-iam-role-list
Lists the GCP IAM predefined roles.
Base Command
gcp-iam-role-list
Input
| Argument Name | Description | Required |
|---|---|---|
| include_permissions | Indicates whether to include permissions in the response. Possible values are: True, False. Default is True. | Optional |
| limit | The maximum number of results to retrieve. Minimum value is 1, maximum value is 1,000. Default is 50. | Optional |
| page | The page number of the results to retrieve. Minimum value is 1. Default is 1. | Optional |
| show_deleted | If true, roles that have been deleted will also be retrieved. Possible values are: False, True. Default is False. | Optional |
| title_filter | Used to filter the retrieved roles by the rule title. The command will retrieve the rules that include the provided argument in their title. | Optional |
| permission_filter | A comma-separated list of role permissions. Used to filter the retrieved roles by their permissions. The command will retrieve the rules that include all the provided permissions in their permissions list. If the argument is provided, the command will include the role permissions in the output. | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| GCPIAM.Role.name | String | The resource name of the role. |
Command Example
!gcp-iam-role-list include_permissions="True" limit="2" page="1"
Context Example
{
"GCP": {
"IAM": {
"Role": [
{
"deleted": false,
"description": "Ability to view or act on access approval requests and view configuration",
"etag": "AA==",
"includedPermissions": [
"accessapproval.requests.approve",
"accessapproval.requests.dismiss",
"accessapproval.requests.get",
"accessapproval.requests.list",
"accessapproval.settings.get",
"resourcemanager.projects.get",
"resourcemanager.projects.list"
],
"name": "roles/accessapproval.approver",
"stage": "BETA",
"title": "Access Approval Approver"
},
{
"deleted": false,
"description": "Ability update the Access Approval configuration",
"etag": "AA==",
"includedPermissions": [
"accessapproval.settings.delete",
"accessapproval.settings.get",
"accessapproval.settings.update",
"resourcemanager.projects.get",
"resourcemanager.projects.list"
],
"name": "roles/accessapproval.configEditor",
"stage": "BETA",
"title": "Access Approval Config Editor"
}
]
}
}
}
Human Readable Output
GCP IAM Predefined Roles list
Current page size: 2
Showing page 1 out of others that may exist.
Name Included Permissions Title Description roles/accessapproval.approver accessapproval.requests.approve,
accessapproval.requests.dismiss,
accessapproval.requests.get,
accessapproval.requests.list,
accessapproval.settings.get,
resourcemanager.projects.get,
resourcemanager.projects.listAccess Approval Approver Ability to view or act on access approval requests and view configuration roles/accessapproval.configEditor accessapproval.settings.delete,
accessapproval.settings.get,
accessapproval.settings.update,
resourcemanager.projects.get,
resourcemanager.projects.listAccess Approval Config Editor Ability update the Access Approval configuration gcp-iam-organization-iam-policy-remove
Removes a policy from the organization IAM policies.
Base Command
gcp-iam-organization-iam-policy-remove
Input
| Argument Name | Description | Required |
|---|---|---|
| organization_name | The name of the organization for which the policy is being specified. For example, organizations/3456. | Required |
| role | A comma-separated list of policy role names to remove. | Required |
Context Output
There is no context output for this command.
Command Example
!gcp-iam-organization-iam-policy-remove organization_name="organizations/xsoar-organization" role="organizations/xsoar-organization/roles/xsoar_demo_99"
Human Readable Output
Organization organizations/xsoar-organization IAM policies updated successfully.
gcp-iam-folder-iam-policy-remove
Removes a policy from the folder IAM policies .
Base Command
gcp-iam-folder-iam-policy-remove
Input
| Argument Name | Description | Required |
|---|---|---|
| folder_name | The name of the folder for which the policy is being specified. For example, folders/12342. | Required |
| role | A comma-separated list of policy role names to remove. | Required |
Context Output
There is no context output for this command.
Command Example
!gcp-iam-folder-iam-policy-remove folder_name="folders/folder-name-3" role="organizations/xsoar-organization/roles/xsoar_demo_99"
Human Readable Output
Folder folders/folder-name-3 IAM policies updated successfully.
gcp-iam-project-iam-policy-remove
Removes a policy from the project IAM policies.
Base Command
gcp-iam-project-iam-policy-remove
Input
| Argument Name | Description | Required |
|---|---|---|
| project_name | The name of the project for which the policy is being specified. For example, projects/415104041262. | Required |
| role | A comma-separated list of policy role names to remove. | Required |
Context Output
There is no context output for this command.
Command Example
!gcp-iam-project-iam-policy-remove project_name="projects/project-name-3" role="roles/anthosidentityservice.serviceAgent"
Human Readable Output
Project projects/project-name-3 IAM policies updated successfully.
gcp-iam-tagbindings-list
List tag bindings (key value pair) applied to a project/folder/organization object.
Base Command
gcp-iam-tagbindings-list
Input
| Argument Name | Description | Required |
|---|---|---|
| parent | The name of the resource to list tag bindings under. For example, setting this field to ‘folders/1234’ would list all tags directly applied to that folder. | Required |
Context Output
| Path | Type | Description |
|---|---|---|
| GCPIAM.TagBindings.key | String | Tag bindings key. |
| GCPIAM.TagBindings.value | String | Tag bindings value. |
Command example
!gcp-iam-tagbindings-list parent="//cloudresourcemanager.googleapis.com/folders/111111111111"
Context Example
{
"GCP": {
"IAM": {
"TagBindings": {
"key": "environment",
"value": "non-production"
}
}
}
}
Human Readable Output
Project projects/project-name-1 information
key value environment non-production
gcp-iam-service-account-generate-access-token
Create a short-lived access token for a service account. The generated token will be exposed to the context menu and War Room, and can potentially be logged.
Base Command
gcp-iam-service-account-generate-access-token
Input
| Argument Name | Description | Required |
|---|---|---|
| service_account_email | The email address of the privilege-bearing service account for which the short-lived token is created. | Required |
| lifetime | Lifetime of the Access Token in seconds. Default is 3600. | Required |
Configuration parameters
credentials— (required)proxy— Use system proxy settingsinsecure— Trust any certificate (not secure)
Commands (65)
-
gcp-iam-folder-iam-member-addAdds members to the folder policy.
-
gcp-iam-folder-iam-member-removeRemoves members from the folder policy.
-
gcp-iam-folder-iam-permission-testReturns permissions that a caller has on the specified folder. The permission list can be obtained by running the 'gcp-iam-testable-permission-list' command.
-
gcp-iam-folder-iam-policy-createAdds a new folder IAM policy.
-
gcp-iam-folder-iam-policy-getRetrieves the IAM access control policy for the specified folder.
-
gcp-iam-folder-iam-policy-removeRemoves a policy from the folder IAM policies.
-
gcp-iam-folder-iam-policy-setSets the IAM access control policy for the specified folder. This operation will overwrite any existing policy.
-
gcp-iam-folders-getLists folders under the specified parent, or retrieves a specific folder information. One of the arguments: 'parent' or 'folder_name' must be provided.
-
gcp-iam-grantable-role-listLists roles that can be granted on a Google Cloud resource. A role is grantable if the IAM policy for the resource can contain bindings to the role.
-
gcp-iam-group-createCreate a new group. The end user making the request will be added as the initial owner of the group.
-
gcp-iam-group-deleteDeletes a group.
-
gcp-iam-group-getRetrieves a group information.
-
gcp-iam-group-listLists groups that are visible to the caller.
-
gcp-iam-group-membership-createCreates a group membership.
-
gcp-iam-group-membership-deleteDeletes a group membership.
-
gcp-iam-group-membership-getRetrieves group membership information.
-
gcp-iam-group-membership-listLists group memberships.
-
gcp-iam-group-membership-role-addAdds a group membership role.
-
gcp-iam-group-membership-role-removeRemoves a group membership role.
-
gcp-iam-organization-iam-member-addAdds members to the organization policy.
-
gcp-iam-organization-iam-member-removeRemoves members from the organization policy.
-
gcp-iam-organization-iam-permission-testReturns permissions that a caller has on the specified organization. The permission list can be obtained by running the 'gcp-iam-testable-permission-list' command.
-
gcp-iam-organization-iam-policy-createAdds a new organization IAM policy.
-
gcp-iam-organization-iam-policy-getRetrieves the IAM access control policy for the specified organization.
-
gcp-iam-organization-iam-policy-removeRemoves a policy from the organization IAM policies.
-
gcp-iam-organization-iam-policy-setSets the IAM access control policy for the specified organization. This operation will overwrite any existing policy.
-
gcp-iam-organization-role-createCreates a custom organization role.
-
gcp-iam-organization-role-deleteDeletes a custom organization role.
-
gcp-iam-organization-role-getRetrieves the organization role information.
-
gcp-iam-organization-role-listLists the organization custom roles.
-
gcp-iam-organization-role-permission-addAdds permissions to a custom organization role.
-
gcp-iam-organization-role-permission-removeRemoves permissions from a custom organization role.
-
gcp-iam-organization-role-updateUpdates a custom organization role.
-
gcp-iam-organizations-getLists organization resources that are visible to the caller, or retrieves an organization's information.
-
gcp-iam-project-iam-member-addAdds members to the project policy.
-
gcp-iam-project-iam-member-removeRemoves members from the project policy.
-
gcp-iam-project-iam-permission-testReturns permissions that a caller has on the specified project. The permission list can be obtained by running the 'gcp-iam-testable-permission-list' command.
-
gcp-iam-project-iam-policy-createAdds a new project IAM policy.
-
gcp-iam-project-iam-policy-getRetrieves the IAM access control policy for the specified project.
-
gcp-iam-project-iam-policy-removeRemoves the policy from the project IAM policies.
-
gcp-iam-project-iam-policy-setSets the IAM access control policy for the specified project. This operation will overwrite any existing policy.
-
gcp-iam-project-role-createCreates a custom project role.
-
gcp-iam-project-role-deleteDeletes a custom project role.
-
gcp-iam-project-role-getRetrieves a custom project role.
-
gcp-iam-project-role-listLists a project custom roles.
-
gcp-iam-project-role-permission-addAdds permissions to a custom project role.
-
gcp-iam-project-role-permission-removeRemoves permissions from a custom project role.
-
gcp-iam-project-role-updateUpdates a custom project role.
-
gcp-iam-projects-getLists project under the specified parent, or retrieves a specific project's information. One of the following arguments must be provided: "parent" or "project_name".
-
gcp-iam-role-getRetrieves the GCP IAM predefined role information.
-
gcp-iam-role-listLists every predefined role that IAM supports.
-
gcp-iam-service-account-createCreates a service account in project.
-
gcp-iam-service-account-deleteDeletes a service account.
-
gcp-iam-service-account-disableDisables a project service account.
-
gcp-iam-service-account-enableEnables a project service account.
-
gcp-iam-service-account-generate-access-tokenCreate a short-lived access token for a service account. The generated token will be exposed to the context menu and War Room, and can potentially be logged.
-
gcp-iam-service-account-key-createCreates a service account key. A service account can have up to 10 keys. Service account keys that you create don't have an expiry date and stay valid until you delete them.
-
gcp-iam-service-account-key-deleteDeletes a service account key.
-
gcp-iam-service-account-key-disableDisables a service account key.
-
gcp-iam-service-account-key-enableEnables a service account key.
-
gcp-iam-service-account-keys-getLists service account keys, or retrieves a specific service account key information. One of the arguments: 'service_account_name' or 'key_name' must be provided.
-
gcp-iam-service-account-updateUpdates a service account.
-
gcp-iam-service-accounts-getLists service accounts in project, or retrieves a specific service accounts information. One of the arguments: 'service_account_name' or 'project_name' must be provided.
-
gcp-iam-tagbindings-listList tag bindings (key value pair) applied to a project/folder/organization object.
-
gcp-iam-testable-permission-listLists every permission that can be tested on a resource.
# pylint: disable=no-member import copy from collections.abc import Callable from urllib.parse import urlparse import demistomock as demisto # noqa: F401 import httplib2 from CommonServerPython import * # noqa: F401 from googleapiclient import discovery from oauth2client import service_account class Client: def __init__(self, client_secret: str, proxy: bool = False, verify_certificate: bool = False): client_secret = json.loads(client_secret) scopes = [ "https://www.googleapis.com/auth/cloud-platform", "https://www.googleapis.com/auth/cloud-identity", "https://www.googleapis.com/auth/iam", ] credentials = service_account.ServiceAccountCredentials.from_json_keyfile_dict(client_secret, scopes=scopes) proxies = handle_proxy() if proxy or verify_certificate: http_client = credentials.authorize( self.get_http_client_with_proxy(proxies, disable_ssl_certificate=not verify_certificate) ) self.cloud_identity_service = discovery.build("cloudidentity", "v1", http=http_client) self.cloud_resource_manager_service = discovery.build("cloudresourcemanager", "v3", http=http_client) self.iam_service = discovery.build("iam", "v1", http=http_client) self.iam_credentials = discovery.build("iamcredentials", "v1", http=http_client) else: self.cloud_identity_service = discovery.build("cloudidentity", "v1", credentials=credentials) self.cloud_resource_manager_service = discovery.build("cloudresourcemanager", "v3", credentials=credentials) self.iam_service = discovery.build("iam", "v1", credentials=credentials) self.iam_credentials = discovery.build("iamcredentials", "v1", credentials=credentials) def get_http_client_with_proxy(self, proxies: dict, disable_ssl_certificate: bool = False): proxy_info = None if proxies: if not proxies or not proxies["https"]: raise Exception("https proxy value is empty. Check Demisto server configuration") https_proxy = proxies["https"] if not https_proxy.startswith("https") and not https_proxy.startswith("http"): https_proxy = "https://" + https_proxy parsed_proxy = urlparse(https_proxy) proxy_info = httplib2.ProxyInfo( proxy_type=httplib2.socks.PROXY_TYPE_HTTP, # disable-secrets-detection proxy_host=parsed_proxy.hostname, proxy_port=parsed_proxy.port, proxy_user=parsed_proxy.username, proxy_pass=parsed_proxy.password, ) return httplib2.Http(proxy_info=proxy_info, disable_ssl_certificate_validation=disable_ssl_certificate) def gcp_iam_tagbindings_list_request(self, parent: str, limit: int = None) -> dict: """ List tag bindings (key value pair) applied to a project/folder/organization object. Args: parent (str): The name of the parent resource to list projects under. limit (int): The number of results to retrieve. Returns: dict: API response from GCP. """ params = assign_params(parent=parent, pageSize=limit) request = self.cloud_resource_manager_service.tagBindings().list(**params) response = request.execute() return response def gcp_iam_tagvalues_get_request(self, name: str) -> dict: """ Retrieves a TagValue. Args: name (str): Resource name for TagValue in the format `tagValues/456`. Returns: dict: API response from GCP. """ params = assign_params(name=name) request = self.cloud_resource_manager_service.tagValues().get(**params) response = request.execute() return response def gcp_iam_tagkeys_get_request(self, name: str) -> dict: """ Retrieves a TagKey. Args: name (str): A resource name in the format `tagKeys/{id}`, such as `tagKeys/123`. Returns: dict: API response from GCP. """ params = assign_params(name=name) request = self.cloud_resource_manager_service.tagKeys().get(**params) response = request.execute() return response def gcp_iam_project_list_request( self, parent: str, limit: int = None, page_token: str = None, show_deleted: bool = False ) -> dict: """ List projects under the specified parent. Args: parent (str): The name of the parent resource to list projects under. limit (int): The number of results to retrieve. page_token (str): Pagination token returned from a previous request. show_deleted (bool): Indicate that projects in the DELETE_REQUESTED state should also be retrieved. Returns: dict: API response from GCP. """ params = assign_params(parent=parent, pageSize=limit, pageToken=page_token, showDeleted=show_deleted) request = self.cloud_resource_manager_service.projects().list(**params) response = request.execute() return response def gcp_iam_project_get_request(self, project_name: str) -> dict: """ Retrieve project information. Args: project_name (str): The project name to retrieve. Returns: dict: API response from GCP. """ params = assign_params(name=project_name) request = self.cloud_resource_manager_service.projects().get(**params) response = request.execute() return response def gcp_iam_project_iam_policy_get_request(self, project_name: str) -> dict: """ Retrieve the IAM access control policy for the specified project. Args: project_name (str): The project name for which the policy is being requested. Returns: dict: API response from GCP. """ params = assign_params(resource=project_name) request = self.cloud_resource_manager_service.projects().getIamPolicy(**params) response = request.execute() return response def gcp_iam_project_iam_test_permission_request(self, project_name: str, permissions: list) -> dict: """ Returns permissions that a caller has on the specified project. Args: project_name (str): The project name for which the permissions is being tested. permissions (list): Permissions names to validate. Returns: dict: API response from GCP. """ body = {"permissions": permissions} request = self.cloud_resource_manager_service.projects().testIamPermissions(resource=project_name, body=body) response = request.execute() return response def gcp_iam_project_iam_policy_set_request(self, project_name: str, policy: list) -> dict: """ Sets the IAM access control policy for the specified project. Args: project_name (str): The name of the project for which the policy is being specified. policy (list): Policy objects to set. Returns: dict: API response from GCP. """ body = {"policy": {"bindings": policy}} request = self.cloud_resource_manager_service.projects().setIamPolicy(resource=project_name, body=body) response = request.execute() return response def gcp_iam_folder_list_request( self, parent: str, limit: int = None, page_token: str = None, show_deleted: bool = False ) -> dict: """ List folders under the specified parent. Args: parent (str): The name of the parent resource to list folders under. limit (int): The number of results to retrieve. page_token (str): Pagination token returned from a previous request. show_deleted (bool): Indicate that folders in the DELETE_REQUESTED state should also be retrieved. Returns: dict: API response from GCP. """ params = assign_params(parent=parent, pageSize=limit, pageToken=page_token, showDeleted=show_deleted) request = self.cloud_resource_manager_service.folders().list(**params) response = request.execute() return response def gcp_iam_folder_get_request(self, folder_name: str) -> dict: """ Retrieve folder information. Args: folder_name (str): The name of the folder to retrieve. Returns: dict: API response from GCP. """ request = self.cloud_resource_manager_service.folders().get(name=folder_name) response = request.execute() return response def gcp_iam_folder_iam_policy_get_request(self, folder_name: str) -> dict: """ Retrieve the IAM access control policy for the specified folder. Args: folder_name (str): The folder name for which the policy is being requested. Returns: dict: API response from GCP. """ params = assign_params(resource=folder_name) request = self.cloud_resource_manager_service.folders().getIamPolicy(**params) response = request.execute() return response def gcp_iam_folder_iam_test_permission_request(self, folder_name: str, permissions: list) -> dict: """ Returns permissions that a caller has on the specified folder. Args: folder_name (str): The folder name for which the permissions is being tested. permissions (list): Permissions names to validate. Returns: dict: API response from GCP. """ body = {"permissions": permissions} request = self.cloud_resource_manager_service.folders().testIamPermissions(resource=folder_name, body=body) response = request.execute() return response def gcp_iam_folder_iam_policy_set_request(self, folder_name: str, policy: list) -> dict: """ Sets the IAM access control policy for the specified folder. Args: folder_name (str): The name of the folder for which the policy is being specified. policy (list): Policy objects to set. Returns: dict: API response from GCP. """ body = {"policy": {"bindings": policy}} request = self.cloud_resource_manager_service.folders().setIamPolicy(resource=folder_name, body=body) response = request.execute() return response def gcp_iam_organization_list_request(self, limit: int = None, page_token: str = None) -> dict: """ List organization resources that are visible to the caller. Args: limit (int): The number of results to retrieve. page_token (str): Pagination token returned from a previous request. Returns: dict: API response from GCP. """ params = assign_params(pageSize=limit, pageToken=page_token) request = self.cloud_resource_manager_service.organizations().search(**params) response = request.execute() return response def gcp_iam_organization_get_request(self, organization_name: str) -> dict: """ Retrieve organization information. Args: organization_name (str): The name of the organization to retrieve. Returns: dict: API response from GCP. """ request = self.cloud_resource_manager_service.organizations().get(name=organization_name) response = request.execute() return response def gcp_iam_organization_iam_policy_get_request(self, organization_name: str) -> dict: """ Retrieve the IAM access control policy for the specified organization. Args: organization_name (str): The organization name for which the policy is being requested. Returns: dict: API response from GCP. """ request = self.cloud_resource_manager_service.organizations().getIamPolicy(resource=organization_name) response = request.execute() return response def gcp_iam_organization_iam_test_permission_request(self, organization_name: str, permissions: list) -> dict: """ Returns permissions that a caller has on the specified organization. Args: organization_name (str): The organization name for which the permissions is being tested. permissions (list): Permissions names to validate. Returns: dict: API response from GCP. """ body = {"permissions": permissions} request = self.cloud_resource_manager_service.organizations().testIamPermissions(resource=organization_name, body=body) response = request.execute() return response def gcp_iam_organization_iam_policy_set_request(self, organization_name: str, policy: list) -> dict: """ Sets the IAM access control policy for the specified organization. Args: organization_name (str): The name of the organization for which the policy is being specified. policy (list): Policy objects to set. Returns: dict: API response from GCP. """ body = {"policy": {"bindings": policy}} request = self.cloud_resource_manager_service.organizations().setIamPolicy(resource=organization_name, body=body) response = request.execute() return response def gcp_iam_group_create_request(self, parent: str, display_name: str, group_email_address: str, description: str = None): """ Create a new group. Args: parent (str): The parent resource of the groups to create. display_name (str): The display name of the group. group_email_address (str): The group unique email address. description (str): The description of the group. Returns: dict: API response from GCP. """ params = assign_params(initialGroupConfig="WITH_INITIAL_OWNER") body = remove_empty_elements( { "parent": parent, "description": description, "displayName": display_name, "labels": {"cloudidentity.googleapis.com/groups.discussion_forum": ""}, "groupKey": {"id": group_email_address}, } ) request = self.cloud_identity_service.groups().create(**params, body=body) response = request.execute() return response def gcp_iam_group_list_request(self, parent: str, limit: int = None, page_token: str = None) -> dict: """ List groups under the specified parent. Args: parent (str): The parent resource of the groups to retrieve limit (int): The number of results to retrieve. page_token (str): Pagination token returned from a previous request. Returns: dict: API response from GCP. """ params = assign_params(parent=parent, pageSize=limit, pageToken=page_token) request = self.cloud_identity_service.groups().list(**params) response = request.execute() return response def gcp_iam_group_get_request(self, group_name: str) -> dict: """ Retrieve a group information. Args: group_name (str): The name of the group to retrieve. Returns: dict: API response from GCP. """ request = self.cloud_identity_service.groups().get(name=group_name) response = request.execute() return response def gcp_iam_group_delete_request(self, group_name: str): """ Delete group. Args: group_name (str): The name of the group to delete. Returns: dict: API response from GCP. """ request = self.cloud_identity_service.groups().delete(name=group_name) response = request.execute() return response def gcp_iam_group_membership_create_request(self, group_name: str, member_email: str, roles: list) -> dict: """ Create a group membership Args: group_name (str): The name of the group which will contain the membership. member_email (str): The email address of the user to add to the group. roles (list): Roles to apply to the membership. Returns: dict: API response from GCP. """ body_roles = [{"name": role} for role in roles] body = {"preferredMemberKey": {"id": member_email}, "roles": body_roles} request = self.cloud_identity_service.groups().memberships().create(parent=group_name, body=body) response = request.execute() return response def gcp_iam_group_membership_list_request(self, group_name: str, limit: int = None, page_token: str = None) -> dict: """ List group memberships. Args: group_name (str): The name of the group which contains the membership. limit (int): The number of results to retrieve. page_token (str): Pagination token returned from a previous request. Returns: dict: API response from GCP. """ params = assign_params(parent=group_name, pageSize=limit, pageToken=page_token) request = self.cloud_identity_service.groups().memberships().list(**params) response = request.execute() return response def gcp_iam_group_membership_get_request(self, membership_name: str): """ Retrieve group membership information. Args: membership_name (str): The name of the group membership to retrieve. Returns: dict: API response from GCP. """ request = self.cloud_identity_service.groups().memberships().get(name=membership_name) response = request.execute() return response def gcp_iam_group_membership_role_add_request(self, membership_name: str, roles: list) -> dict: """ Add group membership role. Args: membership_name (str): The name of the group membership to update. roles (list): Membership roles to add to the membership. Returns: dict: API response from GCP. """ body_roles = [{"name": role} for role in roles] body = {"addRoles": body_roles} request = self.cloud_identity_service.groups().memberships().modifyMembershipRoles(name=membership_name, body=body) response = request.execute() return response def gcp_iam_group_membership_role_remove_request(self, membership_name: str, roles: list) -> dict: """ Remove group membership role. Args: membership_name (str): The name of the group membership to update. roles (list): Membership roles to remove from the membership. Returns: dict: API response from GCP. """ body = {"removeRoles": roles} request = self.cloud_identity_service.groups().memberships().modifyMembershipRoles(name=membership_name, body=body) response = request.execute() return response def gcp_iam_group_membership_delete_request(self, membership_name: str) -> dict: """ Delete group membership. Args: membership_name (str): The resource name of the membership to delete. Returns: dict: API response from GCP. """ request = self.cloud_identity_service.groups().memberships().delete(name=membership_name) response = request.execute() return response def gcp_iam_service_account_create_request( self, project_name: str, service_account_id: str, display_name: str = None, description: str = None ): """ Create a service account in project. Args: project_name (str): The name of the project associated with the service account. service_account_id (str): The account ID that is used to generate the service account email address, and a stable unique ID. display_name (str): Human readable name for the created service account. description (str): Human readable description for created the service account. Returns: dict: API response from GCP. """ body = remove_empty_elements( {"accountId": service_account_id, "serviceAccount": {"displayName": display_name, "description": description}} ) request = self.iam_service.projects().serviceAccounts().create(name=project_name, body=body) response = request.execute() return response def gcp_iam_service_account_update_request( self, service_account_name: str, fields_to_update: str, display_name: str = None, description: str = None ) -> dict: """ Update service account. Args: service_account_name (str): The name of the service account to update. fields_to_update (str): Comma-separated names of the fields to update. display_name (str): Human readable name for the updated service account. description (str): Human readable description for updated the service account. Returns: dict: API response from GCP. """ body = remove_empty_elements( {"serviceAccount": {"displayName": display_name, "description": description}, "updateMask": fields_to_update} ) request = self.iam_service.projects().serviceAccounts().patch(name=service_account_name, body=body) response = request.execute() return response def gcp_iam_service_account_list_request(self, project_name: str, limit: int = None, page_token: str = None) -> dict: """ List service accounts in project. Args: project_name (str): The name of the project associated with the service accounts to retrieve. limit (int): The number of results to retrieve. page_token (str): Pagination token returned from a previous request. Returns: dict: API response from GCP. """ params = assign_params(name=project_name, pageSize=limit, pageToken=page_token) request = self.iam_service.projects().serviceAccounts().list(**params) response = request.execute() return response def gcp_iam_service_account_get_request(self, service_account_name: str) -> dict: """ Retrieve project service account information. Args: service_account_name (str): The name of service account to retrieve. Returns: dict: API response from GCP. """ request = self.iam_service.projects().serviceAccounts().get(name=service_account_name) response = request.execute() return response def gcp_iam_service_account_enable_request(self, service_account_name: str) -> dict: """ Enable project service account. Args: service_account_name (str): The name of service account to enable. Returns: dict: API response from GCP. """ request = self.iam_service.projects().serviceAccounts().enable(name=service_account_name) response = request.execute() return response def gcp_iam_service_account_disable_request(self, service_account_name: str) -> dict: """ Disable project service account. Args: service_account_name (str): The name of service account to disable. Returns: dict: API response from GCP. """ request = self.iam_service.projects().serviceAccounts().disable(name=service_account_name) response = request.execute() return response def gcp_iam_service_account_delete_request(self, service_account_name: str) -> dict: """ Delete service account key. Args: service_account_name (str): The name of service account to delete. Returns: dict: API response from GCP. """ request = self.iam_service.projects().serviceAccounts().delete(name=service_account_name) response = request.execute() return response def gcp_iam_service_account_key_create_request(self, service_account_name: str, key_algorithm: str) -> dict: """ Create a service account key. Args: service_account_name (str): The name of the service account associated with the key. key_algorithm (str): The RSA key algorithm. Returns: dict: API response from GCP. """ body = assign_params(keyAlgorithm=key_algorithm) request = self.iam_service.projects().serviceAccounts().keys().create(name=service_account_name, body=body) response = request.execute() return response def gcp_iam_service_account_key_list_request(self, service_account_name: str) -> dict: """ List service accounts keys. Args: service_account_name (str): The name of the service account associated with the keys. Returns: dict: API response from GCP. """ request = self.iam_service.projects().serviceAccounts().keys().list(name=service_account_name) response = request.execute() return response def gcp_iam_service_account_key_get_request(self, key_name: str) -> dict: """ Retrieve service account key information. Args: key_name (str): The resource name of the service account key to retrieve. Returns: dict: API response from GCP. """ request = self.iam_service.projects().serviceAccounts().keys().get(name=key_name) response = request.execute() return response def gcp_iam_service_account_key_enable_request(self, key_name: str) -> dict: """ Enable service account key. Args: key_name (str): The resource name of the service account key to enable. Returns: dict: API response from GCP. """ request = self.iam_service.projects().serviceAccounts().keys().enable(name=key_name) response = request.execute() return response def gcp_iam_service_account_key_disable_request(self, key_name: str) -> dict: """ Disable service account key. Args: key_name (str): The resource name of the service account key to disable. Returns: dict: API response from GCP. """ request = self.iam_service.projects().serviceAccounts().keys().disable(name=key_name) response = request.execute() return response def gcp_iam_service_account_key_delete_request(self, key_name: str) -> dict: """ Delete service account key. Args: key_name (str): The resource name of the service account key to delete. Returns: dict: API response from GCP. """ request = self.iam_service.projects().serviceAccounts().keys().delete(name=key_name) response = request.execute() return response def gcp_iam_service_account_generate_access_token_request(self, service_account_email: str, lifetime: str) -> dict: """ Create a short-lived access token Args: service_account_email (str): E-Mail of the Service Account for wich the token should be generated lifetime (str): Lifetime of the token in seconds. Like 3600 Returns: dict: API response from GCP. """ resource_name = f"projects/-/serviceAccounts/{service_account_email}" body = { "scope": ["https://www.googleapis.com/auth/cloud-platform"], "lifetime": f"{arg_to_number(lifetime, required=True)}s", } request = self.iam_credentials.projects().serviceAccounts().generateAccessToken(name=resource_name, body=body) response = request.execute() return response def gcp_iam_organization_role_create_request( self, organization_name: str, role_id: str, stage: str = None, description: str = None, title: str = None, permissions: list = None, ) -> dict: """ Create a custom organization role. Args: organization_name (str): The name of the organization which contains the custom role. role_id (str): The unique ID of the role to create. stage (str): The current launch stage of the role. description (str): The description of the role to create. title (str): The title of the role to create. permissions (list): Permissions the role grants when bound in an IAM policy. Returns: dict: API response from GCP. """ body = remove_empty_elements( { "roleId": role_id, "role": {"title": title, "description": description, "includedPermissions": permissions, "stage": stage}, } ) request = self.iam_service.organizations().roles().create(parent=organization_name, body=body) response = request.execute() return response def gcp_iam_organization_role_update_request( self, role_name: str, description: str = None, title: str = None, permissions: list = None, stage: str = None, fields_to_update: str = None, ) -> dict: """ Update a custom organization role. Args: role_name (str): The name of the role to update. description (str): The updated description of the role. title (str): The updated title of the role. permissions (list): Permissions the role grants when bound in an IAM policy. stage (str): The current launch stage of the role. fields_to_update (str): Comma-separated names of the fields to update. Returns: dict: API response from GCP. """ body = remove_empty_elements( {"title": title, "description": description, "includedPermissions": permissions, "stage": stage} ) request = self.iam_service.organizations().roles().patch(name=role_name, body=body, updateMask=fields_to_update) response = request.execute() return response def gcp_iam_organization_role_list_request( self, parent: str, include_permissions: bool, limit: int, page_token: str = None, show_deleted: bool = False ) -> dict: """ List organization custom roles. Args: parent (str): The name of the organization which contains the custom roles. include_permissions (bool): Indicates whether to include permissions in the response. limit (int): The number of results to retrieve. page_token (str): Pagination token returned from a previous request. show_deleted (bool): Indicate that roles that have been deleted should also be retrieved. Returns: dict: API response from GCP. """ params = assign_params( parent=parent, pageSize=limit, pageToken=page_token, showDeleted=show_deleted, view="FULL" if include_permissions else "BASIC", ) request = self.iam_service.organizations().roles().list(**params) response = request.execute() return response def gcp_iam_predefined_role_list_request( self, include_permissions: bool, limit: int, page_token: str = None, show_deleted: bool = False ) -> dict: """ List GCP IAM predefined roles. Args: include_permissions (bool): Indicates whether to include permissions in the response. limit (int): The number of results to retrieve. page_token (str): Pagination token returned from a previous request. show_deleted (bool): Indicate that roles that have been deleted should also be retrieved. Returns: dict: API response from GCP. """ params = assign_params( pageSize=limit, pageToken=page_token, showDeleted=show_deleted, view="FULL" if include_permissions else "BASIC" ) request = self.iam_service.roles().list(**params) response = request.execute() return response def gcp_iam_organization_role_get_request(self, role_name: str) -> dict: """ Retrieve organization role information. Args: role_name (str): The resource name of the role to retrieve. Returns: dict: API response from GCP. """ request = self.iam_service.organizations().roles().get(name=role_name) response = request.execute() return response def gcp_iam_organization_role_delete_request(self, role_name: str) -> dict: """ Delete a custom organization role. Args: (str): The name of the role to delete. Returns: dict: API response from GCP. """ request = self.iam_service.organizations().roles().delete(name=role_name) response = request.execute() return response def gcp_iam_project_role_create_request( self, project_id: str, role_id: str, stage: str = None, description: str = None, title: str = None, permissions: list = None, ) -> dict: """ Create a custom project role. Args: project_id (str): The ID of the project which contains the custom role. role_id (str): The unique ID of the role to create. stage (str): The current launch stage of the role. description (str): The description of the role to create. title (str): The title of the role to create. permissions (list): Permissions the role grants when bound in an IAM policy. Returns: dict: API response from GCP. """ body = remove_empty_elements( { "roleId": role_id, "role": {"title": title, "description": description, "includedPermissions": permissions, "stage": stage}, } ) request = self.iam_service.projects().roles().create(parent=f"projects/{project_id}", body=body) response = request.execute() return response def gcp_iam_project_role_update_request( self, role_name: str, description: str = None, title: str = None, permissions: list = None, stage: str = None, fields_to_update: str = None, ) -> dict: """ Update a custom project role. Args: role_name (str): The name of the role to update. description (str): The updated description of the role. title (str): The updated title of the role. permissions (list): Permissions the role grants when bound in an IAM policy. stage (str): The current launch stage of the role. fields_to_update (str): Comma-separated names of the fields to update. Returns: dict: API response from GCP. """ body = remove_empty_elements( {"title": title, "description": description, "includedPermissions": permissions, "stage": stage} ) request = self.iam_service.projects().roles().patch(name=role_name, body=body, updateMask=fields_to_update) response = request.execute() return response def gcp_iam_project_role_list_request( self, parent: str, include_permissions: bool, limit: int, page_token: str = None, show_deleted: bool = False ) -> dict: """ List project custom roles. Args: parent (str): The ID of the project which contains the custom roles. include_permissions (bool): Indicates whether to include permissions in the response. limit (int): The number of results to retrieve. page_token (str): Pagination token returned from a previous request. show_deleted (bool): Indicate that roles that have been deleted should also be retrieved. Returns: dict: API response from GCP. """ params = assign_params( parent=f"projects/{parent}", pageSize=limit, pageToken=page_token, showDeleted=show_deleted, view="FULL" if include_permissions else "BASIC", ) request = self.iam_service.projects().roles().list(**params) response = request.execute() return response def gcp_iam_project_role_get_request(self, role_name: str) -> dict: """ Retrieve project role information. Args: role_name (str): The resource name of the role to retrieve. Returns: dict: API response from GCP. """ request = self.iam_service.projects().roles().get(name=role_name) response = request.execute() return response def gcp_iam_predefined_role_get_request(self, role_name: str) -> dict: """ Retrieve GCP IAM predefined role information. Args: role_name (str): The resource name of the role to retrieve. Returns: dict: API response from GCP. """ request = self.iam_service.roles().get(name=role_name) response = request.execute() return response def gcp_iam_project_role_delete_request(self, role_name: str) -> dict: """ Delete a custom project role. Args: (str): The name of the role to delete. Returns: dict: API response from GCP. """ request = self.iam_service.projects().roles().delete(name=role_name) response = request.execute() return response def gcp_iam_testable_permission_list_request( self, full_resource_name: str, limit: int = None, page_token: str = None ) -> dict: """ Lists permissions that can be tested on a resource. Args: full_resource_name (str): The full resource name to query from the list of testable permissions. limit (int): The number of results to retrieve. page_token (str): Pagination token returned from a previous request. Returns: dict: API response from GCP. """ body = assign_params(fullResourceName=full_resource_name, pageSize=limit, pageToken=page_token) request = self.iam_service.permissions().queryTestablePermissions(body=body) response = request.execute() return response def gcp_iam_grantable_role_list_request(self, full_resource_name: str, limit: int = None, page_token: str = None) -> dict: """ Lists roles that can be granted on a Google Cloud resource. Args: full_resource_name (str): The full resource name to query from the list of grantable roles. limit (int): The number of results to retrieve. page_token (str): Pagination token returned from a previous request. Returns: dict: API response from GCP. """ body = assign_params(fullResourceName=full_resource_name, pageSize=limit, pageToken=page_token) request = self.iam_service.roles().queryGrantableRoles(body=body) response = request.execute() return response def get_pagination_readable_message(header: str, limit: int, page: int) -> str: """ Generate pagination commands readable message. Args: header (str): Message header limit (int): Number of elements to retrieve. page (int): Page number. Returns: str: Readable message. """ readable_message = f"{header}\n Current page size: {limit}\n Showing page {page} out of others that may exist." return readable_message def get_next_page_token(limit: int, page: int, client_request: Callable, args: dict) -> str: """ Get next request page token for request pagination. Args: limit (int): Number of elements to retrieve. page (int): Page number. client_request (Callable): Client request function. args (dict): Request function arguments. Returns: str: Continuation token. """ offset = limit * (page - 1) response = client_request(limit=offset, **args) return response.get("nextPageToken") def validate_pagination_arguments(limit: int, page: int) -> None: """ Validate pagination arguments values. Args: limit (int): Number of elements to retrieve. page (int): Page number. """ if page < 1 or limit < 1: raise Exception("Page and limit arguments must be greater than 0.") def update_time_format(data: Union[dict, list], keys: list) -> list: """ Update dictionary time values to appropriate XSOAR system time format. Args: data (dict/list): Information to update. keys (list): Keys to update. Returns: list: Updated information. """ if not isinstance(data, list): data = [data] for item in data: for key in keys: if key in item: item[key] = arg_to_datetime(item[key]).isoformat() # type: ignore[union-attr] return data def generate_iam_policy_command_output( response: dict, resource_name: str = None, readable_header: str = None, limit: int = None, page: int = None, roles: list = None, ) -> CommandResults: """ Generate command output for iam-policy commands. Args: response (dict): API response from GCP. resource_name (str): The resource for which the policy is being specified. readable_header (str): Readable message header for XSOAR war room. limit (int): Number of elements to retrieve. page (int): Page number. role (list): List of potential GCP IAM roles Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ if not readable_header: readable_header = f"{resource_name} IAM policy information:" outputs = copy.deepcopy(response) outputs["name"] = resource_name bindings = outputs.get("bindings", []) if roles and bindings: bindings_roles_only = [] for index, entry in enumerate(bindings): if entry.get("role") in roles: bindings_roles_only.append(bindings[index]) bindings = bindings_roles_only if limit and page: start = (page - 1) * limit end = start + limit outputs["bindings"] = bindings[start:end] if len(bindings) < limit: resource_type = readable_header.split(" ")[0] readable_header = f"{resource_type} {resource_name} IAM Policy List:\n Current page size: {len(bindings)}" readable_output = tableToMarkdown( readable_header, outputs.get("bindings"), headers=["role", "members"], headerTransform=pascalToSpace ) command_results = CommandResults( readable_output=readable_output, outputs_prefix="GCPIAM.Policy", outputs_key_field="name", outputs=outputs, raw_response=response, ) return command_results def generate_group_membership_readable_output(outputs: list, readable_header: str) -> str: """ Generate command readable output for group membership commands. Args: outputs (dict): API response from GCP. readable_header (str): Readable message header for XSOAR war room. Returns: tableToMarkdown: XSOAR war room output. """ readable_information = [] for membership in outputs: readable_information.append( { "name": membership.get("name"), "roles": [role.get("name") for role in membership.get("roles")], "preferredMemberKey": dict_safe_get(membership, ["preferredMemberKey", "id"]), } ) headers = ["name", "roles"] if len(readable_information) > 0 and readable_information[0].get("preferredMemberKey"): headers.append("preferredMemberKey") readable_output = tableToMarkdown(readable_header, readable_information, headers=headers, headerTransform=pascalToSpace) return readable_output def generate_group_membership_command_output( response: dict, output_key: str = None, readable_header: str = "Membership information:" ) -> CommandResults: """ Generate command output for group membership commands. Args: response (dict): API response from GCP. output_key (str): Used to access to required data in the response. readable_header (str): Readable message header for XSOAR war room. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ if output_key: outputs = copy.deepcopy(response.get(output_key, [])) else: outputs = copy.deepcopy(response) if not isinstance(outputs, list): outputs = [outputs] outputs = update_time_format(outputs, ["createTime", "updateTime"]) readable_output = generate_group_membership_readable_output(outputs, readable_header) command_results = CommandResults( readable_output=readable_output, outputs_prefix="GCPIAM.Membership", outputs_key_field="name", outputs=outputs, raw_response=response, ) return command_results def remove_members_from_policy(role: str, iam_policy: list, members: list, command_name: str) -> list: """ Remove members from policy role. Args: role (str): The name of policy role. iam_policy (list): IAM policies. members (list): Members to remove from policy. command_name (str): An alternative command that will be displayed to the user in case of an error. Returns: list: Updated policies. """ role_found = False for policy in iam_policy: if policy.get("role") == role: for member in members: try: policy["members"].remove(member) except ValueError: raise Exception( f"The member {member} is not part of the project IAM policies members." f"If you wish to add a new policy, consider using the {command_name} command." ) role_found = True break if not role_found: raise Exception( "The provided role is not part of the project IAM policies." f"If you wish to add a new policy, consider using the {command_name} command." ) return iam_policy def add_members_to_policy(role: str, iam_policy: list, members: list, command_name: str) -> list: """ Append members to policy role members. Args: role (str): The name of policy role. iam_policy (list): IAM policies. members (list): Members to append to policy. command_name (str): An alternative command that will be displayed to the user in case of an error. Returns: list: Updated policies. """ role_found = False for policy in iam_policy: if policy.get("role") == role: policy["members"].extend(members) role_found = True break if not role_found: raise Exception( "The provided role is not part of the project IAM policies." f"If you wish to add a new policy, consider using the {command_name} command." ) return iam_policy def generate_service_account_command_output( response: dict, output_key: str = None, readable_header: str = "Service account information:" ) -> CommandResults: """ Generate command output for service account commands. Args: response (dict): API response from GCP. output_key (str): Used to access to required data in the response. readable_header (str): Readable message header for XSOAR war room. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ if output_key: outputs = copy.deepcopy(response.get(output_key, [])) else: outputs = copy.deepcopy(response) if not isinstance(outputs, list): outputs = [outputs] for output in outputs: output["disabled"] = output.get("disabled", False) readable_output = tableToMarkdown( readable_header, outputs, headers=["name", "displayName", "description", "projectId"], headerTransform=pascalToSpace ) command_results = CommandResults( readable_output=readable_output, outputs_prefix="GCPIAM.ServiceAccount", outputs_key_field="name", outputs=outputs, raw_response=response, ) return command_results def generate_project_command_output( response: dict, output_key: str = None, readable_header: str = "Project information:" ) -> CommandResults: """ Generate command output for project commands. Args: response (dict): API response from GCP. output_key (str): Used to access to required data in the response. readable_header (str): Readable message header for XSOAR war room. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ if output_key: outputs = copy.deepcopy(response.get(output_key, [])) else: outputs = copy.deepcopy(response) if not isinstance(outputs, list): outputs = [outputs] outputs = update_time_format(outputs, ["createTime", "updateTime", "deleteTime"]) readable_output = tableToMarkdown( readable_header, outputs, headers=["name", "parent", "projectId", "displayName", "createTime", "updateTime"], headerTransform=pascalToSpace, ) command_results = CommandResults( readable_output=readable_output, outputs_prefix="GCPIAM.Project", outputs_key_field="name", outputs=outputs, raw_response=response, ) return command_results def gcp_iam_projects_get_command(client: Client, args: Dict[str, Any]) -> list: """ List projects under the specified parent, or retrieve specific project information. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: list[CommandResults]: outputs, readable outputs and raw response for XSOAR. """ project_name = argToList(args.get("project_name")) command_results_list: List[CommandResults] = [] if project_name: # Retrieve specific project information. for project in project_name: readable_message = f"Project {project} information:" try: response = client.gcp_iam_project_get_request(project) command_results = generate_project_command_output(response=response, readable_header=readable_message) command_results_list.append(command_results) except Exception as exception: error = CommandResults(readable_output=f"An error occurred while retrieving {project}.\n {exception}") command_results_list.append(error) else: # List project resources. parent = args.get("parent") show_deleted = argToBoolean(args.get("show_deleted", False)) if not parent: raise Exception("One of the arguments: 'parent' or 'project_name' must be provided.") limit = arg_to_number(args.get("limit")) or 50 page = arg_to_number(args.get("page")) or 1 max_limit = 100 validate_pagination_arguments(limit, page) if limit > max_limit: raise Exception("The limit argument is out of range. It must be between 1 and 100.") readable_message = get_pagination_readable_message(header="Projects List:", limit=limit, page=page) if page > 1: response = get_pagination_request_result( limit, page, max_limit, client.gcp_iam_project_list_request, parent=parent, show_deleted=show_deleted ) else: response = client.gcp_iam_project_list_request(parent=parent, limit=limit, show_deleted=show_deleted) command_results = generate_project_command_output( response=response, output_key="projects", readable_header=readable_message ) command_results_list.append(command_results) return command_results_list def gcp_iam_project_iam_policy_get_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Retrieve the IAM access control policy for the specified project. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ project_name = args.get("project_name", "") limit = arg_to_number(args.get("limit")) or 50 page = arg_to_number(args.get("page")) or 1 roles = argToList(args.get("roles", [])) validate_pagination_arguments(limit, page) readable_message = get_pagination_readable_message(header=f"Project {project_name} IAM Policy List:", limit=limit, page=page) response = client.gcp_iam_project_iam_policy_get_request(project_name) return generate_iam_policy_command_output( response, project_name, readable_header=readable_message, limit=limit, page=page, roles=roles ) def generate_test_permission_command_output(response: dict, readable_header: str) -> CommandResults: """ Generate command output for test permission commands. Args: response (dict): API response from GCP. readable_header (str): Readable message header for XSOAR war room. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ outputs = [{"name": permission} for permission in copy.deepcopy(response.get("permissions", []))] readable_output = tableToMarkdown(readable_header, outputs, headers=["name"], headerTransform=pascalToSpace) command_results = CommandResults( readable_output=readable_output, outputs_prefix="GCPIAM.Permission", outputs_key_field="name", outputs=outputs, raw_response=response, ) return command_results def gcp_iam_project_iam_test_permission_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Retrieve permissions that a caller has on the specified project. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ project_name = args.get("project_name", "") permissions = argToList(args.get("permissions")) response = client.gcp_iam_project_iam_test_permission_request(project_name, permissions) return generate_test_permission_command_output(response, readable_header=f"Project {project_name} permissions:") def gcp_iam_project_iam_member_add_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Add members to project policy. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ project_name = args.get("project_name", "") role = args.get("role", "") members = argToList(args.get("members")) iam_policy = client.gcp_iam_project_iam_policy_get_request(project_name).get("bindings", []) updated_policies = add_members_to_policy( role=role, iam_policy=iam_policy, members=members, command_name="gcp-iam-project-iam-policy-create" ) client.gcp_iam_project_iam_policy_set_request(project_name, updated_policies) command_results = CommandResults(readable_output=f"Role {role} updated successfully.") return command_results def gcp_iam_project_iam_member_remove_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Remove members from project policy. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ project_name = args.get("project_name", "") role = args.get("role", "") members = argToList(args.get("members")) iam_policy = client.gcp_iam_project_iam_policy_get_request(project_name).get("bindings", []) updated_policies = remove_members_from_policy( role=role, iam_policy=iam_policy, members=members, command_name="gcp-iam-project-iam-policy-create" ) client.gcp_iam_project_iam_policy_set_request(project_name, updated_policies) command_results = CommandResults(readable_output=f"Role {role} updated successfully.") return command_results def gcp_iam_project_iam_policy_set_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Sets the IAM access control policy for the specified project. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ project_name = args.get("project_name", "") policy = args.get("policy") if isinstance(policy, str): policy = policy.replace("'", '"') if policy and not policy.startswith("["): policy = "[" + policy + "]" policy = safe_load_json(policy) response = client.gcp_iam_project_iam_policy_set_request(project_name, policy) return generate_iam_policy_command_output( response, project_name, readable_header=f"{project_name} IAM policy updated successfully." ) def gcp_iam_project_iam_policy_add_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Add new project IAM policy. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ project_name = args.get("project_name", "") role = args.get("role") members = argToList(args.get("members")) iam_policy = client.gcp_iam_project_iam_policy_get_request(project_name).get("bindings", []) policy = {"role": role, "members": members} iam_policy.append(policy) client.gcp_iam_project_iam_policy_set_request(project_name, iam_policy) command_results = CommandResults(readable_output=f"Role {role} updated successfully.") return command_results def generate_folder_command_output( response: dict, output_key: str = None, readable_header: str = "Folder information:" ) -> CommandResults: """ Generate command output for folder commands. Args: response (dict): API response from GCP. output_key (str): Used to access to required data in the response. readable_header (str): Readable message header for XSOAR war room. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ if output_key: outputs = copy.deepcopy(response.get(output_key, [])) else: outputs = copy.deepcopy(response) if not isinstance(outputs, list): outputs = [outputs] outputs = update_time_format(outputs, ["createTime", "updateTime", "deleteTime"]) readable_output = tableToMarkdown( readable_header, outputs, headers=["name", "parent", "displayName", "createTime", "updateTime"], headerTransform=pascalToSpace, ) command_results = CommandResults( readable_output=readable_output, outputs_prefix="GCPIAM.Folder", outputs_key_field="name", outputs=outputs, raw_response=response, ) return command_results def gcp_iam_folders_get_command(client: Client, args: Dict[str, Any]) -> list: """ List folders under the specified parent, or retrieve specific folder information. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: list[CommandResults]: outputs, readable outputs and raw response for XSOAR. """ folder_name = argToList(args.get("folder_name")) command_results_list: List[CommandResults] = [] if folder_name: # Retrieve specific folder information for folder in folder_name: readable_message = f"Folder {folder} information:" try: response = client.gcp_iam_folder_get_request(folder) command_results = generate_folder_command_output(response=response, readable_header=readable_message) command_results_list.append(command_results) except Exception as exception: error = CommandResults(readable_output=f"An error occurred while retrieving {folder}.\n {exception}") command_results_list.append(error) else: # List folder under the specified parent. parent = args.get("parent") show_deleted = argToBoolean(args.get("show_deleted", False)) if not parent: raise Exception("One of the arguments: 'parent' or 'folder_name' must be provided.") limit = arg_to_number(args.get("limit")) or 50 page = arg_to_number(args.get("page")) or 1 max_limit = 100 validate_pagination_arguments(limit, page) if limit > max_limit: raise Exception("The limit argument is out of range. It must be between 1 and 100.") readable_message = get_pagination_readable_message(header="Folders List:", limit=limit, page=page) if page > 1: response = get_pagination_request_result( limit, page, max_limit, client.gcp_iam_folder_list_request, parent=parent, show_deleted=show_deleted ) else: response = client.gcp_iam_folder_list_request(parent=parent, limit=limit, show_deleted=show_deleted) command_results = generate_folder_command_output( response=response, output_key="folders", readable_header=readable_message ) command_results_list.append(command_results) return command_results_list def gcp_iam_folder_iam_policy_get_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Retrieve the IAM access control policy for the specified folder. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ folder_name = args.get("folder_name", "") limit = arg_to_number(args.get("limit")) or 50 page = arg_to_number(args.get("page")) or 1 validate_pagination_arguments(limit, page) readable_message = get_pagination_readable_message(header=f"Folder {folder_name} IAM Policy List:", limit=limit, page=page) response = client.gcp_iam_folder_iam_policy_get_request(folder_name) return generate_iam_policy_command_output(response, folder_name, readable_header=readable_message, limit=limit, page=page) def gcp_iam_folder_iam_test_permission_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Retrieve permissions that a caller has on the specified folder. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ folder_name = args.get("folder_name", "") permissions = argToList(args.get("permissions")) response = client.gcp_iam_folder_iam_test_permission_request(folder_name, permissions) return generate_test_permission_command_output(response, readable_header=f"Folder {folder_name} permissions:") def gcp_iam_folder_iam_member_add_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Add members to folder policy. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ folder_name = args.get("folder_name", "") role = args.get("role", "") members = argToList(args.get("members")) iam_policy = client.gcp_iam_folder_iam_policy_get_request(folder_name).get("bindings", []) updated_policies = add_members_to_policy( role=role, iam_policy=iam_policy, members=members, command_name="gcp-iam-folder-iam-policy-create" ) client.gcp_iam_folder_iam_policy_set_request(folder_name, updated_policies) command_results = CommandResults(readable_output=f"Role {role} updated successfully.") return command_results def gcp_iam_folder_iam_member_remove_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Remove members from folder policy. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ folder_name = args.get("folder_name", "") role = args.get("role", "") members = argToList(args.get("members")) iam_policy = client.gcp_iam_folder_iam_policy_get_request(folder_name).get("bindings", []) updated_policies = remove_members_from_policy( role=role, iam_policy=iam_policy, members=members, command_name="gcp-iam-folder-iam-policy-create" ) client.gcp_iam_folder_iam_policy_set_request(folder_name, updated_policies) command_results = CommandResults(readable_output=f"Role {role} updated successfully.") return command_results def gcp_iam_folder_iam_policy_set_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Sets the IAM access control policy for the specified folder. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ folder_name = args.get("folder_name", "") policy = args.get("policy") if isinstance(policy, str): policy = policy.replace("'", '"') if policy and not policy.startswith("["): policy = "[" + policy + "]" policy = safe_load_json(policy) response = client.gcp_iam_folder_iam_policy_set_request(folder_name, policy) return generate_iam_policy_command_output( response, folder_name, readable_header=f"{folder_name} IAM policy updated successfully." ) def gcp_iam_folder_iam_policy_add_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Add new folder IAM policy. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ folder_name = args.get("folder_name", "") role = args.get("role") members = argToList(args.get("members")) iam_policy = client.gcp_iam_folder_iam_policy_get_request(folder_name).get("bindings", []) policy = {"role": role, "members": members} iam_policy.append(policy) client.gcp_iam_folder_iam_policy_set_request(folder_name, iam_policy) command_results = CommandResults(readable_output=f"Role {role} updated successfully.") return command_results def generate_organization_command_output( response: dict, output_key: str = None, readable_header: str = "Organization information:" ) -> CommandResults: """ Generate command output for group commands. Args: response (dict): API response from GCP. output_key (str): Used to access to required data in the response. readable_header (str): Readable message header for XSOAR war room. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ if output_key: outputs = copy.deepcopy(response.get(output_key, [])) else: outputs = copy.deepcopy(response) if not isinstance(outputs, list): outputs = [outputs] outputs = update_time_format(outputs, ["createTime", "updateTime"]) readable_output = tableToMarkdown( readable_header, outputs, headers=["name", "displayName", "directoryCustomerId", "createTime", "updateTime"], headerTransform=pascalToSpace, ) command_results = CommandResults( readable_output=readable_output, outputs_prefix="GCPIAM.Organization", outputs_key_field="name", outputs=outputs, raw_response=response, ) return command_results def gcp_iam_organizations_get_command(client: Client, args: Dict[str, Any]) -> list: """ List organization resources that are visible to the caller, or retrieve organization information. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: list[CommandResults]: outputs, readable outputs and raw response for XSOAR. """ organization_name = argToList(args.get("organization_name")) command_results_list: List[CommandResults] = [] if organization_name: # Retrieve specific organization information for organization in organization_name: readable_message = f"Organizations {organization} information:" try: response = client.gcp_iam_organization_get_request(organization) command_results = generate_organization_command_output(response=response, readable_header=readable_message) command_results_list.append(command_results) except Exception as exception: error = CommandResults(readable_output=f"An error occurred while retrieving {organization}.\n {exception}") command_results_list.append(error) else: # List organization resources that are visible to the caller. limit = arg_to_number(args.get("limit")) or 50 page = arg_to_number(args.get("page")) or 1 max_limit = 50 validate_pagination_arguments(limit, page) if limit > max_limit: raise Exception("The limit argument is out of range. It must be between 1 and 100.") readable_message = get_pagination_readable_message(header="Organizations List:", limit=limit, page=page) if page > 1: response = get_pagination_request_result(limit, page, max_limit, client.gcp_iam_organization_list_request) else: response = client.gcp_iam_organization_list_request(limit=limit) command_results = generate_organization_command_output( response=response, output_key="organizations", readable_header=readable_message ) command_results_list.append(command_results) return command_results_list def gcp_iam_organization_iam_policy_get_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Retrieve the IAM access control policy for the specified organization. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ organization_name = args.get("organization_name", "") limit = arg_to_number(args.get("limit")) or 50 page = arg_to_number(args.get("page")) or 1 validate_pagination_arguments(limit, page) readable_message = get_pagination_readable_message( header=f"Organization {organization_name} IAM Policy List:", limit=limit, page=page ) response = client.gcp_iam_organization_iam_policy_get_request(organization_name) return generate_iam_policy_command_output( response, organization_name, readable_header=readable_message, limit=limit, page=page ) def gcp_iam_organization_iam_test_permission_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Retrieve permissions that a caller has on the specified organization. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ organization_name = args.get("organization_name", "") permissions = argToList(args.get("permissions")) response = client.gcp_iam_organization_iam_test_permission_request(organization_name, permissions) return generate_test_permission_command_output(response, readable_header=f"Organization {organization_name} permissions:") def gcp_iam_organization_iam_member_add_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Add members to organization policy. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ organization_name = args.get("organization_name", "") role = args.get("role", "") members = argToList(args.get("members")) iam_policy = client.gcp_iam_organization_iam_policy_get_request(organization_name).get("bindings", []) updated_policies = add_members_to_policy( role=role, iam_policy=iam_policy, members=members, command_name="gcp-iam-organization-iam-policy-create" ) client.gcp_iam_organization_iam_policy_set_request(organization_name, updated_policies) command_results = CommandResults(readable_output=f"Role {role} updated successfully.") return command_results def gcp_iam_organization_iam_member_remove_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Remove members from organization policy. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ organization_name = args.get("organization_name", "") role = args.get("role", "") members = argToList(args.get("members")) iam_policy = client.gcp_iam_organization_iam_policy_get_request(organization_name).get("bindings", []) updated_policies = remove_members_from_policy( role=role, iam_policy=iam_policy, members=members, command_name="gcp-iam-organization-iam-policy-create" ) client.gcp_iam_organization_iam_policy_set_request(organization_name, updated_policies) command_results = CommandResults(readable_output=f"Role {role} updated successfully.") return command_results def gcp_iam_organization_iam_policy_set_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Sets the IAM access control policy for the specified organization. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ organization_name = args.get("organization_name", "") policy = args.get("policy") if isinstance(policy, str): policy = policy.replace("'", '"') if policy and not policy.startswith("["): policy = "[" + policy + "]" policy = safe_load_json(policy) response = client.gcp_iam_organization_iam_policy_set_request(organization_name, policy) return generate_iam_policy_command_output( response, organization_name, readable_header=f"{organization_name} IAM policy updated successfully." ) def gcp_iam_organization_iam_policy_add_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Add new organization IAM policy. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ organization_name = args.get("organization_name", "") role = args.get("role") members = argToList(args.get("members")) iam_policy = client.gcp_iam_organization_iam_policy_get_request(organization_name).get("bindings", []) policy = {"role": role, "members": members} iam_policy.append(policy) client.gcp_iam_organization_iam_policy_set_request(organization_name, iam_policy) command_results = CommandResults(readable_output=f"Role {role} updated successfully.") return command_results def gcp_iam_group_create_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Create a new group. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ parent = args.get("parent", "") description = args.get("description", "") display_name = args.get("display_name", "") group_email_address = args.get("group_email_address", "") response = client.gcp_iam_group_create_request(parent, display_name, group_email_address, description) outputs = copy.deepcopy(response.get("response")) created_group_name = outputs.get("name") outputs = update_time_format(outputs, ["createTime", "updateTime"]) readable_output = tableToMarkdown( f'Successfully Created Group "{created_group_name}"', outputs, headers=["name", "groupKey", "parent", "displayName", "createTime", "updateTime"], headerTransform=pascalToSpace, ) command_results = CommandResults( readable_output=readable_output, outputs_prefix="GCPIAM.Group", outputs_key_field="name", outputs=outputs, raw_response=response, ) return command_results def gcp_iam_group_list_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ List groups under the specified parent. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ parent = args.get("parent", "") limit = arg_to_number(args.get("limit")) or 50 page = arg_to_number(args.get("page")) or 1 page_token = None readable_message = get_pagination_readable_message(header="Groups List:", limit=limit, page=page) validate_pagination_arguments(limit, page) if limit > 500: raise Exception("The limit argument is out of range. It must be between 1 and 500.") if page > 1: page_token = get_next_page_token(limit, page, client.gcp_iam_group_list_request, args={"parent": parent}) if not page_token: return CommandResults(readable_output=readable_message, outputs_prefix="GCPIAM.Group", outputs=[], raw_response=[]) response = client.gcp_iam_group_list_request(parent, limit, page_token) readable_output = tableToMarkdown( readable_message, response.get("groups"), headers=["name", "groupKey", "displayName"], headerTransform=pascalToSpace ) command_results = CommandResults( readable_output=readable_output, outputs_prefix="GCPIAM.Group", outputs_key_field="name", outputs=response.get("groups"), raw_response=response, ) return command_results def gcp_iam_group_get_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Retrieve group information. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ group_name = args.get("group_name", "") response = client.gcp_iam_group_get_request(group_name) outputs = copy.deepcopy(response) outputs = update_time_format(outputs, ["createTime", "updateTime"]) readable_output = tableToMarkdown( "Group information:", outputs, headers=["name", "groupKey", "parent", "displayName", "createTime", "updateTime"], headerTransform=pascalToSpace, ) command_results = CommandResults( readable_output=readable_output, outputs_prefix="GCPIAM.Group", outputs_key_field="name", outputs=outputs, raw_response=response, ) return command_results def gcp_iam_group_delete_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Delete group. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ group_name = args.get("group_name", "") result = client.gcp_iam_group_delete_request(group_name) if not result.get("done"): raise Exception("Operation failed.") readable_output = f"Group {group_name} was successfully deleted." command_results = CommandResults(readable_output=readable_output) return command_results def gcp_iam_group_membership_create_command(client: Client, args: Dict[str, Any]) -> List[CommandResults]: """ Create a group membership. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ groups_name = argToList(args.get("groups_name")) member_email = args.get("member_email", "") role = argToList(args.get("role")) command_results_list: List[CommandResults] = [] for name in groups_name: try: response = client.gcp_iam_group_membership_create_request(name, member_email, role) command_results_list.append(generate_group_membership_command_output(response, "response")) except Exception as exception: error = CommandResults(readable_output=f"An error occurred while creating membership in group {name}.\n {exception}") command_results_list.append(error) return command_results_list def gcp_iam_group_membership_list_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ List group memberships. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ group_name = args.get("group_name", "") limit = arg_to_number(args.get("limit")) or 50 page = arg_to_number(args.get("page")) or 1 page_token = None readable_message = get_pagination_readable_message(header="Membership List:", limit=limit, page=page) validate_pagination_arguments(limit, page) if limit > 500: raise Exception("The limit argument is out of range. It must be between 1 and 500.") if page > 1: page_token = get_next_page_token( limit, page, client.gcp_iam_group_membership_list_request, args={"group_name": group_name} ) if not page_token: return CommandResults( readable_output=readable_message, outputs_prefix="GCPIAM.Membership", outputs=[], raw_response=[] ) response = client.gcp_iam_group_membership_list_request(group_name, limit, page_token) return generate_group_membership_command_output(response, "memberships", readable_message) def gcp_iam_group_membership_get_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Retrieve group membership information. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ membership_name = args.get("membership_name", "") response = client.gcp_iam_group_membership_get_request(membership_name) return generate_group_membership_command_output(response) def gcp_iam_group_membership_role_add_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Add group membership role. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ membership_name = args.get("membership_name", "") role = argToList(args.get("role")) client.gcp_iam_group_membership_role_add_request(membership_name, role) command_results = CommandResults(readable_output=f"Membership {membership_name} updated successfully.") return command_results def gcp_iam_group_membership_role_remove_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Remove group membership role. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ membership_name = args.get("membership_name", "") role = argToList(args.get("role")) client.gcp_iam_group_membership_role_remove_request(membership_name, role) command_results = CommandResults(readable_output=f"Membership {membership_name} updated successfully.") return command_results def gcp_iam_group_membership_delete_command(client: Client, args: Dict[str, Any]) -> List[CommandResults]: """ Delete group membership. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ membership_names = argToList(args.get("membership_names")) command_results_list: List[CommandResults] = [] for membership in membership_names: try: client.gcp_iam_group_membership_delete_request(membership) command_results = CommandResults(readable_output=f"Membership {membership} deleted successfully.") command_results_list.append(command_results) except Exception as exception: error = CommandResults(readable_output=f"An error occurred while deleting the membership {membership}.\n {exception}") command_results_list.append(error) return command_results_list def gcp_iam_service_account_create_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Create a service account in project. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ project_name = args.get("project_name", "") service_account_id = args.get("service_account_id", "") display_name = args.get("display_name", "") description = args.get("description", "") if not 6 <= len(service_account_id) <= 30: raise Exception("Service account ID length has to be between 6-30 characters.") response = client.gcp_iam_service_account_create_request(project_name, service_account_id, display_name, description) return generate_service_account_command_output(response) def gcp_iam_service_account_update_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Update service account. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ service_account_name = args.get("service_account_name", "") display_name = args.get("display_name", "") description = args.get("description", "") fields_to_update = args.get("fields_to_update", "") client.gcp_iam_service_account_update_request(service_account_name, fields_to_update, display_name, description) command_results = CommandResults(readable_output=f"Service account {service_account_name} updated successfully.") return command_results def get_pagination_request_result(limit: int, page: int, max_page_size: int, client_request: Callable, **kwargs) -> dict: """ Perform API request for pagination utility. Args: limit (int): The number of results to retrieve. page (int): The page number of the results to retrieve. max_page_size (int): API maximum page size limitation. client_request (int): API Client function. Returns: dict: API response from GCP. """ offset = (page - 1) * limit page_token = None steps = min(offset, max_page_size) for _i in range(0, offset, steps): response = client_request(limit=steps, page_token=page_token, **kwargs) page_token = response.get("nextPageToken") if not page_token: return {} return client_request(limit=limit, page_token=page_token, **kwargs) def gcp_iam_service_accounts_get_command(client: Client, args: Dict[str, Any]) -> Union[CommandResults, list]: """ List service accounts in project, or retrieve specific project service account information. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ service_account_name = argToList(args.get("service_account_name")) if service_account_name: # Retrieve specific service accounts information, command_results_list: List[CommandResults] = [] for account in service_account_name: try: response = client.gcp_iam_service_account_get_request(account) command_results_list.append(generate_service_account_command_output(response)) except Exception as exception: error = CommandResults(readable_output=f"An error occurred while retrieving {account}.\n {exception}") command_results_list.append(error) return command_results_list else: # List service accounts in project. project_name = args.get("project_name") if not project_name: raise Exception("One of the arguments: 'service_account_name' or 'project_name' must be provided.") limit = arg_to_number(args.get("limit")) or 50 page = arg_to_number(args.get("page")) or 1 max_limit = 100 validate_pagination_arguments(limit, page) if limit > max_limit: raise Exception("The limit argument is out of range. It must be between 1 and 100.") readable_message = get_pagination_readable_message(header="Service Account List:", limit=limit, page=page) if page > 1: response = get_pagination_request_result( limit, page, max_limit, client.gcp_iam_service_account_list_request, project_name=project_name ) else: response = client.gcp_iam_service_account_list_request(project_name=project_name, limit=limit) return generate_service_account_command_output(response, output_key="accounts", readable_header=readable_message) def gcp_iam_service_account_enable_command(client: Client, args: Dict[str, Any]) -> list: """ Enable project service account. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: list[CommandResults]: outputs, readable outputs and raw response for XSOAR. """ service_account_name = argToList(args.get("service_account_name")) command_results_list: List[CommandResults] = [] for account in service_account_name: try: client.gcp_iam_service_account_enable_request(account) command_results_list.append(CommandResults(readable_output=f"Service account {account} updated successfully.")) except Exception as exception: error = CommandResults(readable_output=f"An error occurred while trying to enable {account}.\n {exception}") command_results_list.append(error) return command_results_list def gcp_iam_service_account_disable_command(client: Client, args: Dict[str, Any]) -> list: """ Disable project service account. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: list[CommandResults]: outputs, readable outputs and raw response for XSOAR. """ service_account_name = argToList(args.get("service_account_name")) command_results_list: List[CommandResults] = [] for account in service_account_name: try: client.gcp_iam_service_account_disable_request(account) command_results_list.append(CommandResults(readable_output=f"Service account {account} updated successfully.")) except Exception as exception: error = CommandResults(readable_output=f"An error occurred while trying to disable {account}.\n {exception}") command_results_list.append(error) return command_results_list def gcp_iam_service_account_delete_command(client: Client, args: Dict[str, Any]) -> List[CommandResults]: """ Delete service account key. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ service_account_name = argToList(args.get("service_account_name")) command_results_list: List[CommandResults] = [] for account in service_account_name: try: client.gcp_iam_service_account_delete_request(account) command_results_list.append(CommandResults(readable_output=f"Service account {account} deleted successfully.")) except Exception as exception: error = CommandResults(readable_output=f"An error occurred while trying to delete {account}.\n {exception}") command_results_list.append(error) return command_results_list def generate_service_account_key_command_output( response: dict, output_key: str = None, readable_header: str = "Service account key information:" ) -> CommandResults: """ Generate command output for service account key commands. Args: response (dict): API response from GCP. output_key (str): Used to access to required data in the response. readable_header (str): Readable message header for XSOAR war room. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ if output_key: outputs = copy.deepcopy(response.get(output_key, [])) else: outputs = copy.deepcopy(response) if not isinstance(outputs, list): outputs = [outputs] for output in outputs: output["disabled"] = output.get("disabled", False) outputs = update_time_format(outputs, ["validAfterTime", "validBeforeTime"]) readable_output = tableToMarkdown( readable_header, outputs, headers=["name", "validAfterTime", "validBeforeTime", "disabled", "keyType"], headerTransform=pascalToSpace, ) command_results = CommandResults( readable_output=readable_output, outputs_prefix="GCPIAM.ServiceAccountKey", outputs_key_field="name", outputs=outputs, raw_response=response, ) return command_results def gcp_iam_service_account_key_create_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Create a service account key. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ service_account_name = args.get("service_account_name", "") key_algorithm = args.get("key_algorithm", "") response = client.gcp_iam_service_account_key_create_request(service_account_name, key_algorithm) return generate_service_account_key_command_output(response) def gcp_iam_service_account_keys_get_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ List service accounts keys, or retrieve service account key information. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ key_name = args.get("key_name") if key_name: # Retrieve specific service account key information. response = client.gcp_iam_service_account_key_get_request(key_name) return generate_service_account_key_command_output(response) else: service_account_name = args.get("service_account_name") if not service_account_name: raise Exception("One of the arguments: 'service_account_name' or 'key_name' must be provided.") limit = arg_to_number(args.get("limit")) or 50 page = arg_to_number(args.get("page")) or 1 validate_pagination_arguments(limit, page) response = client.gcp_iam_service_account_key_list_request(service_account_name) readable_message = get_pagination_readable_message(header="Service Account Keys List:", limit=limit, page=page) start = (page - 1) * limit end = start + limit outputs = [] keys = response.get("keys", []) if keys and len(keys) >= start: min_index = min(len(keys), end) for key in keys[start:min_index]: outputs.append(dict(key)) for output in outputs: output["disabled"] = output.get("disabled", False) outputs = update_time_format(outputs, ["validAfterTime", "validBeforeTime"]) readable_output = tableToMarkdown( readable_message, outputs, headers=["name", "validAfterTime", "validBeforeTime", "disabled", "keyType"], headerTransform=pascalToSpace, ) command_results = CommandResults( readable_output=readable_output, outputs_prefix="GCPIAM.ServiceAccountKey", outputs_key_field="name", outputs=outputs, raw_response=response, ) return command_results def gcp_iam_service_account_key_enable_command(client: Client, args: Dict[str, Any]) -> list: """ Enable service account key. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: list[CommandResults]: outputs, readable outputs and raw response for XSOAR. """ key_name = argToList(args.get("key_name")) command_results_list: List[CommandResults] = [] for key in key_name: try: client.gcp_iam_service_account_key_enable_request(key) command_results_list.append(CommandResults(readable_output=f"Service account key {key} updated successfully.")) except Exception as exception: error = CommandResults(readable_output=f"An error occurred while trying to enable {key}.\n {exception}") command_results_list.append(error) return command_results_list def gcp_iam_service_account_key_disable_command(client: Client, args: Dict[str, Any]) -> list: """ Disable service account key. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: list[CommandResults]: outputs, readable outputs and raw response for XSOAR. """ key_name = argToList(args.get("key_name")) command_results_list: List[CommandResults] = [] for key in key_name: try: client.gcp_iam_service_account_key_disable_request(key) command_results_list.append(CommandResults(readable_output=f"Service account key {key} updated successfully.")) except Exception as exception: error = CommandResults(readable_output=f"An error occurred while trying to disable {key}.\n {exception}") command_results_list.append(error) return command_results_list def gcp_iam_service_account_generate_access_token_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Create a serivce account short-lived access token Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ service_account_email = args["service_account_email"] lifetime = args["lifetime"] response = client.gcp_iam_service_account_generate_access_token_request(service_account_email, lifetime) readable_output = tableToMarkdown( f"Access token for {service_account_email}:", response, headers=["accessToken", "expireTime"], headerTransform=pascalToSpace, ) return CommandResults( readable_output=readable_output, outputs_prefix="GCPIAM.ServiceAccountAccessToken", outputs_key_field="name", outputs=response, raw_response=response, ) def gcp_iam_service_account_key_delete_command(client: Client, args: Dict[str, Any]) -> list: """ Delete service account key. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: list[CommandResults]: outputs, readable outputs and raw response for XSOAR. """ key_name = argToList(args.get("key_name")) command_results_list: List[CommandResults] = [] for key in key_name: try: client.gcp_iam_service_account_key_delete_request(key) command_results_list.append(CommandResults(readable_output=f"Service account key {key} deleted successfully.")) except Exception as exception: error = CommandResults(readable_output=f"An error occurred while trying to delete {key}.\n {exception}") command_results_list.append(error) return command_results_list def generate_role_command_output( response: dict, output_key: str = None, readable_header: str = "Role information:", outputs: list = None ) -> CommandResults: """ Generate command output for role commands. Args: response (dict): API response from GCP. output_key (str): Used to access to required data in the response. readable_header (str): Readable message header for XSOAR war room. outputs (list): Command output. If not provided, the command will set this argument. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ if not outputs and not isinstance(outputs, list): if output_key: outputs = copy.deepcopy(response.get(output_key, [])) else: outputs = [copy.deepcopy(response)] if not isinstance(outputs, list): outputs = [outputs] for role in outputs: role["stage"] = role.get("stage", "ALPHA") role["includedPermissions"] = role.get("includedPermissions", []) role["deleted"] = role.get("deleted", False) readable_output = tableToMarkdown( readable_header, outputs, headers=["name", "includedPermissions", "title", "description"], headerTransform=pascalToSpace ) command_results = CommandResults( readable_output=readable_output, outputs_prefix="GCPIAM.Role", outputs_key_field="name", outputs=outputs, raw_response=response, ) return command_results def create_custom_role(client_request_method: Callable, resource_identifier_key: str, args: Dict[str, Any]): """ Create a custom role. Args: client_request_method (Callable): The GCP Client method which create the required resource (organization/project) role. resource_identifier_key (str): The ID of the required resource which contains the custom role. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ resource_identifier = args.get(resource_identifier_key) role_id = args.get("role_id") description = args.get("description") title = args.get("title") stage = args.get("stage") permissions = argToList(args.get("permissions")) response = client_request_method(resource_identifier, role_id, stage, description, title, permissions) role_name = response.get("name") return generate_role_command_output(response, readable_header=f"Role {role_name} information:") def update_custom_role(client_request_method: Callable, args: Dict[str, Any]): """ Update custom role. Args: client_request_method (Callable): The GCP Client method which update the required resource (organization/project) role. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ role_name = args.get("role_name") description = args.get("description") title = args.get("title") permissions = argToList(args.get("permissions")) stage = args.get("stage") fields_to_update = args.get("fields_to_update") client_request_method(role_name, description, title, permissions, stage, fields_to_update) command_results = CommandResults(readable_output=f"Role {role_name} updated successfully.") return command_results def add_custom_role_permissions( client_request_get_method: Callable, client_request_update_method: Callable, args: Dict[str, Any] ): """ Add permissions to custom role. Args: client_request_get_method (Callable): The GCP Client method which retrieved the required resource (organization/project) role. client_request_update_method (Callable): The GCP Client method which update the required resource (organization/project) role. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ role_name = args.get("role_name") permissions = argToList(args.get("permissions")) role_permissions = client_request_get_method(role_name).get("includedPermissions", []) for permission in permissions: role_permissions.append(permission) client_request_update_method(role_name, permissions=role_permissions, fields_to_update="includedPermissions") command_results = CommandResults(readable_output=f"Role {role_name} updated successfully.") return command_results def remove_custom_role_permissions( client_request_get_method: Callable, client_request_update_method: Callable, args: Dict[str, Any] ): """ Remove permissions from custom project role. Args: client_request_get_method (Callable): The GCP Client method which retrieved the required resource (organization/project) role. client_request_update_method (Callable): The GCP Client method which update the required resource (organization/project) role. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ role_name = args.get("role_name") permissions = argToList(args.get("permissions")) role_permissions = client_request_get_method(role_name).get("includedPermissions", []) for permission in permissions: try: role_permissions.remove(permission) except ValueError: raise Exception( f"The permission {permission} is not part of the custom resource permissions." f"If you wish to add a new permission, " f"consider using gcp-iam-organization-role-permission-add " f"or gcp-iam-project-role-permission-add command." ) client_request_update_method(role_name, permissions=role_permissions, fields_to_update="includedPermissions") command_results = CommandResults(readable_output=f"Role {role_name} updated successfully.") return command_results def list_filtered_role( client_request_method: Callable, command_arguments: dict, limit: int, page: int, max_limit: int, title_filter: str = None, permission_filter: list = None, ) -> tuple: """ List and filter roles. Args: client_request_method (Callable): The GCP Client method which list the required resource (predefined/organization/project) role. command_arguments (dict): Client method arguments. limit (int): The number of results to retrieve. page (int): The page number of the results to retrieve. max_limit (int): GCP API max limit. title_filter (str): Used to filter the retrieved roles by the rule title. permission_filter (list): Used to filter the retrieved roles by their permissions. Returns: response , outputs. """ if permission_filter: command_arguments["include_permissions"] = True response = client_request_method(limit=max_limit, **command_arguments) max_result_offset = page * limit offset = (page - 1) * limit outputs = [] response_roles = response.get("roles", []) roles_remain = True while roles_remain and response_roles: for role in response_roles: if (title_filter and title_filter.lower() in role.get("title", "").lower()) or ( permission_filter and all(item in role.get("includedPermissions", []) for item in permission_filter) ): outputs.append(role) if len(outputs) >= max_result_offset: roles_remain = False break if roles_remain: if response.get("nextPageToken"): response = client_request_method(limit=max_limit, page_token=response.get("nextPageToken"), **command_arguments) response_roles = response.get("roles", []) else: roles_remain = False return response, outputs[offset:max_result_offset] def list_roles(client_request_method: Callable, args: Dict[str, Any], readable_header: str, resource_identifier_key: str = None): """ List custom roles. Args: client_request_method (Callable): The GCP Client method which list the required resource (predefined/organization/project) role. resource_identifier_key (str): The ID of the required resource which contains the custom role. args (dict): Command arguments from XSOAR. readable_header (str): Readable message header for XSOAR war room. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ if resource_identifier_key: resource_identifier = args.get(resource_identifier_key) include_permissions = argToBoolean(args.get("include_permissions", True)) limit = arg_to_number(args.get("limit")) or 50 page = arg_to_number(args.get("page")) or 1 show_deleted = argToBoolean(args.get("show_deleted", False)) title_filter = args.get("title_filter") permission_filter = argToList(args.get("permission_filter")) max_limit = 1000 validate_pagination_arguments(limit, page) if limit > max_limit: raise Exception("The limit argument is out of range. It must be between 1 and 1000.") readable_message = get_pagination_readable_message(header=readable_header, limit=limit, page=page) if resource_identifier_key: command_arguments = { "parent": resource_identifier, "include_permissions": include_permissions, "show_deleted": show_deleted, } else: command_arguments = {"include_permissions": include_permissions, "show_deleted": show_deleted} if title_filter or permission_filter: response, outputs = list_filtered_role( client_request_method, command_arguments, limit, page, max_limit, title_filter, permission_filter ) return generate_role_command_output(response, readable_header=readable_message, outputs=outputs) if page > 1: response = get_pagination_request_result(limit, page, max_limit, client_request_method, **command_arguments) else: response = client_request_method(limit=limit, **command_arguments) return generate_role_command_output(response, output_key="roles", readable_header=readable_message) def gcp_iam_organization_role_create_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Create a custom organization role. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ return create_custom_role( client_request_method=client.gcp_iam_organization_role_create_request, resource_identifier_key="organization_name", args=args, ) def gcp_iam_organization_role_update_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Update an organization custom role. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ return update_custom_role(client_request_method=client.gcp_iam_organization_role_update_request, args=args) def gcp_iam_organization_role_permission_add_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Add permissions to custom organization role. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ return add_custom_role_permissions( client_request_get_method=client.gcp_iam_organization_role_get_request, client_request_update_method=client.gcp_iam_organization_role_update_request, args=args, ) def gcp_iam_organization_role_permission_remove_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Remove permissions from custom organization role. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ return remove_custom_role_permissions( client_request_get_method=client.gcp_iam_organization_role_get_request, client_request_update_method=client.gcp_iam_organization_role_update_request, args=args, ) def gcp_iam_organization_role_list_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ List organization custom roles. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ return list_roles( client_request_method=client.gcp_iam_organization_role_list_request, resource_identifier_key="organization_name", args=args, readable_header="Custom Organization Roles list:", ) def gcp_iam_organization_role_get_command(client: Client, args: Dict[str, Any]) -> list: """ Retrieve organization role information. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: list[CommandResults]: outputs, readable outputs and raw response for XSOAR. """ role_name = argToList(args.get("role_name")) command_results_list: List[CommandResults] = [] for role in role_name: try: response = client.gcp_iam_organization_role_get_request(role) retrieved_role_name = response.get("name") command_results_list.append( generate_role_command_output(response, readable_header=f"Role {retrieved_role_name} information:") ) except Exception as exception: error = CommandResults(readable_output=f"An error occurred while retrieving {role}.\n {exception}") command_results_list.append(error) return command_results_list def gcp_iam_organization_role_delete_command(client: Client, args: Dict[str, Any]) -> list: """ Delete a custom organization role. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: list[CommandResults]: outputs, readable outputs and raw response for XSOAR. """ role_name = argToList(args.get("role_name")) command_results_list: List[CommandResults] = [] for role in role_name: try: client.gcp_iam_organization_role_delete_request(role) command_results_list.append(CommandResults(readable_output=f"Role {role} deleted successfully.")) except Exception as exception: error = CommandResults(readable_output=f"An error occurred while trying to delete {role}.\n {exception}") command_results_list.append(error) return command_results_list def gcp_iam_project_role_create_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Create a custom project role. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ return create_custom_role( client_request_method=client.gcp_iam_project_role_create_request, resource_identifier_key="project_id", args=args ) def gcp_iam_project_role_update_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Update an project custom role. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ return update_custom_role(client_request_method=client.gcp_iam_project_role_update_request, args=args) def gcp_iam_project_role_permission_add_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Add permissions to custom project role. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ return add_custom_role_permissions( client_request_get_method=client.gcp_iam_project_role_get_request, client_request_update_method=client.gcp_iam_project_role_update_request, args=args, ) def gcp_iam_project_role_permission_remove_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Remove permissions from custom project role. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ return remove_custom_role_permissions( client_request_get_method=client.gcp_iam_project_role_get_request, client_request_update_method=client.gcp_iam_project_role_update_request, args=args, ) def gcp_iam_project_role_list_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ List custom project roles. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ return list_roles( client_request_method=client.gcp_iam_project_role_list_request, resource_identifier_key="project_id", args=args, readable_header="Custom Project Roles list:", ) def gcp_iam_project_role_get_command(client: Client, args: Dict[str, Any]) -> list: """ Retrieve project role information. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: list[CommandResults]: outputs, readable outputs and raw response for XSOAR. """ role_name = argToList(args.get("role_name")) command_results_list: List[CommandResults] = [] for role in role_name: try: response = client.gcp_iam_project_role_get_request(role) retrieved_role_name = response.get("name") command_results_list.append( generate_role_command_output(response, readable_header=f"Role {retrieved_role_name} information:") ) except Exception as exception: error = CommandResults(readable_output=f"An error occurred while retrieving {role}.\n {exception}") command_results_list.append(error) return command_results_list def gcp_iam_project_role_delete_command(client: Client, args: Dict[str, Any]) -> list: """ Delete custom project role. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: list[CommandResults]: outputs, readable outputs and raw response for XSOAR. """ role_name = argToList(args.get("role_name")) command_results_list: List[CommandResults] = [] for role in role_name: try: client.gcp_iam_project_role_delete_request(role) command_results_list.append(CommandResults(readable_output=f"Role {role} deleted successfully.")) except Exception as exception: error = CommandResults(readable_output=f"An error occurred while trying to delete {role}.\n {exception}") command_results_list.append(error) return command_results_list def gcp_iam_predefined_role_get_command(client: Client, args: Dict[str, Any]) -> list: """ Retrieve GCP IAM predefined role information. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: list[CommandResults]: outputs, readable outputs and raw response for XSOAR. """ role_name = argToList(args.get("role_name")) command_results_list: List[CommandResults] = [] for role in role_name: try: response = client.gcp_iam_predefined_role_get_request(role) retrieved_role_name = response.get("name") command_results_list.append( generate_role_command_output(response, readable_header=f"Role {retrieved_role_name} information:") ) except Exception as exception: error = CommandResults(readable_output=f"An error occurred while retrieving {role}.\n {exception}") command_results_list.append(error) return command_results_list def gcp_iam_predefined_role_list_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Lists every predefined Role that IAM supports. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ return list_roles( client_request_method=client.gcp_iam_predefined_role_list_request, args=args, readable_header="GCP IAM Predefined Roles list:", ) def gcp_iam_testable_permission_list_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Lists permissions that can be tested on a resource. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ resource_name = args.get("resource_name") limit = arg_to_number(args.get("limit")) or 50 page = arg_to_number(args.get("page")) or 1 full_resource_name = f"//cloudresourcemanager.googleapis.com/{resource_name}" page_token = None readable_message = get_pagination_readable_message( header=f"{resource_name} testable permissions list:", limit=limit, page=page ) max_limit = 1000 validate_pagination_arguments(limit, page) if limit > max_limit: raise Exception("The limit argument is out of range. It must be between 1 and 1000.") if page > 1: page_token = get_next_page_token( limit, page, client.gcp_iam_testable_permission_list_request, args={"full_resource_name": full_resource_name} ) if not page_token: return CommandResults( readable_output=readable_message, outputs_prefix="GCPIAM.Permission", outputs=[], raw_response=[] ) response = client.gcp_iam_testable_permission_list_request(full_resource_name, limit, page_token) readable_output = tableToMarkdown( readable_message, response.get("permissions"), headers=["name", "stage"], headerTransform=pascalToSpace ) command_results = CommandResults( readable_output=readable_output, outputs_prefix="GCPIAM.Permission", outputs_key_field="name", outputs=response.get("permissions"), raw_response=response, ) return command_results def gcp_iam_grantable_role_list_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Lists roles that can be granted on a Google Cloud resource. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ resource_name = args.get("resource_name") limit = arg_to_number(args.get("limit")) or 50 page = arg_to_number(args.get("page")) or 1 full_resource_name = f"//cloudresourcemanager.googleapis.com/{resource_name}" page_token = None readable_message = get_pagination_readable_message(header=f"{resource_name} grantable roles list:", limit=limit, page=page) max_limit = 1000 validate_pagination_arguments(limit, page) if limit > max_limit: raise Exception("The limit argument is out of range. It must be between 1 and 1000.") if page > 1: page_token = get_next_page_token( limit, page, client.gcp_iam_grantable_role_list_request, args={"full_resource_name": full_resource_name} ) if not page_token: return CommandResults(readable_output=readable_message, outputs_prefix="GCPIAM.Roles", outputs=[], raw_response=[]) response = client.gcp_iam_grantable_role_list_request(full_resource_name, limit, page_token) readable_output = tableToMarkdown( readable_message, response.get("roles"), headers=["name", "title", "description"], headerTransform=pascalToSpace ) command_results = CommandResults( readable_output=readable_output, outputs_prefix="GCPIAM.Roles", outputs_key_field="name", outputs=response.get("roles"), raw_response=response, ) return command_results def gcp_iam_project_iam_policy_remove_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Remove policy from project IAM policies. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ project_name = args.get("project_name", "") role = argToList(args.get("role")) iam_policy = client.gcp_iam_project_iam_policy_get_request(project_name).get("bindings", []) updated_policies = [policy for policy in iam_policy if policy.get("role") not in role] client.gcp_iam_project_iam_policy_set_request(project_name, updated_policies) command_results = CommandResults(readable_output=f"Project {project_name} IAM policies updated successfully.") return command_results def gcp_iam_organization_iam_policy_remove_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Remove policy from organization IAM policies. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ organization_name = args.get("organization_name", "") role = argToList(args.get("role")) iam_policy = client.gcp_iam_organization_iam_policy_get_request(organization_name).get("bindings", []) updated_policies = [policy for policy in iam_policy if policy.get("role") not in role] client.gcp_iam_organization_iam_policy_set_request(organization_name, updated_policies) command_results = CommandResults(readable_output=f"Organization {organization_name} IAM policies updated successfully.") return command_results def gcp_iam_folder_iam_policy_remove_command(client: Client, args: Dict[str, Any]) -> CommandResults: """ Remove policy from folder IAM policies. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: CommandResults: outputs, readable outputs and raw response for XSOAR. """ folder_name = args.get("folder_name", "") role = argToList(args.get("role")) iam_policy = client.gcp_iam_folder_iam_policy_get_request(folder_name).get("bindings", []) updated_policies = [policy for policy in iam_policy if policy.get("role") not in role] client.gcp_iam_folder_iam_policy_set_request(folder_name, updated_policies) command_results = CommandResults(readable_output=f"Folder {folder_name} IAM policies updated successfully.") return command_results def gcp_iam_tagbindings_list_command(client: Client, args: Dict[str, Any]) -> Union[CommandResults, str]: """ List tag bindings (key value pair) applied to a project/folder/organization object. Args: client (Client): GCP API client. args (dict): Command arguments from XSOAR. Returns: list[CommandResults]: outputs, readable outputs and raw response for XSOAR. """ parent = args.get("parent") if not parent: raise Exception("Argument 'parent' must be provided.") max_limit = 100 res_binding = client.gcp_iam_tagbindings_list_request(parent=parent, limit=max_limit) if not res_binding: return "No tag bindingds found" if not res_binding.get("tagBindings", [{}])[0].get("tagValue"): return "No tag bindingds found" val_list = [] for value in res_binding.get("tagBindings", {}): res_value = client.gcp_iam_tagvalues_get_request(name=value.get("tagValue")) res_key = client.gcp_iam_tagkeys_get_request(name=res_value.get("parent", "")) kv = {"key": res_key["shortName"], "value": res_value["shortName"]} val_list.append(kv) readable_output = tableToMarkdown("Keys and Values", val_list, headers=["key", "value"], headerTransform=pascalToSpace) command_results = CommandResults( readable_output=readable_output, outputs_prefix="GCPIAM.TagBindings", outputs_key_field="key", outputs=val_list, raw_response=val_list, ) return command_results def test_module(service_account_key: str, proxy: bool, verify_certificate: bool) -> None: try: client: Client = Client(client_secret=service_account_key, proxy=proxy, verify_certificate=verify_certificate) client.gcp_iam_predefined_role_list_request(include_permissions=False, limit=1) except Exception as e: demisto.error(f"Error when running test-module {e}") return return_results("Authorization Error: make sure API Service Account Key is valid.") return_results("ok") return None def main() -> None: params: Dict[str, Any] = demisto.params() args: Dict[str, Any] = demisto.args() service_account_key = params["credentials"]["password"] verify_certificate: bool = not argToBoolean(params.get("insecure", False)) proxy: bool = params.get("proxy", False) command = demisto.command() demisto.debug(f"Command being called is {command}") try: if command == "test-module": return test_module(service_account_key, proxy=proxy, verify_certificate=verify_certificate) client: Client = Client(client_secret=service_account_key, proxy=proxy, verify_certificate=verify_certificate) commands = { "gcp-iam-projects-get": gcp_iam_projects_get_command, "gcp-iam-project-iam-policy-get": gcp_iam_project_iam_policy_get_command, "gcp-iam-project-iam-permission-test": gcp_iam_project_iam_test_permission_command, "gcp-iam-project-iam-member-add": gcp_iam_project_iam_member_add_command, "gcp-iam-project-iam-member-remove": gcp_iam_project_iam_member_remove_command, "gcp-iam-project-iam-policy-set": gcp_iam_project_iam_policy_set_command, "gcp-iam-project-iam-policy-create": gcp_iam_project_iam_policy_add_command, "gcp-iam-project-iam-policy-remove": gcp_iam_project_iam_policy_remove_command, "gcp-iam-folders-get": gcp_iam_folders_get_command, "gcp-iam-folder-iam-policy-get": gcp_iam_folder_iam_policy_get_command, "gcp-iam-folder-iam-permission-test": gcp_iam_folder_iam_test_permission_command, "gcp-iam-folder-iam-member-add": gcp_iam_folder_iam_member_add_command, "gcp-iam-folder-iam-member-remove": gcp_iam_folder_iam_member_remove_command, "gcp-iam-folder-iam-policy-set": gcp_iam_folder_iam_policy_set_command, "gcp-iam-folder-iam-policy-create": gcp_iam_folder_iam_policy_add_command, "gcp-iam-folder-iam-policy-remove": gcp_iam_folder_iam_policy_remove_command, "gcp-iam-organizations-get": gcp_iam_organizations_get_command, "gcp-iam-organization-iam-policy-get": gcp_iam_organization_iam_policy_get_command, "gcp-iam-organization-iam-permission-test": gcp_iam_organization_iam_test_permission_command, "gcp-iam-organization-iam-member-add": gcp_iam_organization_iam_member_add_command, "gcp-iam-organization-iam-member-remove": gcp_iam_organization_iam_member_remove_command, "gcp-iam-organization-iam-policy-set": gcp_iam_organization_iam_policy_set_command, "gcp-iam-organization-iam-policy-create": gcp_iam_organization_iam_policy_add_command, "gcp-iam-organization-iam-policy-remove": gcp_iam_organization_iam_policy_remove_command, "gcp-iam-group-create": gcp_iam_group_create_command, "gcp-iam-group-list": gcp_iam_group_list_command, "gcp-iam-group-get": gcp_iam_group_get_command, "gcp-iam-group-delete": gcp_iam_group_delete_command, "gcp-iam-group-membership-create": gcp_iam_group_membership_create_command, "gcp-iam-group-membership-list": gcp_iam_group_membership_list_command, "gcp-iam-group-membership-get": gcp_iam_group_membership_get_command, "gcp-iam-group-membership-role-add": gcp_iam_group_membership_role_add_command, "gcp-iam-group-membership-role-remove": gcp_iam_group_membership_role_remove_command, "gcp-iam-group-membership-delete": gcp_iam_group_membership_delete_command, "gcp-iam-service-account-create": gcp_iam_service_account_create_command, "gcp-iam-service-account-update": gcp_iam_service_account_update_command, "gcp-iam-service-accounts-get": gcp_iam_service_accounts_get_command, "gcp-iam-service-account-enable": gcp_iam_service_account_enable_command, "gcp-iam-service-account-disable": gcp_iam_service_account_disable_command, "gcp-iam-service-account-delete": gcp_iam_service_account_delete_command, "gcp-iam-service-account-key-create": gcp_iam_service_account_key_create_command, "gcp-iam-service-account-keys-get": gcp_iam_service_account_keys_get_command, "gcp-iam-service-account-key-enable": gcp_iam_service_account_key_enable_command, "gcp-iam-service-account-key-disable": gcp_iam_service_account_key_disable_command, "gcp-iam-service-account-generate-access-token": gcp_iam_service_account_generate_access_token_command, "gcp-iam-service-account-key-delete": gcp_iam_service_account_key_delete_command, "gcp-iam-organization-role-create": gcp_iam_organization_role_create_command, "gcp-iam-organization-role-update": gcp_iam_organization_role_update_command, "gcp-iam-organization-role-permission-add": gcp_iam_organization_role_permission_add_command, "gcp-iam-organization-role-permission-remove": gcp_iam_organization_role_permission_remove_command, "gcp-iam-organization-role-list": gcp_iam_organization_role_list_command, "gcp-iam-organization-role-get": gcp_iam_organization_role_get_command, "gcp-iam-organization-role-delete": gcp_iam_organization_role_delete_command, "gcp-iam-project-role-create": gcp_iam_project_role_create_command, "gcp-iam-project-role-update": gcp_iam_project_role_update_command, "gcp-iam-project-role-permission-add": gcp_iam_project_role_permission_add_command, "gcp-iam-project-role-permission-remove": gcp_iam_project_role_permission_remove_command, "gcp-iam-project-role-list": gcp_iam_project_role_list_command, "gcp-iam-project-role-get": gcp_iam_project_role_get_command, "gcp-iam-project-role-delete": gcp_iam_project_role_delete_command, "gcp-iam-testable-permission-list": gcp_iam_testable_permission_list_command, "gcp-iam-grantable-role-list": gcp_iam_grantable_role_list_command, "gcp-iam-role-get": gcp_iam_predefined_role_get_command, "gcp-iam-role-list": gcp_iam_predefined_role_list_command, "gcp-iam-tagbindings-list": gcp_iam_tagbindings_list_command, } if command in commands: return_results(commands[command](client, args)) else: raise NotImplementedError(f"{command} command is not implemented.") except Exception as e: return_error(str(e)) if __name__ in ["__main__", "builtin", "builtins"]: main()