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

#88: add delete protections #105

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ func configLambda() {
func addFlags(cmd *cobra.Command, cfg *config.Config) {
rootCmd.PersistentFlags().StringVarP(&cfg.GoogleCredentials, "google-admin", "a", config.DefaultGoogleCredentials, "path to find credentials file for Google Workspace")
rootCmd.PersistentFlags().BoolVarP(&cfg.Debug, "debug", "d", config.DefaultDebug, "enable verbose / debug logging")
rootCmd.PersistentFlags().BoolVarP(&cfg.Delete, "delete", "", config.DefaultDelete, "delete users and groups on AWS")
rootCmd.PersistentFlags().StringVarP(&cfg.LogFormat, "log-format", "", config.DefaultLogFormat, "log format")
rootCmd.PersistentFlags().StringVarP(&cfg.LogLevel, "log-level", "", config.DefaultLogLevel, "log level")
rootCmd.Flags().StringVarP(&cfg.SCIMAccessToken, "access-token", "t", "", "AWS SSO SCIM API Access Token")
Expand Down
5 changes: 5 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package config
type Config struct {
// Verbose toggles the verbosity
Debug bool
// Delete is whether to delete on AWS
Delete bool
// LogLevel is the level with with to log for this config
LogLevel string `mapstructure:"log_level"`
// LogFormat is the format that is used for logging
Expand Down Expand Up @@ -44,12 +46,15 @@ const (
DefaultGoogleCredentials = "credentials.json"
// DefaultSyncMethod is the default sync method to use.
DefaultSyncMethod = "groups"
// DefaultDelete is whether to delete users and groups from AWS
DefaultDelete = false
)

// New returns a new Config
func New() *Config {
return &Config{
Debug: DefaultDebug,
Delete: DefaultDelete,
LogLevel: DefaultLogLevel,
LogFormat: DefaultLogFormat,
SyncMethod: DefaultSyncMethod,
Expand Down
33 changes: 24 additions & 9 deletions internal/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,15 @@ func (s *syncGSuite) SyncGroupsUsers(query string) error {
return err
}

log.Warn("deleting user")
if err := s.aws.DeleteUser(awsUserFull); err != nil {
log.Error("error deleting user")
return err
if s.cfg.Delete {
if err := s.aws.DeleteUser(awsUserFull); err != nil {
log.Error("error deleting user")
return err
}
} else {
log.Error("Not deleting user from AWS users (use --delete to delete users and groups)")
}

}

// update aws users (updated in google)
Expand Down Expand Up @@ -449,17 +453,28 @@ func (s *syncGSuite) SyncGroupsUsers(query string) error {

log := log.WithFields(log.Fields{"group": awsGroup.DisplayName})

// In mid-2022, AWS started using the prefix "AWS" for administrative
// purposes. Without this, ssosync deletes these administrative groups.
if awsGroup.DisplayName[:3] == "AWS" {
log.Warn("Refusing to delete")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
log.Warn("Refusing to delete")
log.Warn("Refusing to delete group with the prefix 'AWS'")

continue
}

log.Debug("finding group")
awsGroupFull, err := s.aws.FindGroupByDisplayName(awsGroup.DisplayName)
if err != nil {
return err
}

log.Warn("deleting group")
err = s.aws.DeleteGroup(awsGroupFull)
if err != nil {
log.Error("deleting group")
return err
if s.cfg.Delete {
log.Warn("deleting group")
err = s.aws.DeleteGroup(awsGroupFull)
if err != nil {
log.Error("deleting group")
return err
}
} else {
log.Error("Not deleting group from AWS groups (use --delete to delete users and groups)")
}
}

Expand Down