-
Notifications
You must be signed in to change notification settings - Fork 248
OTA-2109: harden console plugin nginx TLS configuration #1453
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
jrangelramos
wants to merge
2
commits into
openshift:main
Choose a base branch
from
jrangelramos:fix/nginx-tls-hardening-OTA-2109
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
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,163 @@ | ||
| package agenticrun | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
|
|
||
| configv1 "github.com/openshift/api/config/v1" | ||
| ) | ||
|
|
||
| func TestResolveTLSProfileSpec(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| profile *configv1.TLSSecurityProfile | ||
| wantMinVersion configv1.TLSProtocolVersion | ||
| }{ | ||
| { | ||
| name: "nil defaults to Intermediate", | ||
| profile: nil, | ||
| wantMinVersion: configv1.VersionTLS12, | ||
| }, | ||
| { | ||
| name: "Intermediate", | ||
| profile: &configv1.TLSSecurityProfile{ | ||
| Type: configv1.TLSProfileIntermediateType, | ||
| Intermediate: &configv1.IntermediateTLSProfile{}, | ||
| }, | ||
| wantMinVersion: configv1.VersionTLS12, | ||
| }, | ||
| { | ||
| name: "Modern", | ||
| profile: &configv1.TLSSecurityProfile{ | ||
| Type: configv1.TLSProfileModernType, | ||
| Modern: &configv1.ModernTLSProfile{}, | ||
| }, | ||
| wantMinVersion: configv1.VersionTLS13, | ||
| }, | ||
| { | ||
| name: "Old", | ||
| profile: &configv1.TLSSecurityProfile{ | ||
| Type: configv1.TLSProfileOldType, | ||
| Old: &configv1.OldTLSProfile{}, | ||
| }, | ||
| wantMinVersion: configv1.VersionTLS10, | ||
| }, | ||
| { | ||
| name: "Custom", | ||
| profile: &configv1.TLSSecurityProfile{ | ||
| Type: configv1.TLSProfileCustomType, | ||
| Custom: &configv1.CustomTLSProfile{ | ||
| TLSProfileSpec: configv1.TLSProfileSpec{ | ||
| Ciphers: []string{"ECDHE-RSA-AES128-GCM-SHA256"}, | ||
| MinTLSVersion: configv1.VersionTLS13, | ||
| }, | ||
| }, | ||
| }, | ||
| wantMinVersion: configv1.VersionTLS13, | ||
| }, | ||
| { | ||
| name: "Custom with nil Custom field falls back to Intermediate", | ||
| profile: &configv1.TLSSecurityProfile{ | ||
| Type: configv1.TLSProfileCustomType, | ||
| Custom: nil, | ||
| }, | ||
| wantMinVersion: configv1.VersionTLS12, | ||
| }, | ||
| { | ||
| name: "unknown type falls back to Intermediate", | ||
| profile: &configv1.TLSSecurityProfile{ | ||
| Type: configv1.TLSProfileType("FutureTLSType"), | ||
| }, | ||
| wantMinVersion: configv1.VersionTLS12, | ||
| }, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| spec := resolveTLSProfileSpec(tt.profile) | ||
| if spec == nil { | ||
| t.Fatal("got nil spec") | ||
| } | ||
| if spec.MinTLSVersion != tt.wantMinVersion { | ||
| t.Errorf("MinTLSVersion = %q, want %q", spec.MinTLSVersion, tt.wantMinVersion) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestNginxTLSDirectives(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| profile *configv1.TLSProfileSpec | ||
| wantProtocols string | ||
| wantCiphers string | ||
| noCipherContains string // substring that must NOT appear in ciphers | ||
| }{ | ||
| { | ||
| name: "Intermediate profile", | ||
| profile: configv1.TLSProfiles[configv1.TLSProfileIntermediateType], | ||
| wantProtocols: "TLSv1.2 TLSv1.3", | ||
| }, | ||
| { | ||
| name: "Modern profile uses TLS 1.3 only with placeholder cipher", | ||
| profile: configv1.TLSProfiles[configv1.TLSProfileModernType], | ||
| wantProtocols: "TLSv1.3", | ||
| wantCiphers: "ECDHE-ECDSA-AES128-GCM-SHA256", | ||
| noCipherContains: "TLS_", | ||
| }, | ||
| { | ||
| name: "Old profile", | ||
| profile: configv1.TLSProfiles[configv1.TLSProfileOldType], | ||
| wantProtocols: "TLSv1 TLSv1.1 TLSv1.2 TLSv1.3", | ||
| }, | ||
| { | ||
| name: "unknown MinTLSVersion falls back to TLS 1.2 protocols", | ||
| profile: &configv1.TLSProfileSpec{ | ||
| MinTLSVersion: configv1.TLSProtocolVersion("VersionTLS99"), | ||
| Ciphers: []string{"ECDHE-RSA-AES128-GCM-SHA256"}, | ||
| }, | ||
| wantProtocols: "TLSv1.2 TLSv1.3", | ||
| wantCiphers: "ECDHE-RSA-AES128-GCM-SHA256", | ||
| }, | ||
| { | ||
| name: "TLS 1.3 ciphers are filtered out", | ||
| profile: &configv1.TLSProfileSpec{ | ||
| MinTLSVersion: configv1.VersionTLS12, | ||
| Ciphers: []string{ | ||
| "TLS_AES_128_GCM_SHA256", | ||
| "ECDHE-RSA-AES128-GCM-SHA256", | ||
| "TLS_CHACHA20_POLY1305_SHA256", | ||
| "ECDHE-RSA-AES256-GCM-SHA384", | ||
| }, | ||
| }, | ||
| wantProtocols: "TLSv1.2 TLSv1.3", | ||
| wantCiphers: "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384", | ||
| noCipherContains: "TLS_", | ||
| }, | ||
| { | ||
| name: "all TLS 1.3 ciphers get placeholder", | ||
| profile: &configv1.TLSProfileSpec{ | ||
| MinTLSVersion: configv1.VersionTLS13, | ||
| Ciphers: []string{"TLS_AES_128_GCM_SHA256", "TLS_AES_256_GCM_SHA384"}, | ||
| }, | ||
| wantProtocols: "TLSv1.3", | ||
| wantCiphers: "ECDHE-ECDSA-AES128-GCM-SHA256", | ||
| }, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| protocols, ciphers := nginxTLSDirectives(tt.profile) | ||
| if protocols != tt.wantProtocols { | ||
| t.Errorf("protocols = %q, want %q", protocols, tt.wantProtocols) | ||
| } | ||
| if tt.wantCiphers != "" && ciphers != tt.wantCiphers { | ||
| t.Errorf("ciphers = %q, want %q", ciphers, tt.wantCiphers) | ||
| } | ||
| if tt.noCipherContains != "" && strings.Contains(ciphers, tt.noCipherContains) { | ||
| t.Errorf("ciphers %q should not contain %q", ciphers, tt.noCipherContains) | ||
| } | ||
| if ciphers == "" { | ||
| t.Error("ciphers must never be empty (nginx rejects empty ssl_ciphers)") | ||
| } | ||
| }) | ||
| } | ||
| } |
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.