Giter Site home page Giter Site logo

vcluster-runasuser-plugin's Introduction

RunAsUser Plugin

This plugin borrow logic from Kubernetes Admission Controller for RunAsUser as running as vcluster sidecar container.

Idea is that when this plugin is enabled users can use vcluster isolated mode with Restricted Pod Security Standard and still use kubectl create deployment ... normal way.

Using the Plugin

To use the plugin, create a new vcluster with the plugin.yaml:

# Use public plugin.yaml
vcluster create my-vcluster -n my-vcluster -f https://raw.githubusercontent.com/k8s4u/vcluster-runasuser-plugin/main/plugin.yaml

After that, wait for vcluster to start up and create deployment:

vcluster connect my-vcluster --namespace my-vcluster -- kubectl create deployment test --image=busybox -- sleep infinity

# Check if pod has started:
vcluster connect my-vcluster --namespace my-vcluster -- kubectl get pods

# Check if pod run with non-root user
vcluster connect my-vcluster --namespace my-vcluster -- kubectl exec -it <pod name> -- whoami

Building the Plugin

To just build the plugin image and push it to the registry, run:

# Build
docker build . -t k8s4u/vcluster-runasuser-plugin:dev

# Push
docker push k8s4u/vcluster-runasuser-plugin:dev

Then exchange the image in the plugin.yaml.

Development

General vcluster plugin project structure:

.
├── go.mod              # Go module definition
├── go.sum
├── devspace.yaml       # Development environment definition
├── devspace_start.sh   # Development entrypoint script
├── Dockerfile          # Production Dockerfile 
├── Dockerfile.dev      # Development Dockerfile
├── main.go             # Go Entrypoint
├── plugin.yaml         # Plugin Helm Values
├── syncers/            # Plugin Syncers
└── manifests/          # Additional plugin resources

Before starting to develop, make sure you have installed the following tools on your computer:

  • docker
  • kubectl with a valid kube context configured
  • helm, which is used to deploy vcluster and the plugin
  • vcluster CLI v0.6.0 or higher
  • DevSpace, which is used to spin up a development environment

If you want to develop within a remote Kubernetes cluster (as opposed to docker-desktop or minikube), make sure to exchange PLUGIN_IMAGE in the devspace.yaml with a valid registry path you can push to.

After successfully setting up the tools, start the development environment with:

devspace dev -n vcluster

After a while a terminal should show up with additional instructions. Enter the following command to start the plugin:

go run -mod vendor ./cmd/main.go

The output should look something like this:

I0124 11:20:14.702799    4185 logr.go:249] plugin: Try creating context...
I0124 11:20:14.730044    4185 logr.go:249] plugin: Waiting for vcluster to become leader...
I0124 11:20:14.731097    4185 logr.go:249] plugin: Starting syncers...
[...]
I0124 11:20:15.957331    4185 logr.go:249] plugin: Successfully started plugin.

You can now change a file locally in your IDE and then restart the command in the terminal to apply the changes to the plugin.

Delete the development environment with:

devspace purge -n vcluster

vcluster-runasuser-plugin's People

Contributors

olljanat avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.