Skip to content
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

feat(vault config): set up access for users to access KVs through OIDC. #2

Merged
merged 16 commits into from
Jun 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
vendor
kubeflow-controller
.DS_Store
/.idea/
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ populate the `vendor` directory.

## Purpose

This is an example of how to build a kube-like controller with a single type controlling kubeflow.
This controller updates the state of Vault to allow access to secrets from OIDC users and from inside a profile's namespace.

![Example object diagram](docs/images/kubeflow-controller.svg)

## Running

Expand Down
32 changes: 23 additions & 9 deletions controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"reflect"
"time"

vault "github.com/hashicorp/vault/api"
v1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -89,9 +88,7 @@ type Controller struct {

dockerConfigJSON []byte

vaultClient *vault.Client
minioInstances []string
kubernetesAuthPath string
vaultConfigurer VaultConfigurer

// workqueue is a rate limited work queue. This is used to queue work to be
// processed instead of performing it as soon as a change happens. This
Expand All @@ -114,7 +111,7 @@ func NewController(
roleBindingInformer rbacv1informers.RoleBindingInformer,
profileInformer informers.ProfileInformer,
dockerConfigJSON []byte,
vaultClient *vault.Client, minioInstances []string, kubernetesAuthPath string) *Controller {
vaultConfigurer VaultConfigurer) *Controller {

// Create event broadcaster
// Add kubeflow-controller types to the default Kubernetes Scheme so Events can be
Expand All @@ -140,9 +137,7 @@ func NewController(
profilesLister: profileInformer.Lister(),
profilesSynced: profileInformer.Informer().HasSynced,
dockerConfigJSON: dockerConfigJSON,
vaultClient: vaultClient,
minioInstances: minioInstances,
kubernetesAuthPath: kubernetesAuthPath,
vaultConfigurer: vaultConfigurer,
workqueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "Profiles"),
recorder: recorder,
}
Expand Down Expand Up @@ -517,7 +512,26 @@ func (c *Controller) syncHandler(key string) error {
}

// Configure vault
err = doVaultConfiguration(c.vaultClient, profile.Name, c.minioInstances, c.kubernetesAuthPath)
//Get users that have access to the namespace
roleBindingsList, err := c.kubeclientset.RbacV1beta1().ClusterRoleBindings().List(context.TODO(), metav1.ListOptions{
FieldSelector: "metadata.namespace=" + profile.Name,
})
if err != nil {
return err
}

users := make([]string, 0)
for _, currentRoleBinding := range roleBindingsList.Items {
if currentRoleBinding.RoleRef.Name == "kubeflow-edit" {
for _, subject := range currentRoleBinding.Subjects {
if subject.Kind == "User" {
users = append(users, subject.Name)
}
}
}
}

err = c.vaultConfigurer.ConfigVaultForProfile(profile.Name, profile.Spec.Owner.Name, users)

// If an error occurs during Update, we'll requeue the item so we can
// attempt processing again later. This could have been caused by a
Expand Down
1 change: 1 addition & 0 deletions docs/images/kubeflow-controller.drawio
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<mxfile host="app.diagrams.net" modified="2020-05-21T14:06:48.491Z" agent="5.0 (Windows)" etag="mBREqsnoY0GnJDBDHRGY" version="13.1.1" type="device"><diagram name="Page-1" id="5f0bae14-7c28-e335-631c-24af17079c00">7V1Zc6O4Fv41fpmqUFpYH7N0uufe2zNdk+pZnqZom9hMMOQC7sT960fYCKMFIxbZOJU8dAchCTjnO6uOlBm+Xb9+TP3n1edkEUQzBBavM3w3QwiayCT/FS3bfYtjgn3DMg0XZadDw0P4IygbabdNuAgypmOeJFEePrON8ySOg3nOtPlpmryw3R6TiH3qs78MhIaHuR+JrX+Ei3xVtkIADjc+BeFyVT7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