Skip to content

Commit

Permalink
Merge pull request #495 from dquagebeur/feature/azurekv
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddeco authored Mar 14, 2022
2 parents 608531e + 9f76861 commit 423cdde
Show file tree
Hide file tree
Showing 8 changed files with 880 additions and 158 deletions.
23 changes: 18 additions & 5 deletions controllers/kustomization_decryptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"sigs.k8s.io/yaml"

kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
"github.com/fluxcd/kustomize-controller/internal/sops/azkv"
intkeyservice "github.com/fluxcd/kustomize-controller/internal/sops/keyservice"
)

Expand All @@ -50,14 +51,18 @@ const (
DecryptionProviderSOPS = "sops"
// DecryptionVaultTokenFileName is the name of the file containing the Vault token
DecryptionVaultTokenFileName = "sops.vault-token"
// DecryptionAzureAuthFile is the Azure authentication file
DecryptionAzureAuthFile = "sops.azure-kv"
)

type KustomizeDecryptor struct {
client.Client
kustomization kustomizev1.Kustomization
homeDir string
ageIdentities []string
vaultToken string

kustomization kustomizev1.Kustomization
homeDir string
ageIdentities []string
vaultToken string
azureAADConfig *azkv.AADConfig
}

func NewDecryptor(kubeClient client.Client,
Expand Down Expand Up @@ -155,6 +160,14 @@ func (kd *KustomizeDecryptor) ImportKeys(ctx context.Context) error {
var ageIdentities []string
var vaultToken string
for name, value := range secret.Data {
if name == DecryptionAzureAuthFile {
azureConf := azkv.AADConfig{}
if err = azkv.LoadAADConfigFromBytes(value, &azureConf); err != nil {
return err
}
kd.azureAADConfig = &azureConf
continue
}
switch filepath.Ext(name) {
case ".asc":
keyPath, err := securejoin.SecureJoin(tmpDir, name)
Expand Down Expand Up @@ -272,7 +285,7 @@ func (kd KustomizeDecryptor) DataWithFormat(data []byte, inputFormat, outputForm

metadataKey, err := tree.Metadata.GetDataKeyWithKeyServices(
[]keyservice.KeyServiceClient{
intkeyservice.NewLocalClient(intkeyservice.NewServer(false, kd.homeDir, kd.vaultToken, kd.ageIdentities)),
intkeyservice.NewLocalClient(intkeyservice.NewServer(false, kd.homeDir, kd.vaultToken, kd.ageIdentities, kd.azureAADConfig)),
},
)
if err != nil {
Expand Down
Loading

0 comments on commit 423cdde

Please sign in to comment.