-
Notifications
You must be signed in to change notification settings - Fork 955
Add support for automatic client authentication via TLS certificate fields #1920
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
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## unstable #1920 +/- ##
============================================
- Coverage 71.46% 71.46% -0.01%
============================================
Files 123 123
Lines 66927 67132 +205
============================================
+ Hits 47831 47973 +142
- Misses 19096 19159 +63
🚀 New features to boost your workflow:
|
zuiderkwast
left a comment
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.
Nice! I didn't do a complete review. For example I didn't look at the tests at all yet.
I'm not sure if the config should allow any field. Maybe only CN makes sense ever and then the config should maybe not be selecting a field. But let's discuss it and think about what we can do.
I found the corresponding features in ETCD and Kubernetes. The both use only common name as username:
-
ETCD: https://etcd.io/docs/v3.4/op-guide/authentication/#using-tls-common-name
As of version v3.2 if an etcd server is launched with the option --client-cert-auth=true, the field of Common Name (CN) in the client’s TLS cert will be used as an etcd user.
-
Kubernetes: https://kubernetes.io/docs/reference/access-authn-authz/authentication/#x509-client-certificates
If a client certificate is presented and verified, the common name of the subject is used as the user name for the request. As of Kubernetes 1.4, client certificates can also indicate a user's group memberships using the certificate's organization fields.
6574657 to
e2fd2c4
Compare
|
@valkey-io/core-team Trying to make an asynchronous decision. You can read the feature at the high level. We are discussing adding a new config flag, Please 👍 if you are okay with the recommendation of just a simple yes/no bool. Otherwise, please comment. |
|
I haven't seen any system using "O" as the user name, but I'm OK with it if we also anticipate that we'll support other fields. Common Name (CN) seems to be the most common, but I've seen read about systems and/or recommendations for using these:
What about combinations? If we use an enum, we'd need to define enum values like "CN or SAN DNS". Or shouldn't we accept combinations? |
|
Even if there is a remote chance of having some amount of customizations would lead me to recommend we should just use an enum with one option for now CN. |
@madolson I thought you were advocating for using |
There is a team at amazon who wanted it off the O field, but they honestly said they didn't care. They wrote all this logic in a module so they probably won't adopt what we build regardless. |
gotcha. I am less concerned about a specific team's implementation decision but if they see this being a legit use case maybe we should consider a special config instead, just to leave that door open? I feel that authentication on a team/org level isn't a uncommon use case. |
|
@omanges Will you have time to update this? We would like to have in Valkey 9.0, and just trying to gauge the status of open PRs. |
Signed-off-by: Omkar Mestry <[email protected]>
zuiderkwast
left a comment
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.
Almost there. I noticed the new INFO field. We may need to think about the naming.
c8a800b to
584a53e
Compare
zuiderkwast
left a comment
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.
Yeah, LGTM. Just one nit about a code comment.
…denied_tls_cert and formatting changes Signed-off-by: Omkar Mestry <[email protected]>
Signed-off-by: Omkar Mestry <[email protected]>
Signed-off-by: Omkar Mestry <[email protected]>
|
The test were passing earlier like I just changed the text, that shouldn't fail the test :) |
|
Flaky tests, yeah, don't worry about it. CI looks good for this change. |
zuiderkwast
left a comment
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.
Before merging I took a quick look. Noticed some config details to change. I will apply the change and merge. Thank you!
Config: Remove volatile flag, don't call applyTlsCfg, reorder to next to tls-auth-clients. Signed-off-by: Viktor Söderqvist <[email protected]>
Signed-off-by: Viktor Söderqvist <[email protected]>
madolson
left a comment
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.
Sorry. I was late to review this. Would you be able to address some of these comments in a followup, otherwise I can address them.
|
Will address these comments by raising another PR |
1. To check if the user is enabled 2. To use clientSetUser 3. To notify user change has happened
1. To check if the user is enabled 2. To use clientSetUser 3. To notify user change has happened Signed-off-by: Omkar Mestry <[email protected]>
This PR implements support for automatic client authentication based on a field in the client's TLS certificate.
API Changes:
tls-auth-clients-user, valuesCN|off, defaultoff. CN means take username from the CommonName field in the client's certificate.acl_access_denied_tls_certunder theStatssection, indicating the number of failed authentications using this feature, i.e. client certificates for which no matching username was found.🔒 Feature Overview:
Introduces a new configuration directive: tls-auth-clients-user.
Allows specifying a certificate field (only CN for now) to map to a Valkey user.
If a matching user is found, the client is automatically authenticated as that user upon TLS handshake.
Falls back to the default user if no match is found.
⚙️ Implementation Details:
Added getCertFieldByName() utility to extract fields from peer certificates.
Added autoAuthenticateClientFromCert() to handle automatic login logic post-handshake.
Integrated automatic authentication into the TLSAccept function after handshake completion.
Updated test suite (tests/integration/tls.tcl) to validate the feature.
✅ Benefits:
Enables smoother integration with mTLS-based infrastructures.
Reduces the need for clients to manually send AUTH commands.
Enhances security by tightly coupling certificate identity with Valkey access control.
🔬 Example:
This will authenticate the client as the user matching the certificate's Common Name.
Closes #1866