-
Notifications
You must be signed in to change notification settings - Fork 56
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
Implement an authorization layer for operator-to-workspace communication #712
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## v2 #712 +/- ##
==========================================
- Coverage 53.68% 53.00% -0.69%
==========================================
Files 27 29 +2
Lines 2902 3081 +179
==========================================
+ Hits 1558 1633 +75
- Misses 1164 1267 +103
- Partials 180 181 +1 ☔ View full report in Codecov by Sentry. |
Note that the chart tests are failing for unrelated reasons - the job doesn't build the docker image and uses the wrong image name. |
} | ||
a.log.Debugw("authorization allowed", zap.String("reason", reason)) | ||
|
||
return context.WithValue(ctx, "k8s.user", res.User), 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.
Where is this k8s.user
key consumed?
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.
Nowhere, it is for hypothetical chained interceptors. But when you look at grpc examples, you see that the context is typically amended and I would like to retain the pattern.
) | ||
|
||
const ( | ||
ServiceAccountPermissionsErrorMessage = ` |
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 reminds me we should move the agent's pkg to internal. Defaulting everything to private spares us the overhead of having to worry about what's exported here. We can do this later.
Overview
This PR implements an authentication and authorization layer for the agent's RPC endpoint.
Authentication is performed by authenticating a bearer token via the TokenReview API. The operator uses its built-in service account token. Authorization is performed via the SubjectAccessReview API, which checks for following RBAC permission:
The workspace pod's service account must be granted the
system:auth-delegator
role using aClusterRoleBinding
. For. convenience, the installer creates a service account namedpulumi
into thedefault
namespace, with an associated binding.The operator itself is granted the necessary permission to access the RPC endpoint.
Proposed changes
--auth-mode=kube
,--kube-workspace-name=random-yaml
)cluster role binding for workspace service account (to ClusterRole namedsystem:auth-delegator
)Future Enhancement
This implementation uses the operator's default service account token, but to further improve security it should use
an audience-scoped token, where the audience is the agent service address as opposed to the API server. Such tokens may be created by the operator with a call to TokenRequest, and checked with TokenReview by adding the expected audience to the context (
authenticator.WithAudience
).Related issues (optional)
Closes #609
Examples
Some example requests: