Skip to content

Commit 68bd182

Browse files
authored
feat: support setting samesite cookie param (#1097)
1 parent 4008c79 commit 68bd182

4 files changed

Lines changed: 25 additions & 0 deletions

File tree

api/v1alpha1/amaltheasession_children.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const TunnelPort int32 = 65531
4848
var sidecarsImage string = getSidecarsImage()
4949
var rcloneStorageClass string = getStorageClass()
5050
var rcloneDefaultStorage resource.Quantity = resource.MustParse("1Gi")
51+
var useNoneSameSiteSessionCookie = getUseNoneSameSiteSessionCookie()
5152

5253
const rcloneStorageSecretNameAnnotation = "csi-rclone.dev/secretName"
5354

@@ -606,6 +607,10 @@ func getSidecarsImage() string {
606607
return sc
607608
}
608609

610+
func getUseNoneSameSiteSessionCookie() bool {
611+
return strings.ToLower(os.Getenv("USE_NONE_SAME_SITE_SESSION_COOKIE")) == "true"
612+
}
613+
609614
// InternalSecretName returns the name of the secret that is a child
610615
// of the AmaltheaSession CR, as opposed to all other adopted secrets that
611616
// are not children of the AmaltheaSession CR and are created by the creator of each AmaltheaSession CR.

api/v1alpha1/auth_templates.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ func (as *AmaltheaSession) auth() (manifests, error) {
4747
Port: intstr.FromInt32(authenticatedPort),
4848
},
4949
}
50+
sameSiteCookieFlag := "strict"
51+
if useNoneSameSiteSessionCookie {
52+
sameSiteCookieFlag = "none"
53+
}
5054
oauth2ProxyContainer := v1.Container{
5155
Image: authproxyImage,
5256
Name: "oauth2-proxy",
@@ -59,6 +63,7 @@ func (as *AmaltheaSession) auth() (manifests, error) {
5963
fmt.Sprintf("--http-address=:%d", authenticatedPort),
6064
"--silence-ping-logging",
6165
"--config=/etc/oauth2-proxy/" + auth.SecretRef.Key,
66+
fmt.Sprintf("--cookie-samesite=%s", sameSiteCookieFlag),
6267
},
6368
VolumeMounts: append(
6469
[]v1.VolumeMount{
@@ -89,6 +94,9 @@ func (as *AmaltheaSession) auth() (manifests, error) {
8994

9095
output.Containers = append(output.Containers, oauth2ProxyContainer)
9196
case Token:
97+
if useNoneSameSiteSessionCookie {
98+
return output, fmt.Errorf("cannot set the same site cookie parameter for anonymous sessions")
99+
}
92100
volName := fmt.Sprintf("%sproxy-configuration-secret", prefix)
93101
output.Volumes = append(output.Volumes, v1.Volume{
94102
Name: volName,
@@ -143,6 +151,10 @@ func (as *AmaltheaSession) auth() (manifests, error) {
143151
Port: intstr.FromInt32(authenticatedPort),
144152
},
145153
}
154+
sameSiteCookieFlag := "strict"
155+
if useNoneSameSiteSessionCookie {
156+
sameSiteCookieFlag = "none"
157+
}
146158
oauth2ProxyContainer := v1.Container{
147159
Image: authproxyImage,
148160
Name: "oauth2-proxy",
@@ -154,6 +166,7 @@ func (as *AmaltheaSession) auth() (manifests, error) {
154166
"--silence-ping-logging",
155167
"--alpha-config=/etc/oauth2-proxy/oauth2-proxy-alpha-config.yaml",
156168
"--config=/etc/oauth2-proxy/oauth2-proxy-config.yaml",
169+
fmt.Sprintf("--cookie-samesite=%s", sameSiteCookieFlag),
157170
},
158171
EnvFrom: []v1.EnvFromSource{
159172
{

helm-chart/amalthea-sessions/templates/deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ spec:
4242
value: {{ .Values.rcloneStorageClass | quote }}
4343
- name: SIDECARS_IMAGE
4444
value: {{ .Values.sidecars.image.repository }}:{{ .Values.sidecars.image.tag }}
45+
- name: USE_NONE_SAME_SITE_SESSION_COOKIE
46+
value: {{ .Values.useNoneSameSiteSessionCookie | quote }}
4547
image: {{ .Values.controllerManager.manager.image.repository }}:{{ .Values.controllerManager.manager.image.tag
4648
| default .Chart.AppVersion }}
4749
livenessProbe:

helm-chart/amalthea-sessions/values.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,8 @@ cloner:
6767
image:
6868
repository: renku/cloner
6969
tag: latest
70+
71+
# Setting this flag to true will make the oauth2-proxy session cookie set its
72+
# SameSite parameter to None. This is only useful in specific cases for remote Renku cluster.
73+
# Setting this value to true can have security implications without adjusting CSP and CORS on the session ingress.
74+
useNoneSameSiteSessionCookie: false

0 commit comments

Comments
 (0)