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

ambient: fix auto-allow waypoint #50617

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1073,15 +1073,15 @@ func TestAmbientIndex_Policy(t *testing.T) {

func TestDefaultAllowWaypointPolicy(t *testing.T) {
// while the Waypoint is in testNS, the policies live in the Pods' namespaces
policyName := "istio_allow_waypoint_" + testNS + "_" + "waypoint-ns"
policyName := "ns1/istio_allow_waypoint_" + testNS + "_" + "waypoint-ns"
test.SetForTest(t, &features.DefaultAllowFromWaypoint, true)

s := newAmbientTestServer(t, testC, testNW)
setupPolicyTest(t, s)

t.Run("policy with service accounts", func(t *testing.T) {
assert.EventuallyEqual(t, func() []string {
waypointPolicy := s.authorizationPolicies.GetKey(krt.Key[model.WorkloadAuthorization]("ns1/" + policyName))
waypointPolicy := s.authorizationPolicies.GetKey(krt.Key[model.WorkloadAuthorization](policyName))
if waypointPolicy == nil {
return nil
}
Expand All @@ -1090,8 +1090,8 @@ func TestDefaultAllowWaypointPolicy(t *testing.T) {
return sm.GetExact()
})
}, []string{
"spiffe://cluster.local/ns/ns1/sa/namespace-wide",
"spiffe://cluster.local/ns/ns1/sa/waypoint-sa",
"cluster.local/ns/ns1/sa/namespace-wide",
"cluster.local/ns/ns1/sa/waypoint-sa",
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
package ambient

import (
"strings"

v1 "k8s.io/api/core/v1"

securityclient "istio.io/client-go/pkg/apis/security/v1beta1"
Expand Down Expand Up @@ -124,7 +126,7 @@ func implicitWaypointPolicy(ctx krt.HandlerContext, waypoint Waypoint) *model.Wo
{
Principals: slices.Map(waypoint.ServiceAccounts, func(sa string) *security.StringMatch {
return &security.StringMatch{MatchType: &security.StringMatch_Exact{
Exact: spiffe.MustGenSpiffeURI(waypoint.Namespace, sa),
Exact: strings.TrimPrefix(spiffe.MustGenSpiffeURI(waypoint.Namespace, sa), spiffe.URIPrefix),
}}
}),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,6 @@ func implicitWaypointPolicies(ctx krt.HandlerContext, Waypoints krt.Collection[W
if policy == "" {
return nil
}
return &policy
return ptr.Of(w.Namespace + "/" + policy)
})
}