-
Notifications
You must be signed in to change notification settings - Fork 182
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
feat: add simple fallback to kargo controller IAM when project-specific credentials cannot be assumed for GAR. #3597
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for docs-kargo-io ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
97a02cf
to
30446ca
Compare
30446ca
to
b1799a6
Compare
With this approach there is needed to fix or disable caching as using Tested inside GKE. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3597 +/- ##
==========================================
- Coverage 52.63% 52.61% -0.03%
==========================================
Files 296 296
Lines 26881 26891 +10
==========================================
- Hits 14150 14149 -1
- Misses 11957 11968 +11
Partials 774 774 ☔ View full report in Codecov by Sentry. |
}, | ||
).Do() | ||
if err != nil { | ||
logger.Error(err, "error generating access token") | ||
return "", nil | ||
logger.Error(err, "Error generating access token; falling back to Application Default Credentials (ADC)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there needs to be some effort here to determine whether the failure is an auth failure or something else. If it's (for instance) a connectivity issue, we should be returning that error right away.
If it is an auth failure, I also don't believe this should be logged as an error. In your own intended usage, this first token request failing and then falling back on this logic that attempts to use the controller's own identity directly is actually business as usual. You're not going to want to see the logs cluttered with "errors" that reflect things working as intended.
if w.tokenSource == nil { | ||
tokenSource, err := google.DefaultTokenSource(ctx, tokenRequestScope...) | ||
if err != nil { | ||
logger.Error(err, "Failed to find Application Default Credentials") | ||
return "", false, nil | ||
} | ||
w.tokenSource = tokenSource | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not concurrency safe.
This warrants some research, because I wonder if this is actually true or if this observation is actually an artifact of this concurrency safety issue: |
Please verify: |
I agree that a single And through research and experimentation, I can verify that the This can be demonstrated with a simple program: package main
import (
"context"
"log"
"os"
"golang.org/x/oauth2/google"
)
const (
credsPath = "/Users/krancour/Downloads/kents-test-project-317520-e3fb3e962f2d.json" // nolint: gosec
tokenRequestScope = "https://www.googleapis.com/auth/cloud-platform" // nolint: gosec
)
func init() {
if err := os.Setenv("GOOGLE_APPLICATION_CREDENTIALS", credsPath); err != nil {
log.Fatal(err)
}
}
func main() {
ctx := context.Background()
tokenSource, err := google.DefaultTokenSource(ctx, tokenRequestScope)
if err != nil {
log.Fatal(err)
}
token1, err := tokenSource.Token()
if err != nil {
log.Fatal(err)
}
token2, err := tokenSource.Token()
if err != nil {
log.Fatal(err)
}
if token1.AccessToken == token2.AccessToken {
log.Println("Tokens are the same")
} else {
log.Println("Tokens are different")
}
} go run main.go
2025/03/04 12:16:11 Tokens are the same But two different instances of func main() {
ctx := context.Background()
tokenSource1, err := google.DefaultTokenSource(ctx, tokenRequestScope)
if err != nil {
log.Fatal(err)
}
tokenSource2, err := google.DefaultTokenSource(ctx, tokenRequestScope)
if err != nil {
log.Fatal(err)
}
token1, err := tokenSource1.Token()
if err != nil {
log.Fatal(err)
}
token2, err := tokenSource2.Token()
if err != nil {
log.Fatal(err)
}
if token1.AccessToken == token2.AccessToken {
log.Println("Tokens are the same")
fmt.Println(token1.AccessToken)
} else {
log.Println("Tokens are different")
}
} go run main.go
2025/03/04 12:18:05 Tokens are different Your code is currently resembles the first program because you're re-using a single If you were to tackle the concurrency safety issue, academic though it may be, by not reusing a single You could take a different approach to solving the concurrency safety issue, or we could just leave it alone, since I acknowledge that it's mainly academic in this instance. In either case, you'd be reusing the same So the thing I am asking myself is why I actually care about preserving the existing caching strategy. I like that the existing strategy is consistent for both controller-level and project-level tokens, which makes this code, overall, easier to comprehend and maintain. |
94007a1
to
d210c47
Compare
Add simple fallback to kargo controller IAM when project-specific credentials could not be assumed for Google Artifact Registry Signed-off-by: Kacper Cesarz <[email protected]> improvements Signed-off-by: Kacper Cesarz <[email protected]>
d210c47
to
3e01bf3
Compare
Signed-off-by: Kacper Cesarz <[email protected]>
Add simple fallback to kargo controller IAM when project-specific credentials could not be assumed for Google Artifact Registry
closes: issue