2022-04-20 00:24:21 +00:00
|
|
|
package dataplane
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
"strings"
|
|
|
|
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
"google.golang.org/grpc/status"
|
|
|
|
"google.golang.org/protobuf/types/known/structpb"
|
|
|
|
|
2022-04-20 00:24:21 +00:00
|
|
|
acl "github.com/hashicorp/consul/acl"
|
|
|
|
"github.com/hashicorp/consul/agent/consul/state"
|
|
|
|
"github.com/hashicorp/consul/agent/grpc/public"
|
|
|
|
structs "github.com/hashicorp/consul/agent/structs"
|
|
|
|
"github.com/hashicorp/consul/proto-public/pbdataplane"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s *Server) GetEnvoyBootstrapParams(ctx context.Context, req *pbdataplane.GetEnvoyBootstrapParamsRequest) (*pbdataplane.GetEnvoyBootstrapParamsResponse, error) {
|
|
|
|
logger := s.Logger.Named("get-envoy-bootstrap-params").With("service_id", req.GetServiceId(), "request_id", public.TraceID())
|
|
|
|
|
|
|
|
logger.Trace("Started processing request")
|
|
|
|
defer logger.Trace("Finished processing request")
|
|
|
|
|
|
|
|
token := public.TokenFromContext(ctx)
|
|
|
|
var authzContext acl.AuthorizerContext
|
|
|
|
entMeta := acl.NewEnterpriseMetaWithPartition(req.GetPartition(), req.GetNamespace())
|
|
|
|
authz, err := s.ACLResolver.ResolveTokenAndDefaultMeta(token, &entMeta, &authzContext)
|
|
|
|
if err != nil {
|
|
|
|
return nil, status.Error(codes.Unauthenticated, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
store := s.GetStore()
|
|
|
|
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
_, svc, err := store.ServiceNode(req.GetNodeId(), req.GetNodeName(), req.GetServiceId(), &entMeta, structs.DefaultPeerKeyword)
|
2022-04-20 00:24:21 +00:00
|
|
|
if err != nil {
|
|
|
|
logger.Error("Error looking up service", "error", err)
|
|
|
|
if errors.Is(err, state.ErrNodeNotFound) {
|
|
|
|
return nil, status.Error(codes.NotFound, err.Error())
|
|
|
|
} else if strings.Contains(err.Error(), "Node ID or name required") {
|
|
|
|
return nil, status.Error(codes.InvalidArgument, err.Error())
|
|
|
|
} else {
|
|
|
|
return nil, status.Error(codes.Internal, "Failure looking up service")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if svc == nil {
|
|
|
|
return nil, status.Error(codes.NotFound, "Service not found")
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := authz.ToAllowAuthorizer().ServiceReadAllowed(svc.ServiceName, &authzContext); err != nil {
|
|
|
|
return nil, status.Error(codes.PermissionDenied, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build out the response
|
|
|
|
|
|
|
|
resp := &pbdataplane.GetEnvoyBootstrapParamsResponse{
|
|
|
|
Service: svc.ServiceProxy.DestinationServiceName,
|
|
|
|
Partition: svc.EnterpriseMeta.PartitionOrDefault(),
|
|
|
|
Namespace: svc.EnterpriseMeta.NamespaceOrDefault(),
|
|
|
|
Datacenter: s.Datacenter,
|
|
|
|
ServiceKind: convertToResponseServiceKind(svc.ServiceKind),
|
|
|
|
}
|
|
|
|
|
|
|
|
bootstrapConfig, err := structpb.NewStruct(svc.ServiceProxy.Config)
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("Error creating the envoy boostrap params config", "error", err)
|
|
|
|
return nil, status.Error(codes.Unknown, "Error creating the envoy boostrap params config")
|
|
|
|
}
|
|
|
|
resp.Config = bootstrapConfig
|
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func convertToResponseServiceKind(serviceKind structs.ServiceKind) (respKind pbdataplane.ServiceKind) {
|
|
|
|
switch serviceKind {
|
|
|
|
case structs.ServiceKindConnectProxy:
|
2022-05-23 14:37:52 +00:00
|
|
|
respKind = pbdataplane.ServiceKind_SERVICE_KIND_CONNECT_PROXY
|
2022-04-20 00:24:21 +00:00
|
|
|
case structs.ServiceKindMeshGateway:
|
2022-05-23 14:37:52 +00:00
|
|
|
respKind = pbdataplane.ServiceKind_SERVICE_KIND_MESH_GATEWAY
|
2022-04-20 00:24:21 +00:00
|
|
|
case structs.ServiceKindTerminatingGateway:
|
2022-05-23 14:37:52 +00:00
|
|
|
respKind = pbdataplane.ServiceKind_SERVICE_KIND_TERMINATING_GATEWAY
|
2022-04-20 00:24:21 +00:00
|
|
|
case structs.ServiceKindIngressGateway:
|
2022-05-23 14:37:52 +00:00
|
|
|
respKind = pbdataplane.ServiceKind_SERVICE_KIND_INGRESS_GATEWAY
|
2022-04-20 00:24:21 +00:00
|
|
|
case structs.ServiceKindTypical:
|
2022-05-23 14:37:52 +00:00
|
|
|
respKind = pbdataplane.ServiceKind_SERVICE_KIND_TYPICAL
|
2022-04-20 00:24:21 +00:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|