Skip to content

Commit

Permalink
fixup! Add support for TCP traffic permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
erichaberkorn committed Sep 11, 2023
1 parent 157a0c2 commit b71ac4f
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 172 deletions.
6 changes: 3 additions & 3 deletions agent/xds/proxystateconverter/listeners.go
Original file line number Diff line number Diff line change
Expand Up @@ -1053,9 +1053,9 @@ func (s *Converter) makeInboundListener(cfgSnap *proxycfg.ConfigSnapshot, name s
l4Dest.MaxInboundConnections = uint64(cfg.MaxInboundConnections)
}

defaultAction := pbproxystate.TrafficPermissionAction_INTENTION_ACTION_DENY
defaultAction := pbproxystate.TrafficPermissionAction_TRAFFIC_PERMISSION_ACTION_DENY
if cfgSnap.IntentionDefaultAllow {
defaultAction = pbproxystate.TrafficPermissionAction_INTENTION_ACTION_ALLOW
defaultAction = pbproxystate.TrafficPermissionAction_TRAFFIC_PERMISSION_ACTION_ALLOW
}
l4Dest.TrafficPermissions = &pbproxystate.L4TrafficPermissions{
DefaultAction: defaultAction,
Expand Down Expand Up @@ -1580,7 +1580,7 @@ func (g *Converter) makeL7Destination(opts destinationOpts) (*pbproxystate.L7Des
// access and that every filter chain uses our TLS certs.
if len(opts.httpAuthzFilters) > 0 {
// TODO(proxystate) support intentions in the future
dest.TrafficPermissions = make([]*pbproxystate.L7TrafficPermission, 0)
dest.TrafficPermissions = &pbproxystate.L7TrafficPermissions{}
//cfg.HttpFilters = append(opts.httpAuthzFilters, cfg.HttpFilters...)
}

Expand Down
4 changes: 2 additions & 2 deletions agent/xds/rbac_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1126,9 +1126,9 @@ func TestMakeRBACNetworkAndHTTPFilters(t *testing.T) {
if tt.v2L4TrafficPermissions == nil {
return
}
tt.v2L4TrafficPermissions.DefaultAction = pbproxystate.TrafficPermissionAction_INTENTION_ACTION_DENY
tt.v2L4TrafficPermissions.DefaultAction = pbproxystate.TrafficPermissionAction_TRAFFIC_PERMISSION_ACTION_DENY
if tt.intentionDefaultAllow {
tt.v2L4TrafficPermissions.DefaultAction = pbproxystate.TrafficPermissionAction_INTENTION_ACTION_ALLOW
tt.v2L4TrafficPermissions.DefaultAction = pbproxystate.TrafficPermissionAction_TRAFFIC_PERMISSION_ACTION_ALLOW
}

filters, err := xdsv2.MakeL4RBAC(tt.v2L4TrafficPermissions)
Expand Down
2 changes: 1 addition & 1 deletion agent/xdsv2/rbac_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func makeRBACs(trafficPermissions *pbproxystate.L4TrafficPermissions) ([]*envoy_

func finalizeRBAC(rbac *envoy_rbac_v3.RBAC, defaultAction pbproxystate.TrafficPermissionAction) *envoy_rbac_v3.RBAC {
isRBACAllow := rbac.Action == envoy_rbac_v3.RBAC_ALLOW
isConsulAllow := defaultAction == pbproxystate.TrafficPermissionAction_INTENTION_ACTION_ALLOW
isConsulAllow := defaultAction == pbproxystate.TrafficPermissionAction_TRAFFIC_PERMISSION_ACTION_ALLOW
// Remove allow traffic permissions with default allow. This is required because including an allow RBAC filter enforces default deny.
// It is safe because deny traffic permissions are applied before allow permissions, so explicit allow is equivalent to default allow.
removeAllows := isRBACAllow && isConsulAllow
Expand Down
138 changes: 69 additions & 69 deletions proto-public/pbmesh/v1alpha1/pbproxystate/listener.pb.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion proto-public/pbmesh/v1alpha1/pbproxystate/listener.proto
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ message L7Destination {
// protocol for the destination.
L7Protocol protocol = 3;
// traffic_permissions is a list of intentions for this destination.
repeated L7TrafficPermission traffic_permissions = 4;
L7TrafficPermissions traffic_permissions = 4;
// add_empty_intention specifies whether to add an empty intention for this destination, when there are no other intentions specified.
bool add_empty_intention = 5;
// include_xfcc specifies whether to add xfcc header.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

188 changes: 97 additions & 91 deletions proto-public/pbmesh/v1alpha1/pbproxystate/traffic_permissions.pb.go

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ syntax = "proto3";

package hashicorp.consul.mesh.v1alpha1.pbproxystate;

message L7TrafficPermission {}
message L7TrafficPermissions {}

enum TrafficPermissionAction {
INTENTION_ACTION_DENY = 0;
INTENTION_ACTION_ALLOW = 1;
TRAFFIC_PERMISSION_ACTION_UNSPECIFIED = 0;
TRAFFIC_PERMISSION_ACTION_DENY = 1;
TRAFFIC_PERMISSION_ACTION_ALLOW = 2;
}

message L4TrafficPermissions {
Expand Down

0 comments on commit b71ac4f

Please sign in to comment.