-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add auth-tls-strict configuration key
`auth-tls-strict` allows to build a strict configuration if an invalid auth-tls configuration is provided, either due to misconfiguration or due to asynchronous events that's going to happen and will fix the temporarily broken config. The strict config is made using a self-generated certificate authority in the `ca-file` option, which will lead to two desired effects: 1. A certificate, if provided by the client, will be identified by the server. HAProxy doesn't allow to configure `verify optional` without a `ca-file`. If this option wasn't used, we couldn't distinguish between a request with or without a certificate on configs whose crt is optional 2. The request will always be denied due to invalid certificate authority (when verify-client is `on`) or when a client certificate is used (when verify-client is `optional`) because, since the right configuration is broken, there is no way to know if the certificate is a valid one.
- Loading branch information
1 parent
108006d
commit 2fc72ce
Showing
9 changed files
with
201 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,136 @@ | ||
/* | ||
Copyright 2020 The HAProxy Ingress Controller Authors. | ||
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. | ||
*/ | ||
|
||
package annotations | ||
|
||
import ( | ||
"testing" | ||
|
||
ingtypes "github.com/jcmoraisjr/haproxy-ingress/pkg/converters/ingress/types" | ||
hatypes "github.com/jcmoraisjr/haproxy-ingress/pkg/haproxy/types" | ||
) | ||
|
||
func TestAuthTLS(t *testing.T) { | ||
testCases := []struct { | ||
annDefault map[string]string | ||
ann map[string]string | ||
expected hatypes.HostTLSConfig | ||
logging string | ||
}{ | ||
// 0 | ||
{}, | ||
// 1 | ||
{ | ||
ann: map[string]string{ | ||
ingtypes.HostAuthTLSSecret: "caerr", | ||
}, | ||
expected: hatypes.HostTLSConfig{}, | ||
logging: "ERROR error building TLS auth config on ingress 'system/ing1': secret not found: 'system/caerr'", | ||
}, | ||
// 2 | ||
{ | ||
ann: map[string]string{ | ||
ingtypes.HostAuthTLSStrict: "true", | ||
}, | ||
}, | ||
// 3 | ||
{ | ||
ann: map[string]string{ | ||
ingtypes.HostAuthTLSSecret: "caerr", | ||
ingtypes.HostAuthTLSStrict: "true", | ||
}, | ||
expected: hatypes.HostTLSConfig{ | ||
CAFilename: fakeCAFilename, | ||
CAHash: fakeCAHash, | ||
}, | ||
logging: "ERROR error building TLS auth config on ingress 'system/ing1': secret not found: 'system/caerr'", | ||
}, | ||
// 4 | ||
{ | ||
ann: map[string]string{ | ||
ingtypes.HostAuthTLSSecret: "cafile", | ||
}, | ||
expected: hatypes.HostTLSConfig{ | ||
CAFilename: "/path/ca.crt", | ||
CAHash: "c0e1bf73caf75d7353cf3ecdd20ceb2f6fa1cab1", | ||
}, | ||
}, | ||
// 5 | ||
{ | ||
ann: map[string]string{ | ||
ingtypes.HostAuthTLSVerifyClient: "optional", | ||
}, | ||
}, | ||
// 6 | ||
{ | ||
ann: map[string]string{ | ||
ingtypes.HostAuthTLSStrict: "true", | ||
ingtypes.HostAuthTLSVerifyClient: "optional", | ||
}, | ||
}, | ||
// 7 | ||
{ | ||
ann: map[string]string{ | ||
ingtypes.HostAuthTLSSecret: "caerr", | ||
ingtypes.HostAuthTLSStrict: "true", | ||
ingtypes.HostAuthTLSVerifyClient: "optional", | ||
}, | ||
expected: hatypes.HostTLSConfig{ | ||
CAFilename: fakeCAFilename, | ||
CAHash: fakeCAHash, | ||
CAVerifyOptional: true, | ||
}, | ||
logging: "ERROR error building TLS auth config on ingress 'system/ing1': secret not found: 'system/caerr'", | ||
}, | ||
// 8 | ||
{ | ||
ann: map[string]string{ | ||
ingtypes.HostAuthTLSSecret: "cafile", | ||
ingtypes.HostAuthTLSStrict: "true", | ||
ingtypes.HostAuthTLSVerifyClient: "optional", | ||
}, | ||
expected: hatypes.HostTLSConfig{ | ||
CAFilename: "/path/ca.crt", | ||
CAHash: "c0e1bf73caf75d7353cf3ecdd20ceb2f6fa1cab1", | ||
CAVerifyOptional: true, | ||
}, | ||
}, | ||
// 9 | ||
{ | ||
ann: map[string]string{ | ||
ingtypes.HostAuthTLSSecret: "cafile", | ||
ingtypes.HostAuthTLSVerifyClient: "optional", | ||
}, | ||
expected: hatypes.HostTLSConfig{ | ||
CAFilename: "/path/ca.crt", | ||
CAHash: "c0e1bf73caf75d7353cf3ecdd20ceb2f6fa1cab1", | ||
CAVerifyOptional: true, | ||
}, | ||
}, | ||
} | ||
source := &Source{Namespace: "system", Name: "ing1", Type: "ingress"} | ||
for i, test := range testCases { | ||
c := setup(t) | ||
c.cache.SecretCAPath = map[string]string{ | ||
"system/cafile": "/path/ca.crt", | ||
} | ||
d := c.createHostData(source, test.ann, test.annDefault) | ||
c.createUpdater().buildHostAuthTLS(d) | ||
c.compareObjects("auth-tls", i, d.host.TLS, test.expected) | ||
c.logger.CompareLogging(test.logging) | ||
c.teardown() | ||
} | ||
} |
This file contains 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 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 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 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 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