-
Notifications
You must be signed in to change notification settings - Fork 360
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
WX-1264 Don't expire an unexpirable filesystem #7216
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ import java.net.URI | |
import java.nio.file._ | ||
import java.nio.file.spi.FileSystemProvider | ||
import java.time.temporal.ChronoUnit | ||
import java.time.{Duration, Instant, OffsetDateTime} | ||
import java.time.{Duration, OffsetDateTime} | ||
import java.util.UUID | ||
import scala.jdk.CollectionConverters._ | ||
import scala.util.{Failure, Success, Try} | ||
|
@@ -32,10 +32,6 @@ case class AzureFileSystemAPI(private val provider: FileSystemProvider = new Azu | |
* See BlobSasTokenGenerator for more information on how a SAS token is generated | ||
*/ | ||
object BlobFileSystemManager { | ||
def parseTokenExpiry(token: AzureSasCredential): Option[Instant] = for { | ||
expiryString <- token.getSignature.split("&").find(_.startsWith("se")).map(_.replaceFirst("se=","")).map(_.replace("%3A", ":")) | ||
instant = Instant.parse(expiryString) | ||
} yield instant | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This functionality moved to |
||
|
||
def buildConfigMap(credential: AzureSasCredential, container: BlobContainerName): Map[String, Object] = { | ||
// Special handling is done here to provide a special key value pair if the placeholder token is provided | ||
|
@@ -226,9 +222,12 @@ case class NativeBlobSasTokenGenerator(subscription: Option[SubscriptionId] = No | |
* | ||
* @return an AzureSasCredential for accessing a blob container | ||
*/ | ||
def generateBlobSasToken(endpoint: EndpointURL, container: BlobContainerName): Try[AzureSasCredential] = for { | ||
bcc <- AzureUtils.buildContainerClientFromLocalEnvironment(container.toString, endpoint.toString, subscription.map(_.toString)) | ||
bsssv = new BlobServiceSasSignatureValues(OffsetDateTime.now.plusDays(1), bcsp) | ||
asc = new AzureSasCredential(bcc.generateSas(bsssv)) | ||
} yield asc | ||
def generateBlobSasToken(endpoint: EndpointURL, container: BlobContainerName): Try[AzureSasCredential] = { | ||
val c = AzureUtils.buildContainerClientFromLocalEnvironment(container.toString, endpoint.toString, subscription.map(_.toString)) | ||
|
||
c.map { bcc => | ||
val bsssv = new BlobServiceSasSignatureValues(OffsetDateTime.now.plusDays(1), bcsp) | ||
new AzureSasCredential(bcc.generateSas(bsssv)) | ||
}.orElse(Try(BlobFileSystemManager.PLACEHOLDER_TOKEN)) | ||
} | ||
} |
56 changes: 46 additions & 10 deletions
56
filesystems/blob/src/test/scala/cromwell/filesystems/blob/AzureFileSystemSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,61 @@ | ||
package cromwell.filesystems.blob | ||
|
||
import com.azure.core.credential.AzureSasCredential | ||
import com.azure.storage.blob.nio.{AzureFileSystem, AzureFileSystemProvider} | ||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
import java.time.Instant | ||
import java.time.{Duration, Instant} | ||
import java.time.temporal.ChronoUnit | ||
import scala.compat.java8.OptionConverters._ | ||
import scala.jdk.CollectionConverters._ | ||
|
||
class AzureFileSystemSpec extends AnyFlatSpec with Matchers { | ||
val now = Instant.now() | ||
val container = BlobContainerName("testConainer") | ||
val exampleSas = BlobPathBuilderFactorySpec.buildExampleSasToken(now) | ||
val exampleConfig = BlobFileSystemManager.buildConfigMap(exampleSas, container) | ||
val exampleStorageEndpoint = BlobPathBuilderSpec.buildEndpoint("testStorageAccount") | ||
val exampleCombinedEndpoint = BlobFileSystemManager.combinedEnpointContainerUri(exampleStorageEndpoint, container) | ||
|
||
it should "parse an expiration from a sas token" in { | ||
val fiveMinutes: Duration = Duration.of(5, ChronoUnit.MINUTES) | ||
|
||
private def makeFilesystemWithExpiration(expiration: Instant): AzureFileSystem = | ||
makeFilesystemWithCreds(BlobPathBuilderFactorySpec.buildExampleSasToken(expiration)) | ||
|
||
private def makeFilesystemWithCreds(creds: AzureSasCredential): AzureFileSystem = { | ||
val storageEndpoint = BlobPathBuilderSpec.buildEndpoint("testStorageAccount") | ||
val container = BlobContainerName("testContainer") | ||
val combinedEndpoint = BlobFileSystemManager.combinedEnpointContainerUri(storageEndpoint, container) | ||
|
||
val provider = new AzureFileSystemProvider() | ||
val filesystem : AzureFileSystem = provider.newFileSystem(exampleCombinedEndpoint, exampleConfig.asJava).asInstanceOf[AzureFileSystem] | ||
provider.newFileSystem( | ||
combinedEndpoint, | ||
BlobFileSystemManager.buildConfigMap(creds, container).asJava | ||
).asInstanceOf[AzureFileSystem] | ||
} | ||
|
||
it should "parse an expiration from a sas token" in { | ||
val now = Instant.now() | ||
val filesystem : AzureFileSystem = makeFilesystemWithExpiration(now) | ||
filesystem.getExpiry.asScala shouldBe Some(now) | ||
filesystem.getFileStores.asScala.map(_.name()).exists(_ == container.value) shouldBe true | ||
filesystem.getFileStores.asScala.map(_.name()).exists(_ == "testContainer") shouldBe true | ||
} | ||
|
||
it should "not be expired when the token is fresh" in { | ||
val anHourFromNow = Instant.now().plusSeconds(3600) | ||
val filesystem : AzureFileSystem = makeFilesystemWithExpiration(anHourFromNow) | ||
filesystem.isExpired(fiveMinutes) shouldBe false | ||
} | ||
|
||
it should "be expired when we're within the buffer" in { | ||
val threeMinutesFromNow = Instant.now().plusSeconds(180) | ||
val filesystem : AzureFileSystem = makeFilesystemWithExpiration(threeMinutesFromNow) | ||
filesystem.isExpired(fiveMinutes) shouldBe true | ||
} | ||
|
||
it should "be expired when the token is stale" in { | ||
val anHourAgo = Instant.now().minusSeconds(3600) | ||
val filesystem : AzureFileSystem = makeFilesystemWithExpiration(anHourAgo) | ||
filesystem.isExpired(fiveMinutes) shouldBe true | ||
} | ||
|
||
it should "not be expired with public credentials" in { | ||
val fileSystem = makeFilesystemWithCreds(BlobFileSystemManager.PLACEHOLDER_TOKEN) | ||
fileSystem.isExpired(fiveMinutes) shouldBe false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reasons
this.expiry
could benull
:In the former case, it's correct to return
false
. In the latter case, the token may actually be expired, but we have no way of knowing, so it seems best to assume it isn't and let things fail and be reopened when it eventually is.