Skip to content

Commit 926a374

Browse files
committed
Merge branch 'master' of ssh://github.com/arangodb/kube-arangodb
2 parents 03a4d55 + ebdaa78 commit 926a374

File tree

2 files changed

+41
-13
lines changed

2 files changed

+41
-13
lines changed

deps/github.com/arangodb/go-driver/jwt/jwt.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,29 @@ func CreateArangodJwtAuthorizationHeader(jwtSecret, serverID string) (string, er
5454

5555
return "bearer " + signedToken, nil
5656
}
57+
58+
// CreateArangodJwtAuthorizationHeaderAllowedPaths calculates a JWT authorization header, for authorization
59+
// of a request to an arangod server, based on the given secret.
60+
// If the secret is empty, nothing is done.
61+
// Use the result of this function as input for driver.RawAuthentication.
62+
// Additionally allowed paths can be specified
63+
func CreateArangodJwtAuthorizationHeaderAllowedPaths(jwtSecret, serverID string, paths []string) (string, error) {
64+
if jwtSecret == "" || serverID == "" {
65+
return "", nil
66+
}
67+
// Create a new token object, specifying signing method and the claims
68+
// you would like it to contain.
69+
token := jg.NewWithClaims(jg.SigningMethodHS256, jg.MapClaims{
70+
"iss": issArangod,
71+
"server_id": serverID,
72+
"allowed_paths": paths,
73+
})
74+
75+
// Sign and get the complete encoded token as a string using the secret
76+
signedToken, err := token.SignedString([]byte(jwtSecret))
77+
if err != nil {
78+
return "", driver.WithStack(err)
79+
}
80+
81+
return "bearer " + signedToken, nil
82+
}

pkg/deployment/resources/pod_creator.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ func (r *Resources) createLivenessProbe(spec api.DeploymentSpec, group api.Serve
348348
if err != nil {
349349
return nil, maskAny(err)
350350
}
351-
authorization, err = jwt.CreateArangodJwtAuthorizationHeader(secretData, "kube-arangodb")
351+
authorization, err = jwt.CreateArangodJwtAuthorizationHeaderAllowedPaths(secretData, "kube-arangodb", []string{"/_api/version"})
352352
if err != nil {
353353
return nil, maskAny(err)
354354
}
@@ -382,7 +382,7 @@ func (r *Resources) createLivenessProbe(spec api.DeploymentSpec, group api.Serve
382382
if err != nil {
383383
return nil, maskAny(err)
384384
}
385-
authorization, err = jwt.CreateArangodJwtAuthorizationHeader(secretData, "kube-arangodb")
385+
authorization, err = jwt.CreateArangodJwtAuthorizationHeaderAllowedPaths(secretData, "kube-arangodb", []string{"/_api/version"})
386386
if err != nil {
387387
return nil, maskAny(err)
388388
}
@@ -416,33 +416,35 @@ func (r *Resources) createReadinessProbe(spec api.DeploymentSpec, group api.Serv
416416
return nil, nil
417417
}
418418

419+
localPath := "/_api/version"
420+
switch spec.GetMode() {
421+
case api.DeploymentModeActiveFailover:
422+
localPath = "/_admin/echo"
423+
}
424+
425+
// /_admin/server/availability is the way to go, it is available since 3.3.9
426+
if version.CompareTo("3.3.9") >= 0 {
427+
localPath = "/_admin/server/availability"
428+
}
429+
419430
authorization := ""
420431
if spec.IsAuthenticated() {
421432
secretData, err := r.getJWTSecret(spec)
422433
if err != nil {
423434
return nil, maskAny(err)
424435
}
425-
authorization, err = jwt.CreateArangodJwtAuthorizationHeader(secretData, "kube-arangodb")
436+
authorization, err = jwt.CreateArangodJwtAuthorizationHeaderAllowedPaths(secretData, "kube-arangodb", []string{localPath})
426437
if err != nil {
427438
return nil, maskAny(err)
428439
}
429440
}
430441
probeCfg := &k8sutil.HTTPProbeConfig{
431-
LocalPath: "/_api/version",
442+
LocalPath: localPath,
432443
Secure: spec.IsSecure(),
433444
Authorization: authorization,
434445
InitialDelaySeconds: 2,
435446
PeriodSeconds: 2,
436447
}
437-
switch spec.GetMode() {
438-
case api.DeploymentModeActiveFailover:
439-
probeCfg.LocalPath = "/_admin/echo"
440-
}
441-
442-
// /_admin/server/availability is the way to go, it is available since 3.3.9
443-
if version.CompareTo("3.3.9") >= 0 {
444-
probeCfg.LocalPath = "/_admin/server/availability"
445-
}
446448

447449
return probeCfg, nil
448450
}

0 commit comments

Comments
 (0)