Skip to content

Add Infisical KMS provider#88

Open
victorvhs017 wants to merge 3 commits into
libopenstorage:masterfrom
victorvhs017:infisical-kms-integration
Open

Add Infisical KMS provider#88
victorvhs017 wants to merge 3 commits into
libopenstorage:masterfrom
victorvhs017:infisical-kms-integration

Conversation

@victorvhs017
Copy link
Copy Markdown

@victorvhs017 victorvhs017 commented Apr 13, 2026

Summary

  • Add infisical-kms secrets backend that delegates encryption/decryption to Infisical KMS
  • Follows the same pattern as existing KMS integrations (gcloud, ibm, aws)
  • Uses Universal Auth (client-id + client-secret) with automatic token refresh
  • Ciphertext persisted via KVDB-backed PersistenceStore
  • Uses Infisical API directly instead of the Infisical Go SDK to avoid adding new dependencies

Victor Hugo dos Santos added 2 commits April 13, 2026 19:08
…nfisical_kms_integration_test.go`, and `infisical_kms_test.go` files.

- Add support for Infisical in the secrets management system, including methods for putting, getting, and deleting secrets.
- Implement integration tests for full lifecycle operations with Infisical KMS.
…dependency changes, implement `infisical/client.go` for KMS client functionality, and modify tests in `infisical_kms_test.go` to align with new client structure.
@varonix0
Copy link
Copy Markdown

Hi @Adityadan, can we please get a review on this PR? It should be good to go with no new dependencies!

Copy link
Copy Markdown
Collaborator

@adityadani adityadani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general this library provides three modes:

  1. Integration with KMS providers that generate a "DEK" which then can be used for encrypting data/credentials etc. -> Vaulttransit, AWS KMS etc
  2. Integration with KMS providers that actually store the secrets used for encryption with them -> Vault, Azure KV etc
  3. Google Cloud is another mode and a special case which is similar to what you have implemented which is to encrypt the provided data and store it in the persistence store. But it then supports two KeyContexts: PublicData and CustomData.

Which model suits Infisical better? And if it is 3. can we honor PublicData and CustomData behavior similar to what has been done in Google Cloud so that the clients of this library do not see any changes?

Comment thread infisical/client.go
base += "/api"
}
return &kmsClient{
httpClient: &http.Client{Timeout: 30 * time.Second},
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Infisical support TLSConfig? Or can we enforce an "https" URL check to ensure that clientSecret is not passed as plaintext over the wire

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll update the code to add HTTPS enforcement.

Comment thread infisical/client.go

c.mu.Lock()
c.token = result.AccessToken
c.expiresAt = time.Now().Add(time.Duration(result.ExpiresIn)*time.Second - tokenExpiryBuffer)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We wont renew the token if it is revoked before this expiry time. Can we check for 401 Unauthorized errors in doKmsRequest and renew the token?

Copy link
Copy Markdown
Author

@victorvhs017 victorvhs017 May 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we get a 401 or 403 error (also used for expired tokens in Infisical API), we'll log in again and retry once.

Comment thread infisical/infisical_kms.go Outdated

logrus.WithFields(logrus.Fields{
"site": siteURL,
"kmsKeyID": kmsKeyID,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is a KMS Key ID and is it ok to log it? Is it some sort of a Master Key ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This KMS Key ID is not a master key, it's the ID handle that identifies the key on the Infisical KMS server.

I'm dropping this to keep the same pattern used in other providers.

Comment thread infisical/infisical_kms.go Outdated
Comment on lines +150 to +153
ciphertext, err := k.client.encrypt(string(jsonBytes))
if err != nil {
return secrets.NoVersion, fmt.Errorf("infisical-kms: encryption failed: %w", err)
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you envision the use of Infisical with this library? The callers of this library in certain cases also expect a KMS provider to store "secret data". I see that Infisical supports that, so in such a case you wont encrypt and return back the ciphertext but instead simply store this "secret data" in the KMS provider.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Infisical indeed also has a secrets management product. However, for the purposes of Portworx, we are currently only looking to integrate our KMS product. If there's demand for integrating secrets management, we can absolutely look into that in the future.

…ty in `client_test.go`, covering authentication retries, error handling, and secure URL validation.
@victorvhs017
Copy link
Copy Markdown
Author

In general this library provides three modes:

  1. Integration with KMS providers that generate a "DEK" which then can be used for encrypting data/credentials etc. -> Vaulttransit, AWS KMS etc
  2. Integration with KMS providers that actually store the secrets used for encryption with them -> Vault, Azure KV etc
  3. Google Cloud is another mode and a special case which is similar to what you have implemented which is to encrypt the provided data and store it in the persistence store. But it then supports two KeyContexts: PublicData and CustomData.

Which model suits Infisical better? And if it is 3. can we honor PublicData and CustomData behavior similar to what has been done in Google Cloud so that the clients of this library do not see any changes?

Hey @adityadani, thank you for the review!

The model that suits Infisical is indeed the model 3. I updated the PR to handle PublicData and CustomData behavior as it's done in the Google Cloud provider.

I also addressed all the other comments on the PR.

@victorvhs017 victorvhs017 requested a review from adityadani May 14, 2026 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants