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

Add PreSignURL method #255

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f9f205f
Add PreSignRequest to stow container
EngHabu Mar 16, 2022
1190b61
Add stubs for sftp and swift
EngHabu Mar 17, 2022
b6548d4
cleanup
EngHabu Mar 17, 2022
57524be
Implement Presigned URL for Azure
EngHabu Mar 23, 2022
e1ea081
Add Azure Unit Test
EngHabu Mar 23, 2022
61cf833
Merge pull request #1 from flyteorg/signed-url
EngHabu Mar 23, 2022
8e760b6
Rename module to flyteorg/stow
EngHabu Mar 26, 2022
0d51bcb
Support ContentMD5 as an optional param
EngHabu Apr 7, 2022
8ee1921
Merge pull request #3 from flyteorg/rename
EngHabu Apr 7, 2022
b9d38a1
Merge branch 'master' of github.com:flyteorg/stow into content-md5
EngHabu Apr 7, 2022
31630d5
Merge pull request #2 from flyteorg/content-md5
EngHabu Apr 7, 2022
cab99a8
Upgrade dependencies
mayitbeegh Apr 12, 2022
2a2e10f
Merge pull request #4 from flyteorg/upgrade-dependencies
mayitbeegh Apr 13, 2022
536e0c9
Use latest google cloud lib
EngHabu Apr 28, 2022
9495372
Update all deps
EngHabu Apr 28, 2022
9c3f5f9
Merge pull request #5 from flyteorg/gcp-presigned
EngHabu Apr 28, 2022
6237dc1
combine write and update to one request
ckiosidis Jul 14, 2022
e9c5e6f
Merge pull request #6 from ckiosidis/avoid-double-write-to-gcs
EngHabu Jul 15, 2022
0266c8e
adding sovereign cloud support
gvashishtha Aug 1, 2023
a953565
defaulting to public
gvashishtha Aug 1, 2023
1a6e32e
updating docs
gvashishtha Aug 1, 2023
54b0bc9
populating defaults correctly
gvashishtha Aug 1, 2023
d4dcff2
put defaults at top of file
gvashishtha Aug 1, 2023
78e3158
clean up bool parsing
gvashishtha Aug 1, 2023
52271ec
updating comments
gvashishtha Aug 2, 2023
6bd7f9a
Merge pull request #7 from gvashishtha/gkv/add-azure-sovereign
kumare3 Aug 2, 2023
c7a3695
Adds Azure sovereign cloud support to getSignedUrl (#8)
gvashishtha Aug 22, 2023
2b4d0dc
Azure AD authentication support (and SDK upgrade) (#9)
tkent Oct 19, 2023
d829e76
check for error before accessing s3 response (#10)
EngHabu Oct 24, 2023
9b497fb
Add extra header to signed url (#13)
pingsutw Mar 5, 2024
2912959
PreSignRequest returns a PresignResponse instead (#14)
pingsutw Mar 11, 2024
ad68b70
Ensure that requestHeaders is correctly assigned a value (#15)
pingsutw Mar 12, 2024
632adef
Update azure sdk azblob 1.1.0 -> 1.4.0 / azcore 1.7.2 -> 1.13.0 (#16)
ddl-ebrown Jul 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ tests.xml
vendor/

.vscode/
.terragrunt-cache
136 changes: 111 additions & 25 deletions azure/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,92 @@ package azure

import (
"errors"
"fmt"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
"net/url"
"strconv"

az "github.com/Azure/azure-sdk-for-go/storage"
"github.com/graymeta/stow"
"github.com/flyteorg/stow"
)

// ConfigAccount and ConfigKey are the supported configuration items for
// Azure blob storage.
// ConfigAccount should be the name of your storage account in the Azure portal
// ConfigKey should be an access key
// ConfigDomainSuffix the domain suffix to use for storage account communication. The default is the Azure Public cloud
// ConfigUploadConcurrency the upload concurrency to use when uploading. Default is 4.
// ConfigBaseUrlDepreciated Kept for backwards compatability, use ConfigDomainSuffix instead
const (
ConfigAccount = "account"
ConfigKey = "key"
ConfigAccount = "account"
ConfigKey = "key"
ConfigDomainSuffix = "domain_suffix"
ConfigUploadConcurrency = "upload_concurrency"
ConfigBaseUrlDepreciated = "base_url"
)

// Removed configuration values, will cause failures if used.
const (
ConfigUseHttpsRemoved = "use_https"
ConfigApiVersionRemoved = "api_version"
)

var removedConfigKeys = []string{ConfigUseHttpsRemoved, ConfigApiVersionRemoved}

// Kind is the kind of Location this package provides.
const Kind = "azure"

// defaultDomainSuffix is the domain suffix for the Azure Public Cloud
const defaultDomainSuffix = "core.windows.net"

// defaultUploadConcurrency is the default upload concurrency
const defaultUploadConcurrency = 4

func init() {
validatefn := func(config stow.Config) error {
_, ok := config.Config(ConfigAccount)
if !ok {
return errors.New("missing account id")
}
_, ok = config.Config(ConfigKey)
if !ok {
return errors.New("missing auth key")
for _, removedConfigKey := range removedConfigKeys {
_, ok = config.Config(removedConfigKey)
if ok {
return fmt.Errorf("removed config option used [%s]", removedConfigKey)
}
}
return nil
}
makefn := func(config stow.Config) (stow.Location, error) {
_, ok := config.Config(ConfigAccount)
acctName, ok := config.Config(ConfigAccount)
if !ok {
return nil, errors.New("missing account id")
}
_, ok = config.Config(ConfigKey)
if !ok {
return nil, errors.New("missing auth key")

var uploadConcurrency int
var err error
uploadConcurrencyStr, ok := config.Config(ConfigUploadConcurrency)
if !ok || len(uploadConcurrencyStr) == 0 {
uploadConcurrency = defaultUploadConcurrency
} else {
uploadConcurrency, err = strconv.Atoi(uploadConcurrencyStr)
if err != nil {
return nil, fmt.Errorf("invalid upload concurrency [%v]", uploadConcurrency)
}
}
l := &location{
config: config,
accountName: acctName,
uploadConcurrency: uploadConcurrency,
}
var err error
l.client, err = newBlobStorageClient(l.config)

l.client, l.preSigner, err = makeAccountClient(config)
if err != nil {
return nil, err
}

// test the connection
_, _, err = l.Containers("", stow.CursorStart, 1)
if err != nil {
return nil, err
}

return l, nil
}
kindfn := func(u *url.URL) bool {
Expand All @@ -60,19 +96,69 @@ func init() {
stow.Register(Kind, makefn, kindfn, validatefn)
}

func newBlobStorageClient(cfg stow.Config) (*az.BlobStorageClient, error) {
acc, ok := cfg.Config(ConfigAccount)
// makeAccountClient is a factory function for producing client instances
func makeAccountClient(cfg stow.Config) (*azblob.Client, RequestPreSigner, error) {
accountName, ok := cfg.Config(ConfigAccount)
if !ok {
return nil, errors.New("missing account id")
return nil, nil, errors.New("missing account id")
}

domainSuffix := resolveAzureDomainSuffix(cfg)
serviceUrl := fmt.Sprintf("https://%s.blob.%s", accountName, domainSuffix)

key, ok := cfg.Config(ConfigKey)
if !ok {
return nil, errors.New("missing auth key")
if ok && key != "" {
return newSharedKeyClient(accountName, key, serviceUrl)
}
basicClient, err := az.NewBasicClient(acc, key)
return newDefaultAzureIdentityClient(serviceUrl)
}

// newSharedKeyClient creates client objects for working with a storage account
// using shared keys.
func newSharedKeyClient(accountName, key, serviceUrl string) (*azblob.Client, RequestPreSigner, error) {
sharedKeyCred, err := azblob.NewSharedKeyCredential(accountName, key)
if err != nil {
return nil, errors.New("bad credentials")
return nil, nil, err
}
client, err := azblob.NewClientWithSharedKeyCredential(
serviceUrl,
sharedKeyCred,
nil)
if err != nil {
return nil, nil, err
}
preSigner, err := NewSharedKeyRequestPreSigner(accountName, key)
if err != nil {
return nil, nil, err
}
return client, preSigner, nil
}

// newDefaultAzureIdentityClient creates client objects for working with a storage
// account using Azure AD auth, resolved using the default Azure credential chain.
func newDefaultAzureIdentityClient(serviceUrl string) (*azblob.Client, RequestPreSigner, error) {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
return nil, nil, err
}
client, err := azblob.NewClient(serviceUrl, cred, nil)
if err != nil {
return nil, nil, err
}
preSigner, err := NewDelegatedKeyPreSigner(client.ServiceClient())
return client, preSigner, nil
}

// resolveAzureDomainSuffix returns the Azure domain suffix to use
func resolveAzureDomainSuffix(cfg stow.Config) string {
domainSuffix, ok := cfg.Config(ConfigDomainSuffix)
if ok && domainSuffix != "" {
return domainSuffix
}

domainSuffix, ok = cfg.Config(ConfigBaseUrlDepreciated)
if ok && domainSuffix != "" {
return domainSuffix
}
client := basicClient.GetBlobService()
return &client, err
return defaultDomainSuffix
}
Loading