Skip to content

Conversation

javirln
Copy link
Member

@javirln javirln commented Mar 27, 2025

This patch adds a new column, has_restricted_access, to the Users table. While not currently in use, it is synchronized with the allowlist configured on the server.

A background goroutine runs at startup, syncing the Users table with the allowlist every 10 seconds.

As we have in the allowlist middleware, if the allowlist is empty, we allow all users to get in. In this scenario, it means to update all users has_restricted_access=true to switch it false.

@javirln javirln requested review from migmartri and jiparis March 27, 2025 10:39
@javirln javirln self-assigned this Mar 27, 2025
javirln added 2 commits March 27, 2025 11:52
Signed-off-by: Javier Rodriguez <javier@chainloop.dev>
Signed-off-by: Javier Rodriguez <javier@chainloop.dev>
u.logger.Infow("msg", "Syncing user access")

// Count the number of users with restricted access
usersWithRestrictedAccess, err := u.userRepo.CountUsersWithRestrictedAccess(ctx)
Copy link
Member

Choose a reason for hiding this comment

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

move inside

// updateUserAccessBasedOnAllowList updates the access restriction status of all users based on the allowlist
func (u *UserAccessSyncerUseCase) updateUserAccessBasedOnAllowList(ctx context.Context, usersWithRestrictedAccess int) error {
// If the allowlist is empty and there are users with restricted access, give access to those users
if u.allowList != nil && len(u.allowList.GetRules()) == 0 && usersWithRestrictedAccess > 0 {
Copy link
Member

Choose a reason for hiding this comment

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

we are missing the default configuration. if allowlist not set but nothing to update

Copy link
Member

Choose a reason for hiding this comment

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

and I'd remove this case since it only applies once


// updateUserAccessRestriction updates the access restriction status of a user
func (u *UserAccessSyncerUseCase) updateUserAccessRestriction(ctx context.Context, user *User, isAllowListDeactivated bool) error {
allow, err := UserEmailInAllowlist(u.allowList.GetRules(), user.Email)
Copy link
Member

Choose a reason for hiding this comment

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

we do not need to do it if deactivated

Annotations(&entsql.Annotation{
Default: "CURRENT_TIMESTAMP",
}),
field.Bool("has_restricted_access").Default(true).Comment("Whether the user is blocked from accessing the system"),
Copy link
Member

Choose a reason for hiding this comment

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

the denormalized access state based on allow_list_settings

func (User) Indexes() []ent.Index {
return []ent.Index{
index.Fields("has_restricted_access").Annotations(
entsql.IndexWhere("has_restricted_access IS true"),
Copy link
Member

Choose a reason for hiding this comment

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

remove optimization

Signed-off-by: Javier Rodriguez <javier@chainloop.dev>
@javirln
Copy link
Member Author

javirln commented Mar 27, 2025

Updated the PR to:

  • By default has_restricted_access to NULL
  • No sync if the allow list is empty and no users with restricted access
  • Remove index optimization
  • Code cleanup

Signed-off-by: Javier Rodriguez <javier@chainloop.dev>
@javirln javirln merged commit 1f2a869 into chainloop-dev:main Mar 27, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants