Skip to content

Commit

Permalink
[sec_scan][14] create AccessGraphSettings on first auth init (#44032)
Browse files Browse the repository at this point in the history
* [sec_scan][14] create `AccessGraphSettings` on first auth init

This PR adds a init script that sets `AccessGraphSettings` into Teleport backend when auth first inits and there is no `AccessGraphSettings`.

This PR is part of gravitational/access-graph#637.

Signed-off-by: Tiago Silva <[email protected]>

* remove iterations

---------

Signed-off-by: Tiago Silva <[email protected]>
  • Loading branch information
tigrato committed Jul 30, 2024
1 parent b0fb747 commit d968d0c
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions lib/auth/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ import (
"github.com/gravitational/teleport"
"github.com/gravitational/teleport/api/client/proto"
apidefaults "github.com/gravitational/teleport/api/defaults"
clusterconfigpb "github.com/gravitational/teleport/api/gen/proto/go/teleport/clusterconfig/v1"
dbobjectimportrulev1pb "github.com/gravitational/teleport/api/gen/proto/go/teleport/dbobjectimportrule/v1"
machineidv1pb "github.com/gravitational/teleport/api/gen/proto/go/teleport/machineid/v1"
"github.com/gravitational/teleport/api/types"
"github.com/gravitational/teleport/api/types/clusterconfig"
apievents "github.com/gravitational/teleport/api/types/events"
"github.com/gravitational/teleport/lib"
"github.com/gravitational/teleport/lib/ai"
Expand Down Expand Up @@ -445,6 +447,12 @@ func initCluster(ctx context.Context, cfg InitConfig, asrv *Server) error {
return trace.Wrap(initializeSessionRecordingConfig(ctx, asrv, cfg.SessionRecordingConfig))
})

g.Go(func() error {
ctx, span := cfg.Tracer.Start(gctx, "auth/InitializeAccessGraphSettings")
defer span.End()
return trace.Wrap(initializeAccessGraphSettings(ctx, asrv))
})

g.Go(func() error {
ctx, span := cfg.Tracer.Start(gctx, "auth/initializeAuthPreference")
defer span.End()
Expand Down Expand Up @@ -848,6 +856,31 @@ func initializeSessionRecordingConfig(ctx context.Context, asrv *Server, newRecC
return trace.LimitExceeded("failed to initialize session recording config in %v iterations", iterationLimit)
}

func initializeAccessGraphSettings(ctx context.Context, asrv *Server) error {
stored, err := asrv.Services.GetAccessGraphSettings(ctx)
if err != nil && !trace.IsNotFound(err) {
return trace.Wrap(err)
}
if stored != nil {
return nil
}

stored, err = clusterconfig.NewAccessGraphSettings(&clusterconfigpb.AccessGraphSettingsSpec{
SecretsScanConfig: clusterconfigpb.AccessGraphSecretsScanConfig_ACCESS_GRAPH_SECRETS_SCAN_CONFIG_DISABLED,
})
if err != nil {
return trace.Wrap(err)
}

log.Infof("Creating access graph settings: %v.", stored)
_, err = asrv.CreateAccessGraphSettings(ctx, stored)
if trace.IsAlreadyExists(err) {
return nil
}

return trace.Wrap(err)
}

// shouldInitReplaceResourceWithOrigin determines whether the candidate
// resource should be used to replace the stored resource during auth server
// initialization. Dynamically configured resources must not be overwritten
Expand Down

0 comments on commit d968d0c

Please sign in to comment.