-
Notifications
You must be signed in to change notification settings - Fork 788
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: refactor out a sub-interface from Vault for VaultURL injection #4330
Conversation
Looks good to me for the URL parts. @ccojocar you should look too though for a final lgtm :-) |
pkg/vaulturl/vaulturl_client.go
Outdated
@@ -0,0 +1,17 @@ | |||
package vaulturl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am wondering if we should name this secreturl
instead. it is something more generic than vault. In my mind, vault is just one implementation of this interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good call!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then I guess the URLs need to be secret:
too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok refactoring to secreturl
package but gonna stick with vault:
and local:
URLs
pkg/vaulturl/helpers.go
Outdated
var vaultURIRegex = regexp.MustCompile(`vault:[-_\w\/:]*`) | ||
|
||
// ReplaceURIs will replace any vault: URIs in a string, using the vault client | ||
func ReplaceURIs(s string, client Client) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather make this a method part of secreturl.Client
, this will allow us to extend it with other URI schemes (e.g. k8s secret).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the main reason I kept it here for now was to avoid touching vault.Client
in case it interfered with your refactor ;). Maybe we add a ReplaceURIs
function to the secreturl.Client
which for vault + localvault can reuse the same code + URL scheme - then do something different for k8s?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about we support secret:
for either vault or local and vault:
for only vault and local:
for only local? then if folks want to be generic they use secret:
URLs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could add other URLs for vault - e.g. to use a specific named vault too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'secret:` sounds better to me in this case
pkg/vaulturl/helpers.go
Outdated
"github.com/pkg/errors" | ||
) | ||
|
||
var vaultURIRegex = regexp.MustCompile(`vault:[-_\w\/:]*`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be explicit a use a URI scheme per client (e.g. vault:..., local:..., k8s:...) instead of hiding this. In this way, the user will be aware of the place where the secrets are stored.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW one of the motivations of this was so that we don't have to search / replace all the values.yaml in a GitOps install if someone decides to switch from local file system secrets to vault - i.e. to use the same URI scheme in values.yaml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm hoping we can have a canonical git repo for installing Jenkins X with prow + tekton with + without vault without having to do a global replace of vault:
<-> local:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use secret
instead. It will be difficult to use the same path for both vault and local, because vault is using a relative path to the root of the secrets backend which normally is mounted with a fix name secret
for KV secret engine. It will be something like secret/<path-in-vault>:secret-name
but the secret
prefix is omitted from the URI, which is not totally correct if we want to support multiple vault secrets backends. Another backend will be mounted on a different prefix so the user won't be able to use that backend.
I think the user will be forced to store the secrets file to the same relative path which is similar with the relative path in vault.
Given this example:
https://github.com/jenkins-x/environment-tekton-mole-dev/blob/783a8f6178c050c0b96c61016d1581bd0bc7a3a0/env/values.yaml#L98
the user will have to store the secrets on a local path like this:
<root-folder>/gitOps/jenkins-x/environment-tekton-mole-dev/jenkins-x-demo-sa:data
Codecov Report
@@ Coverage Diff @@
## master #4330 +/- ##
==========================================
- Coverage 43.4% 43.36% -0.05%
==========================================
Files 804 807 +3
Lines 100748 101016 +268
==========================================
+ Hits 43726 43801 +75
- Misses 53392 53559 +167
- Partials 3630 3656 +26
Continue to review full report at Codecov.
|
/test integration |
/test all |
1 similar comment
/test all |
/lgtm |
/test all |
* so we can support local file system vault-like behaviour or real Vault from a small simple interface (which is a small subset of Vault client) * same URL structure works for vault + local file system referencing Signed-off-by: James Strachan <james.strachan@gmail.com>
Signed-off-by: James Strachan <james.strachan@gmail.com>
Signed-off-by: James Strachan <james.strachan@gmail.com>
and add support for `vault:` for the vault client and `local:` for the local file system client Signed-off-by: James Strachan <james.strachan@gmail.com> jenkins-x#4328
Signed-off-by: James Strachan <james.strachan@gmail.com>
* also support referencing logical Parameters in a `parameters.yaml` file which can include a logical structure + schema (for nice install tooling) which then contains inline values for simple values or URLs to vault/local secret files for better secret management fixes jenkins-x#4328 Signed-off-by: James Strachan <james.strachan@gmail.com>
Signed-off-by: James Strachan <james.strachan@gmail.com>
Signed-off-by: James Strachan <james.strachan@gmail.com>
/test integration |
/test lint |
Signed-off-by: James Strachan <james.strachan@gmail.com>
and we don't yet have the install config ConfigMap setup Signed-off-by: James Strachan <james.strachan@gmail.com>
/test bdd |
Signed-off-by: James Strachan <james.strachan@gmail.com>
Signed-off-by: James Strachan <james.strachan@gmail.com>
added a test + fix for templating in the root dir as well as any nested `values.yaml` files Signed-off-by: James Strachan <james.strachan@gmail.com>
thanks for the great feedback @ccojocar * renamed `vaultClient` -> `secretURLClient` * fixed up mock generation * zapped the `GetClusterName` and reused the existing helper Signed-off-by: James Strachan <james.strachan@gmail.com>
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ccojocar, pmuir The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
…enkins-x#4330) * fix: refactor out a sub-interface from Vault for VaultURL injection * so we can support local file system vault-like behaviour or real Vault from a small simple interface (which is a small subset of Vault client) * same URL structure works for vault + local file system referencing Signed-off-by: James Strachan <james.strachan@gmail.com> * chore: fix hound warning Signed-off-by: James Strachan <james.strachan@gmail.com> * chore: refactor vaulturl -> secreturl Signed-off-by: James Strachan <james.strachan@gmail.com> * fix: lets move URL handling into the secreturl.Client and add support for `vault:` for the vault client and `local:` for the local file system client Signed-off-by: James Strachan <james.strachan@gmail.com> jenkins-x#4328 * chore: fix hound warning Signed-off-by: James Strachan <james.strachan@gmail.com> * fix: allow `values.yaml` to include go template functions * also support referencing logical Parameters in a `parameters.yaml` file which can include a logical structure + schema (for nice install tooling) which then contains inline values for simple values or URLs to vault/local secret files for better secret management fixes jenkins-x#4328 Signed-off-by: James Strachan <james.strachan@gmail.com> * chore: fix hound warning Signed-off-by: James Strachan <james.strachan@gmail.com> * chore: fix failing tests due to refactor Signed-off-by: James Strachan <james.strachan@gmail.com> * chore: fix failing tests due to refactor Signed-off-by: James Strachan <james.strachan@gmail.com> * chore: avoid failing when bootstrapping a cluster and we don't yet have the install config ConfigMap setup Signed-off-by: James Strachan <james.strachan@gmail.com> * fix: lets populate the cluster information in the cluster/values.yaml Signed-off-by: James Strachan <james.strachan@gmail.com> * chore: fix broken test Signed-off-by: James Strachan <james.strachan@gmail.com> * fix: lets allow templating in the root `values.yaml` too added a test + fix for templating in the root dir as well as any nested `values.yaml` files Signed-off-by: James Strachan <james.strachan@gmail.com> * chore: polished the code thanks for the great feedback @ccojocar * renamed `vaultClient` -> `secretURLClient` * fixed up mock generation * zapped the `GetClusterName` and reused the existing helper Signed-off-by: James Strachan <james.strachan@gmail.com>
Signed-off-by: James Strachan james.strachan@gmail.com