Skip to content

Is there a way to pass in the credentials as environment variables? #196

Open

Description

@ciso-davidpham

Hello, I am attempting to build out some custom integrations, however I am unable to find an example of authentication where it does not require a human to input anything at runtime. The custom integration that will be using this module will be running in a container on kubernetes and having a documented way to provide the creds dynamically without requiring human interaction would be very helpful.

In Keeper Commander you can do this by passing in the creds and parsing it into KeeperParams, in this "SDK" correct me if I'm wrong, I'm not seeing offhand a similar class or method to do this which I thought was the whole point of the SDK being created so that it can be implemented in fully automated solutions vs having human inputs like Keeper Commander.

Activity

  1. adeshmukh-ks commented on Jun 29, 2026

    @adeshmukh-ks
    Contributor

    Hi @ciso-davidpham
    You would need a config file to be loaded in the environment variable to be pulled in the Kubernetes container. This step is necessary to avoid the device verification step that is added as a security measure on unknown devices. The config can be populated with your login credentials and the account you are using should ideally be an account without MFA methods which require additional user interaction. The config structure can be checked in the README.md here.
    To create a usable config, first login on a local machine with the account you want to use in the cloud script. Turn on persistent-login for the account. Note: To have uninterrupted persistent-login, do not use the same account on local machine again as this would break the session. You can upload the config on cloud environment to ensure automated script executions without interaction in login flow and as an additional check, the password field can be populated in the config

  2. ciso-davidpham commented on Jun 29, 2026

    @ciso-davidpham
    Author

    Hey @adeshmukh-ks I forgot to mention with Keeper Commander I convert the config file to base64 then pass it into the as environment variable, as it is much easier to store the base64 string in Keeper Secrets Manager and use a custom pydantic settings module to pull the secret into the client is there a similar method in keepersdk? I am attaching an example snippet of the code I wrote to allow this for Keeper Commander.

    from pydantic import SecretStr
    
    class KeeperMSPClient:
        def __init__(self, base64_config: SecretStr):
            self.params = self._get_params_from_base64(
                base64_input=base64_config.get_secret_value()
            )
            self.api = self._login_sync_api()
    
        # convert base64 config to params keeper client needs
        def _get_params_from_base64(self, base64_input: str) -> KeeperParams:
            config_dict = base64_json_to_dict(encoded_str=base64_input)
            user = config_dict["user"]
            pw = config_dict["password"]
            server = config_dict["server"]
            private_key = config_dict["private_key"]
            token = config_dict["device_token"]
            self.params = KeeperParams()
            self.params.user = user
            self.params.password = pw
            self.params.server = server
            self.params.device_private_key = private_key
            self.params.device_token = token
            return self.params
    
  3. adeshmukh-ks commented on Jun 30, 2026

    @adeshmukh-ks
    Contributor

    Hi @ciso-davidpham
    We do not currently have a similar function which would directly decode the base64 for login flow.
    This is something that we have in pipeline and it will be available soon.

  4. ciso-davidpham commented on Jun 30, 2026

    @ciso-davidpham
    Author

    Hello @adeshmukh-ks, thank you, decoding the base64 would be very helpful, I'm currently using the following code to allow this in the meantime.

    import base64
    import json
    
    from keepersdk.authentication.configuration import IJsonLoader
    
    
    class Base64JsonMemoryLoader(IJsonLoader):
        def __init__(self, encoded_config: str) -> None:
            self._data = base64.b64decode(encoded_config, validate=True)
            self._validate_json(self._data)
    
        def load_json(self) -> bytes:
            return self._data
    
        def store_json(self, data: bytes) -> None:
            self._validate_json(data)
            self._data = data
    
        @staticmethod
        def _validate_json(data: bytes) -> None:
            obj = json.loads(data.decode("utf-8"))
            if not isinstance(obj, dict):
                raise ValueError("Keeper config JSON must be a JSON object")
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions