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 helm chart #273

Open
wants to merge 24 commits into
base: add-helm-chart
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3799449
Update cloudbuild-dev.yaml
bhavanapalle2023 Jul 6, 2023
f8deca8
Update provider-gcp-plugin-wif.yaml.tmpl
bhavanapalle2023 Jul 6, 2023
c4933dc
Update provider-gcp-plugin.yaml.tmpl
bhavanapalle2023 Jul 6, 2023
43ccd5a
Update mount_test.go
bhavanapalle2023 Jul 6, 2023
fda1008
Update runner.sh
bhavanapalle2023 Jul 6, 2023
f3595d3
Update Chart.yaml
bhavanapalle2023 Jul 6, 2023
1827c55
Update values.yaml
bhavanapalle2023 Jul 6, 2023
29f62d1
Update daemonset.yaml
bhavanapalle2023 Jul 6, 2023
885426c
helm image files
bhavanapalle2023 Jul 6, 2023
e12e42b
Update README.md
bhavanapalle2023 Jul 6, 2023
01c7cd9
Update mount_test.go
bhavanapalle2023 Jul 7, 2023
076279c
tag to hash
bhavanapalle2023 Jul 7, 2023
fd86509
tag to hash
bhavanapalle2023 Jul 7, 2023
88396a6
create Artifact repository
bhavanapalle2023 Jul 7, 2023
7b4245a
Update mount_test.go
bhavanapalle2023 Jul 7, 2023
aaadfcb
Update README.md
bhavanapalle2023 Jul 10, 2023
4023393
Removed the comment in cloudbuild-dev.yaml
bhavanapalle2023 Jul 10, 2023
334468b
Update Chart.yaml
bhavanapalle2023 Jul 10, 2023
ab22de2
version to app version cloudbuild-dev.yaml
bhavanapalle2023 Jul 10, 2023
18fe1ef
version to appversion mount_test.go
bhavanapalle2023 Jul 10, 2023
5a2b060
New line cloudbuild-dev.yaml
bhavanapalle2023 Jul 10, 2023
87c45d1
removed inconsistent spaces between keywords - build.sh
bhavanapalle2023 Jul 17, 2023
f3c021f
inconsistent spaces runner.sh
bhavanapalle2023 Jul 17, 2023
71f8e8f
Update build.sh
bhavanapalle2023 Jul 17, 2023
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
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@ to access secrets stored in Secret Manager as files mounted in Kubernetes pods.
* Create a new GKE cluster with Workload Identity or enable
[Workload Identity](https://cloud.google.com/kubernetes-engine/docs/how-to/workload-identity#enable_on_existing_cluster)
on an existing cluster.
* Install the
[Secret Store CSI Driver](https://secrets-store-csi-driver.sigs.k8s.io/getting-started/installation.html)
v1.0.1 or higher to the cluster.
* Install the Google plugin DaemonSet & additional RoleBindings:
* Install Google plugin DaemonSet & additional RoleBindings:

```shell
kubectl apply -f deploy/provider-gcp-plugin.yaml
# if you want to use helm
# helm upgrade --install secrets-store-csi-driver-provider-gcp charts/secrets-store-csi-driver-provider-gcp
$ export PROJECT_ID=<your gcp project>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not merge this change in instructions unless the package is indeed available in the public repo.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, back to original ReadMe

$ helm repo add secrets-store-csi-driver-provider-gcp <repo>
$ helm install provider-chart secrets-store-csi-driver-provider-gcp/secrets-store-csi-driver-provider-gcp --set secrets-store-csi-driver.tokenRequests[0].audience=$PROJECT_ID.svc.id.goog --namespace kube-system
```

* The provider has a dependency on the driver and hence will automatically install the [CSI Secret Store Driver](https://github.com/kubernetes-sigs/secrets-store-csi-driver).

During installation, it will set the tokenRequests audience value to PROJECT_ID.svc.id.goog i.e. [Workload Identity](https://cloud.google.com/kubernetes-engine/docs/how-to/workload-identity#enable_on_existing_cluster)
which will enable the provider to utlize the same k8s token as the driver.

NOTE: The driver's rotation and secret syncing functionality is still in Alpha and requires [additional installation
steps](https://secrets-store-csi-driver.sigs.k8s.io/getting-started/installation.html#optional-values).

Expand Down
4 changes: 4 additions & 0 deletions charts/secrets-store-csi-driver-provider-gcp/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ description: A Helm chart to install Google Secret Manager Provider for Secret S
type: application
version: 0.1.0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its okay to keep the version same as appVersion

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

appVersion: "1.2.0"
dependencies:
- name: secrets-store-csi-driver
version: "1.3.4"
repository: "https://kubernetes-sigs.github.io/secrets-store-csi-driver/charts"
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ spec:
serviceAccountName: {{ include "secrets-store-csi-driver-provider-gcp.serviceAccountName" . }}
containers:
- name: provider
image: "{{ .Values.image.repository }}@{{ .Values.image.hash }}"
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a hash is considered more secure and we should continue to reference by hash.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

imagePullPolicy: {{ .Values.image.pullPolicy }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
Expand Down
7 changes: 6 additions & 1 deletion charts/secrets-store-csi-driver-provider-gcp/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ serviceAccount:

image:
repository: us-docker.pkg.dev/secretmanager-csi/secrets-store-csi-driver-provider-gcp/plugin
tag: v1.2.0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, please continue to use hash references.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

pullPolicy: IfNotPresent
hash: sha256:b7dde5ed536b2c6500c9237e14f6851cf8a2ff6d7a72656c3741be38e2cddf4d

app: csi-secrets-store-provider-gcp

Expand All @@ -27,3 +27,8 @@ nodeSelector:
tolerations: []

affinity: {}

secrets-store-csi-driver:
fullnameOverride: secrets-store-csi-driver
tokenRequests:
- audience: $PROJECT_ID.svc.id.goog
24 changes: 24 additions & 0 deletions helm/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM gcr.io/cloud-builders/gcloud

ARG HELM_VERSION=v3.12.0
ENV HELM_VERSION=$HELM_VERSION
ENV USE_GKE_GCLOUD_AUTH_PLUGIN=True

COPY helm.bash /builder/helm.bash

RUN chmod +x /builder/helm.bash && \
mkdir -p /builder/helm && \
apt-get update && \
apt-get install -y --no-install-recommends curl && \
curl -SL https://get.helm.sh/helm-${HELM_VERSION}-linux-amd64.tar.gz -o helm.tar.gz && \
tar zxvf helm.tar.gz --strip-components=1 -C /builder/helm linux-amd64 && \
rm helm.tar.gz && \
apt-get --purge -y autoremove && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

RUN gcloud -q components install gke-gcloud-auth-plugin

ENV PATH=/builder/helm/:$PATH

ENTRYPOINT ["/builder/helm.bash"]
64 changes: 64 additions & 0 deletions helm/helm.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash -e

# If there is no current context, get one.
if [[ $(kubectl config current-context 2> /dev/null) == "" && "$SKIP_CLUSTER_CONFIG" != true ]]; then
# This tries to read environment variables. If not set, it grabs from gcloud
cluster=${CLOUDSDK_CONTAINER_CLUSTER:-$(gcloud config get-value container/cluster 2> /dev/null)}
region=${CLOUDSDK_COMPUTE_REGION:-$(gcloud config get-value compute/region 2> /dev/null)}
zone=${CLOUDSDK_COMPUTE_ZONE:-$(gcloud config get-value compute/zone 2> /dev/null)}
project=${GCLOUD_PROJECT:-$(gcloud config get-value core/project 2> /dev/null)}

function var_usage() {
cat <<EOF
No cluster is set. To set the cluster (and the region/zone where it is found), set the environment variables
CLOUDSDK_COMPUTE_REGION=<cluster region> (regional clusters)
CLOUDSDK_COMPUTE_ZONE=<cluster zone> (zonal clusters)
CLOUDSDK_CONTAINER_CLUSTER=<cluster name>
EOF
exit 1
}

[[ -z "$cluster" ]] && var_usage
[ ! "$zone" -o "$region" ] && var_usage

if [ -n "$region" ]; then
echo "Running: gcloud container clusters get-credentials --project=\"$project\" --region=\"$region\" \"$cluster\""
gcloud container clusters get-credentials --project="$project" --region="$region" "$cluster"
else
echo "Running: gcloud container clusters get-credentials --project=\"$project\" --zone=\"$zone\" \"$cluster\""
gcloud container clusters get-credentials --project="$project" --zone="$zone" "$cluster"
fi
fi

# if GCS_PLUGIN_VERSION is set, install the plugin
if [[ -n $GCS_PLUGIN_VERSION ]]; then
echo "Installing helm GCS plugin version $GCS_PLUGIN_VERSION "
helm plugin install https://github.com/nouney/helm-gcs --version $GCS_PLUGIN_VERSION
fi

# if DIFF_PLUGIN_VERSION is set, install the plugin
if [[ -n $DIFF_PLUGIN_VERSION ]]; then
echo "Installing helm DIFF plugin version $DIFF_PLUGIN_VERSION "
helm plugin install https://github.com/databus23/helm-diff --version $DIFF_PLUGIN_VERSION
fi

# if HELMFILE_VERSION is set, install Helmfile
if [[ -n $HELMFILE_VERSION ]]; then
echo "Installing Helmfile version $HELMFILE_VERSION "
curl -SsL https://github.com/helmfile/helmfile/releases/download/$HELMFILE_VERSION/helmfile_linux_amd64 > helmfile
chmod 700 helmfile
fi

# check if repo values provided then add that repo
if [[ -n $HELM_REPO_NAME && -n $HELM_REPO_URL ]]; then
echo "Adding chart helm repo $HELM_REPO_URL"
helm repo add $HELM_REPO_NAME $HELM_REPO_URL
fi

echo "Running: helm repo update"
helm repo list && helm repo update || true

if [ "$DEBUG" = true ]; then
echo "Running: helm $@"
fi
helm "$@"
25 changes: 23 additions & 2 deletions scripts/cloudbuild-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,30 @@
# Usage: from the root directory run:
#
# $ gcloud builds submit --config scripts/cloudbuild-dev.yaml
timeout: 1200s
timeout: 3600s #increasing timeout else build crashes
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: no need for the comment

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the comment

options:
machineType: N1_HIGHCPU_8
steps:
- name: 'gcr.io/cloud-builders/docker'
args: ['buildx', 'build',
'--build-arg',
'VERSION=$TAG_NAME',
'-t',
'asia-east1-docker.pkg.dev/$PROJECT_ID/secrets-store-csi-driver-provider-gcp/helm-image:$TAG_NAME',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this change required?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To create helm docker image, As there are no publicaly available helm image. Used Artifact Registry for Repo.

'--push',
'./helm']
- name: 'asia-east1-docker.pkg.dev/$PROJECT_ID/secrets-store-csi-driver-provider-gcp/helm-image:$TAG_NAME'
args: ['dependency', 'update', './charts/secrets-store-csi-driver-provider-gcp']
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: it might be good to put each arg on a new line.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

env:
- SKIP_CLUSTER_CONFIG=true
- name: 'asia-east1-docker.pkg.dev/$PROJECT_ID/secrets-store-csi-driver-provider-gcp/helm-image:$TAG_NAME'
args: ['package', './charts/secrets-store-csi-driver-provider-gcp', '--version', '0.1.0-$TAG_NAME']
env:
- SKIP_CLUSTER_CONFIG=true
- name: 'asia-east1-docker.pkg.dev/$PROJECT_ID/secrets-store-csi-driver-provider-gcp/helm-image:$TAG_NAME'
args: ['push', 'secrets-store-csi-driver-provider-gcp-0.1.0-$TAG_NAME.tgz', 'oci://asia-east1-docker.pkg.dev/$PROJECT_ID/secrets-store-csi-driver-provider-gcp' ]
env:
- SKIP_CLUSTER_CONFIG=true
- name: 'gcr.io/cloud-builders/docker'
args: ['buildx', 'create', '--use']
- name: 'gcr.io/cloud-builders/docker'
Expand All @@ -27,6 +47,7 @@ steps:
'--build-arg',
'VERSION=$TAG_NAME',
'-t',
'gcr.io/$PROJECT_ID/secrets-store-csi-driver-provider-gcp:$TAG_NAME',
'asia-east1-docker.pkg.dev/$PROJECT_ID/secrets-store-csi-driver-provider-gcp/provider-image:$TAG_NAME',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this change required?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As Container Registry is Depreciating, Made helm image repo, helm chart repo and provider image in the Artifact registry

'--push',
'.']

37 changes: 25 additions & 12 deletions test/e2e/mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,19 +136,31 @@ func setupTestSuite() {
gcloudCmd.Env = append(os.Environ(), "KUBECONFIG="+f.kubeconfigFile)
check(execCmd(gcloudCmd))

// Install Secret Store
check(execCmd(exec.Command("kubectl", "apply", "--kubeconfig", f.kubeconfigFile,
"-f", fmt.Sprintf("https://raw.githubusercontent.com/kubernetes-sigs/secrets-store-csi-driver/%s/deploy/rbac-secretproviderclass.yaml", f.secretStoreVersion),
"-f", fmt.Sprintf("https://raw.githubusercontent.com/kubernetes-sigs/secrets-store-csi-driver/%s/deploy/rbac-secretprovidersyncing.yaml", f.secretStoreVersion),
"-f", fmt.Sprintf("https://raw.githubusercontent.com/kubernetes-sigs/secrets-store-csi-driver/%s/deploy/csidriver.yaml", f.secretStoreVersion),
"-f", fmt.Sprintf("https://raw.githubusercontent.com/kubernetes-sigs/secrets-store-csi-driver/%s/deploy/secrets-store.csi.x-k8s.io_secretproviderclasses.yaml", f.secretStoreVersion),
"-f", fmt.Sprintf("https://raw.githubusercontent.com/kubernetes-sigs/secrets-store-csi-driver/%s/deploy/secrets-store.csi.x-k8s.io_secretproviderclasspodstatuses.yaml", f.secretStoreVersion),
"-f", fmt.Sprintf("https://raw.githubusercontent.com/kubernetes-sigs/secrets-store-csi-driver/%s/deploy/secrets-store-csi-driver.yaml", f.secretStoreVersion),
)))
// Helm authentication
gcloudCmd := exec.Command("gcloud", "auth", "application-default", "print-access-token")

// Capture the output of the gcloud command
gcloudOutput, err := gcloudCmd.Output()

if err != nil {
fmt.Printf("Error running gcloud command: %s\n", err.Error())
os.Exit(1)
}
// Create the helm registry login command
helmCmd := exec.Command("helm", "registry", "login", "-u", "oauth2accesstoken", "--password-stdin", "https://asia-east1-docker.pkg.dev")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you confirm if the usage of asia-east1 across this commit is just a choice of region & it can be substituted with a different supported region if required?
If yes, can this be made a constant which is referred everywhere?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, we should use gcr.io instead of regional endpoints wherever possible.


// Install GCP Plugin and Workload Identity bindings
check(execCmd(exec.Command("kubectl", "apply", "--kubeconfig", f.kubeconfigFile,
"-f", pluginFile)))
// Set the access token as the input for the helm command
helmCmd.Stdin = strings.NewReader(string(gcloudOutput))

// Run the helm command
check(execCmd(helmCmd))

// Install GCP Plugin and Workload Identity bindings
// set: drive image to oci://asia-east1-docker.pkg.dev/$PROJECT_ID/secrets-store-csi-driver-provider-gcp/provider-image with tag GCP_PROVIDER_SHA
// set: audience token to PROJECT_ID.svc.id.goog
check(execCmd(exec.Command("helm", "install", "provider-chart", fmt.Sprintf("oci://asia-east1-docker.pkg.dev/%s/secrets-store-csi-driver-provider-gcp/secrets-store-csi-driver-provider-gcp", f.testProjectID),
"--version", fmt.Sprintf("0.1.0-%s", f.gcpProviderBranch), "--set", fmt.Sprintf("image.repository=asia-east1-docker.pkg.dev/%s/secrets-store-csi-driver-provider-gcp/provider-image", f.testProjectID),
"--set", fmt.Sprintf("image.tag=%s", f.gcpProviderBranch), "--set", fmt.Sprintf("secrets-store-csi-driver.tokenRequests[0].audience=%s.svc.id.goog", f.testProjectID), "--namespace", "kube-system" )))

// Create test secret
secretFile := filepath.Join(f.tempDir, "secretValue")
Expand Down Expand Up @@ -494,3 +506,4 @@ func TestMountRotateSecret(t *testing.T) {
t.Fatalf("Secret value is %v, want: %v", got, secretB)
}
}

2 changes: 1 addition & 1 deletion test/e2e/templates/provider-gcp-plugin-wif.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ spec:
serviceAccountName: secrets-store-csi-driver-provider-gcp
containers:
- name: provider
image: gcr.io/$PROJECT_ID/secrets-store-csi-driver-provider-gcp:$GCP_PROVIDER_SHA
image: asia-east1-dev.pkg/$PROJECT_ID/secrets-store-csi-driver-provider-gcp/provider-image:$GCP_PROVIDER_SHA
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why has the name of the image changed?

args:
- "-v=5"
imagePullPolicy: Always
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/templates/provider-gcp-plugin.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ spec:
serviceAccountName: secrets-store-csi-driver-provider-gcp
containers:
- name: provider
image: gcr.io/$PROJECT_ID/secrets-store-csi-driver-provider-gcp:$GCP_PROVIDER_SHA
image: asia-east1-dev.pkg/$PROJECT_ID/secrets-store-csi-driver-provider-gcp/provider-image:$GCP_PROVIDER_SHA
args:
- "-v=5"
imagePullPolicy: Always
Expand Down
3 changes: 3 additions & 0 deletions test/infra/runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export GKE_VERSION=${GKE_VERSION:-STABLE}
export GCP_PROVIDER_SHA=${GITHUB_SHA:-main}
export USE_GKE_GCLOUD_AUTH_PLUGIN=True

# Creating a new repository secrets-store-csi-driver-provider-gcp
gcloud artifacts repositories create secrets-store-csi-driver-provider-gcp --repository-format=docker --location=asia-east1

# Build the driver image
gcloud builds submit --config scripts/cloudbuild-dev.yaml --substitutions=TAG_NAME=${GCP_PROVIDER_SHA} --project $PROJECT_ID

Expand Down