All right. Welcome, everyone, to our next talk. I'd like to welcome Barton Rhodes on securing your Kubeflow clusters. Everybody, please give him a round of applause. Thank you. So, yeah. I'll talk to you a bit about Kubeflow and Kubernetes and how to get it set up in a way that is not going to compromise your data. So, first of all, what is Kubeflow? Kubeflow is a set of open source components that are running on Kubernetes and are designed for end-to-end deployments of your machine learning models. So, you may have seen this quote or heard it on a recent podcast. It's a quote by Ian Coldwater. She said that containers are only as secure as their runtimes and their orchestration frameworks and their kernels and their operating systems and everything else. So, this is not a talk about Kubernetes security, per se, or container security, and we have excellent venues and talks at cons right now where you can go and learn about these things. What I wanted to do, rather than go into detail on that, is to introduce you to Kubeflow, let you know that it exists, and help you get started with it in a way that will give you some secure defaults and will allow you to prevent data exfiltration and help you to understand a little bit about the security model of Kubeflow and point you at resources that you can use to learn more about the underlying stack. So, this may not be new to most of you. I think originally I saw this chart in the paper called the Hidden Technical Debt Machine Learning. So, the actual machine learning code, the training code that you use to run your model is only a small portion of most of the things that go into making a successful deployment of a machine learning project. In many cases, the hard part begins once you have illustrated the value of the project, once you've shown that it works on your test data set, and you are asked to integrate it. And this is not a skill set that a lot of people coming from statistics or data science are equipped with. Obviously, people in this room are a slightly different mix from a typical data science environment, but that's effectively the goal of the project is to find open source components, existing cloud native technologies for every step of the way in deploying the model, starting with data pre-processing in a consistent manner to training your model to actually tuning your hyperparameters, keeping track of your experiments and metadata associated with actual model training. So, it's also a nice way of making data scientists comfortable with a number of Kubernetes concepts. Arguably, Kubernetes is not the right level of abstraction for a lot of us to understand the data science people and analysts understand the infrastructure that we consume. Typically, we just want to have compute. We want to be able to run our models within a certain amount of time. We want to be able to migrate our workloads between different deployment environments. And we want to do it in a manner that's familiar to us and using the tools that are commonly used by us every day. And so, that's the why of it. So, Kubeflow, like I said, reuses open source components. And it is designed to give you a sane defaults and integration pieces for every likely aspect of what you use. And so, here's an example of one of the possible deployment scenarios where, as a data scientist, you may start in Jupyter Notebook, which is a natural environment for a lot of data scientists, and then have the same workload that you run for training and prediction in the cloud. And including a managed service like AI Platform and run it on premise and basically anywhere Kubernetes runs. So, that's the goal. In order to accomplish this goal, it's a very young project. And so, my background coming into it is I am deploying this in a healthcare setting where you may have considerations of cost, considerations of data locality. You need to have sort of building blocks that are stackable by data scientists. And so, these building blocks is a project, subproject of Kubeflow called Faring. So, to introduce you to this, I would like to sort of point you to a series of blog posts by Netflix. And sort of it's trying to bring the Netflix model of notebook deployments to an open source project where a lot of not just data exploration, but, you know, model training or model inferencing happens inside of notebook. But also, the data engineering tasks and tasks that are repeatable. And there's lyrical paper mill that Faring integrates. So, Faring allows you to ask a question. How much of the actual workflow can we make reproducible directly from the Jupyter notebook? And so, this may sound crazy, but if you think about, you know, typical workloads that you encounter in large projects, the actual execution of your IPython kernel and things like that is a minor part of that. So, computationally, that's not a hard constraint. And Faring is a project that allows you to do that. So, to illustrate the benefits of Faring SDK, which is a Python SDK, you can see the current approach to deployments that are local. So, you may work in your preferred environment, not necessarily notebook. You know, Faring is equally usable from your favorite ID. You then would have to adapt it to some deployment surface, like it's a platform or actual managed service of some kind or your own API endpoint that you build. And then the way to deploy it in Kubeflow right now is through consuming the TF job type deployments. And so, that's a lot of modification and refactoring in every step where your target deployment and your local deployment differ introduces potential for bugs to creep in. So, with Faring, you can have a fairly simple way of migrating your workloads by abstracting away the backend and the deployment procedure for your model. So, that's one of the ways that Kubeflow allows you to benefit from coderies. And you can transition the environments pretty seamlessly by just swapping out whichever Kubeflow config that you have. So, you could target the cluster that's isolated. Healthcare cluster that has spatial data, you can target GKE. And so, pretty much any scenario where you would have Kubernetes can be easily addressed, including local environments. So, if you're used to developing locally with a minikube, if you're exposed to that, you don't have to change a lot of the templates that you work with in the cloud to be able to execute it. So, here's where it gets into security. So, like, all of these niceties are nice to have. But, you know, it's very, very important that we understand the security model and different permissions and exposure that you get by using these services. So, once again, my goal is to inform you as to where we are today and give you an idea as to what is affected by permissions that you have and sort of put it in front of you and let you examine it and, you know, understand the different approaches. So, as a part of the Jupyter Notebook service that comes into Kubeflow, you get access to a variety of resources. So, you can schedule pods, create deployment services, including training jobs and inference jobs in PyTorch, TensorFlow, and other frameworks are being added all the time. So, you can create this directly from your notebook. And you can once again have that as a repeatable step in your MLOps workload. That's the blog post that actually goes into it. So, the end result of this is to be able to, instead of making every deployment a one-off deployment where, you know, majority of data science projects actually end up not realizing their investment, you want to be able to have something that's automated and repeatable. So, that's the Netflix model that fairing enables. So, you can find the fairing SDK on GitHub. And the scenarios in which you use it is through consumption by the notebook and some sort of environment where you can use Python. So, you can imagine an airflow trigger. It can be any variety of different scenarios where the workflow needs to be automated. However, you get to a point where, you know, you want to be able to have a more defined workflow. Let's say you have deployed it. You've exposed your endpoint. So, typically, the end result of the fairing workflow is some sort of an endpoint where you have the ability to pass it on to your UI team, for instance, to build a simple UI around it. Or you have some other downstream service consuming it. So, that's as far as fairing gets you. And you can get that from the notebook or from a repeatable process. But what if you have a complex end-to-end process that requires a lot of many different steps that fail and you want to isolate each of those steps and control the security permission model on each individual part of the DAG. So, that's where Kubeflow Pipelines comes in. So, Pipelines is a different component I wanted to introduce you to before we jump into what you can do to make these deployments secure. It's a UI for managing experiments, jobs, and runs. So, it's also an SDK that effectively allows you to break down your entire end-to-end workflow into a number of containerized operations. So, instead of thinking in terms of an entire function that does a number of different things, from data preprocessing to outlier removal to training and then tuning, you can imagine your scenario. You isolate each component of that workflow into its own component. And you have the Docker image or something that captures the requirements of your model in one place. And you then can add things like monitoring to it. And all you have to do is to follow a number of standard interfaces that are defined in the container ops spec. So, the benefit of that is to be able to not only get performance out of your models by addressing bottlenecks, but you can also freeze a version of your model in time by looking at the exact image that was used to run at any given step of the model. So, if your goal is reproducibility, which I think it should be, you can get back to exact versions of containers that were used to run your model. So, visualization of the DAG might look like this. So, that's an example of the XGBoost run that you can find in the docs. So, as you can see, the operations here are not limited to just the ML tasks, like, you know, training and transformation of the data. But things like creating clusters. And if you go a few slides back, we can find that we have access to pods, deployment services, and jobs. So, you can not only do the modeling, but everything required for it in terms of infrastructure and service requirements that are needed. And then introduce monitoring and outputs in intermediate steps. So, one of the things you could do is visualize the HTML output of the Jupyter notebook that gives you some reference metrics for how well your model is doing. Or visualize a confusion matrix or an ROC curve. Something that will give you a way of visually debugging it. Which is one more place where the notebooks sort of make an appearance. You can take the same fairy notebooks that you use for analysis and integrate them into these intermediate steps as a form of, like, debugging intermediate steps. This is a diagram of what happens behind the scenes as far as allowing it to happen. So, if you actually look at the way pipelines are implemented, they're Argo workflows with a very thin sort of layer that makes it adaptable to Kubeflow pipelines. But if you are familiar with Argo, everything that Argo normally gets you, which is event driven workloads, isolation of individual steps, and you get with it. And so, in the recent version, you actually have the metadata store. So, every run of a Kubeflow pipeline is versioned. And the information about it is stored into a metadata database, which is a MySQL database with a JSON schema that allows you to track artifacts. The artifacts are pipelines or individual container operations in the pipeline. Once again, it's a lot of opportunity to mess up and expose some part of the architecture to the outside world. So, it's imperative that we talk more about how we isolate that. And as you can see, the entire architecture is quite complex. So, this talks a little bit about the domain specific language that Kubeflow pipelines gives you. So, you have container ops, pipeline parameters, components. There are a number of standard components that come with prebuilt containers and images that allow you to run simple Python functions that don't require a lot of dependencies. There are operations that allow you to handle volumes. So, you can actually create a data store that's needed for your storage of intermediate artifacts, like weights on your model or some debugging outputs. And this is an example of a specification, like a lot of things in Granny's world, you define it using YAML. So, as long as you are consistent in what inputs, outputs each individual step takes. So, you can attach an image to it and you can actually run a train command that or any other sort of entry point that will take arguments and allow you to execute a specific workload in a specific manner with a number of arguments that will power it. What does it get us? Take a step back from the concrete detail over there. It gets us a standard reusable component structure that allows us to take our work and be able to take it with us or generalize it to problems that we might encounter down the line. So, instead of learning a specific stack at one of the big four, we can actually go ahead and build in a manner that is shareable and is available to be executed anywhere. So, as a Google project, it initially had more contributors from Google. It recently passed the point where a majority of contributors actually come from the community. David Aronchik, the person who started as a PM of the project with Google, is now at Microsoft and bringing it to Azure. So, it's got broad support by the community and it's a community-driven project. In the future, you can imagine individual pieces of your pipelines becoming shared with others in a reusable manner. So, that's it about Kubeflow. I just wanted to give you a brief introduction. There's a lot more to it. And that's just scratching the surface by looking at these two components that get you from notebook interface to something that's event-driven and triggerable and reusable. So, I want to talk about benefits of this approach and how we think about security in Kubeflow. So, principle of least privilege, I think, is a benefit not just for this project, but Kubernetes in general. And then it's a good argument for running things in containers in the first place instead of having one service account with access to everything in your infrastructure. You can isolate your workloads by specific tasks that they're needed to perform. So, in this case, you can think about a container operation that needs to read data from a Google Cloud Storage bucket. The service accounts, the secrets that you expose to that container do not need to have anything beyond that. And if there is a vulnerability in some component of that container or if the container gets compromised, you don't lose access to the entire infrastructure. So, once again, to inform you what is happening now. And for context, a lot of this is still not like GA or it's not 1.0 version. So, the latest stable version is 0.6. Security tends to take a backseat when rapid development is a goal. And so, right now is the time to start thinking about how can we improve this? And so, my goal is to, by informing you, let you get to the GitHub, play with the code, see what you can do, see how you can break and hopefully open some issues and pull requests to help us do better. So, from that perspective, I will introduce you to the three service accounts and permissions that are currently deployed with them. So, we have... and a lot of this maps into the on-premise deployment, but of necessity, Google Cloud Platform has been more of a stable target for Kubeflow as of now. So, if you're dealing in the on-premise environment, I think things like IAM roles I'll be describing now, they're more specific to Google Cloud Platform and won't translate as easily to your on-premise role-based authentication. So, one service account is admin and it's used to actually deploy and configure the cluster. So, you can find the KFCTL script that is going to use the admin service account to perform most of the deployments. User is what most data scientists will encounter in their day-to-day. So, that allows you to use and consume GCP resources and interact with GCP resources from your container operations or fairing if you're using a Jupyter notebook. And we have the logging account as well, which uses VM, which is called VM and it's used to take audit logs and send them to Stackdriver. So, as far as concrete roles for the account, and all of these can be adjusted, by the way. So, this is taken directly from a Cloud Deployment Manager template that you can find in the repository. The admin service account has source admin, which is allowing you to push the application to Cloud Repository. It has the management account, which allows you to control the endpoints and the host names of those endpoints. Network admin is used to enable identity-aware proxy, which allows you to use your Google account to authenticate against different resources and consume them, as well as health checks. So, that's the admin account. If you wanted to change these, you would add things to the template, but that would be specific to your organization's security policy. The user service account allows you to do things like build custom things in Container Builder. That's important if you want to run your application in the context where you don't have access to GCR, Google Container Registry. And so, the builder allows you to actually package it up as a coherent sort of end-to-end application and deploy it potentially in an air-gapped environment, which could be a concern for security. You can have a viewer role for actually viewing the resources of the builds. And then, this is just an example. Your services may vary. So, for instance, you want to add Dataproc or something. This is not currently captured here, but this is a minimal set of permissions for interacting with Cloud Storage buckets, BigQuery, Dataflow, all of which will probably help you with data. And then, of course, the monitoring account, Log Writer, Metric Writer, and Object Viewer. So, these are the roles that you can review and decide whether they're appropriate or not. One of the things that hasn't been mentioned in the earlier slide is an IAP account. So, this actually goes to your user account that authenticates against Identity-Aware Proxy. So, you have to be able to have an Object Viewer role on that as a part of the implementation. And then, VM Service Account, like I said, has Log Writer and all that. So, okay. So, that's based on Kubeflow's built-in roles right now. The way that it relates to role-based authentication in Kubernetes is it complements it. So, when you are trying to define that, IAM can only get you so far. And it's probably better for metadata and access to other objects that are accessible through IAM and controlled through IAM roles. If you wanted to actually interact with Kubernetes permissions themselves, you could create other objects like cluster roles and cluster bindings that will help you control the management of your resources using the Kubernetes model. So, once again, I point you to resources towards the end where this can be addressed in more detail. So, this is a brief description of how that works. And just to clarify, one thing is that at point six, we now have per user namespace isolation. So, if you start with a new project and you add your own user, all of your pods, notebook services, endpoints that you deploy will be contained to that namespace. And so, other data scientists or other teams may not necessarily have access to your namespace. That buys you multi-tenancy and things like that. So, it's important to, for instance, if you are in a context where certain projects require a separate set of NDAs or have some PII that should not be accessible outside of your particular analysis. Okay. So, the gist of this talk is actually quite simple. There are two main things you can do as a data scientist when deploying this. My goal is for you to go back to your place of employment and try this. And when you try it, I don't want you to add cryptocurrency miners to your company's infrastructure. So, a few simple precautions can help you avoid that. So, the main one, honestly, is the VPC service control idea. So, what that allows you to do is to restrict access to certain API endpoints that will be consumed by your application to only the services and pods that come from within your Kubeflow deployment. VPC service control model. Gives you the secure perimeter within which only the clients that are authorized can have private access to resources, create them, copy them. And so, to be clear, this only applies to the content within those resources, not the metadata about those resources. If you wanted to manage the metadata, you would have to fall back on the IAM models. So, if you're trying to copy things from Google Cloud Storage or do things in BigQuery, if you want to make sure that your team in a different geographic locale will not have the same access, you just use VPC service controls to isolate them. So, these are some of the benefits that allow you to... that I could go into more detail on if there are any questions. But effectively, it's configurable using standard credentials. You have ability to restrict it by service. And here's an example of how you would do that. Of course, all of these environment variables actually have to be set. But this is the command line approach in which case you enable the resource manager API and the other prerequisite steps. There are similar ways of defining a secure perimeter in the UI in GCP. Once again, this would be different on your actual on-premise deployment. But you could say that your application should only be able to access PubSub or Storage API and should not be able to access Bigtable or other services within the perimeter. And you can restrict it to specific projects which in GCP land have come with their own set of isolations. So, when you're setting it up and trying to justify it to your boss, just make sure to say that you will not have issues with some high security service. Let's say BigQuery has all of your critical data. Another thing you can do, and I recommend doing this especially if you're exposing any resources that have a load balancer in front of them, restrict it by authorized networks by using a specific IP range that you'll be heading them from. So, it's something that can save you from unfortunate outcomes. Here's another command line example of what you saw earlier in the UI. So, in this case, you once again define a secure perimeter. But that's something that you can automate for creation of new projects either with Cloud Deployment Manager Terraform or other tool like that. Don't make it a guesswork every time. And try to you know, fall back on good practices and discuss with your team and understand like what is within your security budget. So, effectively, we have different APIs here. In this case, we're enabling BigQuery container registry and storage. But you know, your use case may vary. And so, I added some diagrams in case you wanted to see practically what this gives you. So, once you have a certain service perimeter that allows within which you run Kubeflow, you will not have to worry about unauthorized access from outside world or other clients that will consume it in ways that you didn't intend. This is the case for cloud. The on-premise situation a little bit more complicated, especially with GKE on-prem and Anthos. You know, you can have these things a bit more configured. But once again, this has been mostly GCP focused. In this case, you can extend your VPC perimeter into a on-premise network by using some sort of a VPN gateway that could come with its own subnet. And by defining strict firewall rules for how different VPCs talk to each other, you can prevent that from happening. Honestly, if you get to this point, you should probably work with your own operations as DLC teams. But as a one-off experiment, I recommend just running on GCP and configuring very basic service perimeter like so. One last step. I think it may seem obvious, but one of the most common ways GCP accounts get compromised is service account leakage. It's either somebody commits to GitHub or, like, that can happen. Especially for newer data analysts, data scientists, a lot of the tutorials advise you to add everything in your directory to get committed. So that's how a lot of that stuff happens. It's a true story. Luckily, Kubernetes allows you to store credentials in a secure manner that can be accessed from a variety of places in Kubeflow infrastructure. And I wanted to show you how to go through that really briefly. So you can add a secret by using standard secret creation interface. Secret can be a service account, JSON, environment variable that you set. I recommend using secrets for anything JSON or even the passwords that you want to consume later. You can spread the credentials to your entire infrastructure by using Google application credentials, which is your environment variable that stores your service account files and that every pod that will start with a certain service account within your cluster will have access to those resources. Let's say there is something every pod has to hit. Once again, per namespace, so you don't have to worry about leaking to your colleagues. You can authenticate from the pod directly by picking it up from a secret store and mounting a GCP secret as a volume. Once again, this environment variable is how your SDK will know what to authenticate with. You can access secrets from a pipeline. So if you remember the components earlier, it's part of the DSL to be able to include a specific secret into your pipeline. So think of this as a critical step. So it may be very tempting to add your secret to your Docker image if you're on a deadline, but if you just follow these simple procedures and you add secrets by using the DSL directly, you're preventing unnecessary harm from leaking your service accounts to your registry. Lastly, I had a little bit of material on the .6 edition, which just happened. What migration from .5 was the replacement of Ambassador Proxy with the Istio gateway. And at this point, it may not be as relevant to a day-to-day use by data scientists, but Istio comes with a number of very nice ways of controlling flow of data and security between different services in your cluster. And so you get a lot of things for free, like AuthC, authentication, authorization, and things like fault injections, which allow you to test your model. And so I'll wrap up real quick, but I wanted to point you to some resources and references. So Kubeflow.org is great. There are private clusters, description over there. And a lot of this material came from Kubeflow documentation, and as well as the blog post by Arikto, which did a really good write-up on authentication. Please join our Slack, start contributing. We need security people to look at this before it hits 1.0 so that we don't have nasty surprises down the line. And thank you. You can find me on Twitter, Keybase, GitHub, or feel free to email me directly.