Skip to content

Commit

Permalink
Merge branch 'master' into edwarddowling/discord-plugin-amr
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwardDowling authored Aug 22, 2024
2 parents f5a6306 + 8495398 commit f5182a9
Show file tree
Hide file tree
Showing 261 changed files with 13,111 additions and 7,276 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,6 @@ output:
uniq-by-line: false

run:
go: '1.23'
go: '1.22'
build-tags: []
timeout: 15m
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ endif
# todo: Use gotestsum when it is compatible with benchmark output. Currently will consider all benchmarks failed.
.PHONY: test-go-bench
test-go-bench: PACKAGES = $(shell grep --exclude-dir api --include "*_test.go" -lr testing.B . | xargs dirname | xargs go list | sort -u)
test-go-bench: BENCHMARK_SKIP_PATTERN = "^BenchmarkRoot|^BenchmarkGetMaxNodes$$"
test-go-bench: BENCHMARK_SKIP_PATTERN = "^BenchmarkRoot"
test-go-bench: | $(TEST_LOG_DIR)
go test -run ^$$ -bench . -skip $(BENCHMARK_SKIP_PATTERN) -benchtime 1x $(PACKAGES) \
| tee $(TEST_LOG_DIR)/bench.txt
Expand Down
80 changes: 50 additions & 30 deletions api/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import (
"github.com/gravitational/teleport/api/client/proto"
"github.com/gravitational/teleport/api/client/scim"
"github.com/gravitational/teleport/api/client/secreport"
statichostuserclient "github.com/gravitational/teleport/api/client/statichostuser"
"github.com/gravitational/teleport/api/client/userloginstate"
"github.com/gravitational/teleport/api/constants"
"github.com/gravitational/teleport/api/defaults"
Expand Down Expand Up @@ -86,6 +87,7 @@ import (
secreportsv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/secreports/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"
userprovisioningpb "github.com/gravitational/teleport/api/gen/proto/go/teleport/userprovisioning/v1"
userspb "github.com/gravitational/teleport/api/gen/proto/go/teleport/users/v1"
"github.com/gravitational/teleport/api/gen/proto/go/teleport/vnet/v1"
userpreferencespb "github.com/gravitational/teleport/api/gen/proto/go/userpreferences/v1"
Expand Down Expand Up @@ -858,6 +860,10 @@ func (c *Client) BotInstanceServiceClient() machineidv1pb.BotInstanceServiceClie
return machineidv1pb.NewBotInstanceServiceClient(c.conn)
}

func (c *Client) SPIFFEFederationServiceClient() machineidv1pb.SPIFFEFederationServiceClient {
return machineidv1pb.NewSPIFFEFederationServiceClient(c.conn)
}

// PresenceServiceClient returns an unadorned client for the presence service.
func (c *Client) PresenceServiceClient() presencepb.PresenceServiceClient {
return presencepb.NewPresenceServiceClient(c.conn)
Expand Down Expand Up @@ -1492,6 +1498,8 @@ func (c *Client) GetSnowflakeSessions(ctx context.Context) ([]types.WebSession,
}

// ListSAMLIdPSessions gets a paginated list of SAML IdP sessions.
// Deprecated: Do not use. The Concept of SAML IdP Sessions is no longer in use.
// SAML IdP Sessions are directly tied to their parent web sessions instead.
func (c *Client) ListSAMLIdPSessions(ctx context.Context, pageSize int, pageToken, user string) ([]types.WebSession, string, error) {
resp, err := c.grpc.ListSAMLIdPSessions(
ctx,
Expand Down Expand Up @@ -1537,6 +1545,8 @@ func (c *Client) CreateSnowflakeSession(ctx context.Context, req types.CreateSno
}

// CreateSAMLIdPSession creates a SAML IdP session.
// Deprecated: Do not use. The Concept of SAML IdP Sessions is no longer in use.
// SAML IdP Sessions are directly tied to their parent web sessions instead.
func (c *Client) CreateSAMLIdPSession(ctx context.Context, req types.CreateSAMLIdPSessionRequest) (types.WebSession, error) {
resp, err := c.grpc.CreateSAMLIdPSession(ctx, &proto.CreateSAMLIdPSessionRequest{
SessionID: req.SessionID,
Expand All @@ -1563,6 +1573,8 @@ func (c *Client) GetSnowflakeSession(ctx context.Context, req types.GetSnowflake
}

// GetSAMLIdPSession gets a SAML IdP session.
// Deprecated: Do not use. The Concept of SAML IdP Sessions is no longer in use.
// SAML IdP Sessions are directly tied to their parent web sessions instead.
func (c *Client) GetSAMLIdPSession(ctx context.Context, req types.GetSAMLIdPSessionRequest) (types.WebSession, error) {
resp, err := c.grpc.GetSAMLIdPSession(ctx, &proto.GetSAMLIdPSessionRequest{
SessionID: req.SessionID,
Expand Down Expand Up @@ -1591,6 +1603,9 @@ func (c *Client) DeleteSnowflakeSession(ctx context.Context, req types.DeleteSno
}

// DeleteSAMLIdPSession removes a SAML IdP session.
// Deprecated: Do not use. As of v16, the Concept of SAML IdP Sessions is no longer in use.
// SAML IdP Sessions are directly tied to their parent web sessions instead. This endpoint
// will be removed in v17.
func (c *Client) DeleteSAMLIdPSession(ctx context.Context, req types.DeleteSAMLIdPSessionRequest) error {
_, err := c.grpc.DeleteSAMLIdPSession(ctx, &proto.DeleteSAMLIdPSessionRequest{
SessionID: req.SessionID,
Expand All @@ -1611,6 +1626,8 @@ func (c *Client) DeleteAllSnowflakeSessions(ctx context.Context) error {
}

// DeleteAllSAMLIdPSessions removes all SAML IdP sessions.
// Deprecated: Do not use. The Concept of SAML IdP Sessions is no longer in use.
// SAML IdP Sessions are directly tied to their parent web sessions instead.
func (c *Client) DeleteAllSAMLIdPSessions(ctx context.Context) error {
_, err := c.grpc.DeleteAllSAMLIdPSessions(ctx, &emptypb.Empty{})
return trace.Wrap(err)
Expand All @@ -1623,6 +1640,8 @@ func (c *Client) DeleteUserAppSessions(ctx context.Context, req *proto.DeleteUse
}

// DeleteUserSAMLIdPSessions deletes all user’s SAML IdP sessions.
// Deprecated: Do not use. The Concept of SAML IdP Sessions is no longer in use.
// SAML IdP Sessions are directly tied to their parent web sessions instead.
func (c *Client) DeleteUserSAMLIdPSessions(ctx context.Context, username string) error {
req := &proto.DeleteUserSAMLIdPSessionsRequest{
Username: username,
Expand Down Expand Up @@ -3184,6 +3203,11 @@ func (c *Client) DeleteKubernetesWaitingContainer(ctx context.Context, req *kube
return c.GetKubernetesWaitingContainerClient().DeleteKubernetesWaitingContainer(ctx, req)
}

// StaticHostUserClient returns a new static host user client.
func (c *Client) StaticHostUserClient() *statichostuserclient.Client {
return statichostuserclient.NewClient(userprovisioningpb.NewStaticHostUsersServiceClient(c.conn))
}

// CreateDatabase creates a new database resource.
func (c *Client) CreateDatabase(ctx context.Context, database types.Database) error {
databaseV3, ok := database.(*types.DatabaseV3)
Expand Down Expand Up @@ -3717,6 +3741,31 @@ func GetUnifiedResourcePage(ctx context.Context, clt ListUnifiedResourcesClient,
}
}

// GetAllUnifiedResources is a helper for getting all existing resources that match the provided request. In addition to
// iterating pages, it also correctly handles downsizing pages when LimitExceeded errors are encountered.
func GetAllUnifiedResources(ctx context.Context, clt ListUnifiedResourcesClient, req *proto.ListUnifiedResourcesRequest) ([]*types.EnrichedResource, error) {
var out []*types.EnrichedResource

// Set the limit to the default size.
req.Limit = int32(defaults.DefaultChunkSize)
for {
resources, nextKey, err := GetUnifiedResourcePage(ctx, clt, req)
if err != nil {
return nil, trace.Wrap(err)
}

out = append(out, resources...)

if nextKey == "" || len(resources) == 0 {
break
}

req.StartKey = nextKey
}

return out, nil
}

// GetEnrichedResourcePage is a helper for getting a single page of enriched resources.
func GetEnrichedResourcePage(ctx context.Context, clt GetResourcesClient, req *proto.ListResourcesRequest) (ResourcePage[*types.EnrichedResource], error) {
var out ResourcePage[*types.EnrichedResource]
Expand Down Expand Up @@ -3993,36 +4042,7 @@ func GetKubernetesResourcesWithFilters(ctx context.Context, clt kubeproto.KubeSe
// but may result in confusing behavior if it is used outside of those contexts.
func (c *Client) GetSSHTargets(ctx context.Context, req *proto.GetSSHTargetsRequest) (*proto.GetSSHTargetsResponse, error) {
rsp, err := c.grpc.GetSSHTargets(ctx, req)
if err := trace.Wrap(err); !trace.IsNotImplemented(err) {
return rsp, err
}

// if we got a not implemented error, fallback to client-side filtering
servers, err := GetAllResources[*types.ServerV2](ctx, c, &proto.ListResourcesRequest{
ResourceType: types.KindNode,
UseSearchAsRoles: true,
})
if err != nil {
return nil, trace.Wrap(err)
}

// we only get here if we hit a NotImplementedError from GetSSHTargets, which means
// we should be performing client-side filtering with default parameters instead.
routeMatcher := utils.NewSSHRouteMatcher(req.Host, req.Port, false)

// do client-side filtering
filtered := servers[:0]
for _, srv := range servers {
if !routeMatcher.RouteToServer(srv) {
continue
}

filtered = append(filtered, srv)
}

return &proto.GetSSHTargetsResponse{
Servers: filtered,
}, nil
return rsp, trace.Wrap(err)
}

// CreateSessionTracker creates a tracker resource for an active session.
Expand Down
8 changes: 8 additions & 0 deletions api/client/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
kubewaitingcontainerpb "github.com/gravitational/teleport/api/gen/proto/go/teleport/kubewaitingcontainer/v1"
machineidv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/machineid/v1"
notificationsv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/notifications/v1"
userprovisioningpb "github.com/gravitational/teleport/api/gen/proto/go/teleport/userprovisioning/v1"
"github.com/gravitational/teleport/api/types"
"github.com/gravitational/teleport/api/types/accesslist"
accesslistv1conv "github.com/gravitational/teleport/api/types/accesslist/convert/v1"
Expand Down Expand Up @@ -94,6 +95,10 @@ func EventToGRPC(in types.Event) (*proto.Event, error) {
out.Resource = &proto.Event_SPIFFEFederation{
SPIFFEFederation: r,
}
case *userprovisioningpb.StaticHostUser:
out.Resource = &proto.Event_StaticHostUser{
StaticHostUser: r,
}
default:
return nil, trace.BadParameter("resource type %T is not supported", r)
}
Expand Down Expand Up @@ -534,6 +539,9 @@ func EventFromGRPC(in *proto.Event) (*types.Event, error) {
} else if r := in.GetSPIFFEFederation(); r != nil {
out.Resource = types.Resource153ToLegacy(r)
return &out, nil
} else if r := in.GetStaticHostUser(); r != nil {
out.Resource = types.Resource153ToLegacy(r)
return &out, nil
} else {
return nil, trace.BadParameter("received unsupported resource %T", in.Resource)
}
Expand Down
Loading

0 comments on commit f5182a9

Please sign in to comment.