Create a Python-based Helm chart generator that produces Kubernetes YAML manifests for the defense sidecar deployment. Includes Workload Identity configuration for secure GKE authentication without stored credentials.
GenAI Security Engineering › AI Security Engineering › Chapter 1 · Prompt Injection Defense › Deploy injection defense as FastAPI sidecar on GKE
5:39
Create a Python-based Helm chart generator that produces Kubernetes YAML manifests for the defense sidecar deployment. Includes Workload Identity configuration for secure GKE authentication without stored credentials.
Host: You're listening to a lab companion for AI Security Engineering, and today's chapter is Prompt Injection Defense. Prompt injection is when someone sneaks malicious instructions into the text your AI system reads — trying to hijack it. This chapter is about building real, layered defenses against that. And the skill in today's exercise is about packaging those defenses so a real operations team can actually deploy them safely in the cloud.
Expert: Let me paint the scene. Imagine you're at a mid-sized company — maybe two hundred engineers, a platform team of six — and you've just built a working defense service that inspects prompts going into your AI features. It works beautifully on your laptop. Now the security team wants it running in production, sitting in front of every AI call the company makes. And here's where most teams hit a wall. The service needs to talk to cloud resources — storage buckets, secret stores, other internal services — and the traditional way to do that is to create a long-lived password, paste it into a config file, and hope nobody leaks it. In a security product, that is absurd. You cannot ship a defense service whose own credentials are a liability. So the platform team needs a clean, repeatable way to deploy this thing, with identity handled by the cloud itself instead of stored secrets. That's what you're solving today.
Host: Okay, so this is exercise two of three in the sequence. In the previous exercise, you wrapped the injection defense logic into a web service — something other applications can send text to and get back a verdict on whether it looks malicious. Now you're extending that. So what exactly are we building in this lab?
Expert: You're building a generator — a small program that produces deployment files. Let me unpack that. When you deploy software to a modern cloud cluster, you describe what you want in configuration files — how many copies to run, how much memory, what network ports, what permissions. These files are written in a format called YAML, which is basically structured text. Now, for any non-trivial service, you end up with a lot of these files, and they share a lot of repeated values. So the community built a tool called Helm, which is essentially a template system for these deployment files. You write templates once, you fill in the blanks for each environment, and Helm stamps out the final files. A bundle of these templates is called a Helm chart. Your job in this exercise is to write a Python program that produces a complete Helm chart for the defense service you built last time. The key idea — the conceptual shift — is this. You are no longer writing the service. You are writing the thing that writes the instructions for running the service. It's one level up. Think of it like the difference between cooking a meal and writing the recipe card that a kitchen staff will follow every night. Your generator is the recipe writer.
Host: And there's a security piece baked in here — Workload Identity. Explain what that is and why it matters.
Expert: Right, this is the heart of the exercise. Workload Identity is a feature of Google's Kubernetes service — Kubernetes being the system that runs containers in the cloud, and GKE being Google's hosted version of it. Normally, if your service needs to read from a cloud storage bucket, you'd give it a credential file — a long secret string. Workload Identity replaces that entirely. Instead of carrying a password, your service gets an identity badge from the cluster itself, and the cloud trusts that badge directly. No secret ever touches disk. No credential can leak because there isn't one. Your generator needs to produce the configuration that sets this up — linking the service's identity inside the cluster to a corresponding identity in the cloud account. This is the modern, correct way to do cloud authentication, and it's exactly what a security-conscious team expects.
Host: Before we wrap — what's the tricky part? What trips people up on this one?
Expert: The trap is thinking of this as a text-templating problem. It's not. It's a correctness problem. The files you generate have to be valid — the right structure, the right indentation, the right cross-references between pieces. A tiny typo in the identity binding, and the service silently fails to authenticate in production. The tip: build your generator so it validates the output before writing it to disk. Produce the structured data first in memory, check it against the known shape of a valid deployment, and only then turn it into text. Treat the YAML as the last step, not the first. That habit will save you hours of debugging in the real world.
Host: Great. So to close out — after this exercise, what will you actually be able to do, and what's coming next?
Expert: After this, you'll be able to take any internal service and produce a production-ready deployment package for it, with cloud-native identity wired in from day one — no stored passwords, no manual steps. That's a genuine platform engineering capability, and it's the kind of reusable building block your team can standardize across every service you ship. Next up in the sequence, you'll configure automatic scaling for this same defense service — teaching the cluster to add more copies when traffic spikes and scale down when things are quiet. With all three exercises together, you'll have a complete, self-defending, self-scaling security layer you can bring straight into your team's architecture discussions. Thanks for listening, and good luck with the lab.
Want to go deeper? Explore disciplines with hands-on labs, quizzes, and chapter podcasts.