Skip to content

Commit 8b6eb2b

Browse files
committed
Fix
1 parent 27bdd17 commit 8b6eb2b

File tree

8 files changed

+68
-19
lines changed

8 files changed

+68
-19
lines changed

components/public-api/go/config/config.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,17 @@ type AuthConfiguration struct {
5252
}
5353

5454
type SessionConfig struct {
55-
LifetimeSeconds int64 `json:"lifetimeSeconds"`
56-
Issuer string `json:"issuer"`
57-
CookieName string `json:"cookieName"`
55+
LifetimeSeconds int64 `json:"lifetimeSeconds"`
56+
Issuer string `json:"issuer"`
57+
Cookie CookieConfig `json:"cookie"`
58+
}
59+
60+
type CookieConfig struct {
61+
Name string `json:"name"`
62+
MaxAge int64 `json:"maxAge"`
63+
SameSite string `json:"sameSite"`
64+
Secure bool `json:"secure"`
65+
HTTPOnly bool `json:"httpOnly"`
5866
}
5967

6068
type AuthPKIConfiguration struct {

components/server/src/auth/login-completion-handler.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ export class LoginCompletionHandler {
100100
if (isJWTCookieExperimentEnabled) {
101101
const token = await this.authJWT.sign(user.id, {});
102102

103-
response.cookie(SessionHandlerProvider.getJWTCookieName(this.config.hostUrl), token, {
104-
maxAge: this.config.session.maxAgeMs,
105-
httpOnly: true,
106-
sameSite: "lax",
107-
secure: true,
103+
response.cookie(SessionHandlerProvider.getJWTCookieName(this.config), token, {
104+
maxAge: this.config.auth.session.cookie.maxAge,
105+
httpOnly: this.config.auth.session.cookie.httpOnly,
106+
sameSite: this.config.auth.session.cookie.sameSite,
107+
secure: this.config.auth.session.cookie.secure,
108108
});
109109

110110
reportJWTCookieIssued();

components/server/src/config.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export type Config = Omit<
5555
session: {
5656
lifetimeSeconds: number;
5757
issuer: string;
58-
cookieName: string;
58+
cookie: CookieConfig;
5959
};
6060
};
6161
};
@@ -259,11 +259,19 @@ export interface ConfigSerialized {
259259
session: {
260260
lifetimeSeconds: number;
261261
issuer: string;
262-
cookieName: string;
262+
cookie: CookieConfig;
263263
};
264264
};
265265
}
266266

267+
export interface CookieConfig {
268+
name: string;
269+
maxAge: number;
270+
sameSite: boolean | "lax" | "strict" | "none";
271+
secure: boolean;
272+
httpOnly: boolean;
273+
}
274+
267275
export interface AuthPKIConfig {
268276
signing: KeyPair;
269277
validating?: KeyPair[];

components/server/src/session-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export class SessionHandlerProvider {
6666
}
6767

6868
static getJWTCookieName(config: Config) {
69-
return config.auth.session.cookieName;
69+
return config.auth.session.cookie.name;
7070
}
7171

7272
public clearSessionCookie(res: express.Response, config: Config): void {

install/installer/pkg/components/auth/config.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,34 @@ type Config struct {
2222

2323
type SessionConfig struct {
2424
// How long shoud the session be valid for?
25-
LifetimeSeconds int64 `json:"lifetimeSeconds"`
26-
Issuer string `json:"issuer"`
27-
CookieName string `json:"cookieName"`
25+
LifetimeSeconds int64 `json:"lifetimeSeconds"`
26+
Issuer string `json:"issuer"`
27+
Cookie CookieConfig `json:"cookie"`
28+
}
29+
30+
type CookieConfig struct {
31+
Name string `json:"name"`
32+
MaxAge int64 `json:"maxAge"`
33+
SameSite string `json:"sameSite"`
34+
Secure bool `json:"secure"`
35+
HTTPOnly bool `json:"httpOnly"`
2836
}
2937

3038
func GetConfig(ctx *common.RenderContext) ([]corev1.Volume, []corev1.VolumeMount, Config) {
3139
volumes, mounts, pki := getPKI()
40+
lifetime := int64((7 * 24 * time.Hour).Seconds())
3241
return volumes, mounts, Config{
3342
PKI: pki,
3443
Session: SessionConfig{
35-
LifetimeSeconds: int64((7 * 24 * time.Hour).Seconds()),
44+
LifetimeSeconds: lifetime,
3645
Issuer: fmt.Sprintf("https://%s", ctx.Config.Domain),
37-
CookieName: cookieNameFromDomain(ctx.Config.Domain),
46+
Cookie: CookieConfig{
47+
Name: cookieNameFromDomain(ctx.Config.Domain),
48+
MaxAge: lifetime,
49+
SameSite: "lax",
50+
Secure: true,
51+
HTTPOnly: true,
52+
},
3853
},
3954
}
4055
}

install/installer/pkg/components/public-api-server/configmap.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,13 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
7474
Session: config.SessionConfig{
7575
LifetimeSeconds: authCfg.Session.LifetimeSeconds,
7676
Issuer: authCfg.Session.Issuer,
77-
CookieName: authCfg.Session.CookieName,
77+
Cookie: config.CookieConfig{
78+
Name: authCfg.Session.Cookie.Name,
79+
MaxAge: authCfg.Session.Cookie.MaxAge,
80+
SameSite: authCfg.Session.Cookie.SameSite,
81+
Secure: authCfg.Session.Cookie.Secure,
82+
HTTPOnly: authCfg.Session.Cookie.HTTPOnly,
83+
},
7884
},
7985
},
8086
Server: &baseserver.Configuration{

install/installer/pkg/components/public-api-server/configmap_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,13 @@ func TestConfigMap(t *testing.T) {
6969
Session: config.SessionConfig{
7070
LifetimeSeconds: int64((24 * 7 * time.Hour).Seconds()),
7171
Issuer: "https://test.domain.everything.awesome.is",
72-
CookieName: "_test_domain_everything_awesome_is_jwt_",
72+
Cookie: config.CookieConfig{
73+
Name: "_test_domain_everything_awesome_is_jwt_",
74+
MaxAge: int64((24 * 7 * time.Hour).Seconds()),
75+
SameSite: "lax",
76+
Secure: true,
77+
HTTPOnly: true,
78+
},
7379
},
7480
},
7581
Server: &baseserver.Configuration{

install/installer/pkg/components/server/configmap_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,13 @@ func TestConfigMap(t *testing.T) {
6666
Session: auth.SessionConfig{
6767
LifetimeSeconds: int64((7 * 24 * time.Hour).Seconds()),
6868
Issuer: "https://awesome.domain",
69-
CookieName: "_awesome_domain_jwt_",
69+
Cookie: auth.CookieConfig{
70+
Name: "_awesome_domain_jwt_",
71+
MaxAge: int64((7 * 24 * time.Hour).Seconds()),
72+
SameSite: "lax",
73+
Secure: true,
74+
HTTPOnly: true,
75+
},
7076
},
7177
},
7278
}

0 commit comments

Comments
 (0)