-
Notifications
You must be signed in to change notification settings - Fork 28
add ACL authentication support with auto-generated and existing secret options #14
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
Open
rawkode
wants to merge
9
commits into
valkey-io:main
Choose a base branch
from
rawkode:add-acl-authentication
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2787b1e
add ACL authentication support with auto-generated and existing secre…
rawkode b228324
fix: don't overwrite an existing password
rawkode 1d7f0d9
fix: use regex for content check to improve performance against large…
rawkode 925cf47
fix: rename test to unittest to avoid conflict
rawkode e2862ee
fix: no need to escape regex
rawkode 8321f22
Merge branch 'main' into add-acl-authentication
mk-raven 1362ccc
Merge branch 'main' into add-acl-authentication
mk-raven 1770aac
Allow multiple users to be defined
sgissi 539f02a
Ensure users are unique, update documentation and tests.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| name: Test Charts | ||
|
|
||
| on: | ||
| pull_request: | ||
| push: | ||
| branches: | ||
| - main | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Helm | ||
| uses: azure/setup-helm@v4 | ||
| with: | ||
| version: v3.15.4 | ||
|
|
||
| - name: Install helm-unittest plugin | ||
| run: helm plugin install https://github.com/helm-unittest/helm-unittest | ||
|
|
||
| - name: Lint chart | ||
| run: helm lint ./valkey | ||
|
|
||
| - name: Run unit tests | ||
| run: helm unittest ./valkey |
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,30 @@ | ||
| # Valkey Helm Chart Tasks | ||
|
|
||
| # Run helm-unittest tests | ||
| test: | ||
| @echo "=== Running Unit Tests ===" | ||
| helm unittest ./valkey | ||
|
|
||
| # Lint the Helm chart | ||
| lint: | ||
| @echo "=== Linting Valkey Helm Chart ===" | ||
| helm lint ./valkey | ||
|
|
||
| # Render templates with default values | ||
| template: | ||
| helm template valkey ./valkey | ||
|
|
||
| # Render templates with auth enabled | ||
| template-auth: | ||
| helm template valkey ./valkey \ | ||
| --set auth.enabled=true \ | ||
| --set auth.generateDefaultUser.enabled=true | ||
|
|
||
| # Package the chart | ||
| package: | ||
| helm package ./valkey | ||
|
|
||
| # Run all validations | ||
| validate: lint test | ||
| @echo "=== All validations passed ===" | ||
|
|
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 |
|---|---|---|
|
|
@@ -22,4 +22,7 @@ | |
| *.tmproj | ||
| .vscode/ | ||
|
|
||
| .github/ | ||
| .github/ | ||
|
|
||
| # Unit tests (only ignore root-level tests/, not templates/tests/) | ||
| /tests/ | ||
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,21 @@ | ||
| {{- if and .Values.auth.enabled .Values.auth.generateDefaultUser.enabled }} | ||
| apiVersion: v1 | ||
| kind: Secret | ||
| metadata: | ||
| name: {{ include "valkey.fullname" . }}-auth | ||
| labels: | ||
| {{- include "valkey.labels" . | nindent 4 }} | ||
| type: Opaque | ||
| data: | ||
| {{- $password := .Values.auth.generateDefaultUser.password }} | ||
| {{- if not $password }} | ||
| {{- $existingSecret := (lookup "v1" "Secret" .Release.Namespace (printf "%s-auth" (include "valkey.fullname" .))) }} | ||
| {{- if and $existingSecret $existingSecret.data $existingSecret.data.password }} | ||
| {{- $password = ($existingSecret.data.password | b64dec) }} | ||
| {{- else }} | ||
| {{- $password = randAlphaNum 32 }} | ||
| {{- end }} | ||
| {{- end }} | ||
| password: {{ $password | b64enc | quote }} | ||
| users.acl: {{ printf "user %s on >%s %s" .Values.auth.generateDefaultUser.username $password .Values.auth.generateDefaultUser.permissions | b64enc | quote }} | ||
| {{- end }} |
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,120 @@ | ||||||||||
| {{- if and .Values.auth.enabled .Values.auth.generateDefaultUser.enabled }} | ||||||||||
| apiVersion: v1 | ||||||||||
| kind: Pod | ||||||||||
| metadata: | ||||||||||
| name: {{ include "valkey.fullname" . }}-test-auth-generated | ||||||||||
| labels: | ||||||||||
| {{- include "valkey.labels" . | nindent 4 }} | ||||||||||
| annotations: | ||||||||||
| "helm.sh/hook": test | ||||||||||
| "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded | ||||||||||
| spec: | ||||||||||
| restartPolicy: Never | ||||||||||
| containers: | ||||||||||
| - name: test-auth | ||||||||||
| image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" | ||||||||||
| command: | ||||||||||
| - sh | ||||||||||
| - -c | ||||||||||
| - | | ||||||||||
| set -e | ||||||||||
| echo "Testing authentication with generated default user..." | ||||||||||
| # Extract password from secret | ||||||||||
| PASSWORD=$(cat /valkey-auth/password) | ||||||||||
| # Test authentication | ||||||||||
| valkey-cli -h {{ include "valkey.fullname" . }} -p {{ .Values.service.port }} --user {{ .Values.auth.generateDefaultUser.username }} --pass "$PASSWORD" PING | ||||||||||
| # Test that we can set and get a value | ||||||||||
| valkey-cli -h {{ include "valkey.fullname" . }} -p {{ .Values.service.port }} --user {{ .Values.auth.generateDefaultUser.username }} --pass "$PASSWORD" SET test-key-generated "test-value" | ||||||||||
| VALUE=$(valkey-cli -h {{ include "valkey.fullname" . }} -p {{ .Values.service.port }} --user {{ .Values.auth.generateDefaultUser.username }} --pass "$PASSWORD" GET test-key-generated) | ||||||||||
| if [ "$VALUE" = "test-value" ]; then | ||||||||||
| echo "✓ Authentication test passed (generated user)" | ||||||||||
| exit 0 | ||||||||||
| else | ||||||||||
| echo "✗ Authentication test failed: expected 'test-value', got '$VALUE'" | ||||||||||
| exit 1 | ||||||||||
| fi | ||||||||||
| volumeMounts: | ||||||||||
| - name: valkey-auth | ||||||||||
| mountPath: /valkey-auth | ||||||||||
| readOnly: true | ||||||||||
| volumes: | ||||||||||
| - name: valkey-auth | ||||||||||
| secret: | ||||||||||
| secretName: {{ include "valkey.fullname" . }}-auth | ||||||||||
| {{- end }} | ||||||||||
| --- | ||||||||||
| {{- if and .Values.auth.enabled .Values.auth.existingSecret }} | ||||||||||
| apiVersion: v1 | ||||||||||
| kind: Pod | ||||||||||
| metadata: | ||||||||||
| name: {{ include "valkey.fullname" . }}-test-auth-existing | ||||||||||
| labels: | ||||||||||
| {{- include "valkey.labels" . | nindent 4 }} | ||||||||||
| annotations: | ||||||||||
| "helm.sh/hook": test | ||||||||||
| "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded | ||||||||||
| spec: | ||||||||||
| restartPolicy: Never | ||||||||||
| containers: | ||||||||||
| - name: test-auth | ||||||||||
| image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" | ||||||||||
| command: | ||||||||||
| - sh | ||||||||||
| - -c | ||||||||||
| - | | ||||||||||
| set -e | ||||||||||
| echo "Testing authentication with existing secret..." | ||||||||||
| # Verify ACL file exists | ||||||||||
| if [ ! -f /valkey-auth/users.acl ]; then | ||||||||||
| echo "✗ ACL file not found in existing secret" | ||||||||||
| exit 1 | ||||||||||
| fi | ||||||||||
| # Extract first user and password from ACL file (basic parsing) | ||||||||||
| # Expected format: user <username> on ><password> ... | ||||||||||
| ACL_CONTENT=$(cat /valkey-auth/users.acl) | ||||||||||
| echo "ACL content preview: $(echo "$ACL_CONTENT" | head -c 100)" | ||||||||||
| # Test basic connection (no auth - will fail if auth is properly configured) | ||||||||||
| if valkey-cli -h {{ include "valkey.fullname" . }} -p {{ .Values.service.port }} PING 2>/dev/null; then | ||||||||||
| echo "✗ Authentication test failed: server allows unauthenticated access" | ||||||||||
| exit 1 | ||||||||||
| fi | ||||||||||
| echo "✓ Authentication is enforced (unauthenticated access denied)" | ||||||||||
| # If password key exists in secret, test with it | ||||||||||
| if [ -f /valkey-auth/password ]; then | ||||||||||
| PASSWORD=$(cat /valkey-auth/password) | ||||||||||
|
||||||||||
| PASSWORD=$(cat /valkey-auth/password) | |
| PASSWORD=$(cat /valkey-auth/password) | |
| # Extract the first username from the ACL file, fallback to "default" if not found | |
| USERNAME=$(awk '/^user / {print $2; exit}' /valkey-auth/users.acl) |
rawkode marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
rawkode marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
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.
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.
[nitpick] The regex pattern uses
(?m)multiline flag but could be simplified. Consider using a more readable approach or add a comment explaining the regex logic for maintainability.