This repository has been archived by the owner on Nov 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
make security requirements optional #56
Merged
+91
−72
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -95,7 +95,7 @@ func (is *IstioProvider) Reconcile(ctx context.Context, apip *networkingv1beta1. | |
return ctrl.Result{}, err | ||
} | ||
|
||
authPolicy, err := is.getAuthorizationPolicy(existingVS) | ||
authPolicy, err := is.getAuthorizationPolicy(apip, existingVS) | ||
if err != nil { | ||
return ctrl.Result{}, err | ||
} | ||
|
@@ -121,17 +121,7 @@ func (is *IstioProvider) ReconcileIstioAuthorizationPolicy(ctx context.Context, | |
return is.ReconcileResource(ctx, &istioSecurity.AuthorizationPolicy{}, desired, mutatefn) | ||
} | ||
|
||
func (is *IstioProvider) getAuthorizationPolicy(virtualService *istio.VirtualService) (*istioSecurity.AuthorizationPolicy, error) { | ||
policyHosts := []string{} | ||
|
||
// Now we need to generate the list of hosts that will match the authorization policy, | ||
// to be sure, we will match the "$host" and "$host:*". | ||
for _, host := range virtualService.Spec.Hosts { | ||
//TODO(jmprusi): avoid duplicates | ||
hostSplitted := strings.Split(host, ":") | ||
policyHosts = append(policyHosts, hostSplitted[0]+":*") | ||
policyHosts = append(policyHosts, hostSplitted[0]) | ||
} | ||
func (is *IstioProvider) getAuthorizationPolicy(apip *networkingv1beta1.APIProduct, virtualService *istio.VirtualService) (*istioSecurity.AuthorizationPolicy, error) { | ||
authPolicy := &istioSecurity.AuthorizationPolicy{ | ||
TypeMeta: metav1.TypeMeta{ | ||
Kind: "AuthorizationPolicy", | ||
|
@@ -141,26 +131,42 @@ func (is *IstioProvider) getAuthorizationPolicy(virtualService *istio.VirtualSer | |
Name: virtualService.GetName(), | ||
Namespace: common.KuadrantNamespace, | ||
}, | ||
Spec: v1beta12.AuthorizationPolicy{ | ||
Selector: &v1beta13.WorkloadSelector{ | ||
MatchLabels: map[string]string{ | ||
"app": "istio-ingressgateway", | ||
}, | ||
} | ||
|
||
if !apip.HasSecurity() { | ||
common.TagObjectToDelete(authPolicy) | ||
return authPolicy, nil | ||
} | ||
|
||
// Now we need to generate the list of hosts that will match the authorization policy, | ||
// to be sure, we will match the "$host" and "$host:*". | ||
policyHosts := []string{} | ||
for _, host := range virtualService.Spec.Hosts { | ||
//TODO(jmprusi): avoid duplicates | ||
hostSplitted := strings.Split(host, ":") | ||
policyHosts = append(policyHosts, hostSplitted[0]+":*") | ||
policyHosts = append(policyHosts, hostSplitted[0]) | ||
} | ||
|
||
authPolicy.Spec = v1beta12.AuthorizationPolicy{ | ||
Selector: &v1beta13.WorkloadSelector{ | ||
MatchLabels: map[string]string{ | ||
"app": "istio-ingressgateway", | ||
}, | ||
Rules: []*v1beta12.Rule{ | ||
{ | ||
To: []*v1beta12.Rule_To{{ | ||
Operation: &v1beta12.Operation{ | ||
Hosts: policyHosts, | ||
}, | ||
}}, | ||
}, | ||
}, | ||
Rules: []*v1beta12.Rule{ | ||
{ | ||
To: []*v1beta12.Rule_To{{ | ||
Operation: &v1beta12.Operation{ | ||
Hosts: policyHosts, | ||
}, | ||
}}, | ||
}, | ||
Action: v1beta12.AuthorizationPolicy_CUSTOM, | ||
ActionDetail: &v1beta12.AuthorizationPolicy_Provider{ | ||
Provider: &v1beta12.AuthorizationPolicy_ExtensionProvider{ | ||
Name: common.KuadrantAuthorizationProvider, | ||
}, | ||
}, | ||
Action: v1beta12.AuthorizationPolicy_CUSTOM, | ||
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. Out of scope here, but there's a request for discussing the conventions across components at Kuadrant/authorino#164 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. istio constant :) |
||
ActionDetail: &v1beta12.AuthorizationPolicy_Provider{ | ||
Provider: &v1beta12.AuthorizationPolicy_ExtensionProvider{ | ||
Name: common.KuadrantAuthorizationProvider, | ||
}, | ||
}, | ||
} | ||
|
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
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.
Is this needed for controller-gen to make it optional? I usually rely only on
omitempty
and it does the trick, but I'd love to learn about any other extra advantage.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.
I have experienced that too. That's confusing as the kubebulder doc says it should be the
'+optional
marker.To make it explicit and easy to read, I always add it for optional fields
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.
Perhaps
+kubebuilder:validation:Optional
then, so there's no doubt it's for kubebuilder?