-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
11097e7
commit 5be4477
Showing
7 changed files
with
251 additions
and
22 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package connection | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/flanksource/duty/context" | ||
"github.com/flanksource/duty/models" | ||
"gocloud.dev/secrets" | ||
"gocloud.dev/secrets/awskms" | ||
) | ||
|
||
type AWSKMS struct { | ||
AWSConnection `json:",inline"` | ||
|
||
// keyID can be an alias (eg: alias/ExampleAlias?region=us-east-1) or the ARN | ||
KeyID string `json:"keyID,omitempty"` | ||
} | ||
|
||
func (t *AWSKMS) Populate(ctx ConnectionContext) error { | ||
return t.AWSConnection.Populate(ctx) | ||
} | ||
|
||
func (t *AWSKMS) FromModel(conn models.Connection) { | ||
t.AWSConnection.FromModel(conn) | ||
t.KeyID = conn.Properties["keyID"] | ||
} | ||
|
||
func (t *AWSKMS) SecretKeeper(ctx context.Context) (*secrets.Keeper, error) { | ||
awsConfig, err := t.AWSConnection.Client(ctx) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create AWS client: %w", err) | ||
} | ||
|
||
kmsClient, err := awskms.DialV2(awsConfig) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create AWS KMS client: %w", err) | ||
} | ||
|
||
keeper := awskms.OpenKeeperV2(kmsClient, t.KeyID, nil) | ||
return keeper, nil | ||
} |
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package connection | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" | ||
"github.com/Azure/azure-sdk-for-go/sdk/keyvault/azkeys" | ||
"github.com/flanksource/duty/context" | ||
"github.com/flanksource/duty/models" | ||
"gocloud.dev/secrets" | ||
"gocloud.dev/secrets/azurekeyvault" | ||
) | ||
|
||
type AzureKeyVault struct { | ||
AzureConnection `json:",inline"` | ||
|
||
// keyID is a URL to the key in the format | ||
// https://<vault-name>.vault.azure.net/keys/<key-name> | ||
KeyID string `json:"keyID,omitempty"` | ||
} | ||
|
||
func (t *AzureKeyVault) Populate(ctx ConnectionContext) error { | ||
return t.AzureConnection.HydrateConnection(ctx) | ||
} | ||
|
||
func (t *AzureKeyVault) FromModel(conn models.Connection) { | ||
t.AzureConnection.FromModel(conn) | ||
t.KeyID = conn.Properties["keyID"] | ||
} | ||
|
||
func (t *AzureKeyVault) SecretKeeper(ctx context.Context) (*secrets.Keeper, error) { | ||
creds, err := t.AzureConnection.TokenCredential() | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create Azure token credential: %w", err) | ||
} | ||
|
||
clientMaker := func(keyVaultURI string) (*azkeys.Client, error) { | ||
return azkeys.NewClient(keyVaultURI, creds, &azkeys.ClientOptions{ | ||
ClientOptions: policy.ClientOptions{}, | ||
}) | ||
} | ||
|
||
keeper, err := azurekeyvault.OpenKeeper(clientMaker, t.KeyID, nil) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create Azure Key Vault keeper: %w", err) | ||
} | ||
|
||
return keeper, nil | ||
} |
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package connection | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/flanksource/duty/context" | ||
"github.com/flanksource/duty/models" | ||
"gocloud.dev/secrets" | ||
"gocloud.dev/secrets/gcpkms" | ||
) | ||
|
||
type GCPKMS struct { | ||
GCPConnection `json:",inline"` | ||
|
||
// keyID points to the key in the format | ||
// projects/MYPROJECT/locations/MYLOCATION/keyRings/MYKEYRING/cryptoKeys/MYKEY | ||
KeyID string `json:"keyID,omitempty"` | ||
} | ||
|
||
func (t *GCPKMS) Populate(ctx ConnectionContext) error { | ||
return t.GCPConnection.HydrateConnection(ctx) | ||
} | ||
|
||
func (t *GCPKMS) FromModel(conn models.Connection) { | ||
t.GCPConnection.FromModel(conn) | ||
t.KeyID = conn.Properties["keyID"] | ||
} | ||
|
||
func (t *GCPKMS) SecretKeeper(ctx context.Context) (*secrets.Keeper, error) { | ||
oauthToken, err := t.GCPConnection.TokenSource(ctx, "https://www.googleapis.com/auth/cloudkms") | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create GCP oauth2 token: %w", err) | ||
} | ||
|
||
kmsClient, _, err := gcpkms.Dial(ctx, oauthToken) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create GCP KMS client: %w", err) | ||
} | ||
|
||
keeper := gcpkms.OpenKeeper(kmsClient, t.KeyID, nil) | ||
return keeper, nil | ||
} |
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
Oops, something went wrong.