-
Notifications
You must be signed in to change notification settings - Fork 3
feat: Upload DCs secrets #1173
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
base: sambuc/chore/rename-path-variables-for-clarity
Are you sure you want to change the base?
feat: Upload DCs secrets #1173
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -4,16 +4,19 @@ import ( | |||||
| "context" | ||||||
| "crypto/rand" | ||||||
| "encoding/base64" | ||||||
| "encoding/json" | ||||||
| "errors" | ||||||
| "fmt" | ||||||
| "io" | ||||||
| "maps" | ||||||
| "net/url" | ||||||
| "os" | ||||||
| "path" | ||||||
| "sort" | ||||||
| "strings" | ||||||
| "time" | ||||||
|
|
||||||
| "github.com/SwissDataScienceCenter/amalthea/internal/common" | ||||||
| "github.com/SwissDataScienceCenter/amalthea/internal/controller/config" | ||||||
| "gopkg.in/yaml.v3" | ||||||
| appsv1 "k8s.io/api/apps/v1" | ||||||
|
|
@@ -642,11 +645,92 @@ func (cr *AmaltheaSession) AdoptedSecrets() v1.SecretList { | |||||
| // Assuming that the csi-rclone driver from https://github.com/SwissDataScienceCenter/csi-rclone | ||||||
| // is installed, this will generate PVCs for the data sources that have the rclone type. | ||||||
| func (as *AmaltheaSession) DataSources() ([]v1.PersistentVolumeClaim, []v1.Volume, []v1.VolumeMount) { | ||||||
| // TODO: Configure this for remote sessions | ||||||
| if as.Spec.SessionLocation == Remote { | ||||||
| return []v1.PersistentVolumeClaim{}, []v1.Volume{}, []v1.VolumeMount{} | ||||||
| switch as.Spec.SessionLocation { | ||||||
| case Remote: | ||||||
| return as.RemoteSessionDataSources() | ||||||
| case Local: | ||||||
| return as.LocalSessionDataSources() | ||||||
| default: | ||||||
| panic("invalid session location") | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| func (as *AmaltheaSession) RemoteSessionDataSources() ([]v1.PersistentVolumeClaim, []v1.Volume, []v1.VolumeMount) { | ||||||
| pvcs := []v1.PersistentVolumeClaim{} | ||||||
| vols := []v1.Volume{ | ||||||
| { | ||||||
| Name: fmt.Sprintf("%s-%s", prefix, as.Name), | ||||||
| VolumeSource: v1.VolumeSource{ | ||||||
| Secret: &v1.SecretVolumeSource{ | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should add |
||||||
| SecretName: as.InternalSecretName(), | ||||||
| DefaultMode: ptr.To(int32(256)), // decimal value of 0400 for the access flags (chmod-like) | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| }, | ||||||
| }, | ||||||
| }, | ||||||
| } | ||||||
| volMounts := []v1.VolumeMount{ | ||||||
| { | ||||||
| Name: fmt.Sprintf("%s-%s", prefix, as.Name), | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You will have two dashes
Suggested change
|
||||||
| ReadOnly: true, | ||||||
| MountPath: common.UserSecretProxyFolder, | ||||||
| }, | ||||||
| } | ||||||
|
|
||||||
| ids := 0 | ||||||
| for _, pv := range as.Spec.DataSources { | ||||||
| if pv.SecretRef.isAdopted() { | ||||||
| volName := fmt.Sprintf("%s%s-ds-%d", prefix, as.Name, ids) | ||||||
| vols = append( | ||||||
| vols, | ||||||
| v1.Volume{ | ||||||
| Name: volName, | ||||||
| VolumeSource: v1.VolumeSource{ | ||||||
| Secret: &v1.SecretVolumeSource{ | ||||||
| SecretName: pv.SecretRef.Name, | ||||||
| DefaultMode: ptr.To(int32(256)), // decimal value of 0400 for the access flags (chmod-like) | ||||||
| }, | ||||||
| }, | ||||||
| }, | ||||||
| ) | ||||||
| volMounts = append( | ||||||
| volMounts, | ||||||
| v1.VolumeMount{ | ||||||
| Name: volName, | ||||||
| ReadOnly: true, | ||||||
| MountPath: path.Join(common.DataConnectorProxyFolder, volName), | ||||||
| }, | ||||||
| ) | ||||||
| // If there is a user secret linked to the data connector, mount it as it contains required credentials | ||||||
| userSecretName := fmt.Sprintf("%s-secrets", pv.SecretRef.Name) | ||||||
| volNameSecret := fmt.Sprintf("%s-secrets", volName) | ||||||
| vols = append( | ||||||
| vols, | ||||||
| v1.Volume{ | ||||||
| Name: volNameSecret, | ||||||
| VolumeSource: v1.VolumeSource{ | ||||||
| Secret: &v1.SecretVolumeSource{ | ||||||
| SecretName: userSecretName, | ||||||
| Optional: ptr.To(true), | ||||||
| DefaultMode: ptr.To(int32(256)), // decimal value of 0400 for the access flags (chmod-like) | ||||||
| }, | ||||||
| }, | ||||||
| }, | ||||||
| ) | ||||||
| volMounts = append( | ||||||
| volMounts, | ||||||
| v1.VolumeMount{ | ||||||
| Name: volNameSecret, | ||||||
| ReadOnly: true, | ||||||
| MountPath: path.Join(common.DataConnectorSecretProxyFolder, volName), | ||||||
| }, | ||||||
| ) | ||||||
| ids += 1 | ||||||
| } | ||||||
| } | ||||||
| return pvcs, vols, volMounts | ||||||
| } | ||||||
|
|
||||||
| func (as *AmaltheaSession) LocalSessionDataSources() ([]v1.PersistentVolumeClaim, []v1.Volume, []v1.VolumeMount) { | ||||||
| pvcs := []v1.PersistentVolumeClaim{} | ||||||
| vols := []v1.Volume{} | ||||||
| volMounts := []v1.VolumeMount{} | ||||||
|
|
@@ -759,14 +843,30 @@ func (as *AmaltheaSession) Secret() v1.Secret { | |||||
| }, | ||||||
| StringData: map[string]string{}, | ||||||
| } | ||||||
| // Secret used to secure the tunnel for remote sessions | ||||||
|
|
||||||
| if as.Spec.SessionLocation == Remote { | ||||||
| // Secret used to secure the tunnel for remote sessions | ||||||
| tunnelSecret, err := makeTunnelSecret(16) | ||||||
| if err != nil { | ||||||
| panic(err) | ||||||
| } | ||||||
|
|
||||||
| secret.StringData["WSTUNNEL_SECRET"] = tunnelSecret | ||||||
| secret.StringData["wstunnel_secret"] = tunnelSecret | ||||||
|
|
||||||
| // Add the Datasources Specifications so that the proxy container can write them out to the HPC cluster | ||||||
| ids := 0 | ||||||
| for _, pv := range as.Spec.DataSources { | ||||||
| if pv.SecretRef.isAdopted() { | ||||||
|
|
||||||
| var content []byte | ||||||
| content, err = json.Marshal(pv) | ||||||
| if err != nil { | ||||||
| panic(err) | ||||||
| } | ||||||
|
|
||||||
| secret.StringData[fmt.Sprintf("%s%s-ds-%d", prefix, as.Name, ids)] = string(content) | ||||||
| ids += 1 | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // Add the 'oidc' configuration if requested | ||||||
|
|
@@ -988,15 +1088,6 @@ func (cr *AmaltheaSession) sessionContainerRemote(volumeMounts []v1.VolumeMount) | |||||
| Name: "RSC_SERVER_PORT", | ||||||
| Value: fmt.Sprintf("%d", RemoteSessionControllerPort), | ||||||
| }, | ||||||
| v1.EnvVar{ | ||||||
| Name: "RSC_WSTUNNEL_SECRET", | ||||||
| ValueFrom: ptr.To(v1.EnvVarSource{ | ||||||
| SecretKeyRef: ptr.To(v1.SecretKeySelector{ | ||||||
| LocalObjectReference: v1.LocalObjectReference{Name: cr.InternalSecretName()}, | ||||||
| Key: "WSTUNNEL_SECRET", | ||||||
| }), | ||||||
| }), | ||||||
| }, | ||||||
| ) | ||||||
|
|
||||||
| if session.RemoteSecretRef != nil { | ||||||
|
|
@@ -1056,7 +1147,7 @@ func (cr *AmaltheaSession) tunnelContainer() v1.Container { | |||||
| ValueFrom: ptr.To(v1.EnvVarSource{ | ||||||
| SecretKeyRef: ptr.To(v1.SecretKeySelector{ | ||||||
| LocalObjectReference: v1.LocalObjectReference{Name: cr.InternalSecretName()}, | ||||||
| Key: "WSTUNNEL_SECRET", | ||||||
| Key: "wstunnel_secret", | ||||||
| }), | ||||||
| }), | ||||||
| }, | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should do a little bit of defensive programming here: this method should work even if the CRD is outdated and doesn't have the location field.
See also: #1121, #1120