-
Notifications
You must be signed in to change notification settings - Fork 29
✨ Add cipher suite support to gRPC server TLS config #219
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
Changes from 3 commits
ab940fd
cfb088e
bb0e27b
e850e70
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,11 +5,14 @@ import ( | |||||||||||||||||
| "fmt" | ||||||||||||||||||
| "math" | ||||||||||||||||||
| "os" | ||||||||||||||||||
| "strings" | ||||||||||||||||||
| "time" | ||||||||||||||||||
|
|
||||||||||||||||||
| "github.com/spf13/pflag" | ||||||||||||||||||
| "gopkg.in/yaml.v2" | ||||||||||||||||||
| "k8s.io/klog/v2" | ||||||||||||||||||
|
|
||||||||||||||||||
| pkgtls "open-cluster-management.io/sdk-go/pkg/tls" | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
||||||||||||||||||
| type GRPCServerOptions struct { | ||||||||||||||||||
|
|
@@ -18,6 +21,7 @@ type GRPCServerOptions struct { | |||||||||||||||||
| ClientCAFile string `json:"client_ca_file" yaml:"client_ca_file"` | ||||||||||||||||||
| TLSMinVersion uint16 `json:"tls_min_version" yaml:"tls_min_version"` | ||||||||||||||||||
| TLSMaxVersion uint16 `json:"tls_max_version" yaml:"tls_max_version"` | ||||||||||||||||||
| CipherSuites []string `json:"cipher_suites" yaml:"cipher_suites"` | ||||||||||||||||||
| ServerBindPort string `json:"server_bind_port" yaml:"server_bind_port"` | ||||||||||||||||||
| MaxConcurrentStreams uint32 `json:"max_concurrent_streams" yaml:"max_concurrent_streams"` | ||||||||||||||||||
| MaxReceiveMessageSize int `json:"max_receive_message_size" yaml:"max_receive_message_size"` | ||||||||||||||||||
|
|
@@ -31,6 +35,9 @@ type GRPCServerOptions struct { | |||||||||||||||||
| ServerPingTimeout time.Duration `json:"server_ping_timeout" yaml:"server_ping_timeout"` | ||||||||||||||||||
| PermitPingWithoutStream bool `json:"permit_ping_without_stream" yaml:"permit_ping_without_stream"` | ||||||||||||||||||
| CertWatchInterval time.Duration `json:"cert_watch_interval" yaml:"cert_watch_interval"` | ||||||||||||||||||
|
|
||||||||||||||||||
| // cipherSuiteIDs holds the parsed uint16 IDs from CipherSuites, populated by Validate(). | ||||||||||||||||||
| cipherSuiteIDs []uint16 | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| func LoadGRPCServerOptions(configPath string) (*GRPCServerOptions, error) { | ||||||||||||||||||
|
|
@@ -110,5 +117,41 @@ func (o *GRPCServerOptions) Validate() error { | |||||||||||||||||
| if o.CertWatchInterval <= 30*time.Second { | ||||||||||||||||||
| return fmt.Errorf("cert_watch_interval (%v) must be greater than 30 seconds", o.CertWatchInterval) | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| return o.validateCipherSuites() | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| // ApplyTLSFlags overrides TLS settings loaded from the config file with values | ||||||||||||||||||
| // from --tls-min-version and --tls-cipher-suites command-line flags. | ||||||||||||||||||
| // Called after LoadGRPCServerOptions so flags take precedence over the config file. | ||||||||||||||||||
| func (o *GRPCServerOptions) ApplyTLSFlags(minVersion, cipherSuites string) error { | ||||||||||||||||||
| if minVersion != "" { | ||||||||||||||||||
| ver, err := pkgtls.ParseTLSVersion(minVersion) | ||||||||||||||||||
| if err != nil { | ||||||||||||||||||
| return fmt.Errorf("invalid --tls-min-version: %w", err) | ||||||||||||||||||
| } | ||||||||||||||||||
| o.TLSMinVersion = ver | ||||||||||||||||||
| } | ||||||||||||||||||
| if cipherSuites != "" { | ||||||||||||||||||
| o.CipherSuites = strings.Split(cipherSuites, ",") | ||||||||||||||||||
| for i := range o.CipherSuites { | ||||||||||||||||||
| o.CipherSuites[i] = strings.TrimSpace(o.CipherSuites[i]) | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| return o.Validate() | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| // validateCipherSuites parses CipherSuites IANA names into uint16 IDs | ||||||||||||||||||
| // using the shared pkg/tls parsing utilities. | ||||||||||||||||||
| func (o *GRPCServerOptions) validateCipherSuites() error { | ||||||||||||||||||
| if len(o.CipherSuites) == 0 { | ||||||||||||||||||
| return nil | ||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clear the cached cipher IDs when Line 144 returns before resetting the derived 💡 Proposed fix func (o *GRPCServerOptions) validateCipherSuites() error {
if len(o.CipherSuites) == 0 {
+ o.cipherSuiteIDs = nil
return nil
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
✏️ Learnings added
🧠 Learnings used |
||||||||||||||||||
| } | ||||||||||||||||||
| cipherString := strings.Join(o.CipherSuites, ",") | ||||||||||||||||||
| ids, unsupported := pkgtls.ParseCipherSuites(cipherString) | ||||||||||||||||||
| if len(unsupported) > 0 { | ||||||||||||||||||
| return fmt.Errorf("unrecognized cipher suite: %s", unsupported[0]) | ||||||||||||||||||
| } | ||||||||||||||||||
| o.cipherSuiteIDs = ids | ||||||||||||||||||
| return nil | ||||||||||||||||||
| } | ||||||||||||||||||
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.
So currently we use the server-config file to configure the
tls_min_version, but the type is uint16, so the user needs to configure it like: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.
@skeeey Should we change the
TLSMinVersionandTLSMaxVersionfromuint16(772) tostring(VersionTLS13)?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, using string is more readable
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.
Has anyone already been using this? Will it break?
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.
@ncr38 PTAL, can we change this? do you use it?
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.
How about we merge the current pr first, and if we decide to change the
tls_min_versionto string, we do it as a follow-up PR.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.
yes, that would be best
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.
@skeeey No, we don't use tls_min_version.