-
Notifications
You must be signed in to change notification settings - Fork 3k
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
az account get-access-token
: Use epoch expiresOn
/expires_on
#19700
Comments
az account get-access-token
: Use integer expiresOn
/expires_on
az account get-access-token
: Use epoch expiresOn
/expires_on
Another possible approach is to
A downside with this approach is that it breaks interoperability between certain combinations of Azure CLI and Azure Identity. For example:
The bottom line is that we can't live with |
Now that #27410 brings this discussion back to life, I would personally prefer introducing epoch Even though it has naming inconsistency with other properties of Azure CLI output, it is consistent with other services or tools, such as
so this "inconsistency with other properties of Azure CLI output" should be acceptable. In fact, a deeper reason for the inconsistency comes from the fact that ARM uses camelCase as JSON keys, while authentication-related services, such as AAD and managed identity, use snake_case as JSON keys. When they meet in Azure CLI, Azure CLI must coordinate them. A big advantage with this approach is that it introduces zero breaking change. On the other hand, |
Daylight Saving Time problemThe current local datetime string format According to https://aa.usno.navy.mil/faq/daylight_time
Consider
As there is no way for A code snippet demonstrating this: from datetime import datetime
from zoneinfo import ZoneInfo
tz = ZoneInfo("America/Los_Angeles")
dt = datetime(2023, 11, 5, 1, 15, tzinfo=tz, fold=0)
epoch0 = dt.timestamp() # The first 01:15
epoch1 = dt.timestamp() + 3600 # The second 01:15
dt0 = datetime.fromtimestamp(epoch0, tz=tz)
dt1 = datetime.fromtimestamp(epoch1, tz=tz)
print(epoch0, repr(dt0), dt0)
# output: 1699172100.0 datetime.datetime(2023, 11, 5, 1, 15, tzinfo=zoneinfo.ZoneInfo(key='America/Los_Angeles')) 2023-11-05 01:15:00-07:00
print(epoch1, repr(dt1), dt1)
# output: 1699175700.0 datetime.datetime(2023, 11, 5, 1, 15, fold=1, tzinfo=zoneinfo.ZoneInfo(key='America/Los_Angeles')) 2023-11-05 01:15:00-08:00 Notice the second
Because the current format When the timezone of the machine is set to Pacific Time, there will be 7200 seconds between dt0 = datetime.strptime('2023-11-05 01:15:00.00000', "%Y-%m-%d %H:%M:%S.%f")
dt1 = datetime.strptime('2023-11-05 02:15:00.00000', "%Y-%m-%d %H:%M:%S.%f")
print(dt1.timestamp() - dt0.timestamp())
# output: 7200.0 |
Year 2038 problemReturning I use this script to determine the max timestamp supported by Python: from datetime import datetime, timezone
import traceback
import time
max_epoch = time.time()
seconds_of_one_year = 365 * 24 * 3600
dt = None
while True:
try:
dt = datetime.fromtimestamp(max_epoch, tz=timezone.utc)
max_epoch += seconds_of_one_year
except:
traceback.print_exc()
break
print(dt) On Windows, the max year is 3000:
On Linux, the max year is 9999:
Even if Azure CLI can return an See https://stackoverflow.com/questions/46133223/maximum-value-of-timestamp |
Another reason for returning |
Do you think it could be possible to keep the token expiration in RFC3339 format and not Unix epoch, but to convert to UTC and add |
@antkmsft, we chose to use Unix epoch because many other Azure tools or services use it, such as MSAL, Azure SDKs, Managed Identity, as explained in #19700 (comment). Changing If you need UTC datetime, you may convert
See https://stackoverflow.com/questions/12400256/converting-epoch-time-into-the-datetime |
Context
Currently, the
expiresOn
property in the output ofaz account get-access-token
is a string representing the local time:This inherits from the ADAL behavior: https://github.com/AzureAD/azure-activedirectory-library-for-python/blob/35f9e003bed47936a1df3c6eb696691dc1fa91c3/adal/oauth2_client.py#L187
This causes various time computation problems and difficulties, especially for daylight saving time, such as
Other tools or services are already using an integer to represent the epoch time:
expires_on
: https://github.com/Azure/azure-sdk-for-python/blob/844e16db0abc553ab1adf104128cbf0e223af189/sdk/core/azure-core/azure/core/credentials.py#L14expires_on
: https://github.com/AzureAD/microsoft-authentication-library-for-python/blob/db6f001060e0adcc1edccac1a86ec05bd59f15f0/msal/token_cache.py#L176expires_on
:azure-cli/src/azure-cli-core/azure/cli/core/adal_authentication.py
Line 116 in 14cc787
This approach is universal and eliminates all necessary complexity.
Proposal
There are possible approaches:
expiresOn
in the output ofaz account get-access-token
to an integer representing the epoch time. This can be done during MSAL migration: ADAL to MSAL migration #18944expires_on
. This will not be a BREAKING CHANGE, but introduces naming inconsistency as other properties uses camelCase, butexpires_on
is snake_case.expiresOnEpoch
, but naming like this is non-conventional.The text was updated successfully, but these errors were encountered: