Basic Usage
API_KEY from the dev environment of the YOUR_PROJECT_ID project.
Installation
Configuration
Import the SDK and create a client instance.Configuration Options
Automatic token refreshing
The Infisical Go SDK supports automatic token refreshing, enabled by default. After using one of the auth methods such as Universal Auth, the SDK will automatically renew and re-authenticate when needed. You can opt-out by settingAutoTokenRefresh to false in the client settings.
Client Lifecycle
When using automatic token refreshing it’s important to understand how your application uses the Infisical client. If you are instantiating new instances of the client often, it’s important to cancel the context when the client is no longer needed to avoid the token refreshing process from running indefinitely.Authentication
Authentication Methods
The SDK supports a variety of authentication methods. The most common authentication method is Universal Auth, which uses a client ID and client secret to authenticate.Universal Auth
Universal Auth
Using environment variablesCall
.Auth().UniversalAuthLogin() with empty arguments to use the following environment variables:INFISICAL_UNIVERSAL_AUTH_CLIENT_ID- Your machine identity client ID.INFISICAL_UNIVERSAL_AUTH_CLIENT_SECRET- Your machine identity client secret.
GCP ID Token
GCP ID Token
Please note that this authentication method will only work if you’re running
your application on Google Cloud Platform. Please read
more about this authentication
method.
.Auth().GcpIdTokenAuthLogin() with empty arguments to use the following environment variables:INFISICAL_GCP_AUTH_IDENTITY_ID- Your Infisical Machine Identity ID.
GCP IAM Auth
GCP IAM Auth
Using environment variablesCall
.Auth().GcpIamAuthLogin() with empty arguments to use the following environment variables:INFISICAL_GCP_IAM_AUTH_IDENTITY_ID- Your Infisical Machine Identity ID.INFISICAL_GCP_IAM_SERVICE_ACCOUNT_KEY_FILE_PATH- The path to your GCP service account key file.
AWS IAM Auth
AWS IAM Auth
Please note that this authentication method will only work if you’re running
your application on AWS. Please read
more about this authentication
method.
.Auth().AwsIamAuthLogin() with empty arguments to use the following environment variables:INFISICAL_AWS_IAM_AUTH_IDENTITY_ID- Your Infisical Machine Identity ID.
Azure Auth
Azure Auth
Please note that this authentication method will only work if you’re running
your application on Azure. Please read
more about this authentication
method.
.Auth().AzureAuthLogin() with empty arguments to use the following environment variables:INFISICAL_AZURE_AUTH_IDENTITY_ID- Your Infisical Machine Identity ID.
Kubernetes Auth
Kubernetes Auth
Please note that this authentication method will only work if you’re running
your application on Kubernetes. Please read
more about this
authentication method.
.Auth().KubernetesAuthLogin() with empty arguments to use the following environment variables:INFISICAL_KUBERNETES_IDENTITY_ID- Your Infisical Machine Identity ID.INFISICAL_KUBERNETES_SERVICE_ACCOUNT_TOKEN_PATH_ENV_NAME- The environment variable name that contains the path to the service account token. This is optional and will default to/var/run/secrets/kubernetes.io/serviceaccount/token.
JWT Auth
JWT Auth
Please note that this authentication method requires a valid JWT token from
your JWT issuer. Please read
more about this authentication
method.
LDAP Auth
LDAP Auth
Please note that this authentication method requires LDAP credentials. Please
read more about this
authentication method.
INFISICAL_LDAP_AUTH_IDENTITY_ID environment variable and pass empty string for the identity ID:OCI Auth
OCI Auth
Please note that this authentication method will only work if you’re running
your application on Oracle Cloud Infrastructure. Please read
more about this authentication
method.
INFISICAL_OCI_AUTH_IDENTITY_ID environment variable and omit the IdentityID field:IdentityID(string) - Your Infisical Machine Identity ID. Can be set viaINFISICAL_OCI_AUTH_IDENTITY_IDenvironment variable.UserID(string) - Your OCI user OCID.TenancyID(string) - Your OCI tenancy OCID.Fingerprint(string) - Your OCI API key fingerprint.PrivateKey(string) - Your OCI private key (PEM format).Region(string) - Your OCI region (e.g.,us-ashburn-1).Passphrase(*string) - Optional: pointer to passphrase string if your private key is encrypted.
Sub-Organization Authentication
This section is only relevant to you if your organization is utilizing sub-organizations within Infisical.
.Auth().WithOrganizationSlug("<organization-slug>") method to specify which organization to authenticate against:
Secrets
List Secrets
client.Secrets().List(options)
Retrieve all secrets within the Infisical project and environment that client is connected to.
Parameters
Retrieve Secret
client.Secrets().Retrieve(options)
Retrieve a secret from Infisical. By default Secrets().Retrieve() fetches and returns a shared secret.
Parameters
Create Secret
client.Secrets().Create(options)
Create a new secret in Infisical.
Parameters
Update Secret
client.Secrets().Update(options)
Update an existing secret in Infisical.
Parameters
Delete Secret
client.Secrets().Delete(options)
Delete a secret in Infisical.
Parameters
Batch Create Secrets
client.Secrets().Batch().Create(options)
Create multiple secrets in Infisical.
Parameters
Folders
List Folders
client.Folders().List(options)
Retrieve all within the Infisical project and environment that client is connected to.
Parameters
Create Folder
client.Folders().Create(options)
Create a new folder in Infisical.
Parameters
Update Folder
client.Folders().Update(options)
Update an existing folder in Infisical.
Parameters
Delete Folder
client.Folders().Delete(options)
Delete a folder in Infisical.
Parameters
Dynamic Secrets
Dynamic secrets generate credentials on-demand instead of storing static values. Credentials are issued through short-lived leases that Infisical automatically revokes when they expire.The Go SDK reads dynamic secret configurations and manages their leases.
Creating or updating a dynamic secret’s configuration is done through the
Infisical dashboard or the
API.
List Dynamic Secrets
client.DynamicSecrets().List(options)
Retrieve all dynamic secrets within a project environment and path.
Parameters
Get Dynamic Secret by Name
client.DynamicSecrets().GetByName(options)
Retrieve a single dynamic secret configuration by name.
Parameters
Dynamic Secret Leases
A lease represents a single set of generated credentials with its own TTL. Use leases to generate, inspect, renew, and revoke credentials from a dynamic secret. Access the leases interface withclient.DynamicSecrets().Leases().
Create Lease
client.DynamicSecrets().Leases().Create(options)
Generate a new set of credentials from a dynamic secret.
Your generated credentials are returned in the first return value
(
credentials, a map[string]any). The exact keys depend on the dynamic
secret provider.Parameters
Return
The generated credentials, the dynamic secret the lease was created from, the
lease details, and an error if the request failed.
List Leases
client.DynamicSecrets().Leases().List(options)
Retrieve all leases for a dynamic secret.
Parameters
Get Lease by ID
client.DynamicSecrets().Leases().GetById(options)
Retrieve a single lease, including its associated dynamic secret.
Parameters
Return (map)
The lease, with the associated dynamic secret nested in its
DynamicSecret
field, and an error if the request failed.Renew Lease
client.DynamicSecrets().Leases().RenewById(options)
Extend the TTL of an existing lease.
Renewals must happen before the lease expires. Renewing does not issue new
credentials; it extends the expiration of the existing credentials.
Parameters
Delete Lease
client.DynamicSecrets().Leases().DeleteById(options)
Revoke a lease and its associated credentials.
Parameters
KMS
Create Key
client.Kms().Keys().Create(options)
Create a new key in Infisical.
Parameters
Return (object)
Delete Key
client.Kms().Keys().Delete(options)
Delete a key in Infisical.
Parameters
Return
Signing Data
client.Kms().Signing().Sign(options)
Sign data in Infisical.
Parameters
Return ([]byte)
The signature of the data that was signed.
Verifying Data
client.Kms().Signing().Verify(options)
Verify data in Infisical.
Parameters
Return (object)
List Signing Algorithms
client.Kms().Signing().ListSigningAlgorithms(options)
List signing algorithms in Infisical.
Parameters
Return ([]string)
The signing algorithms that are available for the key.
Get Public Key
This method is only available for keys with key usage
sign-verify. If you
attempt to use this method on a key that is intended for
encryption/decryption, it will return an error.client.Kms().Signing().GetPublicKey(options)
Get the public key in Infisical.
Parameters
Return (string)
The public key for the key.
Encrypt Data
client.Kms().Encryption().Encrypt(options)
Encrypt data with a key in Infisical KMS.
Parameters
Return (string)
The encrypted data.
Decrypt Data
client.Kms().DecryptData(options)
Decrypt data with a key in Infisical KMS.
Parameters
Return (string)
The decrypted data.