(feat) Support for creating users on cluster init#82
Conversation
Signed-off-by: utdrmac <matthew.boehm@percona.com>
|
e2e tests pass in my local kind cluster |
| var _ = BeforeSuite(func() { | ||
| By("building the manager image") | ||
| cmd := exec.Command("make", "docker-build", fmt.Sprintf("IMG=%s", managerImage)) | ||
| By("purging old events") |
There was a problem hiding this comment.
K8S holds on to events for an extended period of time, even after a cluster is deleted. This call to purge events was added because subsequent e2e tests would fail if a previous test failed due to the e2e test fetching all events.
There was a problem hiding this comment.
Good catch. We could move it to valkeycluster_test.go to have it close to where its needed.
This is also the only testcase/context where we use involvedObject.name=valkeycluster-sample.
I guess it needs to be in a BeforeEach instead then.
|
|
||
| .PHONY: build | ||
| build: manifests generate fmt vet ## Build manager binary. | ||
| build: manifests generate fmt vet lint ## Build manager binary. |
There was a problem hiding this comment.
The golangci-lint was only ran during github e2e tests, and it was frustrating for this to fail remotely. Simple change to check this locally first.
jdheyburn
left a comment
There was a problem hiding this comment.
This is great to see, thank you for putting the time in! Just left some comments for clarity
| // Do not apply a password to this user | ||
| // +kubebuilder:default=false | ||
| NoPassword bool `json:"nopass,omitempty"` | ||
|
|
There was a problem hiding this comment.
i think passwordEnabled or enabledPassword would be good naming here instead of NoPassword. Also i am not sure this is general use case of having nopass attached to user. if they really want to acheieve this they can always use rawacl.
There was a problem hiding this comment.
It might not be general or recommended, but if Valkey exposes it as an option it might be useful to abstract it away.
https://valkey.io/topics/acl/#configure-acls-with-the-acl-command
This boolean is used in the PR in a few places. If we were to remove NoPassword here, would we change those conditions to be 'nopass' in RawAcl (pseudocode) ?
There was a problem hiding this comment.
I think the idea was since the ACL keyword is nopass then this follows-ish 1:1. Since the default is false if not specified, is there a strong reason to remove it? As the code is now, if removed, then passwords are always searched for even in a nopass=true case. The code would then need to check rawAcl for presence of nopass to achieve same logic.
Signed-off-by: utdrmac <matthew.boehm@percona.com>
|
I think we're almost there with this PR, just pending @sandeepkunusoth approval from their remaining comments |
| var _ = BeforeSuite(func() { | ||
| By("building the manager image") | ||
| cmd := exec.Command("make", "docker-build", fmt.Sprintf("IMG=%s", managerImage)) | ||
| By("purging old events") |
There was a problem hiding this comment.
Good catch. We could move it to valkeycluster_test.go to have it close to where its needed.
This is also the only testcase/context where we use involvedObject.name=valkeycluster-sample.
I guess it needs to be in a BeforeEach instead then.
| for _, shard := range s.Shards { | ||
| for _, slot := range shard.Slots { | ||
| var next []SlotsRange | ||
| var next []SlotsRange //nolint:prealloc |
There was a problem hiding this comment.
Interesting that this isn't showing in CI, our current main (given by kubebuilder) uses
make lint
...
Downloading github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.7.2
0 issues.
which is using
go: downloading github.com/alexkohler/prealloc v1.0.0
Is this seen with newer versions of golangci-lint/prealloc?
There was a problem hiding this comment.
Must be. I'm using golangci-lint has version 2.8.0 built with go1.25.5
bjosv
left a comment
There was a problem hiding this comment.
LGTM, my previous comments are nits
Signed-off-by: utdrmac <matthew.boehm@percona.com>
|
Resolved conflict with c679809 |
|
@utdrmac I think there is a bad merge pulling in some functions that no longer exist. Would you mind double checking to see what can be removed? Once that's done I'll approve and merge. Thanks again! |
|
Hmm, I didn't run into any issues with git merge main. 🤷 Anyooo, I merged main and reran test suite: |
318c67e to
f976ef7
Compare
| // primary, regardless of its node-index label. This handles the post-failover | ||
| // case where node-index=1 (or higher) was promoted by Valkey. | ||
| // Returns ("", "") if no primary is found. | ||
| func findShardPrimary(state *valkey.ClusterState, shardIndex int, pods *corev1.PodList) (nodeID, ip string) { |
There was a problem hiding this comment.
Is this, and the other functions above it, the result of a bad merge?
There was a problem hiding this comment.
upsertAnnotation is added by this PR. findShardPrimary was added in d777c83 I'm not seeing any merge issues.
There was a problem hiding this comment.
My apologies, the comparison I was making made it appear as something different :(
|
Thank for your time and effort on this @utdrmac ! |
|
Hey @utdrmac, I just deployed the sample cluster to a test cluster with this commit. I am wanting to check on the expectation for the charlie user which does not have a password (although they are disabled). The logs are erroring on that there is a missing password key for the user. |
|
@jdheyburn That is correct due to the logic flow. The first thing checked for is a password. If NoPassword is true, I guess it comes down to a design decision: Should users that are disabled appear in the ACL file? If yes, (current behavior), then the error is correct. If no, then the logic can be changed to completely skip users which are disabled (and print info message that user was skipped due to being disabled). |
Resolves valkey-io#36 This feature allows for the creation of Valkey users on cluster initialization. The feature abstracts Valkey ACL permissions into several objects, giving better readability, and creation flexibility to users that may not be intimately familiar with Valkey ACLs. --------- Signed-off-by: utdrmac <matthew.boehm@percona.com>
|
@utdrmac I think we should still create users if no password is provided. Otherwise modules that override the authentication flow (i.e valkey-ldap) will not works |
for nopass users we need to allow users with resetpass |
@sandeepkunusoth Can you expand on the workflow you're describing and how it might be used? @utdrmac @hieu2102 I think we should still create the user, but perhaps the logs could be tidied. If NoPass is defined then we don't need to error out, because we're not expecting a password. |
|
@hieu2102 Gotcha; easy enough to change |
Resolves #36
This feature allows for the creation of Valkey users on cluster initialization. The feature abstracts Valkey ACL permissions into several objects, giving better readability, and creation flexibility to users that may not be intimately familiar with Valkey ACLs.