Azure / Azure/azure-cli

webapp: support storage for logging config

Open
#10,043 10 comments 0 reactions 1 assignee Assigned to @tulikac View on GitHub
act-observability-squad App Services app-service-logging-monitoring customer-reported feature-request Service Attention Web Apps
Dominant language
Python
Stars
4.6k
Forks
3.5k
Avg merge
3d 2h
Merged PRs (30d)
60

Description

`az webapp log config` should support logging to storage, as well as filesystem, for both application logging and web server logging.

Ideally it would have the option to automatically configure storage account permissions, like the portal does.

Currently the workaround is to use the portal, or to script via REST APIs.

A workaround bash script is:
```
TOKEN=$(az account get-access-token --query accessToken -o tsv)

# unfortunately, Mac doesn't use GNU date, so the arguments are different....
if [[ "$OSTYPE" == "darwin"* ]]; then
SAS_EXPIRY=$(date -v +200y '+%Y-%m-%dT%H:%MZ')
else
SAS_EXPIRY=$(date -d '200 years' '+%Y-%m-%dT%H:%MZ')
fi

SAS=$(echo https://OUR-BLOB-CONTAINER.blob.core.windows.net/logs?$(az storage container generate-sas -n logs --account-name OUR-BLOB-CONTAINER --expiry $SAS_EXPIRY --permissions rwl -o tsv))

curl -X GET -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" https://management.azure.com/subscriptions/$SUBSCRIPTION_ID/resourceGroups/$GROUP_NAME/providers/Microsoft.Web/sites/$SITE_NAME/config/logs?api-version=2018-02-01 \
| jq "
. * {
\"properties\": {
\"applicationLogs\": {
\"azureBlobStorage\": {
\"level\": \"Warning\",
\"sasUrl\": \"$SAS\",
\"retentionInDays\": 14
}
},
\"httpLogs\": {
\"azureBlobStorage\": {
\"sasUrl\": \"$SAS\",
\"retentionInDays\":400,
\"enabled\": true
}
}
}
}
" | curl -X PUT -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" -d @- https://management.azure.com/subscriptions/$SUBSCRIPTION_ID/resourceGroups/$GROUP_NAME/providers/Microsoft.Web/sites/$SITE_NAME/config/logs?api-version=2018-02-01
```

Related to #4764 - filing a new issue from a customer perspective as requested by @panchagnula in https://github.com/Azure/azure-cli/issues/4764#issuecomment-514850099

Re https://github.com/Azure/azure-cli/issues/4764#issuecomment-514850099 :

> this is not something we have plans to support on CLI since this this needs the customer to share some secrets in the Sass-URL

I may be missing something because I don't understand the problem with sharing secrets on the CLI. Firstly, there are other az CLI commands which take secrets on the command line (e.g. `az webapp config storage-account add --access-key`. Secondly, ideally this could be managed within the CLI without needing the user to specify secrets. As demonstrated by the script above, az CLI already knows how to generate tokens with `az storage container generate-sas` without needing any secrets hard-coded in the script.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.