Skip to content
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

Error parsing expiration date "" #668

Open
petganev opened this issue Dec 10, 2021 · 0 comments
Open

Error parsing expiration date "" #668

petganev opened this issue Dec 10, 2021 · 0 comments

Comments

@petganev
Copy link

Hi, recently I'm receiving an error when using "terrafrom" from within the Azure Cloud Shell. See the error description bellow:

╷
│ Error: unable to get authorization token for resource manager: converting Authorization Token to an ADAL Token: Error parsing Token Expiration Date "": Error parsing expiration date "".
│
│ CloudShell Error:
│ parsing time "" as "2006-01-02T15:04:05Z07:00": cannot parse "" as "2006"
│
│ CLI Error:
│ parsing time "" as "2006-01-02 15:04:05.999999": cannot parse "" as "2006"
│
│   with provider["registry.terraform.io/hashicorp/azurerm"],
│   on main.tf line 20, in provider "azurerm":
│   20: provider "azurerm" {
│
╵

When validating the Azure token I receive this:

$ az account get-access-token
{
  "accessToken": "some token data",
  "expiresOn": null,
  "subscription": "subscription id",
  "tenant": "token id",
  "tokenType": "Bearer"
}

Clearly there isn't any expiration date/time.

I traced the code chain and it seams that Terrafrom azurerm uses master/autorest/azure/cli/token.go::ToADALToken

// ToADALToken converts an Azure CLI `Token`` to an `adal.Token``
func (t Token) ToADALToken() (converted adal.Token, err error) {
	tokenExpirationDate, err := ParseExpirationDate(t.ExpiresOn)
	if err != nil {
		err = fmt.Errorf("Error parsing Token Expiration Date %q: %+v", t.ExpiresOn, err)
		return
	}

	difference := tokenExpirationDate.Sub(date.UnixEpoch())

	converted = adal.Token{
		AccessToken:  t.AccessToken,
		Type:         t.TokenType,
		ExpiresIn:    "3600",
		ExpiresOn:    json.Number(strconv.Itoa(int(difference.Seconds()))),
		RefreshToken: t.RefreshToken,
		Resource:     t.Resource,
	}
	return
}

As it may be seen as a Terrafrom azurerm issue, for me is clearly an issue with ToADALToken as nativly Azure CLI returns an empty value in expireon field and should be addressed within ToADALToken.

Thanks for taking this issue in consideration and find an appropriate fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant