Providers¶
Infisical Client Credentials and Providers.
InfisicalCredentials
¶
Contains Infisical Credentials and methods to manage them.
Supported authentication methods:
- Token Auth: An already generated JWT token (e.g. FileKeyringBackend).
- Universal Auth
Token Auth
This method is not eligible for refresh as there is no endpoint or mechanism to refresh the token. If you need to have refreshable credentials, you should use the Universal Auth method.
An explicit url or provider-based url will always be preferred. If none is provided, it will default to
checking the INFISICAL_URL environment variable, ultimately defaulting to https://us.infisical.com if not set.
Source code in src/infisical/credentials/providers.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
__init__
¶
Initialize the class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The base URL for the Infisical API. |
required |
token
|
str
|
The JWT token for authentication. |
required |
client_id
|
str
|
The client ID for refreshing the token. |
required |
client_secret
|
str
|
The client secret for refreshing the token. |
required |
Source code in src/infisical/credentials/providers.py
get_token
¶
get_token() -> str
Get the JWT token.
Calls __check_refresh__ first before returning the token.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The JWT token. |
refresh
¶
Refresh the credentials if refreshable.
Calls the Login endpoint to refresh the credentials.
SSL Verification
By default, SSL verification is enabled. If you need to disable it, set the INFISICAL_VERIFY_SSL
environment variable to false, 0, or no. This is not recommended in production environments.
Source code in src/infisical/credentials/providers.py
__check_refresh__
¶
Check if the credentials are expired, and refreshes them if available.
The token is either explicitly set by the provider, or it is set by the refresh method called by the
provider. If the token is expired and refreshable, it will be refreshed. If it is not refreshable, it will
raise an InfisicalCredentialsError.
Raises:
| Type | Description |
|---|---|
InfisicalCredentialsError
|
If the credentials are invalid or expired and not refreshable. |
Source code in src/infisical/credentials/providers.py
BaseInfisicalProvider
¶
Bases: ABC
Abstract Class for Infisical Credential Providers.
This defines the interface for loading credentials and checking their validity.
Its attributes are initialized to empty strings, and subclasses must implement the __load__ method
to load credentials from their respective sources and overwrite the attributes accordingly.
Attributes:
| Name | Type | Description |
|---|---|---|
url |
str
|
The base URL for the Infisical API. Pulls from |
token |
str
|
The JWT token for authentication. |
client_id |
str
|
The client ID for refreshing the token. |
client_secret |
str
|
The client secret for refreshing the token. |
Source code in src/infisical/credentials/providers.py
__load__
abstractmethod
¶
Implement the provider-specific credentials loading method.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the method is not implemented in the subclass. |
Source code in src/infisical/credentials/providers.py
load
¶
load(url: str = '') -> InfisicalCredentials | None
Load the provided credentials.
This method will call the __load__ method of the provider and return the credential object if valid.
If the credentials are not valid, it will return None. If a url is provided, it will override the default
URL for the provider. Otherwise, it checks the INFISICAL_URL environment variable and uses it if set.
If the environment variable is not set, it will default to https://us.infisical.com.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The base URL for the Infisical API. Defaults to "". |
''
|
Returns:
| Type | Description |
|---|---|
InfisicalCredentials
|
If the provider finds correctly configured credentials. |
None
|
If there are no credentials found for the provider. |
Source code in src/infisical/credentials/providers.py
InfisicalConfigFileProvider
¶
Bases: BaseInfisicalProvider
Provides credentials from the Infisical configuration file.
This provider uses the FileKeyringBackend to load the credentials from the keyring
specified in the current user's config. The config is typically found in ~/.infisical/infisical-config.json.
Currently, it will only load a file keyring vault backend.
Tip
While it's not possible to refresh these credentials automatically, you can call the
infisical login command to refresh the credentials
manually. This will update your keyring with a new token.
Source code in src/infisical/credentials/providers.py
__load__
¶
Load credentials from the FileKeyringBackend.
Warning
It is not possible to override the URL for this provider. The URL is always set to the one in the configuration file, as that is the endpoint that authorized the token.
Source code in src/infisical/credentials/providers.py
load
¶
load(url: str = '') -> InfisicalCredentials | None
Load the provided credentials.
This method will call the __load__ method of the provider and return the credential object if valid.
If the credentials are not valid, it will return None. If a url is provided, it will override the default
URL for the provider. Otherwise, it checks the INFISICAL_URL environment variable and uses it if set.
If the environment variable is not set, it will default to https://us.infisical.com.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The base URL for the Infisical API. Defaults to "". |
''
|
Returns:
| Type | Description |
|---|---|
InfisicalCredentials
|
If the provider finds correctly configured credentials. |
None
|
If there are no credentials found for the provider. |
Source code in src/infisical/credentials/providers.py
InfisicalEnvironmentProvider
¶
Bases: BaseInfisicalProvider
Provides credentials from environment variables.
To use this with token authentication, set the INFISICAL_TOKEN environment variable to the token.
For Universal Auth, set the INFISICAL_CLIENT_ID and INFISICAL_CLIENT_SECRET environment variables.
Source code in src/infisical/credentials/providers.py
__load__
¶
Load credentials from environment variables.
Source code in src/infisical/credentials/providers.py
load
¶
load(url: str = '') -> InfisicalCredentials | None
Load the provided credentials.
This method will call the __load__ method of the provider and return the credential object if valid.
If the credentials are not valid, it will return None. If a url is provided, it will override the default
URL for the provider. Otherwise, it checks the INFISICAL_URL environment variable and uses it if set.
If the environment variable is not set, it will default to https://us.infisical.com.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The base URL for the Infisical API. Defaults to "". |
''
|
Returns:
| Type | Description |
|---|---|
InfisicalCredentials
|
If the provider finds correctly configured credentials. |
None
|
If there are no credentials found for the provider. |
Source code in src/infisical/credentials/providers.py
InfisicalExplicitProvider
¶
Bases: BaseInfisicalProvider
Provides explicitly passed credentials.
These are configured by passsing the token keyword argument or both the client_id and client_secret
keyword arguments to the constructor of either the InfisicalClient or the
InfisicalAsyncClient.
Source code in src/infisical/credentials/providers.py
__init__
¶
Initialize the provider with explicit credentials.
Note
The credential keyword arguments are not required, as there are other providers in the chain, and falsy
values are ignored. If values are provided, they will be validated in the __load__ method.
Source code in src/infisical/credentials/providers.py
__load__
¶
Load credentials from explicitly provided values, if the values are truthy.
This method just ensures the values are set correctly and raises an error if they are not. Properly configured credentials means that either a token is set or both the client ID and secret are set.
Raises:
| Type | Description |
|---|---|
InfisicalCredentialsError
|
If the credentials are not set correctly. |
Source code in src/infisical/credentials/providers.py
load
¶
load(url: str = '') -> InfisicalCredentials | None
Load the provided credentials.
This method will call the __load__ method of the provider and return the credential object if valid.
If the credentials are not valid, it will return None. If a url is provided, it will override the default
URL for the provider. Otherwise, it checks the INFISICAL_URL environment variable and uses it if set.
If the environment variable is not set, it will default to https://us.infisical.com.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The base URL for the Infisical API. Defaults to "". |
''
|
Returns:
| Type | Description |
|---|---|
InfisicalCredentials
|
If the provider finds correctly configured credentials. |
None
|
If there are no credentials found for the provider. |
Source code in src/infisical/credentials/providers.py
InfisicalCredentialProviderChain
¶
Credential provider chain for Infisical HTTPX SDK Clients.
Tries to load credentials in the following order:
- Explicitly provided credentials
- Environment variables
- Configuration file.
If no credentials are found in the first provider, it will try the next one in the chain. If no credentials are found in any provider, it will raise an InfisicalCredentialsError. Depending on the provider, misconfigured credentials may also raise an error.
Note
The order of the providers is important. The explicit provider should always be first, as it is the most
obvious way to get credentials, and the user can implement numerous mechanisms to securely pass
credentials. The environment provider should be second, as it is the most typical and fairly secure way to
get credentials even in CI/CD environments. The config file provider should be last, as it is $USER-specific
and not always available. Especially considering that we are unable to refresh the credentials from the config
file provider.
Attributes:
| Name | Type | Description |
|---|---|---|
providers |
list[BaseInfisicalProvider]
|
The list of providers in the chain. |
url |
str
|
The base URL for the Infisical API passed in via `init. |
Source code in src/infisical/credentials/providers.py
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 | |
__init__
¶
Initialize the credential provider chain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The base URL for the Infisical API. |
''
|
token
|
str
|
The JWT token for authentication. |
''
|
client_id
|
str
|
The client ID for refreshing the token. |
''
|
client_secret
|
str
|
The client secret for refreshing the token. |
''
|
Tip
The url kwyword argument can be passed to the constructor of either the
InfisicalClient or the
InfisicalAsyncClient which is passed into this constructor. If a truthy
value is passed, it will override the default URL for every provider in the chain, except the
InfisicalConfigFileProvider.
Source code in src/infisical/credentials/providers.py
add_provider
¶
add_provider(provider: BaseInfisicalProvider, index: int = 0) -> None
Add a provider to the chain.
This method allows you to add custom provider to the chain at a specific index. The default index is 0,
which means the provider will be added to the beginning of the chain. This is also useful if you want to
override the default order of the providers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider
|
BaseInfisicalProvider
|
The provider to add. |
required |
index
|
int
|
The index at which to insert the provider in the chain. Defaults to 0. |
0
|
Custom Provider Example
from infisical.credentials.providers import (
BaseInfisicalProvider,
InfisicalCredentialProviderChain,
)
class CustomProvider(BaseInfisicalProvider):
def __load__(self) -> None:
...
# Custom logic to load a `token` or `client_id` and `client_secret`
provider_chain = InfisicalCredentialProviderChain()
provider_chain.add_provider(CustomProvider()) # add provider to the beginning of the chain
with InfisicalClient(provider_chain=provider_chain) as client:
...
# Use the client with the custom provider
Source code in src/infisical/credentials/providers.py
resolve
¶
resolve() -> InfisicalCredentials
Resolve credentials using the provider chain.
This method will iterate through the providers in the chain and call their load
method. If a provider returns a InfisicalCredentials, it will return it (which is then set in the
client). If no provider returns a valid credential, it will raise an
InfisicalCredentialsError.
Raises:
| Type | Description |
|---|---|
InfisicalCredentialsError
|
If no valid credentials are found in the provider chain. |