Skip to content

infisical: support secrets within paths for data references#4305

Merged
Skarlso merged 2 commits intoexternal-secrets:mainfrom
lgo:joey-infisical-folder-handling
May 13, 2025
Merged

infisical: support secrets within paths for data references#4305
Skarlso merged 2 commits intoexternal-secrets:mainfrom
lgo:joey-infisical-folder-handling

Conversation

@lgo
Copy link
Copy Markdown
Contributor

@lgo lgo commented Jan 19, 2025

(cc @akhilmhdh)

Problem Statement

When attempting to access a secret in a directory, provided secretsPath: /, like so:

apiVersion: external-secrets.io/v1beta1
kind: ExternalSecret
metadata:
  name: infisical-managed-secrets
spec:
  secretStoreRef:
    kind: SecretStore
    name: infisical
  target:
    name: auth-api
  data:
    - secretKey: API_KEY
      remoteRef:
        key: "foo/bar"

This will always result in a 404 API error from Infisical, because the API request is malformed (/api/v3/secrets/raw/foo/bar). The correct API request would instead be /api/v3/secrets/raw/bar?secretPath=/foo. This either:

  • Made it so you simply cannot use secrets in folders with direct references via data
  • Made it so you have to use a separate secret provider with a distinct path, which isn't very usable or very obvious

In combination with #4059, this would result in empty secrets but after that issue is fixed these would fail to sync with an error.

Overall this was also quite confusing with the SecretStore's secretsPath property - would a remoteRef be an additive path? Would it supercede the SecretStore?

Related Issue

Fixes #4298

Proposed Changes

As suggested on the issue (#4298 (comment)) this makes a particular changes:

  • remoteRef's with paths take precedence over any secretsPath on the SecretStore
  • If a remoteRef is detected to be a path (i.e. it contains /), an error is raised if it does not start with / with an actionable error indicating to use / and that it is an absolute reference. This should hopefuly further clarify the interaction between this, and secretsPath
  • Documentation is updated with more specific examples of data in Infisical and how you would retrieve it, now that these features work

I've tested this against a self-hosted Infisical instance. I used a branch rebased off of #4304 to test this (lgo:joey-infisical-folder-handling-testing)

  • With a remoteRef: {key: "foo/bar"}
  • ExternalSecret expectedly fails with a secret key referencing a folder must start with a '/' as it is an absolute path, key: foo/bar
  • With a remoteKey: {key: "/foo/bar"}
  • ✅ the secret successfully syncs.

TODO:

Checklist

  • I have read the contribution guidelines
  • All commits are signed with git commit --signoff
  • My changes have reasonable test coverage
  • All tests pass with make test
  • I ensured my PR is ready for review with make reviewable

@lgo lgo requested a review from a team as a code owner January 19, 2025 10:21
@lgo lgo requested a review from knelasevero January 19, 2025 10:21
@lgo lgo force-pushed the joey-infisical-folder-handling branch from ab735bc to a2234f0 Compare January 19, 2025 21:10
@lgo lgo marked this pull request as draft January 19, 2025 21:22
@lgo lgo marked this pull request as ready for review January 20, 2025 00:20
@akhilmhdh
Copy link
Copy Markdown
Contributor

akhilmhdh commented Jan 20, 2025

Hi @lgo

That was quick. Code wise looking good to me. I'll do the application test today and give my approval on my side.

One small issue is, can we bring back the secret path option. Removing it would be a breaking change and want to keep it backward compatible. Simply keep that option as it is and if user provides it and not defaultSecretPath, the first one will be used. The docs can be kept with new one, may be mentioning secretPath is depreciated would be great. As both option was optional from the start, this should give customers less headache.

@lgo
Copy link
Copy Markdown
Contributor Author

lgo commented Jan 20, 2025

One small issue is, can we bring back the secret path option. Removing it would be a breaking change and want to keep it backward compatible. Simply keep that option as it is and if user provides it and not defaultSecretPath, the first one will be used. The docs can be kept with new one, may be mentioning secretPath is depreciated would be great. As both option was optional from the start, this should give customers less headache.

Sounds good. We could also just keep secretPath and ensure the documentation is clear. Your suggestion of keeping it around if we do add defaultSecretPath is a much better idea than changing it.

@lgo lgo force-pushed the joey-infisical-folder-handling branch 3 times, most recently from b54cfb2 to 5a3da95 Compare January 20, 2025 09:27
@lgo
Copy link
Copy Markdown
Contributor Author

lgo commented Jan 20, 2025

I decided to just avoid adding/changing defaultSecretPath and pushed up the changes, a few test fixes, and quality check fixes. This should now be good and just has a few test conflicts with the other PR (which I'll address once it's in).

@Skarlso
Copy link
Copy Markdown
Contributor

Skarlso commented Jan 26, 2025

@lgo Hello 👋 Could you please sign your commits? :)

@lgo lgo force-pushed the joey-infisical-folder-handling branch from fc5f5e2 to dba1c01 Compare February 1, 2025 16:45
@lgo
Copy link
Copy Markdown
Contributor Author

lgo commented Feb 1, 2025

Done! Sorry, I was away on a trip. I have not yet had a chance to build out the e2e tests either.

Hi @akhilmhdh - just checking if you had any additional testing you'd like to do on your end before checking off?

@Skarlso
Copy link
Copy Markdown
Contributor

Skarlso commented Feb 3, 2025

Is this now ready for review?

@Skarlso Skarlso self-assigned this Feb 3, 2025
@lgo
Copy link
Copy Markdown
Contributor Author

lgo commented Feb 3, 2025

Yep!

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Feb 5, 2025

@gusfcarvalho
Copy link
Copy Markdown
Member

Hi @lgo ! Were you able to address the points @Skarlso mentioned?

@akhilmhdh
Copy link
Copy Markdown
Contributor

akhilmhdh commented Apr 15, 2025

Hi @Skarlso @gusfcarvalho @lgo

I don't have push access to this branch. Can I make the changes requested as another PR with your commits to make this merged, if @lgo doesn't have time to continue working on it? We would love to see this changes getting shipped.

@gusfcarvalho
Copy link
Copy Markdown
Member

gusfcarvalho commented Apr 15, 2025

As long as you’re fork from @lgo repo, so his contributions thus far are correctly accredited to him, I’m up for it 😄

@lgo
Copy link
Copy Markdown
Contributor Author

lgo commented Apr 15, 2025

Heh, yea - sorry this went stale! I haven't had a lot of spare time lately and I've worked around this by using a custom build that included this patch.

Do feel free to fork this to take it over the finish line (if you don't get to it by EOW, I do have a long weekend that I can likely come back and rebase + address those)

@lgo
Copy link
Copy Markdown
Contributor Author

lgo commented Apr 15, 2025

(actually, I'll go ahead and handle the rebase right now as I already had a rebased branch and roll in the existing PR feedback just to leave a slightly cleaner slate, whether or not there's further work needed)

@lgo lgo force-pushed the joey-infisical-folder-handling branch 3 times, most recently from 7affeca to 844a048 Compare April 16, 2025 15:22
@lgo
Copy link
Copy Markdown
Contributor Author

lgo commented Apr 16, 2025

Okay I've pushed up a rebase, squashed the commits down, and addressed the one feedback. Two things that still need to be done:

  • Make sure the unit tests are still working. (For some reason go test <file> isn't working and make unit-test is failing but with a large wall of text so I need to revisit that)
  • Deploy this and step through the test cases I outlined again
  • Check whether Infisical's API requires a leading / on the secretPath query param (https://infisical.com/docs/api-reference/endpoints/secrets/read#parameter-secret-path). If they do, I'll make this much clearer in the code as I've partially written up error / defensive cases for tihs.

I'll take a pass at this later tonight, or tomorrow morning, and see if I can wrap these items up.

@typedrat
Copy link
Copy Markdown

typedrat commented May 11, 2025

Okay I've pushed up a rebase, squashed the commits down, and addressed the one feedback. Two things that still need to be done:

  • Make sure the unit tests are still working. (For some reason go test <file> isn't working and make unit-test is failing but with a large wall of text so I need to revisit that)
  • Deploy this and step through the test cases I outlined again
  • Check whether Infisical's API requires a leading / on the secretPath query param (https://infisical.com/docs/api-reference/endpoints/secrets/read#parameter-secret-path). If they do, I'll make this much clearer in the code as I've partially written up error / defensive cases for tihs.

I'll take a pass at this later tonight, or tomorrow morning, and see if I can wrap these items up.

Any updates on this? I really prefer using external-secrets over the native Infisical operator, and this would really help make it a lot more usable.

@gusfcarvalho
Copy link
Copy Markdown
Member

Hi @typedrat! If you can take the remaining points from these commits and push your contribution to it, I’d gladly review it!

otherwise, chances are this might go stale just because that’s the nature of community driven effort 🤷🏽‍♂️

@typedrat
Copy link
Copy Markdown

Hi @typedrat! If you can take the remaining points from these commits and push your contribution to it, I’d gladly review it!

otherwise, chances are this might go stale just because that’s the nature of community driven effort 🤷🏽‍♂️

Fair enough, I know how open source goes haha

I don't know Go and I've only got the barest bit of experience with using Infisical's API, so I don't know if I'm really the one to get this over the finish line myself, but I'll come back and look at this when I'm out of my work crunch if no one else has picked this up.

@Skarlso
Copy link
Copy Markdown
Contributor

Skarlso commented May 13, 2025

@typedrat I'll take a look. :)

@Skarlso Skarlso force-pushed the joey-infisical-folder-handling branch 3 times, most recently from f3d624c to f989b34 Compare May 13, 2025 05:10
Signed-off-by: Gergely Brautigam <182850+Skarlso@users.noreply.github.com>

On-behalf-of: Joey Pereira
@Skarlso Skarlso force-pushed the joey-infisical-folder-handling branch from f989b34 to ac8ea21 Compare May 13, 2025 05:12
Signed-off-by: Gergely Brautigam <182850+Skarlso@users.noreply.github.com>
@Skarlso
Copy link
Copy Markdown
Contributor

Skarlso commented May 13, 2025

I had to rebase to get the signed commit to work, but I left an On-behalf-of in the commit message to make sure to credit OP. :) I also tested with a free account and it seems to work as expected as far as I understand it.

@sonarqubecloud
Copy link
Copy Markdown

@Skarlso Skarlso merged commit 65a8d4b into external-secrets:main May 13, 2025
20 checks passed
@Adriien-M
Copy link
Copy Markdown

Thanks @Skarlso for your work 👍

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.

[Infisical] accessing nested items doesn't let you choose folder

6 participants