-
Notifications
You must be signed in to change notification settings - Fork 464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add docs for bound service account token trigger authentication #1507
Merged
zroubalik
merged 2 commits into
kedacore:main
from
maxcao13:bound-service-account-token-trigauth
Mar 26, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
101 changes: 101 additions & 0 deletions
101
content/docs/2.17/authentication-providers/bound-service-account-token.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
+++ | ||
title = "Bound service account token" | ||
+++ | ||
|
||
You can pull one or more service account tokens into the trigger by defining the `serviceAccountName` of the Kubernetes service account. | ||
|
||
```yaml | ||
boundServiceAccountToken: # Optional. | ||
- parameter: connectionString # Required - Defined by the scale trigger | ||
serviceAccountName: my-service-account # Required. | ||
``` | ||
|
||
**Assumptions:** `namespace` is in the same resource as referenced by `scaleTargetRef.name` in the ScaledObject, unless specified otherwise. | ||
|
||
## Permissions for KEDA to request service account tokens | ||
|
||
By default, the KEDA operator does not have the necessary permissions to request service account tokens from an arbitrary service account. This is to prevent a privilege escalation where a bad actor could use KEDA to request tokens on behalf of any service account in the cluster. | ||
|
||
To allow KEDA to request tokens from a service account, you must grant the `keda-operator` service account the necessary permissions using RBAC. This can be done by creating a `Role` and a `RoleBinding` in the service account's namespace to allow the `keda-operator` service account the `create` permission on the namespaced `serviceaccounts/token` subresource. | ||
|
||
Here's a minimal example of a `Role` and `RoleBinding` that grants the necessary permissions for the KEDA operator to request and use tokens from the namespaced `my-service-account` service account. | ||
|
||
```yaml | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: Role | ||
metadata: | ||
name: keda-operator-token-creator | ||
namespace: my-namespace # Replace with the namespace of the service account | ||
rules: | ||
- apiGroups: | ||
- "" | ||
resources: | ||
- serviceaccounts/token | ||
verbs: | ||
- create | ||
resourceNames: | ||
- my-service-account # Replace with the name of the service account | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
name: keda-operator-token-creator-binding | ||
namespace: my-namespace # Replace with the namespace of the service account | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: Role | ||
name: keda-operator-token-creator | ||
subjects: | ||
- kind: ServiceAccount | ||
name: keda-operator | ||
namespace: keda # Assuming the keda-operator service account is in the keda namespace | ||
``` | ||
|
||
After applying similar restrictive permissions in your cluster, you can create the `TriggerAuthentication` resource that references the service account name, allowing KEDA to request and use tokens on your behalf with your scaler. Note that the service account must also have the necessary Kubernetes API permissions to perform the actions required by the scaler, such as querying metrics or managing resources, if the scaler delegates authentication to the Kubernetes API. | ||
|
||
### Usage in keda-charts | ||
|
||
If you use Helm Charts to deploy KEDA, you can supply namespaced names of the service accounts that KEDA request tokens from by setting the `boundServiceAccountToken` field in the `values.yaml` file. For example: | ||
|
||
```yaml | ||
# values.yaml | ||
permissions: | ||
operator: | ||
restrict: | ||
serviceAccountTokenCreationRoles: | ||
- name: myServiceAccount | ||
namespace: myServiceAccountNamespace | ||
``` | ||
|
||
This will create the necessary `Role` and `RoleBinding` in the `myServiceAccountNamespace` namespace: | ||
|
||
```yaml | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: Role | ||
metadata: | ||
name: keda-operator-token-creator-myServiceAccount | ||
namespace: myServiceAccountNamespace | ||
rules: | ||
- apiGroups: | ||
- "" | ||
resources: | ||
- serviceaccounts/token | ||
verbs: | ||
- create | ||
resourceNames: | ||
- myServiceAccount | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
name: keda-operator-token-creator-binding-myServiceAccount | ||
namespace: myServiceAccountNamespace | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: Role | ||
name: keda-operator-token-creator-myServiceAccount | ||
subjects: | ||
- kind: ServiceAccount | ||
name: keda-operator | ||
namespace: keda | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should document here the way how to enable this via Helm Chart, once we have the final implemenetation there