Skip to content

Commit

Permalink
Unify naming and location of auth RPC services (#46559) (#46597)
Browse files Browse the repository at this point in the history
This moves packages around and renames things such that all existing
and non-legacy auth RPC services follow the same semantics.

- RPC services are all now under `lib/auth/<rpc_package>/<rpc_package><rpc_version>`
  i.e. lib/auth/accessmonitoringrules/accessmonitoringrulesv1
- Generated proto code imported in lib/auth/grpcserver.go are now
  aliased to <rpc_package><rpc_version>pb
  i.e. accessmonitoringrulesv1pb
  • Loading branch information
rosstimothy authored Sep 13, 2024
1 parent 0f661d4 commit 571f006
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 68 deletions.
73 changes: 37 additions & 36 deletions lib/auth/grpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ import (
"github.com/gravitational/teleport/api/client"
authpb "github.com/gravitational/teleport/api/client/proto"
"github.com/gravitational/teleport/api/constants"
"github.com/gravitational/teleport/api/gen/proto/go/assist/v1"
auditlogpb "github.com/gravitational/teleport/api/gen/proto/go/teleport/auditlog/v1"
clusterconfigpb "github.com/gravitational/teleport/api/gen/proto/go/teleport/clusterconfig/v1"
discoveryconfigpb "github.com/gravitational/teleport/api/gen/proto/go/teleport/discoveryconfig/v1"
integrationpb "github.com/gravitational/teleport/api/gen/proto/go/teleport/integration/v1"
kubewaitingcontainerpb "github.com/gravitational/teleport/api/gen/proto/go/teleport/kubewaitingcontainer/v1"
loginrulepb "github.com/gravitational/teleport/api/gen/proto/go/teleport/loginrule/v1"
oktapb "github.com/gravitational/teleport/api/gen/proto/go/teleport/okta/v1"
trustpb "github.com/gravitational/teleport/api/gen/proto/go/teleport/trust/v1"
userloginstatev1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/userloginstate/v1"
userpreferencespb "github.com/gravitational/teleport/api/gen/proto/go/userpreferences/v1"
assistv1pb "github.com/gravitational/teleport/api/gen/proto/go/assist/v1"
auditlogv1pb "github.com/gravitational/teleport/api/gen/proto/go/teleport/auditlog/v1"
clusterconfigv1pb "github.com/gravitational/teleport/api/gen/proto/go/teleport/clusterconfig/v1"
discoveryconfigv1pb "github.com/gravitational/teleport/api/gen/proto/go/teleport/discoveryconfig/v1"
integrationv1pb "github.com/gravitational/teleport/api/gen/proto/go/teleport/integration/v1"
kubewaitingcontainerv1pb "github.com/gravitational/teleport/api/gen/proto/go/teleport/kubewaitingcontainer/v1"
loginrulev1pb "github.com/gravitational/teleport/api/gen/proto/go/teleport/loginrule/v1"
oktav1pb "github.com/gravitational/teleport/api/gen/proto/go/teleport/okta/v1"
trustv1pb "github.com/gravitational/teleport/api/gen/proto/go/teleport/trust/v1"
userloginstatev1pb "github.com/gravitational/teleport/api/gen/proto/go/teleport/userloginstate/v1"
userpreferencesv1pb "github.com/gravitational/teleport/api/gen/proto/go/userpreferences/v1"
"github.com/gravitational/teleport/api/internalutils/stream"
"github.com/gravitational/teleport/api/metadata"
"github.com/gravitational/teleport/api/types"
Expand All @@ -67,12 +67,12 @@ import (
"github.com/gravitational/teleport/lib/auth/authclient"
"github.com/gravitational/teleport/lib/auth/clusterconfig/clusterconfigv1"
"github.com/gravitational/teleport/lib/auth/discoveryconfig/discoveryconfigv1"
integrationService "github.com/gravitational/teleport/lib/auth/integration/integrationv1"
kubewaitingcontainerv1 "github.com/gravitational/teleport/lib/auth/kubewaitingcontainer"
"github.com/gravitational/teleport/lib/auth/loginrule"
"github.com/gravitational/teleport/lib/auth/integration/integrationv1"
"github.com/gravitational/teleport/lib/auth/kubewaitingcontainer/kubewaitingcontainerv1"
"github.com/gravitational/teleport/lib/auth/loginrule/loginrulev1"
"github.com/gravitational/teleport/lib/auth/okta"
"github.com/gravitational/teleport/lib/auth/trust/trustv1"
"github.com/gravitational/teleport/lib/auth/userloginstate"
"github.com/gravitational/teleport/lib/auth/userloginstate/userloginstatev1"
"github.com/gravitational/teleport/lib/auth/userpreferences/userpreferencesv1"
wanlib "github.com/gravitational/teleport/lib/auth/webauthn"
"github.com/gravitational/teleport/lib/authz"
Expand Down Expand Up @@ -122,7 +122,7 @@ var (

// GRPCServer is gRPC Auth Server API
type GRPCServer struct {
auditlogpb.UnimplementedAuditLogServiceServer
auditlogv1pb.UnimplementedAuditLogServiceServer
*logrus.Entry
APIConfig
server *grpc.Server
Expand Down Expand Up @@ -5588,7 +5588,7 @@ func NewGRPCServer(cfg GRPCServerConfig) (*GRPCServer, error) {

authpb.RegisterAuthServiceServer(server, authServer)
collectortracepb.RegisterTraceServiceServer(server, authServer)
auditlogpb.RegisterAuditLogServiceServer(server, authServer)
auditlogv1pb.RegisterAuditLogServiceServer(server, authServer)

trust, err := trustv1.NewService(&trustv1.ServiceConfig{
Authorizer: cfg.Authorizer,
Expand All @@ -5598,7 +5598,7 @@ func NewGRPCServer(cfg GRPCServerConfig) (*GRPCServer, error) {
if err != nil {
return nil, trace.Wrap(err)
}
trustpb.RegisterTrustServiceServer(server, trust)
trustv1pb.RegisterTrustServiceServer(server, trust)

// Initialize and register the assist service.
assistSrv, err := assistv1.NewService(&assistv1.ServiceConfig{
Expand All @@ -5611,8 +5611,8 @@ func NewGRPCServer(cfg GRPCServerConfig) (*GRPCServer, error) {
if err != nil {
return nil, trace.Wrap(err)
}
assist.RegisterAssistServiceServer(server, assistSrv)
assist.RegisterAssistEmbeddingServiceServer(server, assistSrv)
assistv1pb.RegisterAssistServiceServer(server, assistSrv)
assistv1pb.RegisterAssistEmbeddingServiceServer(server, assistSrv)

// create server with no-op role to pass to JoinService server
serverWithNopRole, err := serverWithNopRole(cfg)
Expand All @@ -5629,9 +5629,9 @@ func NewGRPCServer(cfg GRPCServerConfig) (*GRPCServer, error) {
if err != nil {
return nil, trace.Wrap(err)
}
oktapb.RegisterOktaServiceServer(server, oktaServiceServer)
oktav1pb.RegisterOktaServiceServer(server, oktaServiceServer)

integrationServiceServer, err := integrationService.NewService(&integrationService.ServiceConfig{
integrationServiceServer, err := integrationv1.NewService(&integrationv1.ServiceConfig{
Authorizer: cfg.Authorizer,
Backend: cfg.AuthServer.Services,
Cache: cfg.AuthServer.Cache,
Expand All @@ -5642,17 +5642,17 @@ func NewGRPCServer(cfg GRPCServerConfig) (*GRPCServer, error) {
if err != nil {
return nil, trace.Wrap(err)
}
integrationpb.RegisterIntegrationServiceServer(server, integrationServiceServer)
integrationv1pb.RegisterIntegrationServiceServer(server, integrationServiceServer)

integrationAWSOIDCServiceServer, err := integrationService.NewAWSOIDCService(&integrationService.AWSOIDCServiceConfig{
integrationAWSOIDCServiceServer, err := integrationv1.NewAWSOIDCService(&integrationv1.AWSOIDCServiceConfig{
Authorizer: cfg.Authorizer,
IntegrationService: integrationServiceServer,
Cache: cfg.AuthServer,
})
if err != nil {
return nil, trace.Wrap(err)
}
integrationpb.RegisterAWSOIDCServiceServer(server, integrationAWSOIDCServiceServer)
integrationv1pb.RegisterAWSOIDCServiceServer(server, integrationAWSOIDCServiceServer)

discoveryConfig, err := discoveryconfigv1.NewService(discoveryconfigv1.ServiceConfig{
Authorizer: cfg.Authorizer,
Expand All @@ -5663,7 +5663,7 @@ func NewGRPCServer(cfg GRPCServerConfig) (*GRPCServer, error) {
if err != nil {
return nil, trace.Wrap(err)
}
discoveryconfigpb.RegisterDiscoveryConfigServiceServer(server, discoveryConfig)
discoveryconfigv1pb.RegisterDiscoveryConfigServiceServer(server, discoveryConfig)

// Initialize and register the user preferences service.
userPreferencesSrv, err := userpreferencesv1.NewService(&userpreferencesv1.ServiceConfig{
Expand All @@ -5673,22 +5673,22 @@ func NewGRPCServer(cfg GRPCServerConfig) (*GRPCServer, error) {
if err != nil {
return nil, trace.Wrap(err)
}
userpreferencespb.RegisterUserPreferencesServiceServer(server, userPreferencesSrv)
userpreferencesv1pb.RegisterUserPreferencesServiceServer(server, userPreferencesSrv)

// Initialize and register the user login state service.
userLoginState, err := local.NewUserLoginStateService(cfg.AuthServer.bk)
if err != nil {
return nil, trace.Wrap(err)
}

userLoginStateServer, err := userloginstate.NewService(userloginstate.ServiceConfig{
userLoginStateServer, err := userloginstatev1.NewService(userloginstatev1.ServiceConfig{
Authorizer: cfg.Authorizer,
UserLoginStates: userLoginState,
})
if err != nil {
return nil, trace.Wrap(err)
}
userloginstatev1.RegisterUserLoginStateServiceServer(server, userLoginStateServer)
userloginstatev1pb.RegisterUserLoginStateServiceServer(server, userLoginStateServer)

clusterConfigService, err := clusterconfigv1.NewService(clusterconfigv1.ServiceConfig{
Authorizer: cfg.Authorizer,
Expand All @@ -5702,7 +5702,8 @@ func NewGRPCServer(cfg GRPCServerConfig) (*GRPCServer, error) {
if err != nil {
return nil, trace.Wrap(err)
}
clusterconfigpb.RegisterClusterConfigServiceServer(server, clusterConfigService)

clusterconfigv1pb.RegisterClusterConfigServiceServer(server, clusterConfigService)

// Initialize and register the Kubernetes waiting container service.
kubeWaitingContsServer, err := kubewaitingcontainerv1.NewService(kubewaitingcontainerv1.ServiceConfig{
Expand All @@ -5713,13 +5714,13 @@ func NewGRPCServer(cfg GRPCServerConfig) (*GRPCServer, error) {
if err != nil {
return nil, trace.Wrap(err)
}
kubewaitingcontainerpb.RegisterKubeWaitingContainersServiceServer(server, kubeWaitingContsServer)
kubewaitingcontainerv1pb.RegisterKubeWaitingContainersServiceServer(server, kubeWaitingContsServer)

// Only register the service if this is an open source build. Enterprise builds
// register the actual service via an auth plugin, if we register here then all
// Enterprise builds would fail with a duplicate service registered error.
if cfg.PluginRegistry == nil || !cfg.PluginRegistry.IsRegistered("auth.enterprise") {
loginrulepb.RegisterLoginRuleServiceServer(server, loginrule.NotImplementedService{})
loginrulev1pb.RegisterLoginRuleServiceServer(server, loginrulev1.NotImplementedService{})
}

return authServer, nil
Expand Down Expand Up @@ -5773,7 +5774,7 @@ func (g *GRPCServer) authenticate(ctx context.Context) (*grpcContext, error) {
}

// GetUnstructuredEvents searches for events on the backend and sends them back in an unstructured format.
func (g *GRPCServer) GetUnstructuredEvents(ctx context.Context, req *auditlogpb.GetUnstructuredEventsRequest) (*auditlogpb.EventsUnstructured, error) {
func (g *GRPCServer) GetUnstructuredEvents(ctx context.Context, req *auditlogv1pb.GetUnstructuredEventsRequest) (*auditlogv1pb.EventsUnstructured, error) {
auth, err := g.authenticate(ctx)
if err != nil {
return nil, trace.Wrap(err)
Expand All @@ -5791,7 +5792,7 @@ func (g *GRPCServer) GetUnstructuredEvents(ctx context.Context, req *auditlogpb.
return nil, trace.Wrap(err)
}

unstructuredEvents := make([]*auditlogpb.EventUnstructured, 0, len(rawEvents))
unstructuredEvents := make([]*auditlogv1pb.EventUnstructured, 0, len(rawEvents))
for _, event := range rawEvents {
unstructuredEvent, err := apievents.ToUnstructured(event)
if err != nil {
Expand All @@ -5800,14 +5801,14 @@ func (g *GRPCServer) GetUnstructuredEvents(ctx context.Context, req *auditlogpb.
unstructuredEvents = append(unstructuredEvents, unstructuredEvent)
}

return &auditlogpb.EventsUnstructured{
return &auditlogv1pb.EventsUnstructured{
Items: unstructuredEvents,
LastKey: lastkey,
}, nil
}

// StreamUnstructuredSessionEvents streams all events from a given session recording as an unstructured format.
func (g *GRPCServer) StreamUnstructuredSessionEvents(req *auditlogpb.StreamUnstructuredSessionEventsRequest, stream auditlogpb.AuditLogService_StreamUnstructuredSessionEventsServer) error {
func (g *GRPCServer) StreamUnstructuredSessionEvents(req *auditlogv1pb.StreamUnstructuredSessionEventsRequest, stream auditlogv1pb.AuditLogService_StreamUnstructuredSessionEventsServer) error {
auth, err := g.authenticate(stream.Context())
if err != nil {
return trace.Wrap(err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package kubewaitingcontainer
package kubewaitingcontainerv1

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package kubewaitingcontainer
package kubewaitingcontainerv1

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package loginrule
package loginrulev1

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package userloginstate
package userloginstatev1

import (
"context"
Expand Down
Loading

0 comments on commit 571f006

Please sign in to comment.