-
Notifications
You must be signed in to change notification settings - Fork 769
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
How to use the reference keyword in param to retrieve keyvault secret #1028
Comments
Adding some more context to this one. We have a module that joins VMs to domains.
|
Thanks for pointing this out. This is indeed a gap, and we will need to figure out how to expose this in bicep. |
Had a discussion about this yesterday. The ideal fix here is for keyVault to expose a So given that, we think we could do a syntax like the following:
We thought about "faking" a As a sidenote, we should also improve the type system to ensure that if a module has a Thoughts? |
I'm a fan of the first option, in regards to natively exposing a function for it. Just for my own clarifications sake, I would assume #258 would be a blocker for this implementation then, in terms of referencing kv.Id? |
Good question - I don't think it would be. You should also be able to pass any valid resourceId, so this should work as well:
|
This function would be great, although if we're waiting for the API team I'd rather have this
implemented ASAP. That being stated, I'd eventually love to see this:
|
Just adding my "yes please" to the conversation. I'm OK holding the secret inside a parameter reference -- I'm already using a parameter and passing the secret in from outside as a workaround, but I sure don't like doing this. |
Just to clarify. We'd like to go from this in bicep:
to this in json
Right? I'm also thinking that Also, I'm not convinced that |
@miqm - we are going to discuss the fine details of the work required for this tomorrow in our team meeting. We will update the issue with everything you should need to get started. So I would hold off starting the work until then. |
@alex-frankel any update on the discussion output? |
Meeting notes from 2/8/2021We had a discussion about this yesterday. We discussed the following options: Option 1This option would model the function signature like this: This would look as follows in bicep: resource kv 'Microsoft.KeyVault/vaults@xxxx-xx-xx' existing = {
name: 'myKV'
}
module myMod 'foo.bicep' = {
params: {
...
foo: getKeyVaultSecret(kv, 'adminPassword')
...
}
} Cons:
Pros:
Option 2We could model the function signature like this: Pros:
Cons:
Option 3We could introduce a generic concept of a parameter reference. Cons:
Pros:
Variant AWe can support the new function as a method on a KV resource. This variant can be combined with any of the options above. For example, option 1A would look like the following in the source: bicep
resource kv 'Microsoft.KeyVault/vaults@xxxx-xx-xx' existing = {
name: 'myKV'
}
module myMod 'foo.bicep' = {
params: {
...
foo: kv.getKeyVaultSecret('adminPassword')
...
}
} Pros:
ConclusionThe team consensus is Option 1 above. We feel the improved type safety is worth the extra lines of code. We have not closed on whether we should go with just Option 1 or Option 1A. |
My preference here is to do Option 1A over Option 1. @bmoore-msft, @anthony-c-martin and @alex-frankel can you confirm you're ok with it? |
Implementation notes for Option 1:
|
If we go with Option 1A, we do not need for the method name to include Also a question - should we check if when using the secret reference, the parameter is securestring type? I don't know if it will work with string. If it does - we should at least warn that secret will be exposed. If not - throw error. |
I am happy with 1 or 1A. 1A aligns with the improvements we have planned for list*, so that is worth considering. I think it's important to get people used to the
+1 to this as well |
Yeah, good pt. With 1A, it should be called |
+1 |
The existing syntax being difficult may be more of an indication that we need to make it easier to get resourceIds for resources not defined in the template. Think of a resource in a nested deployment and how you would construct that today vs. bicep. Maybe worth more thought, but orthogonal to this issue. Option 1 certainly works and the second "con" bullet is the same across the board if I'm reading that right. For 1A the method vs. property thing is a little strange to me... we have something that looks like a property but is not and as such can't be used, well, anywhere. My instinct upon seeing that is I no longer need to nest a deployment to get a secret and I can do:
Wherever I want and that won't be allowed. Granted that's true for a standalone function, but there are other standalone functions like that (and will be more in the future IMO). When we blur properties/methods it will be more frustrating when I fall into the pit of failure. (remember users already try to use the parameter reference syntax in templates). |
Both 1 or 1a sound good to me, with a preference for 1a. |
@bmoore-msft Yes that's true that methods can't be called everywhere. This is similar to any object-oriented programming language and doesn't really cause problems there. Completions help a lot with this. And we actually already have the infrastructure for method completions (it's used for namespace-qualified functions right now). We have also already agreed to have list*() work as a method for resources that support it as well. (With an equivalent global function syntax.) |
I can start working on this. As I think we all agreed - Option 1A short: |
I just thought about another variant of referencing secret:
WDYT? |
@miqm - I'm still a fan of option 1A short. |
point taken, thanks @DanniJuhl. |
@miqm I think either work and are good, it just depends on what direction bicep should go in. |
@alex-frankel I guess Option 1 seems the fastest and cleanest way as seems Option 3 requires a lot of work. |
is there any other workaround for this besides just the obvious and ugly way of passing this trough the main template? |
I don't believe so unfortunately. We're fairly close to adding support at this point. Currently waiting for #1915 to be merged, which will then unblock @miqm's PR to add support for this feature #1571. |
Or is it possible to use reference and use keyvault uri? like the one I used for App Service Secret URI? |
not yet. in current state bicep will always generate value object, not reference. we've managed to unblock the PR and it's being reviewed. |
I think just being able to create a parameters file which reference secrets that bicep could use if they are parameters. Today if you want to use a parameters json file with secrets in them, you cannot define any parameters that arent directly utilized by the bicep file |
I apologize if this is already addressed or supported already, but I can't seem to find any way to reference keyvault secrets when using modules.
In ARM one way of doing this in a nested template was;
And the type in the template would be a secure string.
What would be the bicep equivalent when using params in a module?
The text was updated successfully, but these errors were encountered: