-
Notifications
You must be signed in to change notification settings - Fork 0
feat: per-tenant Valkey ACL provisioning #3
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
e0581ef
feat: per-tenant Valkey ACL provisioning
8228744
chore: update Helm chart with Valkey ACL env vars
cf90b59
fix: patch spec.template annotations to trigger Knative Revision
02d1e37
fix: watch valkey-acl Secret deletions to trigger immediate reconcile
fc53247
feat: add VALKEY_URL direct connection for local development
6f9b407
fix: resetpass before setting new password in ACL SETUSER
9f0fc41
feat: add custom metrics and fix redis.Nil in UserExists
adb8cba
fix: seed tenants_provisioned gauge from cluster state on startup
80f0f65
fix: gofmt and lll lint errors
d71c0cd
docs: document sync triggers and ACL replication caveat
ddf895e
fix: provision ACL users on all Valkey nodes, not just master
d034525
feat: configurable ACL resync period via VALKEY_ACL_RESYNC_PERIOD
da55cab
feat: Sentinel failover watch, all-node ACL sync, configurable resync…
a576c8e
fix: goconst and gofmt lint errors
491fdd8
fix: restrict Sentinel failover watcher to leader pod only
174760a
fix: address code review findings
588fee9
fix: remaining code review issues
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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,118 @@ | ||
| /* | ||
| Copyright 2025. | ||
|
|
||
| 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. | ||
| */ | ||
|
|
||
| // bootstrap is a one-shot CLI that annotates existing site Namespaces so the | ||
| // NamespaceReconciler picks them up and provisions Valkey ACL credentials. | ||
| // | ||
| // Usage: | ||
| // | ||
| // go run ./cmd/bootstrap --namespace-pattern sites- | ||
| // go run ./cmd/bootstrap --namespace-pattern sites- --dry-run | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "flag" | ||
| "fmt" | ||
| "os" | ||
| "strings" | ||
|
|
||
| corev1 "k8s.io/api/core/v1" | ||
| "k8s.io/apimachinery/pkg/runtime" | ||
| utilruntime "k8s.io/apimachinery/pkg/util/runtime" | ||
| clientgoscheme "k8s.io/client-go/kubernetes/scheme" | ||
| _ "k8s.io/client-go/plugin/pkg/client/auth" | ||
| ctrl "sigs.k8s.io/controller-runtime" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
| "sigs.k8s.io/controller-runtime/pkg/log/zap" | ||
| ) | ||
|
|
||
| const valkeyACLAnnotation = "deco.sites/valkey-acl" | ||
|
|
||
| func main() { | ||
| var namespacePattern string | ||
| var dryRun bool | ||
|
|
||
| flag.StringVar(&namespacePattern, "namespace-pattern", "sites-", | ||
| "Prefix used to filter Namespaces eligible for Valkey ACL provisioning.") | ||
| flag.BoolVar(&dryRun, "dry-run", false, | ||
| "Print which Namespaces would be annotated without making changes.") | ||
|
|
||
| opts := zap.Options{Development: true} | ||
| opts.BindFlags(flag.CommandLine) | ||
| flag.Parse() | ||
|
|
||
| ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts))) | ||
| log := ctrl.Log.WithName("bootstrap") | ||
|
|
||
| scheme := runtime.NewScheme() | ||
| utilruntime.Must(clientgoscheme.AddToScheme(scheme)) | ||
|
|
||
| cfg, err := ctrl.GetConfig() | ||
| if err != nil { | ||
| log.Error(err, "Failed to get kubeconfig") | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| k8s, err := client.New(cfg, client.Options{Scheme: scheme}) | ||
| if err != nil { | ||
| log.Error(err, "Failed to create Kubernetes client") | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| ctx := context.Background() | ||
|
|
||
| nsList := &corev1.NamespaceList{} | ||
| if err := k8s.List(ctx, nsList); err != nil { | ||
| log.Error(err, "Failed to list Namespaces") | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| annotated, skipped := 0, 0 | ||
| for i := range nsList.Items { | ||
| ns := &nsList.Items[i] | ||
|
|
||
| if !strings.HasPrefix(ns.Name, namespacePattern) { | ||
| continue | ||
| } | ||
|
|
||
| if ns.Annotations[valkeyACLAnnotation] == "true" { | ||
| log.Info("Already annotated, skipping", "namespace", ns.Name) | ||
| skipped++ | ||
| continue | ||
| } | ||
|
|
||
| if dryRun { | ||
| fmt.Printf("[dry-run] would annotate namespace %s\n", ns.Name) | ||
| annotated++ | ||
| continue | ||
| } | ||
|
|
||
| patch := client.MergeFrom(ns.DeepCopy()) | ||
| if ns.Annotations == nil { | ||
| ns.Annotations = make(map[string]string) | ||
| } | ||
| ns.Annotations[valkeyACLAnnotation] = "true" | ||
| if err := k8s.Patch(ctx, ns, patch); err != nil { | ||
| log.Error(err, "Failed to annotate namespace", "namespace", ns.Name) | ||
| continue | ||
| } | ||
| log.Info("Annotated namespace", "namespace", ns.Name) | ||
| annotated++ | ||
| } | ||
|
|
||
| log.Info("Bootstrap complete", "annotated", annotated, "skipped", skipped) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.