-
Notifications
You must be signed in to change notification settings - Fork 386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🌱 Use caching authorizers per-workspace in initializingworkspaces/builder #2477
🌱 Use caching authorizers per-workspace in initializingworkspaces/builder #2477
Conversation
pkg/virtual/initializingworkspaces/builder/caching_authorizer.go
Outdated
Show resolved
Hide resolved
pkg/virtual/initializingworkspaces/builder/caching_authorizer.go
Outdated
Show resolved
Hide resolved
pkg/virtual/initializingworkspaces/builder/caching_authorizer.go
Outdated
Show resolved
Hide resolved
pkg/virtual/initializingworkspaces/builder/caching_authorizer.go
Outdated
Show resolved
Hide resolved
pkg/virtual/initializingworkspaces/builder/caching_authorizer.go
Outdated
Show resolved
Hide resolved
pkg/virtual/initializingworkspaces/builder/caching_authorizer.go
Outdated
Show resolved
Hide resolved
pkg/virtual/initializingworkspaces/builder/caching_authorizer.go
Outdated
Show resolved
Hide resolved
pkg/virtual/initializingworkspaces/builder/caching_authorizer.go
Outdated
Show resolved
Hide resolved
pkg/virtual/initializingworkspaces/builder/caching_authorizer.go
Outdated
Show resolved
Hide resolved
pkg/virtual/initializingworkspaces/builder/caching_authorizer.go
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGMT overall. Would like @s-urbaniak to review the authz/audit pieces
|
||
authz, err := c.loadOrStore(workspace) | ||
if err != nil { | ||
return authorizer.DecisionNoOpinion, "error", err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@s-urbaniak would appreciate guidance on what to use here for the reason
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As commented above, reason
can be left empty string, however the error should be anonmyized.
workspace, name, err := initialization.TypeFrom(tenancyv1alpha1.ClusterWorkspaceInitializer(dynamiccontext.APIDomainKeyFrom(ctx))) | ||
if err != nil { | ||
logger.V(2).Info(err.Error()) | ||
return authorizer.DecisionNoOpinion, "unable to determine initializer", fmt.Errorf("access not permitted") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@s-urbaniak PTAL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is taken 1:1 from the current implementation, so if anything I suggest to take improvements as a separate PR. However, my comment for this (and thus the previous implementation):
- specifying a reason in case of errors is not necessary. If an error occurs, the reason is discarded as per https://github.com/kubernetes/kubernetes/blob/00aae4c10c204d258e62a96f30970e9b91b29149/staging/src/k8s.io/apiserver/pkg/endpoints/filters/authorization.go#L67-L71
- We have to be careful of anonymizing here, so using the authorization decorator
kcp/pkg/authorization/decorator.go
Line 48 in ffc21ea
func NewDecorator(key string, target authorizer.Authorizer) *Decorator {
However, it's ok to address this as a follow-up as this PR introduces caching of delegated authorizers only.
/test e2e-shared |
pkg/virtual/initializingworkspaces/builder/caching_authorizer.go
Outdated
Show resolved
Hide resolved
pkg/virtual/initializingworkspaces/builder/caching_authorizer.go
Outdated
Show resolved
Hide resolved
As this is caching delegated authorizers and not authorize decisions per se I would be rather explicit about this in the godocs by saying that this caches authorizers per requested logical cluster and each cached authorizer additionally caches "allow" results (TTL being 5 minutes) and "deny" results (TTL being 30 seconds) per requested attributes. So it is rather a "cache of caches". Additionally I suggest to add an additional constructor in the delegated authorizer and have the TTLs configurable so we know the exact timings here rather than on relying on central defaults ( kcp/pkg/authorization/delegated/authorizer.go Lines 38 to 39 in 8d95d65
|
/lgtm |
// load loads the authorizer from the cache, if any. | ||
func (c *cachingAuthorizer) load(clusterName logicalcluster.Name) authorizer.Authorizer { | ||
value, ok := c.cache.Get(clusterName) | ||
if !ok && value == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
||
?
|
||
// NewCaching creates a new Authorizer that holds an internal cache of | ||
// Delegated Authorizer(s). | ||
func NewCaching(client kcpkubernetesclientset.ClusterInterface, auth CachingAuthorizerFunc, opts CachingOptions) *cachingAuthorizer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would call this NewCachingAuthorizer
This changeset is scoped to the virtual/initializingworkspace package. Signed-off-by: Vince Prignano <vince@prigna.com>
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ncdc The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/test e2e-multiple-runs |
1 similar comment
/test e2e-multiple-runs |
/retest |
1 similar comment
/retest |
This changeset is scoped to the virtual/initializingworkspace package.
Signed-off-by: Vince Prignano vince@prigna.com
Summary
Related issue(s)
Fixes #