Skip to content

Commit

Permalink
tier: Add support of service principal to Azure (#254)
Browse files Browse the repository at this point in the history
* tier: Add support of service principal to Azure
* Address Harsha comments
* Adress KP comments

---------

Co-authored-by: Anis Elleuch <[email protected]>
  • Loading branch information
vadmeste and Anis Elleuch authored Dec 11, 2023
1 parent 9ef2480 commit d20cff0
Show file tree
Hide file tree
Showing 4 changed files with 437 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/vulncheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [ 1.21.4 ]
go-version: [ 1.21.5 ]
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v3
Expand Down
35 changes: 35 additions & 0 deletions tier-azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,17 @@

package madmin

import "errors"

//go:generate msgp -file $GOFILE

// ServicePrincipalAuth holds fields for a successful SP authentication with Azure
type ServicePrincipalAuth struct {
TenantID string `json:",omitempty"`
ClientID string `json:",omitempty"`
ClientSecret string `json:",omitempty"`
}

// TierAzure represents the remote tier configuration for Azure Blob Storage.
type TierAzure struct {
Endpoint string `json:",omitempty"`
Expand All @@ -30,11 +39,37 @@ type TierAzure struct {
Prefix string `json:",omitempty"`
Region string `json:",omitempty"`
StorageClass string `json:",omitempty"`

SPAuth ServicePrincipalAuth `json:",omitempty"`
}

// IsSPEnabled returns true if all SP related fields are provided
func (ti TierAzure) IsSPEnabled() bool {
return ti.SPAuth.TenantID != "" && ti.SPAuth.ClientID != "" && ti.SPAuth.ClientSecret != ""
}

// AzureOptions supports NewTierAzure to take variadic options
type AzureOptions func(*TierAzure) error

// AzureServicePrincipal helper to supply optional service principal credentials
func AzureServicePrincipal(tenantID, clientID, clientSecret string) func(az *TierAzure) error {
return func(az *TierAzure) error {
if tenantID == "" {
return errors.New("empty tenant ID unsupported")
}
if clientID == "" {
return errors.New("empty client ID unsupported")
}
if clientSecret == "" {
return errors.New("empty client secret unsupported")
}
az.SPAuth.TenantID = tenantID
az.SPAuth.ClientID = clientID
az.SPAuth.ClientSecret = clientSecret
return nil
}
}

// AzurePrefix helper to supply optional object prefix to NewTierAzure
func AzurePrefix(prefix string) func(az *TierAzure) error {
return func(az *TierAzure) error {
Expand Down
Loading

0 comments on commit d20cff0

Please sign in to comment.