PrismaCloud IAM

The Prisma Cloud IAM API consists of a set of API endpoints that allow customers to perform CRUD operation on their user profiles.

Identity and Access Management · Prisma Cloud by Palo Alto Networks

Details

IDPrismaCloud IAM
ProviderPalo Alto Networks
CategoryIdentity and Access Management
From Version6.0.0
Docker Imagedemisto/python3:3.12.13.10116658
Supported ModulesAgentix XSIAM EDR Cortex Cloud Cloud Runtime Security

README

Note: This integration should be used as part of our Identity Lifecycle Management premium pack. For more information, please refer to the Identity Lifecycle Management article.

The Prisma Cloud IAM API consists of a set of API endpoints that allow customers to perform CRUD operation on their user profiles.

Configure PrismaCloud IAM in Cortex

Parameter Description Required
Base URL   True
Username   True
Password   True
Customer name If you are a multi-tenant user you will also need to provide the customerName. False
Trust any certificate (not secure)   False
Use system proxy settings   False
Allow creating users   False
Allow updating users   False
Allow enabling users   False
Allow disabling users   False
Automatically create user if not found in update command   False
Incoming Mapper   True
Outgoing Mapper Cortex XSOAR only parameter. False

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.

iam-create-user


Creates a user.

Base Command

iam-create-user

Input

Argument Name Description Required
user-profile User Profile indicator details. Required
allow-enable When set to true, after the command execution the status of the user in the 3rd-party integration will be active. Possible values are: true, false. Default is true. Optional

Context Output

Path Type Description
IAM.Vendor.active Boolean When true, indicates that the employee’s status is active in the 3rd-party integration.
IAM.Vendor.brand String Name of the integration.
IAM.Vendor.details string Provides the raw data from the 3rd-party integration.
IAM.Vendor.email String The employee’s email address.
IAM.Vendor.errorCode Number HTTP error response code.
IAM.Vendor.errorMessage String Reason why the API failed.
IAM.Vendor.id String The employee’s user ID in the app.
IAM.Vendor.instanceName string Name of the integration instance.
IAM.Vendor.success Boolean When true, indicates that the command was executed successfully.
IAM.Vendor.username String The employee’s username in the app.

Command Example

!iam-create-user user-profile=`{"email": "john.doe@example.com", "givenname": "test", "surname": "test"}`

Context Example

{
    "IAM": {
        "UserProfile": {
            "email": "john.doe@example.com",
            "givenname": "test",
            "surname": "test"
        },
        "Vendor": {
            "action": "update",
            "active": null,
            "brand": "PrismaCloudIAM",
            "details": {
                "email": "john.doe@example.com",
                "firstName": "test",
                "lastName": "test",
                "roleId": "some_role_id",
                "timeZone": "America/Los_Angeles"
            },
            "email": "john.doe@example.com",
            "errorCode": null,
            "errorMessage": "",
            "id": null,
            "instanceName": "PrismaCloudIAM_instance_1",
            "reason": "",
            "skipped": false,
            "success": true,
            "username": null
        }
    }
}

Human Readable Output

Update User Results (PrismaCloudIAM)

brand instanceName success email details
PrismaCloudIAM PrismaCloudIAM_instance_1 true john.doe@example.com email: john.doe@example.com
firstName: test
lastName: test
roleId: some_role_id
timeZone: America/Los_Angeles

iam-update-user


Updates an existing user with the data passed in the user-profile argument.

Base Command

iam-update-user

Input

Argument Name Description Required
user-profile A User Profile indicator. Required
allow-enable When set to true, after the command execution the status of the user in the 3rd-party integration will be active. Possible values are: true, false. Default is true. Optional

Context Output

Path Type Description
IAM.Vendor.active Boolean When true, indicates that the employee’s status is active in the 3rd-party integration.
IAM.Vendor.brand String Name of the integration.
IAM.Vendor.details string Provides the raw data from the 3rd-party integration.
IAM.Vendor.email String The employee’s email address.
IAM.Vendor.errorCode Number HTTP error response code.
IAM.Vendor.errorMessage String Reason why the API failed.
IAM.Vendor.id String The employee’s user ID in the app.
IAM.Vendor.instanceName string Name of the integration instance.
IAM.Vendor.success Boolean When true, indicates that the command was executed successfully.
IAM.Vendor.username String The employee’s username in the app.

Command Example

!iam-update-user user-profile=`{"email": "john.doe@example.com", "givenname": "John"}`

Context Example

{
    "IAM": {
        "UserProfile": {
            "email": "john.doe@example.com",
            "givenname": "John"
        },
        "Vendor": {
            "action": "update",
            "active": null,
            "brand": "PrismaCloudIAM",
            "details": {
                "email": "john.doe@example.com",
                "firstName": "John",
                "roleId": "some_role_id",
                "timeZone": "America/Los_Angeles"
            },
            "email": "john.doe@example.com",
            "errorCode": null,
            "errorMessage": "",
            "id": null,
            "instanceName": "PrismaCloudIAM_instance_1",
            "reason": "",
            "skipped": false,
            "success": true,
            "username": null
        }
    }
}

Human Readable Output

Update User Results (PrismaCloudIAM)

brand instanceName success email details
PrismaCloudIAM PrismaCloudIAM_instance_1 true john.doe@example.com email: john.doe@example.com
firstName: John
roleId: some_role_id
timeZone: America/Los_Angeles

iam-get-user


Retrieves a single user resource.

Base Command

iam-get-user

Input

Argument Name Description Required
user-profile A User Profile indicator. Required

Context Output

Path Type Description
IAM.Vendor.active Boolean When true, indicates that the employee’s status is active in the 3rd-party integration.
IAM.Vendor.brand String Name of the integration.
IAM.Vendor.details string Provides the raw data from the 3rd-party integration.
IAM.Vendor.email String The employee’s email address.
IAM.Vendor.errorCode Number HTTP error response code.
IAM.Vendor.errorMessage String Reason why the API failed.
IAM.Vendor.id String The employee’s user ID in the app.
IAM.Vendor.instanceName string Name of the integration instance.
IAM.Vendor.success Boolean When true, indicates that the command was executed successfully.
IAM.Vendor.username String The employee’s username in the app.

Command Example

!iam-get-user user-profile=`{"email": "john.doe@example.com"}`

Context Example

{
    "IAM": {
        "UserProfile": {
            "Display Name": "test test",
            "Email": "john.doe@example.com",
            "Given Name": "test",
            "Surname": "test"
        },
        "Vendor": {
            "action": "get",
            "active": true,
            "brand": "PrismaCloudIAM",
            "details": {
                "accessKeysAllowed": true,
                "displayName": "test test",
                "email": "john.doe@example.com",
                "enabled": true,
                "firstName": "test",
                "lastLoginTs": -1,
                "lastModifiedBy": "modifier@example.com",
                "lastModifiedTs": 1628152142011,
                "lastName": "test",
                "role": {
                    "id": "some_role_id",
                    "name": "System Admin"
                },
                "roleId": "some_role_id",
                "roleType": "System Admin",
                "timeZone": "America/Los_Angeles"
            },
            "email": null,
            "errorCode": null,
            "errorMessage": "",
            "id": "john.doe@example.com",
            "instanceName": "PrismaCloudIAM_instance_1",
            "reason": "",
            "skipped": false,
            "success": true,
            "username": null
        }
    }
}

Human Readable Output

Get User Results (PrismaCloudIAM)

brand instanceName success active id details
PrismaCloudIAM PrismaCloudIAM_instance_1 true true john.doe@example.com email: john.doe@example.com
firstName: test
lastName: test
timeZone: America/Los_Angeles
enabled: true
roleId: some_role_id
lastModifiedBy: modifier@example.com
lastModifiedTs: 1628152142011
lastLoginTs: -1
role: {“id”: “some_role_id”, “name”: “System Admin”}
roleType: System Admin
displayName: test test
accessKeysAllowed: true

iam-disable-user


Disable an active user.

Base Command

iam-disable-user

Input

Argument Name Description Required
user-profile A User Profile indicator. Required

Context Output

Path Type Description
IAM.Vendor.active Boolean When true, indicates that the employee’s status is active in the 3rd-party integration.
IAM.Vendor.brand String Name of the integration.
IAM.Vendor.details string Provides the raw data from the 3rd-party integration.
IAM.Vendor.email String The employee’s email address.
IAM.Vendor.errorCode Number HTTP error response code.
IAM.Vendor.errorMessage String Reason why the API failed.
IAM.Vendor.id String The employee’s user ID in the app.
IAM.Vendor.instanceName string Name of the integration instance.
IAM.Vendor.success Boolean When true, indicates that the command was executed successfully.
IAM.Vendor.username String The employee’s username in the app.

Command Example

!iam-disable-user user-profile=`{"email": "john.doe@example.com", "givenname": "John"}`

Context Example

{
    "IAM": {
        "UserProfile": {
            "email": "john.doe@example.com",
            "givenname": "John"
        },
        "Vendor": {
            "action": "disable",
            "active": false,
            "brand": "PrismaCloudIAM",
            "details": null,
            "email": "john.doe@example.com",
            "errorCode": null,
            "errorMessage": "",
            "id": null,
            "instanceName": "PrismaCloudIAM_instance_1",
            "reason": "",
            "skipped": false,
            "success": true,
            "username": null
        }
    }
}

Human Readable Output

Disable User Results (PrismaCloudIAM)

brand instanceName success active email
PrismaCloudIAM PrismaCloudIAM_instance_1 true false john.doe@example.com

Outgoing Mapper

  • In the User Profile - PrismaCloudIAM (Outgoing) you should manually configure and map the following required attributes:
    1. timeZone - the time zone of the user.
    2. roleId - the id of the role assigned to the user

Configuration parameters

  • url — Base URL (required)
  • credentials — Username (required)
  • customer_name — Customer name
  • insecure — Trust any certificate (not secure)
  • proxy — Use system proxy settings
  • create_user_enabled — Allow creating users
  • update_user_enabled — Allow updating users
  • enable_user_enabled — Allow enabling users
  • disable_user_enabled — Allow disabling users
  • create_if_not_exists — Automatically create user if not found in update command
  • mapper_in — Incoming Mapper (required)
  • mapper_out — Outgoing Mapper

Commands (5)

  • get-mapping-fields

    Retrieves a User Profile schema, which holds all of the user fields within the application. Used for outgoing-mapping through the Get Schema option.

  • iam-create-user

    Creates a user.

  • iam-disable-user

    Disable an active user.

  • iam-get-user

    Retrieves a single user resource.

  • iam-update-user

    Updates an existing user with the data passed in the user-profile argument.

from IAMApiModule import *
from PrismaCloudIAM import Client, get_mapping_fields
from requests import Response, Session

APP_USER_OUTPUT = {
    "user_id": "mock_id",
    "user_name": "mock_user_name",
    "first_name": "mock_first_name",
    "last_name": "mock_last_name",
    "active": "true",
    "email": "testdemisto2@paloaltonetworks.com",
}

USER_APP_DATA = IAMUserAppData("mock_id", "mock_user_name", is_active=True, app_data=APP_USER_OUTPUT)

APP_DISABLED_USER_OUTPUT = {
    "user_id": "mock_id",
    "user_name": "mock_user_name",
    "first_name": "mock_first_name",
    "last_name": "mock_last_name",
    "active": "false",
    "email": "testdemisto2@paloaltonetworks.com",
}

DISABLED_USER_APP_DATA = IAMUserAppData("mock_id", "mock_user_name", is_active=False, app_data=APP_DISABLED_USER_OUTPUT)


# helpers methods
def mock_client(mocker):
    mocker.patch.object(Client, "login", return_value={})
    client = Client(base_url="https://test.com", username="test", password="test", customer_name="test", headers={})
    return client


def get_outputs_from_user_profile(user_profile):
    entry_context = user_profile.to_entry()
    outputs = entry_context.get("Contents")
    return outputs


# tests classes
class TestGetUserCommand:
    """
    Class to group the get user commands test
    """

    def test_get_user_command__existing_user(self, mocker):
        """
        Given:
            - An app client object
            - A user-profile argument that contains an email of a user
        When:
            - The user exists in the application
            - Calling function get_user_command
        Then:
            - Ensure the resulted User Profile object holds the correct user details
        """
        client = mock_client(mocker)
        args = {"user-profile": {"email": "testdemisto2@paloaltonetworks.com"}}

        mocker.patch.object(client, "get_user", return_value=USER_APP_DATA)
        mocker.patch.object(IAMUserProfile, "update_with_app_data", return_value={})

        user_profile = IAMCommand().get_user(client, args)
        outputs = get_outputs_from_user_profile(user_profile)

        assert outputs.get("action") == IAMActions.GET_USER
        assert outputs.get("success") is True
        assert outputs.get("active") is True
        assert outputs.get("id") == "mock_id"
        assert outputs.get("username") == "mock_user_name"
        assert outputs.get("details", {}).get("first_name") == "mock_first_name"
        assert outputs.get("details", {}).get("last_name") == "mock_last_name"

    def test_get_user_command__non_existing_user(self, mocker):
        """
        Given:
            - An app client object
            - A user-profile argument that contains an email a user
        When:
            - The user does not exist in the application
            - Calling function get_user_command
        Then:
            - Ensure the resulted User Profile object holds information about an unsuccessful result.
        """
        client = mock_client(mocker)
        args = {"user-profile": {"email": "testdemisto2@paloaltonetworks.com"}}

        mocker.patch.object(client, "get_user", return_value=None)

        user_profile = IAMCommand().get_user(client, args)
        outputs = get_outputs_from_user_profile(user_profile)

        assert outputs.get("action") == IAMActions.GET_USER
        assert outputs.get("success") is False
        assert outputs.get("errorCode") == IAMErrors.USER_DOES_NOT_EXIST[0]
        assert outputs.get("errorMessage") == IAMErrors.USER_DOES_NOT_EXIST[1]

    def test_get_user_command__bad_response(self, mocker):
        """
        Given:
            - An app client object
            - A user-profile argument that contains an email of a non-existing user in the application
        When:
            - Calling function get_user_command
            - A bad response (500) is returned from the application API
        Then:
            - Ensure the resulted User Profile object holds information about the bad response.
        """
        import demistomock as demisto

        client = mock_client(mocker)
        args = {"user-profile": {"email": "testdemisto2@paloaltonetworks.com"}}

        bad_response = Response()
        bad_response.headers = {"x-redlock-status": json.dumps([{"i18nKey": "bad request"}])}
        bad_response.status_code = 500

        mocker.patch.object(demisto, "error")
        mocker.patch.object(Session, "request", return_value=bad_response)

        user_profile = IAMCommand().get_user(client, args)
        outputs = get_outputs_from_user_profile(user_profile)

        assert outputs.get("action") == IAMActions.GET_USER
        assert outputs.get("success") is False
        assert outputs.get("errorCode") == 500
        assert "Error in API call [500] - bad request" in outputs.get("errorMessage")


class TestCreateUserCommand:
    """
    Class to group the create user commands test
    """

    def test_create_user_command__success(self, mocker):
        """
        Given:
            - An app client object
            - A user-profile argument that contains an email of a non-existing user in the application
        When:
            - Calling function create_user_command
        Then:
            - Ensure a User Profile object with the user data is returned
        """
        client = mock_client(mocker)
        args = {"user-profile": {"email": "testdemisto2@paloaltonetworks.com"}}

        mocker.patch.object(client, "get_user", return_value=None)
        mocker.patch.object(IAMUserProfile, "map_object", return_value={})
        mocker.patch.object(client, "create_user", return_value=USER_APP_DATA)

        user_profile = IAMCommand().create_user(client, args)
        outputs = get_outputs_from_user_profile(user_profile)

        assert outputs.get("action") == IAMActions.CREATE_USER
        assert outputs.get("success") is True
        assert outputs.get("active") is True
        assert outputs.get("id") == "mock_id"
        assert outputs.get("username") == "mock_user_name"
        assert outputs.get("details", {}).get("first_name") == "mock_first_name"
        assert outputs.get("details", {}).get("last_name") == "mock_last_name"

    def test_create_user_command__user_already_exists(self, mocker):
        """
        Given:
            - An app client object
            - A user-profile argument that contains an email of a user
        When:
            - The user already exists in the application and disabled
            - allow-enable argument is false
            - Calling function create_user_command
        Then:
            - Ensure the command is considered successful and the user is still disabled
        """
        client = mock_client(mocker)
        args = {"user-profile": {"email": "testdemisto2@paloaltonetworks.com"}, "allow-enable": "false"}

        mocker.patch.object(client, "get_user", return_value=DISABLED_USER_APP_DATA)
        mocker.patch.object(client, "update_user", return_value=DISABLED_USER_APP_DATA)

        user_profile = IAMCommand().create_user(client, args)
        outputs = get_outputs_from_user_profile(user_profile)

        assert outputs.get("action") == IAMActions.UPDATE_USER
        assert outputs.get("success") is True
        assert outputs.get("active") is False
        assert outputs.get("id") == "mock_id"
        assert outputs.get("username") == "mock_user_name"
        assert outputs.get("details", {}).get("first_name") == "mock_first_name"
        assert outputs.get("details", {}).get("last_name") == "mock_last_name"


class TestUpdateUserCommand:
    """
    Class to group the update user commands test
    """

    def test_update_user_command__non_existing_user(self, mocker):
        """
        Given:
            - An app client object
            - A user-profile argument that contains user data
        When:
            - The user does not exist in the application
            - create-if-not-exists parameter is checked
            - Create User command is enabled
            - Calling function update_user_command
        Then:
            - Ensure the create action is executed
            - Ensure a User Profile object with the user data is returned
        """
        client = mock_client(mocker)
        args = {"user-profile": {"email": "testdemisto2@paloaltonetworks.com", "givenname": "mock_first_name"}}

        mocker.patch.object(client, "get_user", return_value=None)
        mocker.patch.object(IAMUserProfile, "map_object", return_value={})
        mocker.patch.object(client, "create_user", return_value=USER_APP_DATA)

        user_profile = IAMCommand(create_if_not_exists=True).update_user(client, args)
        outputs = get_outputs_from_user_profile(user_profile)

        assert outputs.get("action") == IAMActions.CREATE_USER
        assert outputs.get("success") is True
        assert outputs.get("active") is True
        assert outputs.get("id") == "mock_id"
        assert outputs.get("username") == "mock_user_name"
        assert outputs.get("details", {}).get("first_name") == "mock_first_name"
        assert outputs.get("details", {}).get("last_name") == "mock_last_name"

    def test_update_user_command__command_is_disabled(self, mocker):
        """
        Given:
            - An app client object
            - A user-profile argument that contains user data
        When:
            - Update User command is disabled
            - Calling function update_user_command
        Then:
            - Ensure the command is considered successful and skipped
        """
        client = mock_client(mocker)
        args = {"user-profile": {"email": "testdemisto2@paloaltonetworks.com", "givenname": "mock_first_name"}}

        mocker.patch.object(client, "get_user", return_value=None)
        mocker.patch.object(IAMUserProfile, "map_object", return_value={})
        mocker.patch.object(client, "update_user", return_value=USER_APP_DATA)

        user_profile = IAMCommand(is_update_enabled=False).update_user(client, args)
        outputs = get_outputs_from_user_profile(user_profile)

        assert outputs.get("action") == IAMActions.UPDATE_USER
        assert outputs.get("success") is True
        assert outputs.get("skipped") is True
        assert outputs.get("reason") == "Command is disabled."

    def test_update_user_command__allow_enable(self, mocker):
        """
        Given:
            - An app client object
            - A user-profile argument that contains user data
        When:
            - The user is disabled in the application
            - allow-enable argument is true
            - Calling function update_user_command
        Then:
            - Ensure the user is enabled at the end of the command execution.
        """
        client = mock_client(mocker)
        args = {
            "user-profile": {"email": "testdemisto2@paloaltonetworks.com", "givenname": "mock_first_name"},
            "allow-enable": "true",
        }

        mocker.patch.object(client, "get_user", return_value=DISABLED_USER_APP_DATA)
        mocker.patch.object(IAMUserProfile, "map_object", return_value={})
        mocker.patch.object(client, "enable_user", return_value=USER_APP_DATA)
        mocker.patch.object(client, "update_user", return_value=USER_APP_DATA)

        user_profile = IAMCommand().update_user(client, args)
        outputs = get_outputs_from_user_profile(user_profile)

        assert outputs.get("action") == IAMActions.UPDATE_USER
        assert outputs.get("success") is True
        assert outputs.get("active") is True
        assert outputs.get("id") == "mock_id"
        assert outputs.get("username") == "mock_user_name"
        assert outputs.get("details", {}).get("first_name") == "mock_first_name"
        assert outputs.get("details", {}).get("last_name") == "mock_last_name"


class TestDisableUserTest:
    """
    Class to group the disable user commands test
    """

    def test_disable_user_command__non_existing_user(self, mocker):
        """
        Given:
            - An app client object
            - A user-profile argument that contains an email of a user
        When:
            - create-if-not-exists parameter is unchecked
            - The user does not exist in the application
            - Calling function disable_user_command
        Then:
            - Ensure the command is considered successful and skipped
        """
        client = mock_client(mocker)
        args = {"user-profile": {"email": "testdemisto2@paloaltonetworks.com"}}

        mocker.patch.object(client, "get_user", return_value=None)

        user_profile = IAMCommand().disable_user(client, args)
        outputs = get_outputs_from_user_profile(user_profile)

        assert outputs.get("action") == IAMActions.DISABLE_USER
        assert outputs.get("success") is True
        assert outputs.get("skipped") is True
        assert outputs.get("reason") == IAMErrors.USER_DOES_NOT_EXIST[1]


class TestGetMappingFieldsTest:
    """
    Class to group the disable user commands test
    """

    def test_get_mapping_fields_command(self, mocker):
        """
        Given:
            - An app client object
        When:
            - User schema in the application contains the fields 'field1' and 'field2'
            - Calling function get_mapping_fields_command
        Then:
            - Ensure a GetMappingFieldsResponse object that contains the application fields is returned
        """
        client = mock_client(mocker)
        mocker.patch.object(client, "get_app_fields", return_value={"field1": "desc1", "field2": "desc2"})

        mapping_response = get_mapping_fields(client)
        mapping = mapping_response.extract_mapping()

        assert mapping.get(IAMUserProfile.DEFAULT_INCIDENT_TYPE, {}).get("field1") == "desc1"
        assert mapping.get(IAMUserProfile.DEFAULT_INCIDENT_TYPE, {}).get("field2") == "desc2"