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

[sec_scan][14] create AccessGraphSettings on first auth init #44032

Merged
merged 2 commits into from
Jul 22, 2024
Merged
Changes from all commits
Commits
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
33 changes: 33 additions & 0 deletions lib/auth/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,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/auth/dbobjectimportrule/dbobjectimportrulev1"
Expand Down Expand Up @@ -437,6 +439,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 @@ -860,6 +868,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
Loading