Skip to content
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

If ACTIVESTATE_API_KEY is set, try to authenticate with it, or explicitly error out. #3520

Closed
wants to merge 1 commit into from

Conversation

mitchell-as
Copy link
Contributor

@mitchell-as mitchell-as commented Oct 2, 2024

TaskDX-3080 We error out if the stored API key is invalid

@mitchell-as mitchell-as closed this Oct 2, 2024
@mitchell-as mitchell-as reopened this Oct 2, 2024
@mitchell-as mitchell-as requested a review from MDrakos October 2, 2024 12:19
@mitchell-as mitchell-as marked this pull request as ready for review October 2, 2024 12:19
Comment on lines +97 to +103
if apiKey := os.Getenv(constants.APIKeyEnvVarName); apiKey != "" {
err := auth.AuthenticateWithToken(apiKey, a.Auth)
if err != nil {
return locale.WrapError(err, "err_auth_api_key", "Failed to authenticate with [ACTIONABLE]{{.V0}}[/RESET] environment variable", constants.APIKeyEnvVarName)
}
return nil
}
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if this error reporting should be in the lower level auth package. The user would only get this error message if they explicitly ran state auth but we are attempting to authenticate with the api key environment variable through multiple code paths in the auth package. See here for one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's what I did originally, but I couldn't trigger it without state auth. We have lots of places that check auth.Authenticated() and bail out with "you must be logged in" if not. I was only able to show my message using state auth. The only callers of your linked method are "Sync" (not applicable to this PR), and "Client". All instances of the latter appear to be walled behind auth.Authenticated() checks, so in practice, I think we're okay.

Given that the confusion arises around the whole state auth flow, I figured this was an okay place to put it.

@mitchell-as mitchell-as requested a review from MDrakos October 2, 2024 20:05
Copy link
Member

@Naatan Naatan left a comment

Choose a reason for hiding this comment

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

This is addressing ONLY the state auth case. The issue here is when we pass the API key through an env var, which is the more common use-case. This scenario would not give any sort of error.

Also re the slack thread with Damien raising the 60 second polling of auth which seemed to come from this PR; we should ensure that we do not retry when the API key is known to be invalid.

I'll update the story to clarify these points.

@mitchell-as
Copy link
Contributor Author

This jumped up in complexity, so closing.

@mitchell-as mitchell-as closed this Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants