Skip to content

Allow the "*,-*" ("no-index") pattern for destructive actions when destructive_requires_name is true #68021

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

Conversation

williamrandolph
Copy link
Contributor

Since the *,-* index name pattern resolves to "no indices", it makes a normally destructive action into a non-destructive one. Rather than throwing a wildcards-not-allowed exception, we can allow this pattern to pass without triggering an exception. This allows the security layer to safely use a *,-* pattern to indicate a "no indices" result for its index resolution step, which is important because otherwise we get wildcards-not-allowed exceptions when trying to delete nonexistent concrete indices, e.g.:

curl -s -XDELETE 'http://elastic:changeme@localhost:9200/functional-test-actions-index?ignore_unavailable=true&pretty'
{
  "error" : {
    "root_cause" : [
      {
        "type" : "illegal_argument_exception",
        "reason" : "Wildcard expressions or all indices are not allowed"
      }
    ],
    "type" : "illegal_argument_exception",
    "reason" : "Wildcard expressions or all indices are not allowed"
  },
  "status" : 400
}

This is a fix for #67958.

I don't have the domain knowledge to know if there is a better way to avoid this issue by changing the security layer, but, if so, it would be fine by me to decline this PR in favor of that approach.

Since the "*,-*" pattern resolves to "no indices", it makes a normally
destructive action into a non-destructive one. Rather than throwing a
wildcards-not-allowed exception, we can allow this pattern to pass
without triggering an exception. This allows the security layer to
safely use a "*,-*" pattern to indicate a "no indices" result for its
index resolution step, which is important because otherwise we get
wildcards-not-allowed exceptions when trying to delete nonexistent
concrete indices.
@williamrandolph williamrandolph added >bug :Core/Infra/Core Core issues without another label v8.0.0 v7.12.0 labels Jan 26, 2021
@elasticmachine elasticmachine added the Team:Core/Infra Meta label for core/infra team label Jan 26, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

@williamrandolph
Copy link
Contributor Author

williamrandolph commented Jan 26, 2021

Todo:

  • fix test failures
  • order matters with wildcards, so check for *,-* exactly
  • make sure all destructive actions have test coverage for this issue

@williamrandolph
Copy link
Contributor Author

I created #68079 for the test failure.

@williamrandolph
Copy link
Contributor Author

@elasticmachine run elasticsearch-ci/2

1 similar comment
@williamrandolph
Copy link
Contributor Author

@elasticmachine run elasticsearch-ci/2

Copy link
Member

@jaymode jaymode left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -59,6 +61,9 @@ public void failDestructive(String[] aliasesOrIndices) {
if (hasWildcardUsage(aliasesOrIndices[0])) {
throw new IllegalArgumentException("Wildcard expressions or all indices are not allowed");
}
} else if (Arrays.equals(aliasesOrIndices, new String[]{"*", "-*"})) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you make the String[] a static final variable?

Copy link
Member

Choose a reason for hiding this comment

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

Also you could simplify the code and remove the else below by making the check Arrays.equals() == false. Either way is fine

@williamrandolph williamrandolph merged commit 42b7485 into elastic:master Jan 28, 2021
williamrandolph added a commit that referenced this pull request Jan 28, 2021
…destructive_requires_name is true (#68021)

Since the "*,-*" pattern resolves to "no indices", it makes a normally
destructive action into a non-destructive one. Rather than throwing a
wildcards-not-allowed exception, we can allow this pattern to pass
without triggering an exception. This allows the security layer to
safely use a "*,-*" pattern to indicate a "no indices" result for its
index resolution step, which is important because otherwise we get
wildcards-not-allowed exceptions when trying to delete nonexistent
concrete indices. For simplicity, we require exactly "*,-*", rather than
any other wildcards that might be logically equivalent.
@williamrandolph
Copy link
Contributor Author

williamrandolph commented Jan 28, 2021

Backport commit for 7.x: ddda5f2

@williamrandolph williamrandolph deleted the allow-no-index-patterns-for-destructive-actions branch May 23, 2022 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Core/Infra/Core Core issues without another label Team:Core/Infra Meta label for core/infra team v7.12.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants