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

Add stricter validation for api key expiration time #103973

Merged
merged 4 commits into from Feb 2, 2024

Conversation

jfreden
Copy link
Contributor

@jfreden jfreden commented Jan 5, 2024

This is a follow up from: #103453

Your PR prompted me to think about this again: it's kinda bogus that in the create API you can set 0 or -1 for expiration -- we've talked in the past about preventing this but didn't get around to it. I like being consistent between APIs, but I don't think we want to inherit API flaws. WDYT about preventing non-positive values for expiration for the update APIs?

@jfreden jfreden added >enhancement :Security/Security Security issues without another label labels Jan 5, 2024
@jfreden jfreden requested a review from n1v0lg January 5, 2024 12:14
@elasticsearchmachine
Copy link
Collaborator

Hi @jfreden, I've created a changelog YAML for you.

@jfreden jfreden marked this pull request as ready for review January 10, 2024 15:31
@elasticsearchmachine elasticsearchmachine added the Team:Security Meta label for security team label Jan 10, 2024
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-security (Team:Security)

Copy link
Contributor

@n1v0lg n1v0lg left a comment

Choose a reason for hiding this comment

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

Wow sorry I really let this one sit way too long. I have a suggestion around moving the validation logic to the request classes instead.

@jakelandis I wanted to get a sanity check on not treating this as a breaking change. I don't think it is, but it's good to call out and discuss explicitly:

Today, it's possible to specify a 0 or negative expiration time when creating an API key. This means the API key is invalid immediately. That really doesn't make any sense -- the only reason I see this happening is users misunderstanding expiration (e.g., maybe they assume -1 means no expiration?).

This PR adds validation that rejects bogus (0 or negative) expiration times. For the update API key APIs this is non-controversial since we're adding the validation in the same minor as we added the field.

We're also adding this check to the create API key API; there the field has been around for a long time. Like I said, I don't see a valid use case for supplying bogus values, and adding the validation is a small but nice improvement. So I'd say, let's move ahead with it and not treat is as a breaking change. Would you agree here?

Thanks!

);
if (workflowsValidationException != null) {
listener.onFailure(workflowsValidationException);
List<IllegalArgumentException> failedValidations = Stream.of(
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this check makes more sense in the request classes (CreateApiKeyRequest and BaseUpdateApiKeyRequest) -- that way we fail early, and keep request validation in one-ish place. The reason validateWorkflowsRestrictionConstraints (and other validation) is here is because that validation requires access to things we only (or at least conveniently) have access to at the service level (e.g., transportVersion).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, good point. I've moved it. Thank you!

@jakelandis
Copy link
Contributor

I wanted to get a sanity check on not treating this as a breaking change.

This is a breaking change. It might be one that goes primarily unnoticed, but it is still breaking. Introduction of this change would be subject to REST API compatibility. We could go through the process of breaking change (approval, deprecation, compatibility) but not sure if this one is worth the effort since given that due to our history, the bar is pretty high.

@jfreden
Copy link
Contributor Author

jfreden commented Feb 1, 2024

Thanks @jakelandis and @n1v0lg ! So our options are:

  1. Skip this validation entirely.
  2. Only do this validation in the update api and lose consistency in the validation between the update and create APIs.
  3. Go through the breaking change process.

I think I'm leaning towards (1). What do you think @jakelandis and @n1v0lg ?

@n1v0lg
Copy link
Contributor

n1v0lg commented Feb 1, 2024

@jakelandis noted, thanks! My rationale for proposing this change is that it feels more like a bug fix -- essentially, the only thing you get out of the "BWC"-behavior is unusable API keys. However, this is subjective and strictly speaking this is for sure a breaking change. There may be an automated test pipeline in a customer's infrastructure that is creating bogus API keys (where it doesn't matter) but would suddenly break due to this change, or some other edge case I'm not thinking of.

@jfreden my (weak) preference would be to go for (2) -- consistency is good, but the Create API key API behavior feels essentially like an oversight/bug so not necessarily worth inheriting. Just my 2 cents though, I don't feel strongly here!

I definitely don't think it's worth going through the breaking changes process.

@jakelandis
Copy link
Contributor

I would also have (weak) preference for (2) assuming there are no BWC concerns. I can see testing usecase to create a pre-expired API key, but much harder to rationalize a usecase for pre-expiring while updating an API key.

@jfreden
Copy link
Contributor Author

jfreden commented Feb 2, 2024

Thanks for the input @jakelandis and @n1v0lg ! I've changed it to (2).

@jfreden jfreden requested a review from n1v0lg February 2, 2024 09:37
Copy link
Contributor

@n1v0lg n1v0lg left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for iterating on this.

@jfreden jfreden merged commit 88d584c into elastic:main Feb 2, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement :Security/Security Security issues without another label Team:Security Meta label for security team v8.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants