Misconfiguring just one word in Kubernetes can expose your AWS environment to the internet, putting your data and applications at serious risk. Kubernetes and AWS are essential tools for managing scalable applications, yet their complexity can sometimes lead to critical misconfigurations. As DevOps and security professionals, we understand the importance of staying ahead of these challenges and ensuring our systems are both robust and secure, but with the introduction of LLMs (Large Language Models) the challenges have grown.
There’s no question that LLMs are redefining how we perform tasks across the organization. From marketing to software engineering, there’s not a single aspect that hasn’t been impacted by the proliferation of tools like ChatGPT and Gemini.
However, along with the obvious boons come certain risks that must be managed. Thanks to the powers of LLMs, what was previously not an issue may now become one.
One example of a misconfiguration that can arise is managing Security Groups for AWS Load Balancers using Kubernetes annotations, specifically Classic Load Balancers (CLB) and Network Load Balancers (NLB).
What we’ve found in our research is that Chat GPT may sometimes suggest one annotation:
service.beta.kubernetes.io/aws-load-balancer-extra-security-groups
and other times the other:
service.beta.kubernetes.io/aws-load-balancer-security-groups
The difference between the annotations that the LLM will suggest will depend on how you prompt the model, and the wrong choice can dramatically amplify your exposure. In this post, we’ll dive into this issue with Kubernetes annotations, understand what can go wrong, and figure out how to avoid this pitfall.
Consider a scenario where a developer wants to set up a simple test environment using an AWS Classic Load Balancer in Kubernetes with the help of ChatGPT. To quickly get started, the developer creates a Security Group that allows traffic from their home IP address , 203.0.113.1/32 in our example, with the following Cloud Formation configurations:
YAML
AWSTemplateFormatVersion: "2010-09-09"
Resources:
MySecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: "Allow HTTP from specific IP"
VpcId: "vpc-12345678"
SecurityGroupIngress:
- IpProtocol: "tcp"
FromPort: 80
ToPort: 80
CidrIp: "203.0.113.1/32"
SecurityGroupEgress:
- IpProtocol: "-1”
CidrIp: "0.0.0.0/0"
After creating the Security Group, it receives the following Security Group ID: « sg-0123456789abcdef0 ».
Then, the developer asks ChatGPT to create a load balancer that sets their Security Group. ChatGPT provides a YAML with the following configuration:
apiVersion: v1
kind: Service
metadata:
name: my-loadbalancer-service
annotations: service.beta.kubernetes.io/aws-load-balancer-extra-security-groups: "sg-0123456789abcdef0"
spec:
selector:
app: my-app
ports:
- protocol: TCP
port: 80
targetPort: 80
type: LoadBalancer
Unaware of the implications, contrary to the intention, the developer unknowingly exposes the load balancer to the entire internet, creating a significant security risk.
When AWS EKS creates a load balancer (for example, through a Kubernetes Service of type LoadBalancer), it also creates a default Security Group that allows access from IP addresses anywhere in the world (0.0.0.0/0) on the port specified in the Service configuration. In the example above, this port is 80.
While the developer created a restricted Security Group to allow traffic only from a specific IP address, the issue arises with the word « extra » in the annotation. Instead of replacing the default Security Group, this annotation adds the developer’s specified Security Group on-top of the default one. That means that the Load Balancer allows traffic from everywhere (0.0.0.0/0), even though the developer meant to configure only the Security Group which allows traffic from the specific IP. In short, this one word can leave your load balancer open to the world.
It’s not a bug; it’s a feature.
aws-load-balancer-security-groups vs. aws-load-balancer-extra-security-groups
When configuring AWS Classic/Network Load Balancers in Kubernetes, there are two kinds of annotations developers can use for managing Security Groups:
There are three types of annotations for AWS Load Balancers in Kubernetes that relates to our use case:
Annotation | Applies To | Default SG Behavior |
service.beta.kubernetes.io/aws-load-balancer-extra-security-groups | Classic Load Balancer Network Load Balancer |
Adds additional Security Groups to the default one. Default SG is created and used. |
service.beta.kubernetes.io/aws-load-balancer-security-groups | Classic Load Balancer Network Load Balancer |
Specifies exact Security Groups for the load balancer. Default SG is not used. |
alb.ingress.kubernetes.io/security-groups | Application Load Balancer | Specifies Security Groups for an ALB |
3 Types of Annotations in Kubernetes
Unlike the CLB and NLB that we discussed in the above scenario, using AWS Application Load Balancer (ALB) is straightforward since there’s only one annotation you can use:
alb.ingress.kubernetes.io/security-groups
There are numerous practices, some of which you might already be familiar with, to avoid this misconfiguration:
Understanding the distinction between Security Groups annotations is crucial for securing your AWS Load Balancers in Kubernetes. The risks of not configuring these annotations correctly can be critical and include:
It’s essential to validate your code—especially if you’re copying it from sources like Google or ChatGPT. Even seemingly small changes in Kubernetes annotations can expose your environment to unnecessary risks. It’s important to familiarize yourself with the different kinds of annotations, what each one is doing, and the implications of even small changes. The other key factor is understanding how LLMs are changing the game. LLMs are becoming increasingly popular across various aspects of work, and this Kubernetes annotation scenario is just one of many emerging with the widespread use of these models. While LLMs provide useful suggestions, may also suggest something that might not fit the situation, and could introduce an unnecessary security risk you didn’t count on.
Stay driven, keep learning, and stay caffeinated.
Begin your journey in security validation and see why leading companies trust us with their cybersecurity validation.