Skip to content

Conversation

fslds
Copy link
Contributor

@fslds fslds commented Dec 16, 2021

Pull request checklist

Please check if your PR fulfills the following requirements:

  • Docs have been reviewed and added / updated if needed (for bug fixes / features)
  • Tests have been added that prove the fix is effective or that the feature works.
  • New and existing tests pass locally with the changes.
  • Code follows the style guidelines of this project (PEP8, clean code).
  • Linter has passed locally and any fixes were made for failures.
  • A self-review of the code has been done.

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes (not tied to bugs/features)
  • Other (please describe):

What is the ticket or issue number?

Issue #303

  • Ticket Number: N/A

  • Issue Number: N/A

Pull Request Description

Users without Admin tokens are unable to connect to Carbon Black EDR with the CbResponseAPI client, starting from version 7.6. This fixes issue #303, as reported by @sevdog.

Upon initialization of the client, the users are presented a ClientError with an underlaying 403 HTTP response code.

Looking into the code, this is caused by a 403 on the _has_legacy_partitions check in the CbResponseAPI.__init__() function.
As we do not have access to this API Endpoint since 7.6, intentionally or not, we should not care about them, and thus the 403 can be ignored.

I chose to wrap the check with a try/except block, ignoring a ClientError exception with a error code 403, so that the average Carbon Black user can continue whatever they need to do, without breaking functionality for the administrative user or whichever user that has rights to work with the partitions.

Does this introduce a breaking change?

  • Yes
  • No

How Has This Been Tested?

Manually, locally by connecting to Carbon Black Instances before and after the change and performing normal and automated tasks of the past.

Other information:

src/cbapi/response/rest_api.py

        self._has_legacy_partitions = False
        try:
            if self.cb_server_version >= LooseVersion('6.0'):
                legacy_partitions = [p for p in self.select(StoragePartition) if p.info.get("isLegacy", False)]
                if legacy_partitions:
                    self._has_legacy_partitions = True
        except ClientError as ce:
            # If we get a 403 on this endpoint, ignore during init,
            # as we will not be able to work with StoragePartitions regardless
            # https://github.com/carbonblack/cbapi-python/issues/303
            if ce.error_code == 403:
                pass
            else:
                raise ce  # no intervention

@kebringer-cb kebringer-cb changed the base branch from master to develop December 17, 2021 16:47
@kebringer-cb kebringer-cb self-requested a review December 17, 2021 16:48
Copy link
Contributor

@kebringer-cb kebringer-cb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed with EDR team and agree to accept the change. Thank you!

@kebringer-cb kebringer-cb merged commit 18dcce5 into carbonblack:develop Dec 17, 2021
@fslds
Copy link
Contributor Author

fslds commented Dec 17, 2021

You're welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants