diff --git a/src/groundlight/client.py b/src/groundlight/client.py index 35eca62b..832632a4 100644 --- a/src/groundlight/client.py +++ b/src/groundlight/client.py @@ -166,6 +166,11 @@ def _verify_connectivity(self) -> None: try: # a simple query to confirm that the endpoint & API token are working self.whoami() + if self._user_is_privileged(): + logger.warning( + "WARNING: The current user has elevated permissions. Please verify such permissions are necessary" + " for your current operation" + ) except UnauthorizedException as e: msg = ( f"Invalid API token '{self.api_token_prefix}...' connecting to endpoint " @@ -201,6 +206,14 @@ def whoami(self) -> str: obj = self.user_api.who_am_i() return obj["username"] + def _user_is_privileged(self) -> bool: + """ + Return a boolean indicating whether the user is privileged. + Privleged users have elevated permissions, so care should be taken when using a privileged account. + """ + obj = self.user_api.who_am_i() + return obj["is_superuser"] or obj["is_staff"] + def get_detector(self, id: Union[str, Detector]) -> Detector: # pylint: disable=redefined-builtin """ Get a detector by id diff --git a/test/unit/conftest.py b/test/unit/conftest.py index 49550bde..472d0c85 100644 --- a/test/unit/conftest.py +++ b/test/unit/conftest.py @@ -5,6 +5,15 @@ from model import Detector, ImageQuery +def pytest_configure(config): + # Run environment check before tests + gl = Groundlight() + if gl._user_is_privileged(): + raise Exception( + "ERROR: You are running tests with a privileged user. Please run tests with a non-privileged user." + ) + + @pytest.fixture(name="gl") def fixture_gl() -> Groundlight: """Creates a Groundlight client object for testing."""