-
Notifications
You must be signed in to change notification settings - Fork 369
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add host-infra provider support (#4481)
* add host-infra provider support Signed-off-by: shawnh2 <[email protected]> * add more tests and polish code for each runner Signed-off-by: shawnh2 <[email protected]> * fix lint Signed-off-by: shawnh2 <[email protected]> --------- Signed-off-by: shawnh2 <[email protected]>
- Loading branch information
Showing
68 changed files
with
1,227 additions
and
434 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
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,57 @@ | ||
// Copyright Envoy Gateway Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// The full text of the Apache license is available in the LICENSE file at | ||
// the root of the repo. | ||
|
||
package crypto | ||
|
||
import ( | ||
"crypto/rand" | ||
"crypto/tls" | ||
"crypto/x509" | ||
"fmt" | ||
"os" | ||
) | ||
|
||
// LoadTLSConfig returns TLSConfig form certificates. | ||
func LoadTLSConfig(tlsCrt, tlsKey, caCrt string) (*tls.Config, error) { | ||
loadConfig := func() (*tls.Config, error) { | ||
cert, err := tls.LoadX509KeyPair(tlsCrt, tlsKey) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Load the CA cert. | ||
ca, err := os.ReadFile(caCrt) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
certPool := x509.NewCertPool() | ||
if !certPool.AppendCertsFromPEM(ca) { | ||
return nil, fmt.Errorf("failed to parse CA certificate") | ||
} | ||
|
||
return &tls.Config{ | ||
Certificates: []tls.Certificate{cert}, | ||
NextProtos: []string{"h2"}, | ||
ClientAuth: tls.RequireAndVerifyClientCert, | ||
ClientCAs: certPool, | ||
MinVersion: tls.VersionTLS13, | ||
}, nil | ||
} | ||
|
||
// Attempt to load certificates and key to catch configuration errors early. | ||
if _, err := loadConfig(); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &tls.Config{ | ||
MinVersion: tls.VersionTLS13, | ||
ClientAuth: tls.RequireAndVerifyClientCert, | ||
Rand: rand.Reader, | ||
GetConfigForClient: func(*tls.ClientHelloInfo) (*tls.Config, error) { | ||
return loadConfig() | ||
}, | ||
}, nil | ||
} |
Oops, something went wrong.