Skip to content

Commit

Permalink
Sync with main
Browse files Browse the repository at this point in the history
  • Loading branch information
vibhansa-msft committed Feb 16, 2024
2 parents 1d70adb + f90d747 commit 16b9d3b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
## 2.2.0 (Unreleased)
## 2.2.1 (Unreleased)
**Bug Fixes**

**Features**

## 2.2.0 (2024-01-24)
**Bug Fixes**
- Invalidate attribute cache entry on `PathAlreadyExists` error in create directory operation.
- When `$HOME` environment variable is not present, use the current directory.
Expand Down
1 change: 1 addition & 0 deletions blobfuse2-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ stages:
- script: |
sudo apt-get update --fix-missing
sudo apt-get install ruby-dev build-essential pkg-config cmake gcc g++ rpm $(fuselib) -y
sudo gem install dotenv -v 2.8.1
sudo gem install fpm -V
displayName: "Installing Dependencies"
Expand Down
32 changes: 21 additions & 11 deletions component/azstorage/azauthmsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"math/rand"
"os"
"os/exec"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -122,7 +123,8 @@ func (azmsi *azAuthMSI) fetchTokenFromCLI() (*common.OAuthTokenInfo, error) {
return nil, fmt.Errorf(msg)
}

log.Info("azAuthMSI::fetchTokenFromCLI : Successfully fetched token from Azure CLI : %s", output)
log.Info("azAuthMSI::fetchTokenFromCLI : Successfully fetched token from Azure CLI")
log.Debug("azAuthMSI::fetchTokenFromCLI : Token: %s", output)
t := struct {
AccessToken string `json:"accessToken"`
Authority string `json:"_authority"`
Expand All @@ -141,7 +143,7 @@ func (azmsi *azAuthMSI) fetchTokenFromCLI() (*common.OAuthTokenInfo, error) {
return nil, err
}
// the Azure CLI's "expiresOn" is local time
_, err = time.ParseInLocation("2006-01-02 15:04:05.999999", t.ExpiresOn, time.Local)
expiresOn, err := time.ParseInLocation("2006-01-02 15:04:05.999999", t.ExpiresOn, time.Local)
if err != nil {
return nil, fmt.Errorf("error parsing token expiration time %q: %v", t.ExpiresOn, err)
}
Expand All @@ -150,7 +152,7 @@ func (azmsi *azAuthMSI) fetchTokenFromCLI() (*common.OAuthTokenInfo, error) {
Token: adal.Token{
AccessToken: t.AccessToken,
RefreshToken: t.RefreshToken,
ExpiresOn: json.Number(t.ExpiresOn),
ExpiresOn: json.Number(strconv.FormatInt(expiresOn.Unix(), 10)),
Resource: t.Resource,
Type: t.TokenType,
},
Expand Down Expand Up @@ -202,7 +204,8 @@ func (azmsi *azAuthBlobMSI) getCredential() interface{} {

var tc azblob.TokenCredential
if norefresh {
log.Info("azAuthBlobMSI::getCredential : MSI Token over CLI retrieved %s (%d)", token.AccessToken, token.Expires())
log.Info("azAuthBlobMSI::getCredential : MSI Token over CLI retrieved")
log.Debug("azAuthBlobMSI::getCredential : Token: %s (%s)", token.AccessToken, token.Expires())
// We are running in cli mode so token can not be refreshed, on expiry just get the new token
tc = azblob.NewTokenCredential(token.AccessToken, func(tc azblob.TokenCredential) time.Duration {
for failCount := 0; failCount < 5; failCount++ {
Expand All @@ -215,7 +218,8 @@ func (azmsi *azAuthBlobMSI) getCredential() interface{} {

// set the new token value
tc.SetToken(newToken.AccessToken)
log.Debug("azAuthBlobMSI::getCredential : MSI Token retrieved %s (%d)", newToken.AccessToken, newToken.Expires())
log.Info("azAuthBlobMSI::getCredential : New MSI Token over CLI retrieved")
log.Debug("azAuthBlobMSI::getCredential : New Token: %s (%s)", newToken.AccessToken, newToken.Expires())

// Get the next token slightly before the current one expires
return getNextExpiryTimer(&newToken.Token)
Expand All @@ -225,7 +229,8 @@ func (azmsi *azAuthBlobMSI) getCredential() interface{} {
return 0
})
} else {
log.Info("azAuthBlobMSI::getCredential : MSI Token retrieved %s (%d)", token.AccessToken, token.Expires())
log.Info("azAuthBlobMSI::getCredential : MSI Token retrieved")
log.Debug("azAuthBlobMSI::getCredential : Token: %s (%s)", token.AccessToken, token.Expires())
// Using token create the credential object, here also register a call back which refreshes the token
tc = azblob.NewTokenCredential(token.AccessToken, func(tc azblob.TokenCredential) time.Duration {
// token, err := azmsi.fetchToken(msi_endpoint)
Expand All @@ -243,7 +248,8 @@ func (azmsi *azAuthBlobMSI) getCredential() interface{} {

// set the new token value
tc.SetToken(newToken.AccessToken)
log.Debug("azAuthBlobMSI::getCredential : MSI Token retrieved %s (%d)", newToken.AccessToken, newToken.Expires())
log.Info("azAuthBlobMSI::getCredential : New MSI Token retrieved")
log.Debug("azAuthBlobMSI::getCredential : New Token: %s (%s)", newToken.AccessToken, newToken.Expires())

// Get the next token slightly before the current one expires
return getNextExpiryTimer(newToken)
Expand Down Expand Up @@ -300,7 +306,8 @@ func (azmsi *azAuthBfsMSI) getCredential() interface{} {

var tc azbfs.TokenCredential
if norefresh {
log.Info("azAuthBfsMSI::getCredential : MSI Token over CLI retrieved %s (%d)", token.AccessToken, token.Expires())
log.Info("azAuthBfsMSI::getCredential : MSI Token over CLI retrieved")
log.Debug("azAuthBfsMSI::getCredential : Token: %s (%s)", token.AccessToken, token.Expires())
// We are running in cli mode so token can not be refreshed, on expiry just get the new token
tc = azbfs.NewTokenCredential(token.AccessToken, func(tc azbfs.TokenCredential) time.Duration {
for failCount := 0; failCount < 5; failCount++ {
Expand All @@ -313,7 +320,8 @@ func (azmsi *azAuthBfsMSI) getCredential() interface{} {

// set the new token value
tc.SetToken(newToken.AccessToken)
log.Debug("azAuthBfsMSI::getCredential : MSI Token retrieved %s (%d)", newToken.AccessToken, newToken.Expires())
log.Info("azAuthBfsMSI::getCredential : New MSI Token over CLI retrieved")
log.Debug("azAuthBfsMSI::getCredential : New Token: %s (%s)", newToken.AccessToken, newToken.Expires())

// Get the next token slightly before the current one expires
return getNextExpiryTimer(&newToken.Token)
Expand All @@ -322,7 +330,8 @@ func (azmsi *azAuthBfsMSI) getCredential() interface{} {
return 0
})
} else {
log.Info("azAuthBfsMSI::getCredential : MSI Token retrieved %s (%d)", token.AccessToken, token.Expires())
log.Info("azAuthBfsMSI::getCredential : MSI Token retrieved")
log.Debug("azAuthBfsMSI::getCredential : Token: %s (%s)", token.AccessToken, token.Expires())
// Using token create the credential object, here also register a call back which refreshes the token
tc = azbfs.NewTokenCredential(token.AccessToken, func(tc azbfs.TokenCredential) time.Duration {
// token, err := azmsi.fetchToken(msi_endpoint)
Expand All @@ -340,7 +349,8 @@ func (azmsi *azAuthBfsMSI) getCredential() interface{} {

// set the new token value
tc.SetToken(newToken.AccessToken)
log.Debug("azAuthBfsMSI::getCredential : MSI Token retrieved %s (%d)", newToken.AccessToken, newToken.Expires())
log.Info("azAuthBfsMSI::getCredential : New MSI Token retrieved")
log.Debug("azAuthBfsMSI::getCredential : New Token: %s (%s)", newToken.AccessToken, newToken.Expires())

// Get the next token slightly before the current one expires
return getNextExpiryTimer(newToken)
Expand Down
6 changes: 4 additions & 2 deletions component/azstorage/azauthspn.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ func (azspn *azAuthBlobSPN) getCredential() interface{} {

// set the new token value
tc.SetToken(spt.Token().AccessToken)
log.Debug("azAuthBlobSPN::getCredential : SPN Token retrieved %s (%d)", spt.Token().AccessToken, spt.Token().Expires())
log.Info("azAuthBlobSPN::getCredential : SPN Token retrieved")
log.Debug("azAuthBlobSPN::getCredential : Token: %s (%s)", spt.Token().AccessToken, spt.Token().Expires())

// Get the next token slightly before the current one expires
return getNextExpiryTimerSPN(spt)
Expand Down Expand Up @@ -186,7 +187,8 @@ func (azspn *azAuthBfsSPN) getCredential() interface{} {

// set the new token value
tc.SetToken(spt.Token().AccessToken)
log.Debug("azAuthBfsSPN::getCredential : SPN Token retrieved %s (%d)", spt.Token().AccessToken, spt.Token().Expires())
log.Info("azAuthBfsSPN::getCredential : SPN Token retrieved")
log.Debug("azAuthBfsSPN::getCredential : Token: %s (%s)", spt.Token().AccessToken, spt.Token().Expires())

// Get the next token slightly before the current one expires
return getNextExpiryTimerSPN(spt)
Expand Down

0 comments on commit 16b9d3b

Please sign in to comment.