You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
✨ Check known required permissions for install before installing with the helm applier (#1858)
* permissions preflight: copy necessary kubernetes libs
Signed-off-by: Joe Lanford <joe.lanford@gmail.com>
* permissions preflight: kubernetes rbac code modifications
Signed-off-by: Joe Lanford <joe.lanford@gmail.com>
* permissions preflight: add preauth implementation
Signed-off-by: Joe Lanford <joe.lanford@gmail.com>
* permissions preflight: enable implementation behind feature gate
Signed-off-by: Joe Lanford <joe.lanford@gmail.com>
* Rm k8s.io/kubernetes copypasta & import/replace
This is the manual version. Needed to change rbac.go a bit to allow for v1.32.2 code changes, but basically as-was
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Adds k8s.io/ lib maintainer tool
go.mod made in the current form the tool generates
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Make debug a flag
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Small fix, fixes err on kubernetes replace itself
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Changes to allow calling as make target
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Run go mod tidy post rebase
Signed-off-by: Brett Tofel <btofel@redhat.com>
* From rebase - add PreAuthorizer to Helm struct
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Fixes to pass linter
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Add needed setups to preflightPerm unit tests
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Address review comments on rbac.go
rbac_test.go likely coming soon
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Add tests for authorization/rbac.go
Signed-off-by: Tayler Geiger <tayler@redhat.com>
* Move k8sMaintainer code to its own dir
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Run k8smaintainer code post rebase
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Lint acceptable format for rbac_test.go
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Add tests for authorization/rbac.go
Signed-off-by: Tayler Geiger <tayler@redhat.com>
* Refactor inline feature gate check
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Change PreAuthorize() return value to []ScopedPolicyRules
Use []ScopedPolicyRules struct for first return value in PreAuthorize()
to avoid issues with random iteration order in previous map return
value.
Signed-off-by: Tayler Geiger <tayler@redhat.com>
* Lint acceptable format for rbac_test.go (take 2)
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Add fakeStorage dry run for escalationCheck
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Revert "Add fakeStorage dry run for escalationCheck"
This reverts commit 2681194.
* Rename template func to renderClientOnlyRelease
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Updated comment on returns of PreAuthorize
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Remove repetition in rbac_test.go
Signed-off-by: Tayler Geiger <tayler@redhat.com>
* k8smaintainer stage repo version pin logic upgrade
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Simplify PreAuthorizer handling via feature gate
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Split pre-auth checks cluster-scoped & ns-scoped
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Handle missing rules from escalation errors
Also sort final missing rules by namespace
Signed-off-by: Tayler Geiger <tayler@redhat.com>
* Clean up escalation error parsing and fix tests
Pass in the clusterextension to PreAuthorize instead of the user.Info
since we need the extension to create the clusterextension/finalizer
Signed-off-by: Tayler Geiger <tayler@redhat.com>
* Make tidy after rebase
Signed-off-by: Brett Tofel <btofel@redhat.com>
* GCI the files so lint passes
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Use slices.SortFunc instead of sort.Slice
Signed-off-by: Tayler Geiger <tayler@redhat.com>
* Lift running pre-auth checks out of Helm Apply
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Add centralized logging for feature gate status
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Err msg reads better
Co-authored-by: Per Goncalves da Silva <perdasilva@redhat.com>
* Run make tidy after rebase
Signed-off-by: Brett Tofel <btofel@redhat.com>
* No more magic numbers
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Sort components of missing rules lists
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Streamline var usage
* Lift to escalationCheckerFor method
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Fix lint prealloc err on allMissingPolicyRules
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Prealloc missingRulesWithDeduplicatedVerbs
* Tidy verb vars together with comment & issue link
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Add comments and protections on parsing err msg
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Improvements to k8smaintainer code
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Linter fix for unused byte slice
Signed-off-by: Brett Tofel <btofel@redhat.com>
* New target now 'k8s-pin', take ENVVAR for k8s ver
Also separate the target from make tiday and some code cleanup.
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Replace x/mod/semver w/ blang - more legible parse
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Move EXHELP for k8s-pin target
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Update README.md to account for changes
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Split permission & resolution error captures
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Improve permission regexp matching
Now handles multiple values in any of APIGroups, Resources, or Verbs.
Adds small utility function for trimming and splitting those values into
a string slice.
Signed-off-by: Tayler Geiger <tayler@redhat.com>
* Run make k8s-pin post-rebase
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Add tests to verify kubernetes API errors vs regex
Signed-off-by: Brett Tofel <btofel@redhat.com>
* permissions preflight: refactoring escalation error parser
Signed-off-by: Joe Lanford <joe.lanford@gmail.com>
* permission preflight: emit error when encountering unknown policy rule field
Signed-off-by: Joe Lanford <joe.lanford@gmail.com>
* permissions preflight: fixup escalation error parser and tests
Signed-off-by: Joe Lanford <joe.lanford@gmail.com>
* permissions preflight: add kubernetes compatibility tests, other small fixups
Signed-off-by: Joe Lanford <joe.lanford@gmail.com>
* preflight permissions: removing clusterextensions/finalizer patch requirement
The clusterextensions/finalizer requirement comes from the desire to
support clusters where OwnerReferencesPermissionEnforcement plugin is
enabled. This plugin requires "update", but not "patch" for the
clusterextensions/finalizers permission.
See: https://kubernetes.io/docs/reference/access-authn-authz/admission-controllers/#ownerreferencespermissionenforcement
Signed-off-by: Joe Lanford <joe.lanford@gmail.com>
* Addressing latest round of PR feedback
Signed-off-by: Tayler Geiger <tayler@redhat.com>
* Fix linting errors
Signed-off-by: Brett Tofel <btofel@redhat.com>
* SingleOwnNSInstallSupport feature gate reset
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Fix feature gate logging unhashable hash problem
Signed-off-by: Tayler Geiger <tayler@redhat.com>
* Remove duplicate test case
Signed-off-by: Tayler Geiger <tayler@redhat.com>
---------
Signed-off-by: Joe Lanford <joe.lanford@gmail.com>
Signed-off-by: Brett Tofel <btofel@redhat.com>
Signed-off-by: Tayler Geiger <tayler@redhat.com>
Co-authored-by: Joe Lanford <joe.lanford@gmail.com>
Co-authored-by: Tayler Geiger <tayler@redhat.com>
Co-authored-by: Per Goncalves da Silva <perdasilva@redhat.com>
verify: tidy fmt generate manifests crd-ref-docs generate-test-data #HELP Verify all generated code is up-to-date.
157
+
verify: k8s-pin fmt generate manifests crd-ref-docs generate-test-data #HELP Verify all generated code is up-to-date. Runs k8s-pin instead of just tidy.
# Kubernetes Staging Module Version Synchronization Tool
2
+
3
+
## Purpose
4
+
This tool ensures that if `k8s.io/kubernetes` changes version in your `go.mod`, all related staging modules (e.g., `k8s.io/api`, `k8s.io/apimachinery`) are automatically pinned to the corresponding published version. Recent improvements include an environment variable override and refined logic for version resolution.
5
+
6
+
## How It Works
7
+
8
+
1.**Parsing and Filtering:**
9
+
- Reads and parses your `go.mod` file.
10
+
- Removes existing `replace` directives for `k8s.io/` modules to avoid stale mappings.
11
+
12
+
2.**Determine Kubernetes Version:**
13
+
-**Environment Variable Override:**
14
+
If the environment variable `K8S_IO_K8S_VERSION` is set, its value is validated (using semver standards) and used as the target version for `k8s.io/kubernetes`. The tool then runs `go get k8s.io/kubernetes@<version>` to update the dependency.
15
+
-**Default Behavior:**
16
+
If `K8S_IO_K8S_VERSION` is not set, the tool reads the version of `k8s.io/kubernetes` from the `go.mod` file.
17
+
18
+
3.**Compute the Target Staging Version:**
19
+
- Converts a Kubernetes version in the form `v1.xx.yy` into the staging version format `v0.xx.yy`.
20
+
- If the target staging version is unavailable, the tool attempts to fall back to the previous patch version.
21
+
22
+
4.**Updating Module Replace Directives:**
23
+
- Retrieves the full dependency graph using `go list -m -json all`.
24
+
- Identifies relevant `k8s.io/*` modules (skipping the main module and version-suffixed modules).
25
+
- Removes outdated `replace` directives (ignoring local path replacements).
26
+
- Adds new `replace` directives to pin modules—including `k8s.io/kubernetes`—to the computed staging version.
27
+
28
+
5.**Finalizing Changes:**
29
+
- Writes the updated `go.mod` file.
30
+
- Runs `go mod tidy` to clean up dependencies.
31
+
- Executes `go mod download k8s.io/kubernetes` to update `go.sum`.
32
+
- Logs any issues, such as modules remaining at an untagged version (`v0.0.0`), which may indicate upstream tagging problems.
33
+
34
+
## Environment Variables
35
+
36
+
-**K8S_IO_K8S_VERSION (optional):**
37
+
When set, this environment variable overrides the Kubernetes version found in `go.mod`. The tool validates this semver string, updates the dependency using `go get`, and processes modules accordingly.
38
+
39
+
## Additional Notes
40
+
41
+
- The tool ensures consistency across all `k8s.io/*` modules, even if they are not explicitly listed in `go.mod`.
42
+
- If a suitable staging version is not found, a warning is logged and the closest valid version is used.
43
+
- All operations are logged, which helps in troubleshooting and verifying the process.
0 commit comments