-
Notifications
You must be signed in to change notification settings - Fork 7
feat: auto-detect TLS security profile from OpenShift cluster #850
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
jcrossley3
wants to merge
1
commit into
trustification:release/3.y.z
Choose a base branch
from
jcrossley3:tc-3426
base: release/3.y.z
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.
+131
−0
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
76 changes: 76 additions & 0 deletions
76
helm-charts/redhat-trusted-profile-analyzer/templates/helpers/_tls_profile.tpl
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,76 @@ | ||
| {{/* | ||
| Environment variables for the TLS security profile. | ||
|
|
||
| Precedence: | ||
| 1. User-specified via .Values.tls.securityProfile (string or object) | ||
| 2. Auto-detected from OpenShift APIServer CR via lookup | ||
| 3. Nothing (trustify server uses its compiled default: modern) | ||
|
|
||
| Arguments (dict): | ||
| * root - . | ||
| */}} | ||
| {{- define "trustification.tls.securityProfile.envVars" -}} | ||
|
|
||
| {{- $profile := (.root.Values.tls).securityProfile -}} | ||
|
|
||
| {{- if $profile -}} | ||
| {{/* User explicitly set tls.securityProfile */}} | ||
| {{- if kindIs "string" $profile }} | ||
| - name: HTTP_SERVER_TLS_SECURITY_PROFILE | ||
| value: {{ $profile | quote }} | ||
| {{- else if kindIs "map" $profile }} | ||
| - name: HTTP_SERVER_TLS_SECURITY_PROFILE | ||
| value: {{ $profile.type | quote }} | ||
| {{- if eq $profile.type "custom" }} | ||
| {{- with $profile.minTLSVersion }} | ||
| - name: HTTP_SERVER_TLS_MIN_VERSION | ||
| value: {{ . | quote }} | ||
| {{- end }} | ||
| {{- with $profile.ciphers }} | ||
| - name: HTTP_SERVER_TLS_CIPHERS | ||
| value: {{ join ":" . | quote }} | ||
| {{- end }} | ||
| {{- with $profile.ciphersuites }} | ||
| - name: HTTP_SERVER_TLS_CIPHERSUITES | ||
| value: {{ join ":" . | quote }} | ||
| {{- end }} | ||
| {{- end }} | ||
| {{- end }} | ||
|
|
||
| {{- else if eq (include "trustification.openshift.detect" .root) "true" -}} | ||
| {{/* Auto-detect from OpenShift APIServer CR */}} | ||
| {{- $apiserver := (lookup "config.openshift.io/v1" "APIServer" "" "cluster") -}} | ||
| {{- $tlsProfile := dig "spec" "tlsSecurityProfile" dict $apiserver -}} | ||
| {{- with $tlsProfile -}} | ||
| {{- $type := .type | lower }} | ||
| - name: HTTP_SERVER_TLS_SECURITY_PROFILE | ||
| value: {{ $type | quote }} | ||
| {{- if eq $type "custom" }} | ||
| {{- with .custom -}} | ||
| {{- with .minTLSVersion }} | ||
| - name: HTTP_SERVER_TLS_MIN_VERSION | ||
| value: {{ include "trustification.tls.securityProfile.mapVersion" . | quote }} | ||
| {{- end }} | ||
| {{- with .ciphers }} | ||
| - name: HTTP_SERVER_TLS_CIPHERS | ||
| value: {{ join ":" . | quote }} | ||
| {{- end }} | ||
| {{- end }} | ||
| {{- end }} | ||
| {{- end }} | ||
|
|
||
| {{- end }} | ||
|
|
||
| {{- end }} | ||
|
|
||
| {{/* | ||
| Map OpenShift TLS version names to trustify version strings. | ||
|
|
||
| VersionTLS10 -> 1.0, VersionTLS11 -> 1.1, VersionTLS12 -> 1.2, VersionTLS13 -> 1.3 | ||
|
|
||
| Arguments: version string (e.g. "VersionTLS12") | ||
| */}} | ||
| {{- define "trustification.tls.securityProfile.mapVersion" -}} | ||
| {{- $map := dict "VersionTLS10" "1.0" "VersionTLS11" "1.1" "VersionTLS12" "1.2" "VersionTLS13" "1.3" -}} | ||
| {{- get $map . | default . -}} | ||
| {{- end }} | ||
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.
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.
issue (bug_risk): Using
dictas the default fordigmay causewith $tlsProfileto execute on an empty map and then fail when accessing.type.Because
digdefaults todict,$tlsProfilebecomes an empty map when the APIServer resource or itstlsSecurityProfilefield is missing. Empty maps are truthy in Go templates, so thewithblock still runs and.type | loweris evaluated on a value withouttype, likely causing a render error. To avoid this, default tonil(or omit the default and handlenil) so thewithblock is skipped when the profile is absent:{{- $tlsProfile := dig "spec" "tlsSecurityProfile" nil $apiserver -}} {{- with $tlsProfile -}} {{- $type := .type | lower }} ... {{- end }}