Get expiration date for all SAS on a Azure storage account (2024)

  • Remove From My Forums

Answered by:

  • Question

  • Hello,

    Have about ten storage accounts that I would like to alert when expiration dates where getting near. Does anyone know how to get the SAS expiry date, which is set against the account as far as I can see. I've examined (in debug)the account, client and container in the test code below and also looked at their corresponding types in ILSpy but cannot see any properties or methods that expose the SAS expiry date.

    Get expiration date for all SAS on a Azure storage account (3)

    void Main(){CloudStorageAccount account = new CloudStorageAccount(new StorageCredentials(GetName(), GetKey()), true);CloudBlobClient client = account.CreateCloudBlobClient(); foreach (CloudBlobContainer container in client.ListContainers()){Console.WriteLine(container.Name);} }

    Wednesday, October 30, 2019 5:15 PM

Answers

  • This from MS Azure support

    Thank you for contacting Microsoft Support.

    My name is Luis Filipe and I will be the Support Engineer that will be assisting you regarding this service request.

    You can reach me replying to this mail or using the contact information in my signature.

    Issue:

    I need to know when account-level SAS on blob storage containers are due to expire. You are looking for some report, PowerShell or something else you can setup to alert you.

    Our analysis:

    The SAS could be generated on Azure Portal, on client application or client side scripts (PowerShell/CLI), and the SAS information are not saved on Azure.

    For that reason there are no way to have an alert from Azure for when the SAS will expire.

    As you probably know the SAS have the “se” on the URI parameter, and this is the only way to know when the SAS will expire.

    You may create some application to save the expiry date every time you create one SAS, and with this you may have some alters from that application, but Azure don’t support this feature.

    Tuesday, November 12, 2019 3:08 PM

All replies

  • There are two ways to set expiry on SAS. The first is to build it into the SAS token itself. Then the only way to check expiry is to inspect the se= parameter of the token. You could maintain a list of known SAS tokens and alert based on the expiry.

    The second way to set expiry is to set it in a stored policy on a container. Then the SAS token would reference it using.

    You can check the expiry in that case using the Get Container ACL API (sometimes called GetPermissions).

    You would need to check each container that may contain a policy and alert based on the time set in the policy.

    Hope this helps!

    Kindly let us know if the above helps or you need further assistance on this issue.
    ------------------------------------------------------------------------------------------

    Do click on "Mark as Answer" and Upvote on the post that helps you, this can be beneficial to other community members.

    Thursday, October 31, 2019 12:27 PM

  • Hello,

    I'm looking at theCloudBlobContainerand specifically the GetPermissions method but I cannot see how to retrieve any existing SAS expiry date.

    Also looking at theGetSharedAccessSignature method as this seems a good candidate. This returns what looks to be a SAS signature but not any properties such as the date.

    Get expiration date for all SAS on a Azure storage account (10)

    Thursday, October 31, 2019 2:25 PM

  • That code also just seems to get the first SAS as I just created new one which runs from today (31/10) for seven days.

    That SAS looks like this ""?sv=2019-02-02*" which must be an old one, there have been at least 10 SAS created on this container.

    Thursday, October 31, 2019 2:36 PM

  • @The real SlartibartfastFirstly, apologies for the delay in responding here and any inconvenience this issue may have caused.

    GetPermissions return a BlobcontainerPermissions object, which contains the SAS policies

    BlobContainerPermissions.SharedAccessPolicies Property


    Hope this helps!

    Kindly let us know if the above helps or you need further assistance on this issue.
    ------------------------------------------------------------------------------------------

    Do click on "Mark as Answer" and Upvote on the post that helps you, this can be beneficial to other community members.

    Friday, November 8, 2019 1:02 PM

  • @The real SlartibartfastFirstly, apologies for the delay in responding here and any inconvenience this issue may have caused.

    GetPermissions return a BlobcontainerPermissions object, which contains the SAS policies

    BlobContainerPermissions.SharedAccessPolicies Property


    Hello,

    Thanks for the response.

    That method GetPermissions is part of theCloudBlobContainer class so this will not work for me.

    I need Account-level SAS so not any SAS that is at the container level.

    Thanks

    Friday, November 8, 2019 5:07 PM

  • @The real SlartibartfastAs for GetPermissions, Account SAS doens't use stored access policies so there is no need for this API.

    Set the expiry on the token itself.

    Kindly let us know if the above helps or you need further assistance on this issue.
    ------------------------------------------------------------------------------------------

    Do click on"Mark as Answer" and Upvote on the post that helps you, this can be beneficial to other community members.

    Monday, November 11, 2019 5:06 PM

  • @The real SlartibartfastAs for GetPermissions, Account SAS doens't use stored access policies so there is no need for this API.

    Set the expiry on the token itself.

    Hello,

    So how do I get the SAS expiry on an account-level SAS that I created in the Azure portal? I'm not trying to SET the expiry, I'm trying to READ it.

    Account-level SAS is used extensively for SQL database backup to URL. Problem is we don;t know when they are expiring.

    Thanks

    Monday, November 11, 2019 5:11 PM

  • This from MS Azure support

    Thank you for contacting Microsoft Support.

    My name is Luis Filipe and I will be the Support Engineer that will be assisting you regarding this service request.

    You can reach me replying to this mail or using the contact information in my signature.

    Issue:

    I need to know when account-level SAS on blob storage containers are due to expire. You are looking for some report, PowerShell or something else you can setup to alert you.

    Our analysis:

    The SAS could be generated on Azure Portal, on client application or client side scripts (PowerShell/CLI), and the SAS information are not saved on Azure.

    For that reason there are no way to have an alert from Azure for when the SAS will expire.

    As you probably know the SAS have the “se” on the URI parameter, and this is the only way to know when the SAS will expire.

    You may create some application to save the expiry date every time you create one SAS, and with this you may have some alters from that application, but Azure don’t support this feature.

    Tuesday, November 12, 2019 3:08 PM

Get expiration date for all SAS on a Azure storage account (2024)

FAQs

How do I know when my SAS token expires? ›

The SAS expiration period appears in the console output. To configure a SAS expiration policy, use the az storage account update command, and then set the --key-exp-days parameter to the number of days, hours, minutes, and seconds that a SAS token can be active from the time that a SAS is signed.

How do I validate my SAS token for Azure storage? ›

Create SAS tokens in the Azure portal
  1. Right-click the container or file and select Generate SAS from the drop-down menu.
  2. Select Signing method → User delegation key.
  3. Define Permissions by checking and/or clearing the appropriate check box: ...
  4. Specify the signed key Start and Expiry times.
Jul 18, 2023

What is the maximum expiry time for Azure blob SAS token? ›

EDIT: according to this SO post, the maximum expiration date for the SAS token is 365 days: You can specify the expiration date for a SAS token, I think the maximum is 365 days, but forever is not a possibility.

Do Azure storage account keys expire? ›

Azure Storage provides a built-in policy for ensuring that storage account access keys are not expired. For more information about the built-in policy, see Storage account keys should not be expired in List of built-in policy definitions.

How do I check my token expiry online? ›

You can see the "accessTokenValiditySeconds" for your OAuth client with the GET/api/v2/oauth/clients/{clientId} endpoint. Based on that value, you can calculate when a token expires by tracking when it gets created. The exipry time is provided when the token is first obtained.

Do SAS tokens expire? ›

Ensure that your Microsoft Azure Storage SAS tokens are configured to expire within an hour in order to protect Azure cloud data against unauthorized access. In this way, even if your SAS tokens get compromised, they are valid only for a short time.

Where is the SAS token for Azure storage account? ›

Get SAS token from the Azure Portal
  1. Navigate to the blob container.
  2. Under. Settings. ...
  3. In the. Signing method. ...
  4. If you select the Account key signing method, select the. Signing key. ...
  5. In the. Permissions. ...
  6. Set the start and expiry date during which the SAS token is valid.
  7. In the. Allowed IP addresses. ...
  8. Click. Generate SAS token and URL.

How do I get SAS token for Azure storage PowerShell? ›

Generating a SAS Token using PowerShell

PowerShell uses Azure's REST API to make calls to Azure to generate the token. To create a SAS token via PowerShell, first, open up a PowerShell console and authenticate with Connect-AzAccount. Once authenticated, then find the storage account you'd like to access.

What is SAS token in Azure storage? ›

The SAS token is a string that you generate on the client side, for example by using one of the Azure Storage client libraries. The SAS token is not tracked by Azure Storage in any way. You can create an unlimited number of SAS tokens on the client side.

What is the length limit for Azure storage account? ›

Storage account names must be between 3 and 24 characters in length and may contain numbers and lowercase letters only.

What is the duration of blob storage lease? ›

About blob leases

A lease creates and manages a lock on a blob for write and delete operations. The lock duration can be 15 to 60 seconds, or can be infinite. A lease on a blob provides exclusive write and delete access to the blob.

How do I change my Azure token expiration time? ›

As of January 30, 2021 you cannot configure refresh and session token lifetimes. Azure Active Directory no longer honors refresh and session token configuration in existing policies. New tokens issued after existing tokens have expired are now set to the default configuration.

How long does a token expire? ›

By default, access tokens are valid for 60 days and programmatic refresh tokens are valid for a year. The member must reauthorize your application when refresh tokens expire.

How do I know when my JWT token expires? ›

To determine the expiration time of the current JWT token that was created for your Azure AD connector app, you can decode the token and check the value of the “exp” claim. There are various online JWT decoding tools available that you can use to decode the token, such as jwt.io or jwt-decode.com.

How does a token expire? ›

User access tokens created by a GitHub App will expire after eight hours by default. Owners of GitHub Apps can optionally change the default expiration period for their user access tokens, or configure the tokens to never expire.

How do I renew my SAS token? ›

Once a token has expired, you will need to create a new SAS token with new expiry date and use that. As such there's no mechanism to extend the expiry of an existing token. If you have created a SAS token using a Shared Access Policy and that has expiry date defined, then the answer is yes.

Top Articles
Latest Posts
Article information

Author: Pres. Lawanda Wiegand

Last Updated:

Views: 5908

Rating: 4 / 5 (51 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Pres. Lawanda Wiegand

Birthday: 1993-01-10

Address: Suite 391 6963 Ullrich Shore, Bellefort, WI 01350-7893

Phone: +6806610432415

Job: Dynamic Manufacturing Assistant

Hobby: amateur radio, Taekwondo, Wood carving, Parkour, Skateboarding, Running, Rafting

Introduction: My name is Pres. Lawanda Wiegand, I am a inquisitive, helpful, glamorous, cheerful, open, clever, innocent person who loves writing and wants to share my knowledge and understanding with you.