Skip to content

Add and use auth factory#8821

Merged
Isan-Rivkin merged 15 commits intomasterfrom
auth-modules
Mar 26, 2025
Merged

Add and use auth factory#8821
Isan-Rivkin merged 15 commits intomasterfrom
auth-modules

Conversation

@Isan-Rivkin
Copy link
Contributor

@Isan-Rivkin Isan-Rivkin commented Mar 20, 2025

Closes #8822

Additional Manual testing performed:

  1. Upgrade OSS version (No auth)
  2. Upgrade OSS no RBAC to RBAC (on-prem solution)

@Isan-Rivkin Isan-Rivkin self-assigned this Mar 20, 2025
@Isan-Rivkin Isan-Rivkin requested a review from yonipeleg33 March 20, 2025 07:24
@Isan-Rivkin Isan-Rivkin added the exclude-changelog PR description should not be included in next release changelog label Mar 20, 2025
@github-actions
Copy link

github-actions bot commented Mar 20, 2025

E2E Test Results - DynamoDB Local - Local Block Adapter

14 passed

@github-actions
Copy link

github-actions bot commented Mar 20, 2025

E2E Test Results - Quickstart

11 passed

@Isan-Rivkin Isan-Rivkin removed the request for review from yonipeleg33 March 20, 2025 08:00
Copy link
Contributor

@nopcoder nopcoder left a comment

Choose a reason for hiding this comment

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

We should avoid using IsAdvancedAuth the factory should provide implementation - basic or advanced.

Comment on lines +10 to +15
type (
CredentialSetFn func() (*model.Credential, error)
UserSetFn func() (*model.User, error)
UserPoliciesSetFn func() ([]*model.Policy, error)
ExternalPrincipalFn func() (*model.ExternalPrincipal, error)
)
Copy link
Contributor

Choose a reason for hiding this comment

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

from a quick look it seems like we need to start using generics here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Elaborate?
I explored several options here but the small changes don't seem very valuable and others i had required larger design that i prefer to be out of scope.

Copy link
Contributor

Choose a reason for hiding this comment

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

not a blocker. but it looks like a copy paste for each type we like to cache

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's indeed the case.
I'm comfortable with this since it happens once in a blue moon.
But open to suggestions

Comment on lines 10 to 15
"github.com/treeverse/lakefs/pkg/config"
"github.com/treeverse/lakefs/pkg/kv"
"github.com/treeverse/lakefs/pkg/logging"
)

var errSimplifiedOrExternalAuth = errors.New(`cannot set auth.ui_config.rbac to non-simplified without setting an external auth service`)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit;

Suggested change
"github.com/treeverse/lakefs/pkg/config"
"github.com/treeverse/lakefs/pkg/kv"
"github.com/treeverse/lakefs/pkg/logging"
)
var errSimplifiedOrExternalAuth = errors.New(`cannot set auth.ui_config.rbac to non-simplified without setting an external auth service`)
"github.com/treeverse/lakefs/pkg/config"
"github.com/treeverse/lakefs/pkg/kv"
"github.com/treeverse/lakefs/pkg/logging"
)
var errSimplifiedOrExternalAuth = errors.New("cannot set auth.ui_config.rbac to non-simplified without setting an external auth service")

return v.([]*model.Policy), nil
}

func (c *LRUCache) GetExternalPrincipal(key string, setFn ExternalPrincipalFn) (*model.ExternalPrincipal, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

everything in cache.go is copied from enterprise

@Isan-Rivkin Isan-Rivkin requested a review from nopcoder March 25, 2025 11:48
@Isan-Rivkin
Copy link
Contributor Author

Isan-Rivkin commented Mar 25, 2025

We should avoid using IsAdvancedAuth the factory should provide implementation - basic or advanced.

I agree but we have some other considerations - The IsAdvancedAuth is used to determine flow during setup, and indicator for our logging middlewares.
The AuthAPI doesn't know if it's advanced or not if we don't tell it, since it also uses ACL.

Copy link
Contributor

@nopcoder nopcoder left a comment

Choose a reason for hiding this comment

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

talked f2f about the use of is advance auth. thanks.

@Isan-Rivkin
Copy link
Contributor Author

@nopcoder FYI, I copied a BUG from fluffy, using policyCache cache.Cache for external principals, added small commit after approve to use dedicated class.

@Isan-Rivkin
Copy link
Contributor Author

Fixed unit-test missing new param

Copy link
Contributor

@yonipeleg33 yonipeleg33 left a comment

Choose a reason for hiding this comment

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

LGTM, very nice work!
Had some minor, non-blocking comments.
I only block because I think this PR calls for more testing - aside from the unit tests, I'd like to see at least a description of manual tests performed on this branch, including backwards compatibility - spinning up a new binary after an old one should proceed from the same state in the auth db seamlessly.

defer func() { _ = c.Close() }()

// usage report setup - default usage reporter is a no-op
// usage report setup - default usage reporter ids a no-op
Copy link
Contributor

Choose a reason for hiding this comment

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

revert, looks like a typo you added

Copy link
Contributor

Choose a reason for hiding this comment

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

this file is a bit odd to me. why not inline everything into modules/auth/factory/build.go?
a good sign that it's serving a questionable purpose is that you call it authfactoryhelper when importing - "helper" is a vague term.

it's not blocking, just not sure what's the purpose

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The initiation logic needs to be re-used in enterprise as well, for context, in enterprise the build new function of the factory looks like this:

import ossauthfactory "github.com/treeverse/lakefs/pkg/auth/factory"

func NewAuthService(ctx context.Context, cfg ossconfig.Config, logger logging.Logger, kvStore kv.Store, metadataManager *ossauth.KVMetadataManager) ossauth.Service {

	if !cfg.(*config.Config).Features.RBAC {
		logging.ContextUnavailable().Info("Creating non-local rbac service")
		return ossauthfactory.NewAuthService(ctx, cfg, logger, kvStore, metadataManager)
	}
       // ... 
      // return RBAC local service
      return auth.NewAuthService(...)
}

logger logging.Logger
cache Cache
externalPrincipalsEnabled bool
isAdvancedAuth bool // Using RBAC, not ACL
Copy link
Contributor

Choose a reason for hiding this comment

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

then why not call it isRbacEnabled?
i can get why you want to use more general terms like "advanced auth" at the interface level, but this is the concrete value here - i don't see a reason not to give it the proper name it deserves.

this code makes more sense to me as a reader:

func (a *APIAuthService) IsAdvancedAuth() bool {
	return a.isRbacEnabled
}

Copy link
Contributor Author

@Isan-Rivkin Isan-Rivkin Mar 25, 2025

Choose a reason for hiding this comment

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

Not done, I am maintaining the terminology we have.
Let's decouple between how we determine ( == RBAC External or External) VS the meaning (advanced auth).
We have an existing terminology which is NoAuth, Simplified Auth (ACL) and Advanced Auth (RBAC Server with more).
The current best way to determine were using "rbac + other features" is based on the RBAC value but that's not the meaning it's just the best we have.
The auth service doesn't need to know RBAC or not. That's encapsulated at the config level, like it was before.

Copy link
Contributor

@yonipeleg33 yonipeleg33 Mar 25, 2025

Choose a reason for hiding this comment

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

sure, i get the decoupling idea. but your comment says otherwise :-)
if the comment is correct, there should be no issue with fusing the comment into the variable name. same meaning, stronger semantics.

(still not blocking)

@Isan-Rivkin
Copy link
Contributor Author

LGTM, very nice work! Had some minor, non-blocking comments. I only block because I think this PR calls for more testing - aside from the unit tests, I'd like to see at least a description of manual tests performed on this branch, including backwards compatibility - spinning up a new binary after an old one should proceed from the same state in the auth db seamlessly.

You're asking a good question - how was this tested, updated in the description PR description now!

@Isan-Rivkin Isan-Rivkin requested a review from yonipeleg33 March 25, 2025 17:09
Copy link
Contributor

@yonipeleg33 yonipeleg33 left a comment

Choose a reason for hiding this comment

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

If you could specify a bit more about the tests that'd be great, I'm not sure what does "Upgrade OSS version" mean exactly.
A short explanation like "built lakefs from master, ran with such and such config, then ran X..." would be very helpful for me.

But not blocking any longer, as there's at least minimal documentation of the tests performed. TYVM, and again - awesome work 💪

@Isan-Rivkin Isan-Rivkin merged commit 236e1a7 into master Mar 26, 2025
43 checks passed
@Isan-Rivkin Isan-Rivkin deleted the auth-modules branch March 26, 2025 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

exclude-changelog PR description should not be included in next release changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add and use auth factory

3 participants

Comments