Skip to content

Commit

Permalink
test: enable workload identity test with deploy manifests
Browse files Browse the repository at this point in the history
Signed-off-by: Anish Ramasekar <anish.ramasekar@gmail.com>
  • Loading branch information
aramase committed Feb 24, 2022
1 parent ce4bf34 commit bf9bd3f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 12 deletions.
4 changes: 2 additions & 2 deletions pkg/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (
tokenTypeBearer = "Bearer"
// For Azure AD Workload Identity, the audience recommended for use is
// "api://AzureADTokenExchange"
defaultTokenAudience = "api://AzureADTokenExchange" //nolint
DefaultTokenAudience = "api://AzureADTokenExchange" //nolint
)

var (
Expand Down Expand Up @@ -329,7 +329,7 @@ func ParseServiceAccountToken(saTokens string) (string, error) {
}
klog.V(5).InfoS("successfully unmarshaled service account tokens")
if tokens.APIAzureADTokenExchange.Token == "" {
return "", fmt.Errorf("token for audience %s not found", defaultTokenAudience)
return "", fmt.Errorf("token for audience %s not found", DefaultTokenAudience)
}
return tokens.APIAzureADTokenExchange.Token, nil
}
50 changes: 44 additions & 6 deletions test/e2e/framework/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,28 @@ package deploy
import (
"fmt"
"io"
"net/http"
"os"
"path/filepath"
"strings"

"github.com/Azure/secrets-store-csi-driver-provider-azure/pkg/auth"
"github.com/Azure/secrets-store-csi-driver-provider-azure/test/e2e/framework"
"github.com/Azure/secrets-store-csi-driver-provider-azure/test/e2e/framework/exec"

"github.com/ghodss/yaml"
. "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
storagev1 "k8s.io/api/storage/v1"
)

var (
driverResourcePath = "https://raw.githubusercontent.com/kubernetes-sigs/secrets-store-csi-driver/v1.1.0/deploy"
providerResourceDirectory = "manifest_staging/deployment"

driverResources = []string{
"csidriver.yaml",
// "csidriver.yaml" will be downloaded, modified and installed in deployDriver()
"rbac-secretproviderclass.yaml",
"rbac-secretproviderrotation.yaml",
"rbac-secretprovidersyncing.yaml",
Expand All @@ -42,10 +45,7 @@ var (

// InstallManifest install driver and provider manifests from yaml files.
func InstallManifest(kubeconfigPath string, config *framework.Config) {
for _, resource := range driverResources {
err := exec.KubectlApply(kubeconfigPath, framework.NamespaceKubeSystem, []string{"-f", fmt.Sprintf("%s/%s", driverResourcePath, resource)})
Expect(err).To(BeNil())
}
deployDriver(kubeconfigPath, config)

wd, err := os.Getwd()
Expect(err).To(BeNil())
Expand All @@ -71,7 +71,7 @@ func InstallManifest(kubeconfigPath string, config *framework.Config) {
if adjustedPos >= len(fileContent) {
return
}
dsYAML := fileContent[adjustedPos:len(fileContent)]
dsYAML := fileContent[adjustedPos:]

ds := &appsv1.DaemonSet{}
err = yaml.Unmarshal([]byte(dsYAML), ds)
Expand Down Expand Up @@ -115,3 +115,41 @@ func InstallManifest(kubeconfigPath string, config *framework.Config) {
Expect(err).To(BeNil())
}
}

func deployDriver(kubeconfigPath string, config *framework.Config) {
resp, err := http.Get(fmt.Sprintf("%s/%s", driverResourcePath, "csidriver.yaml"))
Expect(err).To(BeNil())

csiDriverYAML, err := io.ReadAll(resp.Body)
defer resp.Body.Close()
Expect(err).To(BeNil())

csiDriver := &storagev1.CSIDriver{}
err = yaml.Unmarshal(csiDriverYAML, csiDriver)
Expect(err).To(BeNil())

// Modify the CSI driver spec to include token requests
// With this we can enable workload identity tests with manifests in addition to helm
csiDriver.Spec.TokenRequests = []storagev1.TokenRequest{
{
Audience: auth.DefaultTokenAudience,
},
}

updatedCSIDriver, err := yaml.Marshal(csiDriver)
Expect(err).To(BeNil())

updateCSIDriverYAMLFile := filepath.Join(os.TempDir(), driverResources[0])
err = os.WriteFile(updateCSIDriverYAMLFile, updatedCSIDriver, 0644)
Expect(err).To(BeNil())

// Install the CSIDriver
err = exec.KubectlApply(kubeconfigPath, framework.NamespaceKubeSystem, []string{"-f", updateCSIDriverYAMLFile})
Expect(err).To(BeNil())

// Install the remaining driver resources
for _, resource := range driverResources {
err := exec.KubectlApply(kubeconfigPath, framework.NamespaceKubeSystem, []string{"-f", fmt.Sprintf("%s/%s", driverResourcePath, resource)})
Expect(err).To(BeNil())
}
}
4 changes: 0 additions & 4 deletions test/e2e/workload_identity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,6 @@ var _ = Describe("CSI inline volume test with workload identity", func() {
if !config.IsKindCluster {
Skip("test case currently supported for kind cluster only")
}
// the audience field is configurable only with helm charts
if !config.IsHelmTest {
Skip("test case currently supported for helm test only")
}

pod.WaitFor(pod.WaitForInput{
Getter: kubeClient,
Expand Down

0 comments on commit bf9bd3f

Please sign in to comment.