-
Notifications
You must be signed in to change notification settings - Fork 93
Accept Opaque secrets as TLS credentials for backward compatibility #2524
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
AryanP123
wants to merge
1
commit into
skupperproject:main
Choose a base branch
from
AryanP123:accept-opaque-tls-secrets
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 all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| package secrets | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| corev1 "k8s.io/api/core/v1" | ||
| ) | ||
|
|
||
| func TestIsTlsCredentialSecret(t *testing.T) { | ||
| tlsData := map[string][]byte{ | ||
| "ca.crt": []byte("ca"), | ||
| "tls.crt": []byte("cert"), | ||
| "tls.key": []byte("key"), | ||
| } | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| secret *corev1.Secret | ||
| want bool | ||
| }{ | ||
| { | ||
| name: "kubernetes.io/tls", | ||
| secret: &corev1.Secret{ | ||
| Type: corev1.SecretTypeTLS, | ||
| Data: tlsData, | ||
| }, | ||
| want: true, | ||
| }, | ||
| { | ||
| name: "opaque with tls keys", | ||
| secret: &corev1.Secret{ | ||
| Type: corev1.SecretTypeOpaque, | ||
| Data: tlsData, | ||
| }, | ||
| want: true, | ||
| }, | ||
| { | ||
| name: "empty type with tls keys", | ||
| secret: &corev1.Secret{ | ||
| Data: tlsData, | ||
| }, | ||
| want: true, | ||
| }, | ||
| { | ||
| name: "opaque missing ca.crt", | ||
| secret: &corev1.Secret{ | ||
| Type: corev1.SecretTypeOpaque, | ||
| Data: map[string][]byte{ | ||
| "tls.crt": []byte("cert"), | ||
| "tls.key": []byte("key"), | ||
| }, | ||
| }, | ||
| want: false, | ||
| }, | ||
| { | ||
| name: "basic-auth secret", | ||
| secret: &corev1.Secret{ | ||
| Type: corev1.SecretTypeBasicAuth, | ||
| Data: map[string][]byte{ | ||
| "username": []byte("user"), | ||
| "password": []byte("pass"), | ||
| }, | ||
| }, | ||
| want: false, | ||
| }, | ||
| { | ||
| name: "nil secret", | ||
| secret: nil, | ||
| want: false, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| if got := IsTlsCredentialSecret(tt.secret); got != tt.want { | ||
| t.Fatalf("IsTlsCredentialSecret() = %v, want %v", got, tt.want) | ||
| } | ||
| }) | ||
| } | ||
| } |
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
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.
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.
This last assertion would break at least one (probably untested) thing. Until this regression and the subsequent changes to tls credentials dependencies the controller was designed to mostly turn a blind eye to tlsCredentials secret contents. It mostly tried to sort the contents out in the router/kube-adaptor.
It's probably more work than just this to iron out all of the corner cases, but to tell whether or not a secret is suitable to be used with an sslProfile configuration we need more context. Example: a Connector with spec.useClientCert=false (default) only configures a sslProfile with a CA - no cert or key file.
All that to say - let's either properly solve for this with a path with concrete "reasons" a secret is unacceptable for a particular tlsCredential or return to ye olden days with something wide open like 'secret.Type == "" || opaque || tls'
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.
Not to complicate this more, but just ran into another edge case we've never handled well: Listeners and MultiKeyListeners with requireClientCert=false have no real purpose for a CA certificate. We currently configure the sslProfile with one unconditionally and the router crashes when it is empty/absent. Looks like the kubernetes.io/tls type only requires tls.crt and tls.key (not ca.crt.)
Maybe the least controversial, most backwards compatible
IsTlsCredentialSecretwould be something like this? Would really count on your judgement here: A cryptic "Secret not found" error message is a big improvement over a crashing router deployment, but a major downgrade from a working link/service generated by regular skupper tooling.