diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..305e971 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,31 @@ +--- +name: Bug report +about: Report a bug in the stackit-pod-identity-webhook +--- + +## Description + +_Please add a clear and concise description of what the bug is._ + +## Steps to reproduce + +_Please provide us with the steps to reproduce the behavior._ + +## Actual behavior + +_Please describe the current behavior of the stackit-pod-identity-webhook. Don't forget to add detailed information like error messages._ + +## Expected behavior + +_Please describe the behavior which you would expect from the stackit-pod-identity-webhook in that case._ + +## Environment + +- Kubernetes version: +- Version of the stackit-pod-identity-webhook: + +## Additional information + +_Feel free to add any additional information here._ + +/kind bug diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..8bf707d --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,22 @@ +--- +name: Feature request +about: Suggest an idea for the stackit-pod-identity-webhook +--- + +## Problem description + +_Is your feature request related to a problem? If so, please give us a clear and concise description of what the problem is._ + +## Proposed solution + +_A clear and concise description of what you want to happen._ + +## Alternative solutions (optional) + +_A clear and concise description of any alternative solutions or features you've considered. (optional)_ + +## Additional information + +_Feel free to add any additional information here._ + +/kind enhancement diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..9e610be --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,28 @@ +**How to categorize this PR?** + + + +**What this PR does / why we need it**: + +**Which issue(s) this PR fixes**: +Fixes # + +**Special notes for your reviewer**: + +**Breaking changes**: + + diff --git a/.github/release.yaml b/.github/release.yaml new file mode 100644 index 0000000..812e325 --- /dev/null +++ b/.github/release.yaml @@ -0,0 +1,17 @@ +changelog: + exclude: + labels: + - no-release-note + categories: + - title: âš ī¸ Breaking Changes + labels: + - breaking + - title: ✨ Features + labels: + - kind/enhancement + - title: 🐛 Bug Fixes + labels: + - kind/bug + - title: â„šī¸ Other Changes + labels: + - "*" diff --git a/.github/renovate.json5 b/.github/renovate.json5 new file mode 100644 index 0000000..9575f95 --- /dev/null +++ b/.github/renovate.json5 @@ -0,0 +1,24 @@ +{ + $schema: 'https://docs.renovatebot.com/renovate-schema.json', + extends: [ + 'config:recommended', + ':semanticCommitsDisabled', + 'github>gardener/ci-infra//config/renovate/automerge-with-tide.json5', + 'github>stackitcloud/ske-ci-infra//config/renovate/ske.json5', + ], + additionalReviewers: [ + 'team:ske-security', + ], + packageRules: [ + { + matchManagers: [ + 'gomod', + ], + matchUpdateTypes: [ + 'patch', + 'digest', + ], + automerge: true, + }, + ], +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0f1eb89 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +hack/tools/bin +bin diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..8d5e427 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,29 @@ +# Contributing to `stackit-pod-identity-webhook` + +Welcome and thank you for making it this far and considering contributing to `stackit-pod-identity-webhook`. +We always appreciate any contributions by raising issues, improving the documentation, fixing bugs or adding new features. + +Before opening a PR, please read through this document. + +## Process of making an addition + +For major changes, API changes or features please open an [Issue](https://github.com/stackitcloud/stackit-pod-identity-webhook/issues) +beforehand to clarify if this is in line with the project and to avoid unnecessary work. + +To contribute any code to this repository, just do the following: + +1. Make sure you have Go's latest version installed +2. Fork this repository +3. Make your changes + > Please follow the [seven rules of great Git commit messages](https://chris.beams.io/posts/git-commit/#seven-rules) + > and make sure to keep your commits clean and atomic. + > Your PR will be squashed before merging so the commits can and should tell a story. + > + > Add documentation and tests for your addition if needed. +4. Run `make verify` to ensure your code is ready to be merged + > If any linting issues occur please fix them. + > Using a nolint directive should only be used as a last resort. +5. Open a PR and make sure the CI pipelines succeeds. +6. Wait for one of the maintainers to review your code and react to the comments. +7. After approval by the maintainers the PR will be merged. +8. Thank you for your contribution! :) diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a565a26 --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2026 Schwarz IT KG + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file diff --git a/Makefile b/Makefile index 2980cca..9c6fb26 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,10 @@ SHELL = /usr/bin/env bash -o pipefail .PHONY: all all: verify +.PHONY: help +help: ## Display this help. + @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) + ##@ Development .PHONY: fmt @@ -46,14 +50,20 @@ verify-modules: modules ## Verify go module files are up to date. fi .PHONY: verify -verify: verify-fmt verify-modules check - -##@ Development +verify: verify-fmt verify-modules check ## Runs formatting checks, module tidying, linting, and all tests. .PHONY: skaffold-dev skaffold-dev: ## Run skaffold dev with cert-manager skaffold dev -p cert-manager +.PHONY: kind-up +kind-up: ## Create kind cluster. + kind create cluster + +.PHONY: kind-down +kind-down: ## Delete kind cluster. + kind delete cluster + ##@ Build .PHONY: build diff --git a/README.md b/README.md index 5a03404..4fadfc5 100644 --- a/README.md +++ b/README.md @@ -1 +1,62 @@ -# stackit-pod-identity-webhook \ No newline at end of file +# stackit-pod-identity-webhook + +A Kubernetes mutating admission webhook that injects STACKIT workload identity compatible tokens into pods. +This enables "secret-less" authentication for workloads running in Kubernetes clusters which need to authenticate +for the STACKIT API. + +## Use with SKE (STACKIT Kubernetes Engine) + +If you're using SKE you don't need to setup this webhook in your cluster. It comes preconfigured with every SKE cluster. +Just set the `workload-identity.stackit.cloud/service-account-email` for your desired `ServiceAccount` and the +projected volume and environment variables for the SDK will be injected into your pod spec using the annotated `ServiceAccount`. + +## Features +- **[Projected ServiceAccount Tokens](https://kubernetes.io/docs/concepts/storage/projected-volumes/#serviceaccounttoken):** Injects projected volumes with audience-bound tokens. +- **SDK Configuration:** Automatically sets environment variables (`STACKIT_SERVICE_ACCOUNT_EMAIL`, etc.) for the [STACKIT SDK](https://github.com/stackitcloud/stackit-sdk-go). +- **Configurable:** Supports per-ServiceAccount configuration via annotations for audience, token expiration, and IDP endpoints. + +## Supported Annotations + +### ServiceAccount Annotations +The webhook looks for the following annotations on `ServiceAccounts`: + +| Annotation | Description | Default | +| --- |---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| --- | +| `workload-identity.stackit.cloud/service-account-email` | Enables workload identity and specifies the STACKIT Service Account email. | Required to enable | +| `workload-identity.stackit.cloud/audience` | Audience for the projected token. The audience is part of the configured trust relationship at the Identity Provider. For use with the STACKIT Identity Provider you usually don't need to change this. | `sts.accounts.stackit.cloud` | +| `workload-identity.stackit.cloud/service-account-token-expiration-seconds` | Validity of the projected Kubernetes Service Account token. | `600` | +| `workload-identity.stackit.cloud/idp-token-expiration-seconds` | Validity of the token issued by the Identity Provider. | SDK default | +| `workload-identity.stackit.cloud/idp-token-endpoint` | The Identity Provider endpoint for token exchange. | SDK default | +| `workload-identity.stackit.cloud/federated-token-file` | Path to the projected token file. Also changes mount path. | SDK default | + +## Exclusion Logic +The webhook can be configured to skip mutation for specific resources using labels: + +- **Skip a specific Pod:** Add the label `workload-identity.stackit.cloud/skip-pod-identity-webhook: "true"` to the Pod. +- **Skip a whole Namespace:** Add the label `workload-identity.stackit.cloud/skip-pod-identity-webhook: "true"` to the Namespace. All Pods in this namespace will be ignored. +> [!NOTE] +> Label-based filtering and the exclusion of the `kube-system` namespace depend on the `MutatingWebhookConfiguration` selectors. These are pre-configured in the provided Helm chart and come as a standard feature in STACKIT Kubernetes Engine (SKE). + +# Deployment + +## Production Deployment + +For production, it is recommended to use [cert-manager](https://cert-manager.io/) to manage the webhook's TLS certificates. + +1. **Install cert-manager** in your cluster. +2. **Configure an Issuer or ClusterIssuer.** +3. **Deploy the Helm chart** with cert-manager enabled: + ```bash + helm install stackit-pod-identity-webhook ./charts/stackit-pod-identity-webhook + --set certmanager.enabled=true + --set certmanager.issuerName= + --set certmanager.issuerKind= + ``` + +When `certmanager.enabled` is `true`, the chart will: +- Create a `Certificate` resource. +- Use `cert-manager`'s CA injector to automatically populate the `caBundle` in the `MutatingWebhookConfiguration`. + +## Development + +For information on how to develop and test the webhook, please see [docs/development.md](docs/development.md). diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..810c822 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,9 @@ +# Reporting Security Issues + +**Please do not report security vulnerabilities through public GitHub issues.** + +We at STACKIT take security seriously. We appreciate your efforts to responsibly disclose your findings, and will make every effort to acknowledge your contributions. + +To report a security issue, please email [cybersecurity@stackit.cloud](mailto:cybersecurity@stackit.cloud). + +Our team will send a response indicating the next steps in handling your report. After the initial reply to your report, the security team will keep you informed of the progress towards a fix and full announcement, and may ask for additional information or guidance. diff --git a/docs/development.md b/docs/development.md new file mode 100644 index 0000000..216fc8b --- /dev/null +++ b/docs/development.md @@ -0,0 +1,40 @@ +# Development + +## Prerequisites +- [Go](https://go.dev/) (1.26+) +- [Helm](https://helm.sh/) +- [Skaffold](https://skaffold.dev/) +- A Kubernetes cluster (e.g., [kind](https://kind.sigs.k8s.io/)) + +Development tools like `ko`, `golangci-lint`, and `setup-envtest` are managed automatically via the Go toolchain (`go tool`). + +## Project Structure +- `cmd/stackit-pod-identity-webhook`: Entry point for the webhook manager. +- `pkg/webhook`: Core mutation logic and admission handler. +- `charts/stackit-pod-identity-webhook`: Helm chart for deployment. +- `test/integration`: Integration tests using `envtest` and Ginkgo. +- `hack`: Scripts and tooling configuration. + +## Makefile Targets +To see all available targets and their descriptions, run `make help`. + +# Local Deployment (kind) +The easiest way to deploy locally is using the provided Makefile targets, which automatically manage the cluster and install `cert-manager` and the webhook: + +```bash +make kind-up +make skaffold-dev +``` +## Testing Mutation + +After deploying the webhook you can check if it works: + +1. Apply the sample resources: + ```bash + kubectl apply -f examples/test-identity.yaml + ``` +2. Verify the mutation on the Pod: + ```bash + kubectl get pod test-pod -o yaml + ``` + diff --git a/samples/test-identity.yaml b/examples/test-identity.yaml similarity index 100% rename from samples/test-identity.yaml rename to examples/test-identity.yaml