buildkite / buildkite-agent-metrics

A command-line tool (and Lambda) for collecting Buildkite agent metrics
MIT License
67 stars 51 forks source link

5.9.1 Issue authenticating with `BUILDKITE_AGENT_TOKEN` #242

Closed p33rs closed 9 months ago

p33rs commented 9 months ago

Summary

Authentication via API Token seems to produce an error.

To reproduce

Investigation

I think this is in https://github.com/buildkite/buildkite-agent-metrics/blob/master/lambda/main.go#L185 where providers gets set when checking for tokens/SSM, but returned when checking for Secrets Manager. At the end of the function, we return an error.

If I had to guess, I'd say the solution probably looks like...

diff --git a/lambda/main.go b/lambda/main.go
index a15ff40..2ffd761 100644
--- a/lambda/main.go
+++ b/lambda/main.go
@@ -241,11 +241,15 @@ func initTokenProvider(awsRegion string) ([]token.Provider, error) {
                        }
                        providers = append(providers, secretManager)
                }
-               return providers, nil
        }

-       return nil, fmt.Errorf("failed to initialize Buildkite token provider: one of the [%s] environment variables "+
+       if len(providers) > 0 {
+               return providers, nil
+       } else {
+               return nil, fmt.Errorf("failed to initialize Buildkite token provider: one of the [%s] environment variables "+
                "must be provided", strings.Join(mutuallyExclusiveEnvVars, ","))
+       }
+       
 }

... but I don't know Go, so I could be way off base here.

Workaround

I'm not seeing this error in 5.9.0. However, 5.9.0 does not include #234, so neither of these is working for me at the moment.

DrJosh9000 commented 9 months ago

Hi @p33rs, thanks for the report. This should be fixed in v5.9.2, please let us know if there are still problems!

p33rs commented 9 months ago

Confirmed. Thanks for this!