Skip to content

Commit

Permalink
Register ProxyStateTemplateResource
Browse files Browse the repository at this point in the history
* also change the ProxyState.id to identity. This is because we already have the id of this proxy
  from the resource, and this id should be name-aligned with the workload it represents. It should
  also have the owner ref set to the workload ID if we need that. And so the id field seems unnecessary.
  We do, however, need a reference to workload identity so that we can authorize the proxy when it initially
  connects to the xDS server.
  • Loading branch information
ishustava committed Jul 27, 2023
1 parent 2b0d64e commit 2d5e7d0
Show file tree
Hide file tree
Showing 5 changed files with 187 additions and 135 deletions.
8 changes: 5 additions & 3 deletions internal/mesh/exports.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ var (

ProxyConfigurationKind = types.ProxyConfigurationKind
UpstreamsKind = types.UpstreamsKind
ProxyStateKind = types.ProxyStateTemplateKind

// Resource Types for the v1alpha1 version.

ProxyConfigurationV1Alpha1Type = types.ProxyConfigurationV1Alpha1Type
UpstreamsV1Alpha1Type = types.UpstreamsV1Alpha1Type
UpstreamsConfigurationV1Alpha1Type = types.UpstreamsConfigurationV1Alpha1Type
ProxyConfigurationV1Alpha1Type = types.ProxyConfigurationV1Alpha1Type
UpstreamsV1Alpha1Type = types.UpstreamsV1Alpha1Type
UpstreamsConfigurationV1Alpha1Type = types.UpstreamsConfigurationV1Alpha1Type
ProxyStateTemplateConfigurationV1Alpha1Type = types.ProxyStateTemplateV1Alpha1Type
)

// RegisterTypes adds all resource types within the "catalog" API group
Expand Down
45 changes: 45 additions & 0 deletions internal/mesh/internal/types/proxy_state_template.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package types

import (
"github.com/hashicorp/consul/acl"
"github.com/hashicorp/consul/internal/resource"
pbmesh "github.com/hashicorp/consul/proto-public/pbmesh/v1alpha1"
"github.com/hashicorp/consul/proto-public/pbresource"
)

const (
ProxyStateTemplateKind = "ProxyStateTemplate"
)

var (
ProxyStateTemplateV1Alpha1Type = &pbresource.Type{
Group: GroupName,
GroupVersion: VersionV1Alpha1,
Kind: ProxyStateTemplateKind,
}

ProxyStateTemplateType = ProxyStateTemplateV1Alpha1Type
)

func RegisterProxyStateTemplate(r resource.Registry) {
r.Register(resource.Registration{
Type: ProxyStateTemplateV1Alpha1Type,
Proto: &pbmesh.ProxyStateTemplate{},
Validate: nil,
ACLs: &resource.ACLHooks{
Read: func(authorizer acl.Authorizer, id *pbresource.ID) error {
return authorizer.ToAllowAuthorizer().ServiceReadAllowed(id.Name, resource.AuthorizerContext(id.Tenancy))
},
Write: func(authorizer acl.Authorizer, p *pbresource.Resource) error {
// Require operator:write only for "break-glass" scenarios as this resource should be mostly
// be managed by the mesh controller.
return authorizer.ToAllowAuthorizer().OperatorWriteAllowed(resource.AuthorizerContext(p.Id.Tenancy))
},
List: func(authorizer acl.Authorizer, tenancy *pbresource.Tenancy) error {
// No-op List permission as we want to default to filtering resource resources
// from the list using the Read enforcement.
return nil
},
},
})
}
1 change: 1 addition & 0 deletions internal/mesh/internal/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ func Register(r resource.Registry) {
RegisterProxyConfiguration(r)
RegisterUpstreams(r)
RegisterUpstreamsConfiguration(r)
RegisterProxyStateTemplate(r)
}
Loading

0 comments on commit 2d5e7d0

Please sign in to comment.