Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Crown Jewel resource #40914

Merged
merged 32 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
d5d3d02
Update labels datatype in Teleport crownjewel proto
tigrato Feb 27, 2024
8594cf6
Fixes after rebase
jakule Apr 19, 2024
56058c7
Refactor Crown Jewel resource methods
jakule Apr 25, 2024
8cebc53
Removed CrownJewel converter, updated CrownJewel references
jakule Apr 30, 2024
1c2dbd6
Implement Crown Jewel deletion functionality
jakule Apr 30, 2024
ae2ab2a
Refactored function 'allCombinations' and added authorization checks
jakule May 1, 2024
2c85e2f
Add CrownJewel service to cache tests
jakule May 1, 2024
1a92269
Add access path changed event and update Crown Jewel tests
jakule May 1, 2024
73722b9
Update protobuf import path
jakule May 1, 2024
49432eb
Refactor CrownJewel and AccessGraph services
jakule May 1, 2024
ba4f8fd
Add CrownJewel resource in access controls and tests
jakule May 1, 2024
5be31f7
Simplify implementation
jakule May 1, 2024
634fe16
Update copyright dates and add license headers
jakule May 1, 2024
a71dd4f
Refactor CrownJewel codebase for better readability
jakule May 1, 2024
714daf0
Add validation for Teleport and AWS matchers in service
jakule May 1, 2024
bbe1ab8
gci
jakule May 1, 2024
d7f1045
Add CrownJewel update functionality and refactor related services
jakule May 1, 2024
9eafcfd
Relocate and update crown_jewels_test file
jakule May 2, 2024
2264300
Update crown jewels test with AWS matchers
jakule May 2, 2024
3669ee4
Added upsertCrownJewel function and related proto message
jakule May 2, 2024
651c9ee
Refactor CrownJewelsClient to use upsert
jakule May 2, 2024
367bc89
Add GetCrownJewel functionality and refactor validation
jakule May 2, 2024
04e3234
Add VerbCreate check and test for CrownJewel validation
jakule May 2, 2024
976b4cc
Refactor CrownJewel resource handling and validation
jakule May 2, 2024
d74eb8a
Add cache implementation to CrownJewel service
jakule May 2, 2024
d78c7cb
Add Cache to service configuration in crownjewelv1 tests
jakule May 3, 2024
ab03b20
Update CrownJewelsService to use ConditionalUpdateResource
jakule May 3, 2024
56b35f7
Replace 'Cache' with 'Reader' in crownjewel service & remove DeleteAl…
jakule May 6, 2024
f62dd48
Update tests for Crown Jewel service
jakule May 6, 2024
0cc7e5e
Refactor protobuf marshaling with utils
jakule May 6, 2024
4c47ce3
Update CrownJewel test and serialization methods
jakule May 7, 2024
f292e04
Add missing license
jakule May 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion api/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ import (
"github.com/gravitational/teleport/api/breaker"
"github.com/gravitational/teleport/api/client/accesslist"
"github.com/gravitational/teleport/api/client/accessmonitoringrules"
"github.com/gravitational/teleport/api/client/crownjewel"
crownjewelapi "github.com/gravitational/teleport/api/client/crownjewel"
"github.com/gravitational/teleport/api/client/discoveryconfig"
"github.com/gravitational/teleport/api/client/externalauditstorage"
kubewaitingcontainerclient "github.com/gravitational/teleport/api/client/kubewaitingcontainer"
Expand All @@ -64,6 +66,7 @@ import (
accessmonitoringrulev1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/accessmonitoringrules/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"
crownjewelv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/crownjewel/v1"
dbobjectv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/dbobject/v1"
dbobjectimportrulev1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/dbobjectimportrule/v1"
devicepb "github.com/gravitational/teleport/api/gen/proto/go/teleport/devicetrust/v1"
Expand Down Expand Up @@ -4784,8 +4787,16 @@ func (c *Client) DiscoveryConfigClient() *discoveryconfig.Client {
return discoveryconfig.NewClient(discoveryconfigv1.NewDiscoveryConfigServiceClient(c.conn))
}

// CrownJewelServiceClient returns a CrownJewel client.
// Clients connecting to older Teleport versions, still get a CrownJewel client
// when calling this method, but all RPCs will return "not implemented" errors
// (as per the default gRPC behavior).
func (c *Client) CrownJewelServiceClient() *crownjewelapi.Client {
return crownjewel.NewClient(crownjewelv1.NewCrownJewelServiceClient(c.conn))
}

// UserLoginStateClient returns a user login state client.
// Clients connecting to older Teleport versions, still get a user login state client
// Clients connecting to older Teleport versions, still get a user login state client
// when calling this method, but all RPCs will return "not implemented" errors
// (as per the default gRPC behavior).
func (c *Client) UserLoginStateClient() *userloginstate.Client {
Expand Down
106 changes: 106 additions & 0 deletions api/client/crownjewel/crownjewel.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Copyright 2024 Gravitational, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package crownjewel

import (
"context"

"github.com/gravitational/trace"

crownjewelv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/crownjewel/v1"
)

// Client is a client for the Crown Jewel API.
type Client struct {
grpcClient crownjewelv1.CrownJewelServiceClient
}

// NewClient creates a new Discovery Config client.
func NewClient(grpcClient crownjewelv1.CrownJewelServiceClient) *Client {
return &Client{
grpcClient: grpcClient,
}
}

// ListCrownJewels returns a list of Crown Jewels.
func (c *Client) ListCrownJewels(ctx context.Context, pageSize int64, nextToken string) ([]*crownjewelv1.CrownJewel, string, error) {
resp, err := c.grpcClient.ListCrownJewels(ctx, &crownjewelv1.ListCrownJewelsRequest{
PageSize: pageSize,
PageToken: nextToken,
})
if err != nil {
return nil, "", trace.Wrap(err)
}

return resp.CrownJewels, resp.NextPageToken, nil
}

// CreateCrownJewel creates a new Crown Jewel.
func (c *Client) CreateCrownJewel(ctx context.Context, req *crownjewelv1.CrownJewel) (*crownjewelv1.CrownJewel, error) {
rsp, err := c.grpcClient.CreateCrownJewel(ctx, &crownjewelv1.CreateCrownJewelRequest{
CrownJewels: req,
})
if err != nil {
return nil, trace.Wrap(err)
}
return rsp, nil
}

// GetCrownJewel returns a Crown Jewel by name.
func (c *Client) GetCrownJewel(ctx context.Context, name string) (*crownjewelv1.CrownJewel, error) {
rsp, err := c.grpcClient.GetCrownJewel(ctx, &crownjewelv1.GetCrownJewelRequest{
Name: name,
})
if err != nil {
return nil, trace.Wrap(err)
}
return rsp, nil
}

// UpdateCrownJewel updates an existing Crown Jewel.
func (c *Client) UpdateCrownJewel(ctx context.Context, req *crownjewelv1.CrownJewel) (*crownjewelv1.CrownJewel, error) {
rsp, err := c.grpcClient.UpdateCrownJewel(ctx, &crownjewelv1.UpdateCrownJewelRequest{
CrownJewels: req,
})
if err != nil {
return nil, trace.Wrap(err)
}
return rsp, nil
}

// UpsertCrownJewel upserts a Crown Jewel.
func (c *Client) UpsertCrownJewel(ctx context.Context, req *crownjewelv1.CrownJewel) (*crownjewelv1.CrownJewel, error) {
rsp, err := c.grpcClient.UpsertCrownJewel(ctx, &crownjewelv1.UpsertCrownJewelRequest{
CrownJewels: req,
})
if err != nil {
return nil, trace.Wrap(err)
}
return rsp, nil
}

// DeleteCrownJewel deletes a Crown Jewel.
func (c *Client) DeleteCrownJewel(ctx context.Context, name string) error {
_, err := c.grpcClient.DeleteCrownJewel(ctx, &crownjewelv1.DeleteCrownJewelRequest{
Name: name,
})
return trace.Wrap(err)
}

// DeleteAllCrownJewels deletes all Crown Jewels.
// Not implemented. Added to satisfy the interface.
func (c *Client) DeleteAllCrownJewels(_ context.Context) error {
return trace.NotImplemented("DeleteAllCrownJewels is not implemented")
}
8 changes: 8 additions & 0 deletions api/client/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

"github.com/gravitational/teleport/api/client/proto"
accessmonitoringrulesv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/accessmonitoringrules/v1"
crownjewelv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/crownjewel/v1"
kubewaitingcontainerpb "github.com/gravitational/teleport/api/gen/proto/go/teleport/kubewaitingcontainer/v1"
notificationsv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/notifications/v1"
"github.com/gravitational/teleport/api/types"
Expand Down Expand Up @@ -70,6 +71,10 @@ func EventToGRPC(in types.Event) (*proto.Event, error) {
out.Resource = &proto.Event_AccessMonitoringRule{
AccessMonitoringRule: r,
}
case *crownjewelv1.CrownJewel:
out.Resource = &proto.Event_CrownJewel{
CrownJewel: r,
}
}
case *types.ResourceHeader:
out.Resource = &proto.Event_ResourceHeader{
Expand Down Expand Up @@ -487,6 +492,9 @@ func EventFromGRPC(in *proto.Event) (*types.Event, error) {
} else if r := in.GetAccessMonitoringRule(); r != nil {
out.Resource = types.Resource153ToLegacy(r)
return &out, nil
} else if r := in.GetCrownJewel(); r != nil {
out.Resource = types.Resource153ToLegacy(r)
return &out, nil
} else {
return nil, trace.BadParameter("received unsupported resource %T", in.Resource)
}
Expand Down
Loading
Loading