ManageIQ / kubeclient

A Ruby client for Kubernetes REST API
MIT License
416 stars 166 forks source link

Security in shared environments #517

Open collimarco opened 3 years ago

collimarco commented 3 years ago

I am building a Rails application that manages different K8s clusters for different customers.

Basically the Rails application works like this:

  1. The tenant writes some YAML files for configuring his own cluster
  2. The Rails app connects to the cluster of the customer and applies the new configuration

Is it safe to use this gem for this use case?

Example:

It would be useful to document whether this gem is appropriate or not to be used in shared / multi-tenant environments with untrusted inputs (YAML configuration, etc).

Thanks in advance

cben commented 3 years ago

Have you seen the readme section about config security?

File access (EDIT: and arbitrary command execution!) can be disabled (at the cost that configs referencing external certs etc. won't work).

We've closed a yaml deserialization hole before. We use safe_load now but hard to be 100% certain there are no other holes... More fundamentally, malicious config can cause various http requests not necessarily to the cluster - e.g. can trivially set up MITM - so you might leak data, both on connect and later (e.g. you create a Secret => mitm attacker now knows it); generally it's hard to recommend...

cben commented 3 years ago

If your use case takes zero inputs from your server, all data comes from customer, then its maybe ok, as in a customer can only attack themselves. But there's still quesdion of isolation between customers. If you run them all from same ruby process, that's up to ruby bugs (and side channels)... IMHO cluster credentials are too sensitive for that, if you can say run a per-customer container that feels better. [disclaimer: i'm not an security professional]

collimarco commented 3 years ago

Thanks for the reply.

Our use case: if a customer defines a YML file from our dashboard, we will apply that to the customer K8s cluster.

Said that:

Let's see each point in your answer:

malicious config can cause various http requests not necessarily to the cluster

This is not a security issue because the customer is exposing his own data (voluntary) to a different cluster or server.

so you might leak data

What data? The YML file is already owned by the customer. The only problem would be some kind of interpolation or variable loading made by this library on the YML config... But as you said it uses safe_load.

isolation between customers. If you run them all from same ruby process, that's up to ruby bugs

Ok, this is out of scope... Obviously anything can have security bugs, including Ruby, OS, etc. but that is an entire different topic. You just need to apply the normal security patches when there's a CVE.

collimarco commented 3 years ago

It would be interesting to know more about this:

Config.new(data, nil) is better but Kubeclient was never reviewed for behaving safely with malicious / malformed config. It might crash / misbehave in unexpected ways... https://github.com/abonas/kubeclient#security-dont-use-config-from-untrusted-sources

I wonder what makes the original developer think that it might misbehave. A practical example would be interesting.