-
Notifications
You must be signed in to change notification settings - Fork 206
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
azd env add secret #4517
base: main
Are you sure you want to change the base?
azd env add secret #4517
Conversation
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.
This is looking good but just have some questions and concerns about when and where the secret reference to secret value translation occurs.
e.console.ShowSpinner(ctx, "Adding Administrator Role", input.Step) | ||
principalId, err := azureutil.GetCurrentPrincipalId(ctx, e.userProfileService, tenantId) | ||
e.console.StopSpinner(ctx, "", input.Step) | ||
if err != nil { | ||
return nil, fmt.Errorf("getting current principal ID: %w", err) | ||
} | ||
err = e.entraIdService.CreateRbac(ctx, subId, kvAccount.Id, keyvault.RoleIdKeyVaultAdministrator, principalId) | ||
if err != nil { | ||
return nil, fmt.Errorf("creating Key Vault RBAC: %w", err) | ||
} |
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.
What is the expectation when a template runs in CI that has these vault references? Perhaps we should check if the project has a service principal id set and if so also automatically add secret reader rbac assignment to the SP? Otherwise it would need to be a manual process.
err := h.serviceLocator.Invoke(func(keyvaultService keyvault.KeyVaultService) error { | ||
for key, value := range hookConfig.Secrets { | ||
setValue := value | ||
if valueFromEnv, exists := h.env.LookupEnv(value); exists { | ||
if keyvault.IsAkvs(valueFromEnv) { | ||
secretValue, err := keyvaultService.SecretFromAkvs(ctx, h.env.GetSubscriptionId(), valueFromEnv) | ||
if err != nil { | ||
return err | ||
} | ||
valueFromEnv = secretValue | ||
} | ||
setValue = valueFromEnv | ||
} | ||
hookEnv.DotenvSet(key, setValue) | ||
} | ||
return nil |
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 feel like the secret references => secret value should be a concern handled internally by the environment manager instead of the hook runner having to awkwardly inject the keyvault service to get the value.
Adding
azd env set-secret
Description:
With this change, AZD allows customers to set Azure Key Vault Secrets (Akvs) within the azd environment.
Adding a Akvs
Folks run
azd env set-secret <name>
and they can select to either Akvs or select an existing one. For theCreate a new Akvs
, folks can select an existing Azure Key Vault Account or Create a new one. See the next table for the options for a user:create account
option is turned ONAt the end of the flow, the akvs is persisted within the .env file (the azd environment) using the
<name>
provided by the user for the secret and the reference to the akvs as the value, which looks like:Azd uses the prefix
akvs://
as a way to identify a reference to an Azure key Vault Secret.Using secrets
AZD can get the akvs value during the next flows:
azd provision + bicep + main.parameters.json
.main.parameters.json
for the parameter to the secret from the .env. For example, when callingazd env set-secret OPEN_ID_KEY
the mapping would look like:azd provision + bicep + .bicepparams
. -> WIPazd hooks:
Any other interaction with Azd environment will not resolve akvs into values. For example, running
azd env get-values
will display the akvs reference.