{
  "useCase": "identity/credential-renewal-secret",
  "version": "v1",
  "purpose": "A client secret that EasyLife 365 renews and writes into your key vault.",
  "resourceKind": "KeyVaultSecret",
  "role": {
    "name": "Key Vault Secrets Officer",
    "id": "b86a8fe4-44ce-4948-aee5-eccb2c155cd7",
    "scope": "secret",
    "scopeId": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.KeyVault/vaults/{vaultName}/secrets/{secretName}"
  },
  "requiredActions": [
    "Microsoft.KeyVault/vaults/secrets/readMetadata/action",
    "Microsoft.KeyVault/vaults/secrets/setSecret/action"
  ],
  "whoMayConnect": {
    "roles": [
      "Owner",
      "User Access Administrator",
      "Role Based Access Control Administrator"
    ],
    "action": "Microsoft.Authorization/roleAssignments/write"
  },
  "stopsWhen": "The key vault uses access policies (enableRbacAuthorization is not true). The script stops and changes nothing on that vault.",
  "rules": [
    "Parameters only, no other input",
    "Running a script again changes nothing that exists and lists it as skipped",
    "Never deletes anything and never changes the settings of an existing resource"
  ],
  "files": {
    "create.ps1": {
      "action": "create",
      "shell": "PowerShell 7 or Windows PowerShell 5.1",
      "modules": [
        "Az.Accounts",
        "Az.Resources"
      ],
      "parameters": {
        "vaultName": {
          "powershell": "-VaultName",
          "cli": "--vault-name",
          "required": true,
          "description": "The key vault: 3 to 24 letters, digits and hyphens, starting with a letter, ending with a letter or digit, with no two hyphens in a row. Unique in Azure."
        },
        "secretName": {
          "powershell": "-SecretName",
          "cli": "--secret-name",
          "required": true,
          "description": "The secret: 1 to 127 letters, digits and hyphens. It may start with a hyphen."
        },
        "region": {
          "powershell": "-Region",
          "cli": "--region",
          "required": true,
          "description": "The Azure region of a new resource, for example westeurope. In the template it defaults to the region of the resource group."
        },
        "appId": {
          "powershell": "-AppId",
          "cli": "--app-id",
          "required": true,
          "description": "The application (client) ID of the EasyLife 365 app in your tenant. The role goes to the service principal of this app."
        },
        "resourceGroup": {
          "powershell": "-ResourceGroupName",
          "cli": "--resource-group",
          "required": false,
          "default": "rg-easylife365",
          "description": "The resource group of a new resource. Created in the region when it is missing."
        },
        "subscription": {
          "powershell": "-Subscription",
          "cli": "--subscription",
          "required": false,
          "description": "The subscription ID or name. Without it the script uses the current subscription and asks you to confirm it."
        },
        "yes": {
          "powershell": "-Yes",
          "cli": "--yes",
          "required": false,
          "description": "A switch with no value: uses the current subscription without asking."
        }
      },
      "creates": [
        "Resource group, when the key vault and the group don't exist yet",
        "Key vault: standard tier, Azure role-based access control, soft delete 90 days",
        "Secret with a random value, created through Azure Resource Manager and never shown. An existing secret keeps its value.",
        "Role assignment: Key Vault Secrets Officer for the service principal of the app, at the secret"
      ],
      "runAs": "Owner, or Contributor together with User Access Administrator or Role Based Access Control Administrator, on the subscription"
    },
    "create.sh": {
      "action": "create",
      "shell": "Bash with the Azure CLI",
      "parameters": {
        "vaultName": {
          "powershell": "-VaultName",
          "cli": "--vault-name",
          "required": true,
          "description": "The key vault: 3 to 24 letters, digits and hyphens, starting with a letter, ending with a letter or digit, with no two hyphens in a row. Unique in Azure."
        },
        "secretName": {
          "powershell": "-SecretName",
          "cli": "--secret-name",
          "required": true,
          "description": "The secret: 1 to 127 letters, digits and hyphens. It may start with a hyphen."
        },
        "region": {
          "powershell": "-Region",
          "cli": "--region",
          "required": true,
          "description": "The Azure region of a new resource, for example westeurope. In the template it defaults to the region of the resource group."
        },
        "appId": {
          "powershell": "-AppId",
          "cli": "--app-id",
          "required": true,
          "description": "The application (client) ID of the EasyLife 365 app in your tenant. The role goes to the service principal of this app."
        },
        "resourceGroup": {
          "powershell": "-ResourceGroupName",
          "cli": "--resource-group",
          "required": false,
          "default": "rg-easylife365",
          "description": "The resource group of a new resource. Created in the region when it is missing."
        },
        "subscription": {
          "powershell": "-Subscription",
          "cli": "--subscription",
          "required": false,
          "description": "The subscription ID or name. Without it the script uses the current subscription and asks you to confirm it."
        },
        "yes": {
          "powershell": "-Yes",
          "cli": "--yes",
          "required": false,
          "description": "A switch with no value: uses the current subscription without asking."
        }
      },
      "creates": [
        "Resource group, when the key vault and the group don't exist yet",
        "Key vault: standard tier, Azure role-based access control, soft delete 90 days",
        "Secret with a random value, created through Azure Resource Manager and never shown. An existing secret keeps its value.",
        "Role assignment: Key Vault Secrets Officer for the service principal of the app, at the secret"
      ],
      "runAs": "Owner, or Contributor together with User Access Administrator or Role Based Access Control Administrator, on the subscription"
    },
    "template.json": {
      "action": "template",
      "source": "template.bicep",
      "deployToAzure": "https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fdocs.easylife365.cloud%2Fdownloads%2Fidentity%2Fcredential-renewal-secret%2Fv1%2Ftemplate.json",
      "parameters": {
        "vaultName": "The key vault: 3 to 24 letters, digits and hyphens, starting with a letter, ending with a letter or digit, with no two hyphens in a row. Unique in Azure.",
        "secretName": "The secret: 1 to 127 letters, digits and hyphens. It may start with a hyphen.",
        "region": "The Azure region. Default: the region of the resource group.",
        "secretValue": "Secure. The first value of the secret. Default: newGuid(). Leave the default."
      },
      "creates": [
        "Key vault: standard tier, Azure role-based access control, soft delete 90 days",
        "Secret with a random value (parameter secretValue, default newGuid()). Deploying the template again writes a new value into the secret: deploy it once, for a new vault."
      ],
      "access": "None. Run grant.ps1 or grant.sh afterwards.",
      "runAs": "Contributor or Owner on the resource group"
    },
    "grant.ps1": {
      "action": "grant",
      "shell": "PowerShell 7 or Windows PowerShell 5.1",
      "modules": [
        "Az.Accounts",
        "Az.Resources"
      ],
      "parameters": {
        "vaultName": {
          "powershell": "-VaultName",
          "cli": "--vault-name",
          "required": true,
          "description": "The key vault: 3 to 24 letters, digits and hyphens, starting with a letter, ending with a letter or digit, with no two hyphens in a row. Unique in Azure."
        },
        "secretName": {
          "powershell": "-SecretName",
          "cli": "--secret-name",
          "required": true,
          "description": "The secret: 1 to 127 letters, digits and hyphens. It may start with a hyphen."
        },
        "appId": {
          "powershell": "-AppId",
          "cli": "--app-id",
          "required": true,
          "description": "The application (client) ID of the EasyLife 365 app in your tenant. The role goes to the service principal of this app."
        },
        "subscription": {
          "powershell": "-Subscription",
          "cli": "--subscription",
          "required": false,
          "description": "The subscription ID or name. Default: the current subscription."
        }
      },
      "creates": [
        "Role assignment: Key Vault Secrets Officer for the service principal of the app, at the secret"
      ],
      "runAs": "Owner, User Access Administrator, Role Based Access Control Administrator, at the scope of the role or above"
    },
    "grant.sh": {
      "action": "grant",
      "shell": "Bash with the Azure CLI",
      "parameters": {
        "vaultName": {
          "powershell": "-VaultName",
          "cli": "--vault-name",
          "required": true,
          "description": "The key vault: 3 to 24 letters, digits and hyphens, starting with a letter, ending with a letter or digit, with no two hyphens in a row. Unique in Azure."
        },
        "secretName": {
          "powershell": "-SecretName",
          "cli": "--secret-name",
          "required": true,
          "description": "The secret: 1 to 127 letters, digits and hyphens. It may start with a hyphen."
        },
        "appId": {
          "powershell": "-AppId",
          "cli": "--app-id",
          "required": true,
          "description": "The application (client) ID of the EasyLife 365 app in your tenant. The role goes to the service principal of this app."
        },
        "subscription": {
          "powershell": "-Subscription",
          "cli": "--subscription",
          "required": false,
          "description": "The subscription ID or name. Default: the current subscription."
        }
      },
      "creates": [
        "Role assignment: Key Vault Secrets Officer for the service principal of the app, at the secret"
      ],
      "runAs": "Owner, User Access Administrator, Role Based Access Control Administrator, at the scope of the role or above"
    }
  }
}
