-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Register ProxyStateTemplate Resource (#18316)
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
Showing
5 changed files
with
69 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
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 { | ||
// Check service:read and operator:read permissions. | ||
// If service:read is not allowed, check operator:read. We want to allow both as this | ||
// resource is mostly useful for debuggability and we want to cover | ||
// the most cases that serve that purpose. | ||
serviceReadErr := authorizer.ToAllowAuthorizer().ServiceReadAllowed(id.Name, resource.AuthorizerContext(id.Tenancy)) | ||
operatorReadErr := authorizer.ToAllowAuthorizer().OperatorReadAllowed(resource.AuthorizerContext(id.Tenancy)) | ||
|
||
switch { | ||
case serviceReadErr != nil: | ||
return serviceReadErr | ||
case operatorReadErr != nil: | ||
return operatorReadErr | ||
} | ||
|
||
return nil | ||
}, | ||
Write: func(authorizer acl.Authorizer, p *pbresource.Resource) error { | ||
// Require operator:write only for "break-glass" scenarios as this resource should be mostly | ||
// managed by a 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 resources | ||
// from the list using the Read enforcement. | ||
return nil | ||
}, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters