-
Notifications
You must be signed in to change notification settings - Fork 8
WIP - Kubeconfig RBAC #91
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
Open
xrstf
wants to merge
19
commits into
kcp-dev:main
Choose a base branch
from
xrstf:kubeconfig-authz
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
bcbcd69
extend API types
xrstf 514ffe8
codegen
xrstf 4f5df5d
implement controller and reconciler
xrstf 25139d0
fix RBAC markers
xrstf 78da3a3
appease linter
xrstf 3d4665b
prevent automatic controller naming logic from breaking the operator
xrstf 40c122d
fix copyright year
xrstf c83c80a
deploy operator into kind during e2e tests so it can access any pod/s…
xrstf 27cbe81
WIP
xrstf d1da99a
add provisionedWorkspace field to kubeconfig status
xrstf 09ec22a
rename to cluster because it's more generic
xrstf 3438f01
cleanup in the actually provisioned cluster
xrstf 6fbcf98
first unprovision the old, then provision the new cluster
xrstf eb54ec2
fix nil pointer access
xrstf 20cee06
reload kubeconfig before patching status
xrstf d06dca6
re-enable cleanup
xrstf 947aada
add docs
xrstf af6dc14
cleanup
xrstf 57b2251
fix tests, make them flake much, much less
xrstf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,3 +5,4 @@ resources: | |
| images: | ||
| - name: controller | ||
| newName: ghcr.io/kcp-dev/kcp-operator | ||
| newTag: e2e | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,4 +2,5 @@ nav: | |
| - index.md | ||
| - basics.md | ||
| - front-proxy.md | ||
| - kubeconfig.md | ||
| - Certificate Management: pki.md | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| --- | ||
| description: > | ||
| Shows how `Kubeconfig` objects can be used to provide credentials to kcp. | ||
| --- | ||
|
|
||
| # Kubeconfigs | ||
|
|
||
| Besides provisioning kcp itself, the kcp-operator can also provide [kubeconfigs](https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/) to access kcp. Each kubeconfig will internally be backed by a dedicated client certificate. | ||
|
|
||
| ## Basics | ||
|
|
||
| A minimal `Kubeconfig` object typically looks like this: | ||
|
|
||
| ```yaml | ||
| apiVersion: operator.kcp.io/v1alpha1 | ||
| kind: Kubeconfig | ||
| metadata: | ||
| name: susan | ||
| namespace: my-kcp | ||
| spec: | ||
| # Required: the username inside Kubernetes; | ||
| # this will be the client certificate's common name. | ||
| username: susan | ||
|
|
||
| # required: groups to attach to the user; | ||
| # this will be the organizations in the client cert. | ||
| groups: | ||
| - system:kcp:admin | ||
|
|
||
| # Required: in what Secret the generated kubeconfig should be stored. | ||
| secretRef: | ||
| name: susan-kubeconfig | ||
|
|
||
| # Required: a Kubeconfig must target either a FrontProxy, Shard or RootShard. | ||
| target: | ||
| frontProxyRef: | ||
| name: my-front-proxy | ||
|
|
||
| # Required: how long the certificate should be valid for; | ||
| # the operator will automatically renew the certificate, after which the | ||
| # Secret will be renewed and have to be re-downloaded. | ||
| validity: 8766h | ||
| ``` | ||
|
|
||
| `Kubeconfig` objects must exist in the same namespace as the kcp installation they are meant for. | ||
|
|
||
| Once the `Kubeconfig` has been created, you can observe its status to wait for it to be ready. After that, retrieve the Secret mentioned in the `secretRef` to find the finished kubeconfig, ready to use. | ||
|
|
||
| !!! warning | ||
| Deleting a `Kubeconfig` will also delete the underlying Secret from the hosting cluster, however this will not invalidate the existing certificate that is embedded in the kubeconfig. This means anyone with a copy of the kubeconfig can keep using it until the certificate expires. | ||
|
|
||
| To disarm an old kubeconfig, make sure to revoke any permissions granted through RBAC for the user and/or their groups. | ||
|
|
||
| !!! note | ||
| The `Kubeconfig`'s name is embedded into the certificate in form of a group (organization) named `kubeconfig:<name>`. This is to allow a unique mapping from RBAC rules to `Kubeconfig` objects for the authorization (see further down). Take note that this means the `Kubeconfig`' name is leaked to whoever gets the kubeconfig. | ||
|
|
||
| ## Authorization | ||
|
|
||
| Without any further configuration than shown in the basics section above, the created identity (username + groups) will not get any permissions in kcp. So while the kubeconfig is valid and allows proper authentication, pretty much no actions will be permitted yet. | ||
|
|
||
| The administrator has to either rely on externally-managed RBAC rules to provide permissions, or use the kcp-operator to provision such RBAC in a workspace. | ||
|
|
||
| To make the kcp-operator manage RBAC, use `spec.authorization` inside a `Kubeconfig`: | ||
|
|
||
| ```yaml | ||
| apiVersion: operator.kcp.io/v1alpha1 | ||
| kind: Kubeconfig | ||
| metadata: | ||
| name: susan | ||
| namespace: my-kcp | ||
| spec: | ||
| #...snip... | ||
|
|
||
| authorization: | ||
| clusterRoleBindings: | ||
| # This can be a workspace path (root:something) or a cluster name (ID). | ||
| cluster: root:initech:teamgibbons | ||
| clusterRoles: | ||
| - cluster-admin | ||
| ``` | ||
|
|
||
| This configuration would bind the group `kubeconfig:susan` to the ClusterRole `cluster-admin` inside the given workspace. Note that this is specifically not bound to the user (common name), so that two `Kubeconfig` objects that both have the same `spec.name` to not have colliding RBAC. | ||
|
|
||
| When deleting a `Kubeconfig` with authorization settings, the kcp-operator will first unprovision (delete) the `ClusterRoleBindings` before the `Kubeconfig` can be deleted. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Does
clusterRolesonly reference objects that already exist in the cluster? I am wondering if it could be made possible to also configure RBAC inside the cluster?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.
For now this is only binding to pre-existing ClusterRoles, yes.