Replace CloudScoped with ValidatingStrategy for credential chain filtering#1516
Replace CloudScoped with ValidatingStrategy for credential chain filtering#1516hectorcast-db wants to merge 3 commits intomainfrom
Conversation
renaudhartert-db
left a comment
There was a problem hiding this comment.
It is weird to me that the requirements are not owned by the CredentialsStrategy as one will have to understand the internals of the strategy to be able to decide what requirements to apply. Also, every client (e.g. CLI) who build on top of this will have to re-implement the requirement mapping.
Could we think of an alternative design?
15f8bb0 to
d3d7ee5
Compare
d3d7ee5 to
0db3876
Compare
…CloudRequirements PR #1505 changed NewCredentialsChain to return *credentialsChain (unexported) to enable WithCloudRequirements chaining. This broke the public API. Restore the return type to CredentialsStrategy and introduce NewCredentialsChainWithCloudRequirements for callers that need cloud-based filtering. DefaultCredentials now uses the new constructor directly. The WithCloudRequirements method is removed as it is no longer needed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Hector Castejon Diaz <hector.castejon@databricks.com>
0db3876 to
231965e
Compare
config/auth_default.go
Outdated
| if requiredCloud, ok := c.cloudRequirements[s.Name()]; ok { | ||
| if cfg.Environment().Cloud != requiredCloud { | ||
| logger.Debugf(ctx, "Skipping %q: not configured for %s", s.Name(), requiredCloud) | ||
| if cs, ok := s.(CloudScoped); ok { |
There was a problem hiding this comment.
Do you foresee any reason to generalize this beyond cloud checking?
There was a problem hiding this comment.
Only if we decide to do a full rewrite and align the 3 SDKs. Then we may want to completely change the logic not use nil, nil / nil, error when it does not apply and use explicit functions like this one.
But that would be a big behavioral breaking change, so I don't think redoing this interface would be much of a big deal.
|
If integration tests don't run automatically, an authorized user can run them manually by following the instructions below: Trigger: Inputs:
Checks will be approved automatically on success. |
Changes
Replaces the
CloudScopedinterface (introduced in #1505 follow-up) with a more expressiveValidatingStrategyinterface, and restoresNewCredentialsChainto returnCredentialsStrategy.New interface
Chain behavior
Validatereturns any error, the strategy is skipped (logged at debug level). This covers both cloud mismatches and missing required fields.auth_type:ErrInvalidCloudis ignored so users can force a cloud-specific strategy on any host (e.g.azure-clion a GCP host). Any other validation error is propagated so misconfigured strategies fail fast with a clear message.Per-strategy
ValidatemethodsEach Azure and GCP strategy (
AzureCliCredentials,AzureMsiCredentials,AzureClientSecretCredentials,AzureGithubOIDCCredentials,GoogleCredentials,GoogleDefaultCredentials) now implementsValidatewith:"azure_client_id is required","google_service_account is not set")ErrInvalidCloudif the host's cloud doesn't match; placed last because it is the softer condition (overridable via explicitauth_type)The original
nil, nilguards inConfigureare preserved as a safety net.Tests
TestCredentialsChain_CloudFiltering_*to use avalidatingStrategytest helper implementing the new interfaceconfigpackage tests pass