Skip to content

Commit f533116

Browse files
[Feature] [ML] Support for deployments with JWT auth enabled (#1538)
1 parent edf27fc commit f533116

File tree

11 files changed

+100
-62
lines changed

11 files changed

+100
-62
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
- (Improvement) (ML) BatchJob status update
3737
- (Feature) (ML) Multi DB Settings
3838
- (Feature) (ML) Port adjustments
39+
- (Feature) (ML) Support for deployments with JWT auth enabled
3940

4041
## [1.2.35](https://github.com/arangodb/kube-arangodb/tree/1.2.35) (2023-11-06)
4142
- (Maintenance) Update go-driver to v1.6.0, update IsNotFound() checks

docs/api/ArangoDeployment.V1.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -968,17 +968,15 @@ Default Value: `['amd64']`
968968

969969
### .spec.auth.jwtSecretName
970970

971-
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/deployment/v1/authentication_spec.go#L40)</sup>
971+
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/deployment/v1/authentication_spec.go#L38)</sup>
972972

973-
JWTSecretName setting specifies the name of a kubernetes `Secret` that contains
974-
the JWT token used for accessing all ArangoDB servers.
973+
JWTSecretName setting specifies the name of a kubernetes `Secret` that contains a secret key used for generating
974+
JWT tokens to access all ArangoDB servers.
975975
When no name is specified, it defaults to `<deployment-name>-jwt`.
976976
To disable authentication, set this value to `None`.
977-
If you specify a name of a `Secret`, that secret must have the token
978-
in a data field named `token`.
979-
If you specify a name of a `Secret` that does not exist, a random token is created
980-
and stored in a `Secret` with given name.
981-
Changing a JWT token results in restarting of a whole cluster.
977+
If you specify a name of a `Secret`, that secret must have the key value in a data field named `token`.
978+
If you specify a name of a `Secret` that does not exist, a random key is created and stored in a `Secret` with given name.
979+
Changing secret key results in restarting of a whole cluster.
982980

983981
***
984982

docs/api/ArangoMLExtension.V1Alpha1.md

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,30 @@ UID keeps the information about object UID
11011101

11021102
## Status
11031103

1104+
### .status.arangoDB.jwtTokenSecret.name
1105+
1106+
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/shared/v1/object.go#L46)</sup>
1107+
1108+
Name of the object
1109+
1110+
***
1111+
1112+
### .status.arangoDB.jwtTokenSecret.namespace
1113+
1114+
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/shared/v1/object.go#L49)</sup>
1115+
1116+
Namespace of the object. Should default to the namespace of the parent object
1117+
1118+
***
1119+
1120+
### .status.arangoDB.jwtTokenSecret.uid
1121+
1122+
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/shared/v1/object.go#L52)</sup>
1123+
1124+
UID keeps the information about object UID
1125+
1126+
***
1127+
11041128
### .status.arangoDB.secret.name
11051129

11061130
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/shared/v1/object.go#L46)</sup>
@@ -1133,17 +1157,41 @@ Conditions specific to the entire extension
11331157

11341158
***
11351159

1160+
### .status.metadataService.jwtTokenSecret.name
1161+
1162+
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/shared/v1/object.go#L46)</sup>
1163+
1164+
Name of the object
1165+
1166+
***
1167+
1168+
### .status.metadataService.jwtTokenSecret.namespace
1169+
1170+
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/shared/v1/object.go#L49)</sup>
1171+
1172+
Namespace of the object. Should default to the namespace of the parent object
1173+
1174+
***
1175+
1176+
### .status.metadataService.jwtTokenSecret.uid
1177+
1178+
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/shared/v1/object.go#L52)</sup>
1179+
1180+
UID keeps the information about object UID
1181+
1182+
***
1183+
11361184
### .status.metadataService.local.arangoMLFeatureStore
11371185

1138-
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/ml/v1alpha1/extension_status_metadata_service.go#L38)</sup>
1186+
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/ml/v1alpha1/extension_status_metadata_service.go#L41)</sup>
11391187

11401188
ArangoMLFeatureStoreDatabase define Database name to be used as MetadataService Backend
11411189

11421190
***
11431191

11441192
### .status.metadataService.local.arangoPipe
11451193

1146-
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/ml/v1alpha1/extension_status_metadata_service.go#L35)</sup>
1194+
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/ml/v1alpha1/extension_status_metadata_service.go#L38)</sup>
11471195

11481196
ArangoPipeDatabase define Database name to be used as MetadataService Backend
11491197

pkg/apis/deployment/v1/authentication_spec.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,13 @@ import (
2828

2929
// AuthenticationSpec holds authentication specific configuration settings
3030
type AuthenticationSpec struct {
31-
// JWTSecretName setting specifies the name of a kubernetes `Secret` that contains
32-
// the JWT token used for accessing all ArangoDB servers.
31+
// JWTSecretName setting specifies the name of a kubernetes `Secret` that contains a secret key used for generating
32+
// JWT tokens to access all ArangoDB servers.
3333
// When no name is specified, it defaults to `<deployment-name>-jwt`.
3434
// To disable authentication, set this value to `None`.
35-
// If you specify a name of a `Secret`, that secret must have the token
36-
// in a data field named `token`.
37-
// If you specify a name of a `Secret` that does not exist, a random token is created
38-
// and stored in a `Secret` with given name.
39-
// Changing a JWT token results in restarting of a whole cluster.
35+
// If you specify a name of a `Secret`, that secret must have the key value in a data field named `token`.
36+
// If you specify a name of a `Secret` that does not exist, a random key is created and stored in a `Secret` with given name.
37+
// Changing secret key results in restarting of a whole cluster.
4038
JWTSecretName *string `json:"jwtSecretName,omitempty"`
4139
}
4240

pkg/apis/deployment/v2alpha1/authentication_spec.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,13 @@ import (
2828

2929
// AuthenticationSpec holds authentication specific configuration settings
3030
type AuthenticationSpec struct {
31-
// JWTSecretName setting specifies the name of a kubernetes `Secret` that contains
32-
// the JWT token used for accessing all ArangoDB servers.
31+
// JWTSecretName setting specifies the name of a kubernetes `Secret` that contains a secret key used for generating
32+
// JWT tokens to access all ArangoDB servers.
3333
// When no name is specified, it defaults to `<deployment-name>-jwt`.
3434
// To disable authentication, set this value to `None`.
35-
// If you specify a name of a `Secret`, that secret must have the token
36-
// in a data field named `token`.
37-
// If you specify a name of a `Secret` that does not exist, a random token is created
38-
// and stored in a `Secret` with given name.
39-
// Changing a JWT token results in restarting of a whole cluster.
35+
// If you specify a name of a `Secret`, that secret must have the key value in a data field named `token`.
36+
// If you specify a name of a `Secret` that does not exist, a random key is created and stored in a `Secret` with given name.
37+
// Changing secret key results in restarting of a whole cluster.
4038
JWTSecretName *string `json:"jwtSecretName,omitempty"`
4139
}
4240

pkg/apis/ml/v1alpha1/extension_status_arangodb_ref.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ package v1alpha1
2323
import sharedApi "github.com/arangodb/kube-arangodb/pkg/apis/shared/v1"
2424

2525
type ArangoMLExtensionStatusArangoDBRef struct {
26-
// Secret keeps the information about Secret for ArangoDB Authentication
26+
// Secret keeps the information about ArangoDB deployment
2727
Secret *sharedApi.Object `json:"secret,omitempty"`
28+
// JWTTokenSecret keeps the JWT for ArangoDB authentication (only when ArangoDeployment has JWT enabled)
29+
JWTTokenSecret *sharedApi.Object `json:"jwtTokenSecret,omitempty"`
2830
}

pkg/apis/ml/v1alpha1/extension_status_metadata_service.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ type ArangoMLExtensionStatusMetadataService struct {
2828

2929
// Secret define the Secret specification to store all the details
3030
Secret *sharedApi.Object `json:"secret,omitempty"`
31+
32+
// JWTTokenSecret keeps the JWT for ArangoDB authentication (only when ArangoDeployment has JWT enabled)
33+
JWTTokenSecret *sharedApi.Object `json:"jwtTokenSecret,omitempty"`
3134
}
3235

3336
type ArangoMLExtensionStatusMetadataServiceLocal struct {

pkg/apis/ml/v1alpha1/zz_generated.deepcopy.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/crd/crds/database-deployment.schema.generated.yaml

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2067,15 +2067,13 @@ v1:
20672067
properties:
20682068
jwtSecretName:
20692069
description: |-
2070-
JWTSecretName setting specifies the name of a kubernetes `Secret` that contains
2071-
the JWT token used for accessing all ArangoDB servers.
2070+
JWTSecretName setting specifies the name of a kubernetes `Secret` that contains a secret key used for generating
2071+
JWT tokens to access all ArangoDB servers.
20722072
When no name is specified, it defaults to `<deployment-name>-jwt`.
20732073
To disable authentication, set this value to `None`.
2074-
If you specify a name of a `Secret`, that secret must have the token
2075-
in a data field named `token`.
2076-
If you specify a name of a `Secret` that does not exist, a random token is created
2077-
and stored in a `Secret` with given name.
2078-
Changing a JWT token results in restarting of a whole cluster.
2074+
If you specify a name of a `Secret`, that secret must have the key value in a data field named `token`.
2075+
If you specify a name of a `Secret` that does not exist, a random key is created and stored in a `Secret` with given name.
2076+
Changing secret key results in restarting of a whole cluster.
20792077
type: string
20802078
type: object
20812079
bootstrap:
@@ -15228,15 +15226,13 @@ v1alpha:
1522815226
properties:
1522915227
jwtSecretName:
1523015228
description: |-
15231-
JWTSecretName setting specifies the name of a kubernetes `Secret` that contains
15232-
the JWT token used for accessing all ArangoDB servers.
15229+
JWTSecretName setting specifies the name of a kubernetes `Secret` that contains a secret key used for generating
15230+
JWT tokens to access all ArangoDB servers.
1523315231
When no name is specified, it defaults to `<deployment-name>-jwt`.
1523415232
To disable authentication, set this value to `None`.
15235-
If you specify a name of a `Secret`, that secret must have the token
15236-
in a data field named `token`.
15237-
If you specify a name of a `Secret` that does not exist, a random token is created
15238-
and stored in a `Secret` with given name.
15239-
Changing a JWT token results in restarting of a whole cluster.
15233+
If you specify a name of a `Secret`, that secret must have the key value in a data field named `token`.
15234+
If you specify a name of a `Secret` that does not exist, a random key is created and stored in a `Secret` with given name.
15235+
Changing secret key results in restarting of a whole cluster.
1524015236
type: string
1524115237
type: object
1524215238
bootstrap:
@@ -28389,15 +28385,13 @@ v2alpha1:
2838928385
properties:
2839028386
jwtSecretName:
2839128387
description: |-
28392-
JWTSecretName setting specifies the name of a kubernetes `Secret` that contains
28393-
the JWT token used for accessing all ArangoDB servers.
28388+
JWTSecretName setting specifies the name of a kubernetes `Secret` that contains a secret key used for generating
28389+
JWT tokens to access all ArangoDB servers.
2839428390
When no name is specified, it defaults to `<deployment-name>-jwt`.
2839528391
To disable authentication, set this value to `None`.
28396-
If you specify a name of a `Secret`, that secret must have the token
28397-
in a data field named `token`.
28398-
If you specify a name of a `Secret` that does not exist, a random token is created
28399-
and stored in a `Secret` with given name.
28400-
Changing a JWT token results in restarting of a whole cluster.
28392+
If you specify a name of a `Secret`, that secret must have the key value in a data field named `token`.
28393+
If you specify a name of a `Secret` that does not exist, a random key is created and stored in a `Secret` with given name.
28394+
Changing secret key results in restarting of a whole cluster.
2840128395
type: string
2840228396
type: object
2840328397
bootstrap:

pkg/util/k8sutil/secrets.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -295,21 +295,6 @@ func CreateTokenSecret(ctx context.Context, secrets secretv1.ModInterface, secre
295295
return nil
296296
}
297297

298-
// CreateJWTTokenFromSecret creates a JWT token
299-
func CreateJWTTokenFromSecret(secret string, claims map[string]interface{}) (string, error) {
300-
// Create a new token object, specifying signing method and the claims
301-
// you would like it to contain.
302-
token := jg.NewWithClaims(jg.SigningMethodHS256, jg.MapClaims(claims))
303-
304-
// Sign and get the complete encoded token as a string using the secret
305-
signedToken, err := token.SignedString([]byte(secret))
306-
if err != nil {
307-
return "", errors.WithStack(err)
308-
}
309-
310-
return signedToken, nil
311-
}
312-
313298
// CreateJWTFromSecret creates a JWT using the secret stored in secretSecretName and stores the
314299
// result in a new secret called tokenSecretName
315300
func CreateJWTFromSecret(ctx context.Context, cachedSecrets secretv1.ReadInterface, secrets secretv1.ModInterface, tokenSecretName, secretSecretName string, claims map[string]interface{}, ownerRef *meta.OwnerReference) error {

0 commit comments

Comments
 (0)