I have a solution that dynamically creates SAS tokens for a storage container by API. The API (Azure Fn) uses a Managed Identity to access the storage account. Thus, we use the "DelegationSas" authentication to generate the SAS token and return that to the user, who then uses the token to access the storage account.
This all works fine.
We have diagnostic audit logs on the storage account, connected to Event Grid so that we can record user activity. The events that are recorded include some Json specifying the tokenHash
data for the identity used to access the Storage resource.
The relevant part looks like this:
{
...
"identity": {
...
"tokenHash": "user-delegation([64-hex-chars]),SasSignature([64-hex-chars])",
...
},
...
}
Now, according to the information in MS Docs here, the SasSignature
value should be an "SHA 256 hash of the SAS token", but I am unable to replicate this value given the original SasToken generated for the user. I have captured this token verbatim for experimentation purposes and have tried many permutations to try and match this audit value, including:
- Convert.ToHexString( SHA256.HashData( Encoding.UTF8.GetBytes( "
sasToken incl sig
" ) ) )
- Convert.ToHexString( SHA256.HashData( Encoding.UTF8.GetBytes( "?
sasToken incl sig
" ) ) )
- Convert.ToHexString( SHA256.HashData( Encoding.UTF8.GetBytes( "
complete uri incl sasToken
" ) ) )
- Convert.ToHexString( SHA256.HashData( Encoding.UTF8.GetBytes( HttpUtility.UrlDecode(
"
sasToken incl sig
" ) ) ) )
- Convert.ToHexString( SHA256.HashData( Convert.FromBase64String( HttpUtility.UrlDecode( "
sasToken just the sig
" ) ) ) )
None of these are a match.
Does anyone have any information on how the value in the audit log is actually generated?