Skip to content

Commit b153a1a

Browse files
committed
Pass object type to cel script
1 parent 9fed5a8 commit b153a1a

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

internal/authorization/cel.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func NewCELAuthorizer(reader client.Reader, prefix string) (authorizer.Authorize
4040
celgo.Variable("self", celgo.DynType),
4141
celgo.Variable("user", celgo.DynType),
4242
celgo.Variable("prefix", celgo.StringType),
43+
celgo.Variable("kind", celgo.StringType),
4344
},
4445
})
4546
if err != nil {
@@ -92,7 +93,7 @@ func (b *CELAuthorizer) Authorize(
9293
}
9394

9495
compiled, err := b.compiler.CompileCELExpression(&Expression{
95-
Expression: "(has(self.spec.username) ? self.spec.username : prefix + self.kind.lowerAscii() + ':' + self.metadata.namespace + ':' + self.metadata.name + ':' + self.metadata.uid) == user.username",
96+
Expression: "(has(self.spec.username) ? self.spec.username : prefix + kind.lowerAscii() + ':' + self.metadata.namespace + ':' + self.metadata.name + ':' + self.metadata.uid) == user.username",
9697
})
9798

9899
user := attributes.GetUser()
@@ -105,6 +106,7 @@ func (b *CELAuthorizer) Authorize(
105106
"extra": user.GetExtra(),
106107
},
107108
"prefix": b.prefix,
109+
"kind": attributes.GetResource(),
108110
})
109111
if err != nil {
110112
return authorizer.DecisionDeny, "failed to evaluate expression", err

0 commit comments

Comments
 (0)