How to use Infisical to inject secrets into Kubernetes clusters.
The Infisical Secrets Operator is a Kubernetes controller that retrieves secrets from Infisical and stores them in a designated cluster.
It uses an InfisicalSecret
resource to specify authentication and storage methods.
The operator continuously updates secrets and can also reload dependent deployments automatically.
The operator can be install via Helm or kubectl
Install the latest Infisical Helm repository
Install the Helm chart
To select a specific version, view the application versions here and chart versions here
Install the latest Infisical Helm repository
Install the Helm chart
To select a specific version, view the application versions here and chart versions here
For production deployments, it is highly recommended to set the version of the Kubernetes operator manually instead of pointing to the latest version. Doing so will help you avoid accidental updates to the newest release which may introduce unintended breaking changes. View all application versions here.
The command below will install the most recent version of the Kubernetes operator.
However, to set the version manually, download the manifest and set the image tag version of infisical/kubernetes-operator
according to your desired version.
Once you apply the manifest, the operator will be installed in infisical-operator-system
namespace.
Once you have installed the operator to your cluster, you’ll need to create a InfisicalSecret
custom resource definition (CRD).
hostAPI
If you are fetching secrets from a self hosted instance of Infisical set the value of hostAPI
to
https://your-self-hosted-instace.com/api
When hostAPI
is not defined the operator fetches secrets from Infisical Cloud.
Advanced use case
If you have installed your Infisical instance within the same cluster as the Infisical operator, you can optionally access the Infisical backend’s service directly without having to route through the public internet. To achieve this, use the following address for the hostAPI field:
Make sure to replace <backend-svc-name>
and <namespace>
with the appropriate values for your backend service and namespace.
resyncInterval
This property defines the time in seconds between each secret re-sync from Infisical. Shorter time between re-syncs will require higher rate limits only available on paid plans. Default re-sync interval is every 1 minute.
authentication
This block defines the method that will be used to authenticate with Infisical so that secrets can be fetched
authentication.universalAuth
The universal machine identity authentication method is used to authenticate with Infisical. The client ID and client secret needs to be stored in a Kubernetes secret. This block defines the reference to the name and namespace of secret that stores these credentials.
Create a machine identity
You need to create a machine identity, and give it access to the project(s) you want to interact with. You can read more about machine identities here.
Create Kubernetes secret containing machine identity credentials
Once you have created your machine identity and added it to your project(s), you will need to create a Kubernetes secret containing the identity credentials. To quickly create a Kubernetes secret containing the identity credentials, you can run the command below.
Make sure you replace <your-identity-client-id>
with the identity client ID and <your-identity-client-secret>
with the identity client secret.
Add reference for the Kubernetes secret containing the identity credentials
Once the secret is created, add the secretName
and secretNamespace
of the secret that was just created under authentication.universalAuth.credentialsRef
field in the InfisicalSecret resource.
Make sure to also populate the secretsScope
field with the project slug
projectSlug
, environment slug envSlug
, and secrets path
secretsPath
that you want to fetch secrets from. Please see the example
below.
authentication.kubernetesAuth
The Kubernetes machine identity authentication method is used to authenticate with Infisical. The identity ID is stored in a field in the InfisicalSecret resource. This authentication method can only be used within a Kubernetes environment.
Obtaining the token reviewer JWT for Infisical
1.1. Start by creating a service account in your Kubernetes cluster that will be used by Infisical to authenticate with the Kubernetes API Server.
1.2. Bind the service account to the system:auth-delegator
cluster role. As described here, this role allows delegated authentication and authorization checks, specifically for Infisical to access the TokenReview API. You can apply the following configuration file:
1.3. Next, create a long-lived service account JWT token (i.e. the token reviewer JWT token) for the service account using this configuration file for a new Secret
resource:
1.4. Link the secret in step 1.3 to the service account in step 1.1:
1.5. Finally, retrieve the token reviewer JWT token from the secret.
Keep this JWT token handy as you will need it for the Token Reviewer JWT field when configuring the Kubernetes Auth authentication method for the identity in step 2.
Creating an identity
To create an identity, head to your Organization Settings > Access Control > Machine Identities and press Create identity.
When creating an identity, you specify an organization level role for it to assume; you can configure roles in Organization Settings > Access Control > Organization Roles.
Now input a few details for your new identity. Here’s some guidance for each field:
Once you’ve created an identity, you’ll be prompted to configure the authentication method for it. Here, select Kubernetes Auth.
To learn more about each field of the Kubernetes native authentication method, see step 2 of guide.
Adding an identity to a project
To allow the operator to use the given identity to access secrets, you will need to add the identity to project(s) that you would like to grant it access to.
To do this, head over to the project you want to add the identity to and go to Project Settings > Access Control > Machine Identities and press Add identity.
Next, select the identity you want to add to the project and the project level role you want to allow it to assume. The project role assigned will determine what project level resources this identity can have access to.
Add your identity ID & service account to your InfisicalSecret resource
Once you have created your machine identity and added it to your project(s), you will need to add the identity ID to your InfisicalSecret resource.
In the authentication.kubernetesAuth.identityId
field, add the identity ID of the machine identity you created.
See the example below for more details.
Add your Kubernetes service account token to the InfisicalSecret resource
Add the service account details from the previous steps under authentication.kubernetesAuth.serviceAccountRef
.
Here you will need to enter the name and namespace of the service account.
The example below shows a complete InfisicalSecret resource with all required fields defined.
Make sure to also populate the secretsScope
field with the project slug
projectSlug
, environment slug envSlug
, and secrets path
secretsPath
that you want to fetch secrets from. Please see the example
below.
authentication.awsIamAuth
The AWS IAM machine identity authentication method is used to authenticate with Infisical. The identity ID is stored in a field in the InfisicalSecret resource. This authentication method can only be used within an AWS environment like an EC2 or a Lambda function.
Create a machine identity
You need to create a machine identity, and give it access to the project(s) you want to interact with. You can read more about AWS machine identities here.
Add your identity ID to your InfisicalSecret resource
Once you have created your machine identity and added it to your project(s), you will need to add the identity ID to your InfisicalSecret resource. In the authentication.awsIamAuth.identityId
field, add the identity ID of the machine identity you created. See the example below for more details.
Make sure to also populate the secretsScope
field with the project slug
projectSlug
, environment slug envSlug
, and secrets path
secretsPath
that you want to fetch secrets from. Please see the example
below.
authentication.azureAuth
The Azure machine identity authentication method is used to authenticate with Infisical. The identity ID is stored in a field in the InfisicalSecret resource. This authentication method can only be used within an Azure environment.
Create a machine identity
You need to create a machine identity, and give it access to the project(s) you want to interact with. You can read more about Azure machine identities here.
Add your identity ID to your InfisicalSecret resource
Once you have created your machine identity and added it to your project(s), you will need to add the identity ID to your InfisicalSecret resource. In the authentication.azureAuth.identityId
field, add the identity ID of the machine identity you created. See the example below for more details.
Make sure to also populate the secretsScope
field with the project slug
projectSlug
, environment slug envSlug
, and secrets path
secretsPath
that you want to fetch secrets from. Please see the example
below.
authentication.gcpIdTokenAuth
The GCP ID Token machine identity authentication method is used to authenticate with Infisical. The identity ID is stored in a field in the InfisicalSecret resource. This authentication method can only be used within GCP environments.
Create a machine identity
You need to create a machine identity, and give it access to the project(s) you want to interact with. You can read more about GCP machine identities here.
Add your identity ID to your InfisicalSecret resource
Once you have created your machine identity and added it to your project(s), you will need to add the identity ID to your InfisicalSecret resource. In the authentication.gcpIdTokenAuth.identityId
field, add the identity ID of the machine identity you created. See the example below for more details.
Make sure to also populate the secretsScope
field with the project slug
projectSlug
, environment slug envSlug
, and secrets path
secretsPath
that you want to fetch secrets from. Please see the example
below.
authentication.gcpIamAuth
The GCP IAM machine identity authentication method is used to authenticate with Infisical. The identity ID is stored in a field in the InfisicalSecret resource. This authentication method can only be used both within and outside GCP environments.
Create a machine identity
You need to create a machine identity, and give it access to the project(s) you want to interact with. You can read more about GCP machine identities here.
Add your identity ID and service account token path to your InfisicalSecret resource
Once you have created your machine identity and added it to your project(s), you will need to add the identity ID to your InfisicalSecret resource. In the authentication.gcpIamAuth.identityId
field, add the identity ID of the machine identity you created.
You’ll also need to add the service account key file path to your InfisicalSecret resource. In the authentication.gcpIamAuth.serviceAccountKeyFilePath
field, add the path to your service account key file path. Please see the example below for more details.
Make sure to also populate the secretsScope
field with the project slug
projectSlug
, environment slug envSlug
, and secrets path
secretsPath
that you want to fetch secrets from. Please see the example
below.
authentication.serviceToken
Service tokens are being deprecated in favor of machine identities.
They will be removed in the future in accordance with the deprecation notice and timeline stated here.
The service token required to authenticate with Infisical needs to be stored in a Kubernetes secret. This block defines the reference to the name and namespace of secret that stores this service token. Follow the instructions below to create and store the service token in a Kubernetes secrets and reference it in your CRD.
You can generate a service token for an Infisical project by heading over to the Infisical dashboard then to Project Settings.
Once you have generated the service token, you will need to create a Kubernetes secret containing the service token you generated.
To quickly create a Kubernetes secret containing the generated service token, you can run the command below. Make sure you replace <your-service-token-here>
with your service token.
Once the secret is created, add the name and namespace of the secret that was just created under authentication.serviceToken.serviceTokenSecretReference
field in the InfisicalSecret resource.
Make sure to also populate the secretsScope
field with the, environment slug
envSlug
, and secrets path secretsPath
that you want to fetch secrets
from. Please see the example below.
managedSecretReference
The managedSecretReference
field is used to define the target location for storing secrets retrieved from an Infisical project.
This field requires specifying both the name and namespace of the Kubernetes secret that will hold these secrets.
The Infisical operator will automatically create the Kubernetes secret with the specified name/namespace and keep it continuously updated.
Note: The managed secret be should be created in the same namespace as the deployment that will use it.
managedSecretReference.secretName
The name of the managed Kubernetes secret to be created
managedSecretReference.secretNamespace
The namespace of the managed Kubernetes secret to be created.
managedSecretReference.secretType
Override the default Opaque type for managed secrets with this field. Useful for creating kubernetes.io/dockerconfigjson secrets.
managedSecretReference.creationPolicy
Creation polices allow you to control whether or not owner references should be added to the managed Kubernetes secret that is generated by the Infisical operator. This is useful for tools such as ArgoCD, where every resource requires an owner reference; otherwise, it will be pruned automatically.
Orphan
(default)Owner
When creation policy is set to Owner
, the InfisicalSecret
CRD must be in
the same namespace as where the managed kubernetes secret.
The operator will transfer all labels & annotations present on the InfisicalSecret
CRD to the managed Kubernetes secret to be created.
Thus, if a specific label is required on the resulting secret, it can be applied as demonstrated in the following example:
Example propagation
This would result in the following managed secret to be created:
Once you have configured the Infisical CRD with the required fields, you can apply it to your cluster. After applying, you should notice that the managed secret has been created in the desired namespace your specified.
To verify that the operator has successfully created the managed secret, you can check the secrets in the namespace that was specified.
The Infisical secrets will be synced and stored into the managed secret every 1 minutes.
Incorporating the managed secret created by the operator into your deployment can be achieved through several methods. Here, we will highlight three of the most common ways to utilize it. Learn more about Kubernetes secrets here
envFrom
This will take all the secrets from your managed secret and expose them to your container
env
This will allow you to select individual secrets by key name from your managed secret and expose them to your container
Example usage in a deployment
volumes
This will allow you to create a volume on your container which comprises of files holding the secrets in your managed kubernetes secret
You can then mount this volume to the container’s filesystem so that your deployment can access the files containing the managed secrets
Example usage in a deployment
Deployments using managed secrets don’t reload automatically on updates, so they may use outdated secrets unless manually redeployed. To address this, we added functionality to automatically redeploy your deployment when its managed secret updates.
To enable auto redeployment you simply have to add the following annotation to the deployment that consumes a managed secret
Deployment example with auto redeploy enabled
When a secret change occurs, the operator will check to see which deployments are using the operator-managed Kubernetes secret that received the update. Then, for each deployment that has this annotation present, a rolling update will be triggered.
To configure global settings that will apply to all instances of InfisicalSecret
, you can define these configurations in a Kubernetes ConfigMap.
For example, you can configure all InfisicalSecret
instances to fetch secrets from a single backend API without specifying the hostAPI
parameter for each instance.
Property | Description | Default value |
---|---|---|
hostAPI | If hostAPI in InfisicalSecret instance is left empty, this value will be used | https://app.infisical.com/api |
All global configurations must reside in a Kubernetes ConfigMap named infisical-config
in the namespace infisical-operator-system
.
To apply global configuration to the operator, copy the following yaml into infisical-config.yaml
file.
Then apply this change via kubectl by running the following
If the operator is unable to fetch secrets from the API, it will not affect the managed Kubernetes secret.
It will continue attempting to reconnect to the API indefinitely.
The InfisicalSecret resource uses the status.conditions
field to report its current state and any errors encountered.
The managed secret created by the operator will not be deleted when the operator is uninstalled.
Install Infisical Helm repository
Install Infisical Helm repository