@@ -9,17 +9,18 @@ import (
9
9
"time"
10
10
11
11
"github.com/go-chi/chi/v5"
12
- "github.com/google/cel-go/common/types"
13
12
"github.com/google/uuid"
14
13
"github.com/moby/moby/pkg/namesgenerator"
15
14
"golang.org/x/xerrors"
16
15
16
+ "github.com/expr-lang/expr"
17
+
17
18
"cdr.dev/slog"
18
19
"github.com/coder/coder/v2/coderd/apikey"
19
20
"github.com/coder/coder/v2/coderd/audit"
20
- celtoken"github.com/coder/coder/v2/coderd/cel"
21
21
"github.com/coder/coder/v2/coderd/database"
22
22
"github.com/coder/coder/v2/coderd/database/dbtime"
23
+ exprtoken"github.com/coder/coder/v2/coderd/expr"
23
24
"github.com/coder/coder/v2/coderd/httpapi"
24
25
"github.com/coder/coder/v2/coderd/httpmw"
25
26
"github.com/coder/coder/v2/coderd/rbac"
@@ -392,7 +393,7 @@ func (api *API) validateAPIKeyLifetime(ctx context.Context, lifetime time.Durati
392
393
}
393
394
394
395
// getMaxTokenLifetimeForUser determines the maximum token lifetime a user is entitled to
395
- // based on their attributes and theCEL expression configuration.
396
+ // based on their attributes and theexpr expression configuration.
396
397
func (api * API )getMaxTokenLifetimeForUser (ctx context.Context ,subject rbac.Subject ) time.Duration {
397
398
// Compiled at startup no need to recheck here.
398
399
program ,_ := api .DeploymentValues .Sessions .CompiledMaximumTokenDurationProgram ()
@@ -404,34 +405,30 @@ func (api *API) getMaxTokenLifetimeForUser(ctx context.Context, subject rbac.Sub
404
405
globalMax := api .DeploymentValues .Sessions .MaximumTokenDuration .Value ()
405
406
defaultDuration := api .DeploymentValues .Sessions .DefaultTokenDuration .Value ()
406
407
407
- // Convert subject toCEL -friendly format
408
- celSubject := celtoken . ConvertSubjectToCEL (subject )
408
+ // Convert subject toexpr -friendly format
409
+ exprSubject := exprtoken . ConvertSubjectToExpr (subject )
409
410
410
- // EvaluateCEL expression with typed struct
411
+ // Evaluateexpr expression with typed struct
411
412
// TODO: Consider adding timeout protection in future iterations
412
- out ,_ , err := program . Eval ( map [string ]interface {}{
413
- "subject" :celSubject ,
414
- "globalMaxDuration" :globalMax ,
415
- "defaultDuration" :defaultDuration ,
413
+ out ,err := expr . Run ( program , map [string ]interface {}{
414
+ "subject" :exprSubject ,
415
+ "globalMaxDuration" :int64 ( globalMax ) ,
416
+ "defaultDuration" :int64 ( defaultDuration ) ,
416
417
})
417
418
if err != nil {
418
- api .Logger .Error (ctx ,"theCEL evaluation failed, using default duration" ,slog .Error (err ))
419
+ api .Logger .Error (ctx ,"theexpr evaluation failed, using default duration" ,slog .Error (err ))
419
420
return defaultDuration
420
421
}
421
422
422
- // Convert result to time.Duration
423
- // CEL returns types.Duration, not time.Duration directly
424
- switch v := out .Value ().(type ) {
425
- case types.Duration :
426
- return v .Duration
427
- case time.Duration :
428
- return v
429
- default :
430
- api .Logger .Error (ctx ,"the CEL expression did not return a duration, using default duration" ,
431
- slog .F ("result_type" ,fmt .Sprintf ("%T" ,out .Value ())),
432
- slog .F ("result_value" ,out .Value ()))
423
+ // Convert result to time.Duration (expr returns int64 due to AsInt64 constraint)
424
+ intVal ,ok := out .(int64 )
425
+ if ! ok {
426
+ api .Logger .Error (ctx ,"the expr expression did not return an int64, using default duration" ,
427
+ slog .F ("result_type" ,fmt .Sprintf ("%T" ,out )),
428
+ slog .F ("result_value" ,out ))
433
429
return defaultDuration
434
430
}
431
+ return time .Duration (intVal )
435
432
}
436
433
437
434
func (api * API )createAPIKey (ctx context.Context ,params apikey.CreateParams ) (* http.Cookie ,* database.APIKey ,error ) {