Skip to content

Commit

Permalink
NET-5147: Added placeholder structs for JWT functionality (#18575)
Browse files Browse the repository at this point in the history
* Added placeholder structs for JWT functionality

* Added watches for CE vs ENT

* Add license header

* Undo plumbing work

* Add context arg
  • Loading branch information
jm96441n authored Aug 24, 2023
1 parent 067a011 commit 59ab57f
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 7 deletions.
17 changes: 17 additions & 0 deletions agent/proxycfg/api_gateway_ce.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1

//go:build !consulent
// +build !consulent

package proxycfg

import "context"

func watchJWTProviders(cxt context.Context, h *handlerAPIGateway) error {
return nil
}

func setJWTProvider(u UpdateEvent, snap *ConfigSnapshot) error {
return nil
}
24 changes: 24 additions & 0 deletions agent/xds/gw_per_route_filters_ce.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1

//go:build !consulent
// +build !consulent

package xds

import (
envoy_route_v3 "github.com/envoyproxy/go-control-plane/envoy/config/route/v3"
"google.golang.org/protobuf/types/known/anypb"

"github.com/hashicorp/consul/agent/structs"
)

type perRouteFilterBuilder struct {
providerMap map[string]*structs.JWTProviderConfigEntry
listener *structs.APIGatewayListener
route *structs.HTTPRouteConfigEntry
}

func (p perRouteFilterBuilder) buildFilter(match *envoy_route_v3.RouteMatch) (map[string]*anypb.Any, error) {
return nil, nil
}
25 changes: 25 additions & 0 deletions agent/xds/jwt_authn_ce.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1

//go:build !consulent
// +build !consulent

package xds

import (
envoy_http_jwt_authn_v3 "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/jwt_authn/v3"
envoy_http_v3 "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/http_connection_manager/v3"

"github.com/hashicorp/consul/agent/structs"
)

type GatewayAuthFilterBuilder struct {
listener structs.APIGatewayListener
route *structs.HTTPRouteConfigEntry
providers map[string]*structs.JWTProviderConfigEntry
envoyProviders map[string]*envoy_http_jwt_authn_v3.JwtProvider
}

func (g *GatewayAuthFilterBuilder) makeGatewayAuthFilters() ([]*envoy_http_v3.HttpFilter, error) {
return nil, nil
}
17 changes: 12 additions & 5 deletions agent/xds/rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ import (
"github.com/hashicorp/consul/proto/private/pbpeering"
)

const (
envoyHTTPRBACFilterKey = "envoy.filters.http.rbac"
envoyNetworkRBACFilterKey = "envoy.filters.network.rbac"
)

func makeRBACNetworkFilter(
intentions structs.SimplifiedIntentions,
intentionDefaultAllow bool,
Expand All @@ -38,7 +43,7 @@ func makeRBACNetworkFilter(
StatPrefix: "connect_authz",
Rules: rules,
}
return makeFilter("envoy.filters.network.rbac", cfg)
return makeFilter(envoyNetworkRBACFilterKey, cfg)
}

func makeRBACHTTPFilter(
Expand All @@ -56,7 +61,7 @@ func makeRBACHTTPFilter(
cfg := &envoy_http_rbac_v3.RBAC{
Rules: rules,
}
return makeEnvoyHTTPFilter("envoy.filters.http.rbac", cfg)
return makeEnvoyHTTPFilter(envoyHTTPRBACFilterKey, cfg)
}

func intentionListToIntermediateRBACForm(
Expand Down Expand Up @@ -326,6 +331,7 @@ func intentionActionFromBool(v bool) intentionAction {
return intentionActionDeny
}
}

func intentionActionFromString(s structs.IntentionAction) intentionAction {
if s == structs.IntentionActionAllow {
return intentionActionAllow
Expand Down Expand Up @@ -809,7 +815,6 @@ func segmentToPermission(segments []*envoy_matcher_v3.MetadataMatcher_PathSegmen
// },
// },
func pathToSegments(paths []string, payloadKey string) []*envoy_matcher_v3.MetadataMatcher_PathSegment {

segments := make([]*envoy_matcher_v3.MetadataMatcher_PathSegment, 0, len(paths))
segments = append(segments, makeSegment(payloadKey))

Expand Down Expand Up @@ -1029,8 +1034,10 @@ func xfccPrincipal(src rbacService) *envoy_rbac_v3.Principal {
}
}

const anyPath = `[^/]+`
const trustDomain = anyPath + "." + anyPath
const (
anyPath = `[^/]+`
trustDomain = anyPath + "." + anyPath
)

// downstreamServiceIdentityMatcher needs to match XFCC headers in two cases:
// 1. Requests to cluster peered services through a mesh gateway. In this case, the XFCC header looks like the following (I added a new line after each ; for readability)
Expand Down
4 changes: 3 additions & 1 deletion agent/xds/resources_ce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

package xds

func getEnterpriseGoldenTestCases() []goldenTestCase {
import "testing"

func getEnterpriseGoldenTestCases(t *testing.T) []goldenTestCase {
return nil
}
2 changes: 1 addition & 1 deletion agent/xds/resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func TestAllResourcesFromSnapshot(t *testing.T) {
tests = append(tests, getConnectProxyTransparentProxyGoldenTestCases()...)
tests = append(tests, getMeshGatewayPeeringGoldenTestCases()...)
tests = append(tests, getTrafficControlPeeringGoldenTestCases(false)...)
tests = append(tests, getEnterpriseGoldenTestCases()...)
tests = append(tests, getEnterpriseGoldenTestCases(t)...)
tests = append(tests, getAPIGatewayGoldenTestCases(t)...)

latestEnvoyVersion := xdscommon.EnvoyVersions[0]
Expand Down

0 comments on commit 59ab57f

Please sign in to comment.