Skip to content
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

Use namespace from Rollouts resource to avoid unauthorized access to other HTTPProxies #18

Merged
merged 1 commit into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions pkg/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ type ContourTrafficRouting struct {
// HTTPProxy refers to the name of the HTTPProxy used to route traffic to the
// service
HTTPProxy string `json:"httpProxy" protobuf:"bytes,1,name=httpProxy"`
Namespace string `json:"namespace" protobuf:"bytes,2,name=namespace"`
}

func (r *RpcPlugin) InitPlugin() (re pluginTypes.RpcError) {
Expand Down Expand Up @@ -77,7 +76,7 @@ func (r *RpcPlugin) SetWeight(
utils.Must(json.Unmarshal(rollout.Spec.Strategy.Canary.TrafficRouting.Plugins["argoproj-labs/contour"], &ctr))

var httpProxy contourv1.HTTPProxy
unstr := utils.Must1(r.dynamicClient.Resource(contourv1.HTTPProxyGVR).Namespace(ctr.Namespace).Get(ctx, ctr.HTTPProxy, metav1.GetOptions{}))
unstr := utils.Must1(r.dynamicClient.Resource(contourv1.HTTPProxyGVR).Namespace(rollout.Namespace).Get(ctx, ctr.HTTPProxy, metav1.GetOptions{}))
utils.Must(runtime.DefaultUnstructuredConverter.FromUnstructured(unstr.UnstructuredContent(), &httpProxy))

canarySvcName := rollout.Spec.Strategy.Canary.CanaryService
Expand All @@ -98,7 +97,7 @@ func (r *RpcPlugin) SetWeight(
slog.Debug("new weight", slog.Int64("canary", canarySvc.Weight), slog.Int64("stable", stableSvc.Weight))

m := utils.Must1(runtime.DefaultUnstructuredConverter.ToUnstructured(&httpProxy))
updated, err := r.dynamicClient.Resource(contourv1.HTTPProxyGVR).Namespace(ctr.Namespace).Update(ctx, &unstructured.Unstructured{Object: m}, metav1.UpdateOptions{})
updated, err := r.dynamicClient.Resource(contourv1.HTTPProxyGVR).Namespace(rollout.Namespace).Update(ctx, &unstructured.Unstructured{Object: m}, metav1.UpdateOptions{})
if err != nil {
slog.Error("update the HTTPProxy is failed", slog.String("name", httpProxy.Name), slog.Any("err", err))
utils.Must(err)
Expand Down
1 change: 0 additions & 1 deletion pkg/plugin/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ func TestRunSuccessfully(t *testing.T) {
func newRollout(stableSvc, canarySvc, httpProxyName string) *v1alpha1.Rollout {
contourConfig := ContourTrafficRouting{
HTTPProxy: httpProxyName,
Namespace: "default",
}
encodedContourConfig, err := json.Marshal(contourConfig)
if err != nil {
Expand Down