Skip to content
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

URIs Should Be Properly Constructed Triggers When Referencing KeyVault Secret #724

Open
aolszowka opened this issue Dec 21, 2022 · 2 comments

Comments

@aolszowka
Copy link

Similar issues related to this rule have been reported several times; the most relevant ones seem to be #417, #713, #590 in all these cases they appear to be using a "bare" or "naked" Uri for which the recommended solution of uri() seems appropriate.

However, consider the following example ARM Template:

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
    },
    "resources": [
        {
            "type": "Microsoft.Web/sites/config",
            "apiVersion": "2022-03-01",
            "name": "myCoolFunctionApp/appsettings",
            "dependsOn": [
                "[resourceId('Microsoft.KeyVault/vaults', 'mycoolKeyVault')]",
                "[resourceId('Microsoft.KeyVault/vaults/secrets', 'mycoolKeyVault', 'some-secret')]",
                "[resourceId('Microsoft.KeyVault/vaults/secrets', 'mycoolKeyVault', 'some-other-secret')]",
                "[resourceId('Microsoft.Web/sites', 'myCoolFunctionApp')]"
            ],
            "properties": {
                "Some:SecretUri": "[concat('@Microsoft.KeyVault(SecretUri=', reference(resourceId('Microsoft.KeyVault/vaults/secrets', 'mycoolKeyVault', 'some-secret')).secretUri, ')')]",
                "Some:OtherUriSecret": "[concat('@Microsoft.KeyVault(SecretUri=', reference(resourceId('Microsoft.KeyVault/vaults/secrets', 'mycoolKeyVault', 'some-other-secret')).secretUri, ')')]",
                "SecretUrl": "[format('@Microsoft.KeyVault(SecretUri={0})', reference(resourceId('Microsoft.KeyVault/vaults/secrets', 'mycoolKeyVault', 'some-other-secret')).secretUri)]"
            }
        }
    ]
}

This is using the Azure KeyVault Reference Syntax Documented here: https://learn.microsoft.com/en-us/azure/app-service/app-service-key-vault-references?tabs=azure-cli#reference-syntax. Both syntaxes will trigger the warning:

  URIs Should Be Properly Constructed
    [-] URIs Should Be Properly Constructed (11 ms)
        Function 'concat' found within 'Some:SecretUri'
        Function 'format' found within 'SecretUrl'
        Function 'concat' found within 'Some:SecretUri' Line: 20, Column: 18
        Function 'format' found within 'SecretUrl' Line: 20, Column: 18

Is there an alternate way that the Referenced Secret Syntax should be utilized that avoids this linter error? Even the alternative syntax @Microsoft.KeyVault(VaultName=myvault;SecretName=mysecret) will throw because you're still going to need to use concat() or format() to accomplish this.

The real problem seems to be the detection of what is considered a URI, it appears to only considers properties that end in Uri or Url which is not a bad heuristic.

@ghost ghost added the Needs: triage 🔍 label Dec 21, 2022
@mcs1970
Copy link

mcs1970 commented Aug 24, 2023

I am having the same error flagged by the ARM TTK and would like to know the recommended method to pass a secret URI as an output.

Thanks!

@jimdigriz
Copy link

As mentioned by @aolszowka , probably best to just rename your variable to not have url or uri in it; I use instead var KeyVaultRef = "..."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants