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

Enforce limitations on ILM policy names #35104

Merged
merged 19 commits into from
Nov 9, 2018

Conversation

gwbrown
Copy link
Contributor

@gwbrown gwbrown commented Oct 30, 2018

Enforces restrictions on ILM policy names to ensure we don't accept
policy names the system can't handle, or may reserve for future use.

As of now, the limitations are:

  1. Length < 255 bytes
  2. Cannot start with _
  3. Cannot contain , (as we allow comma-separated names in e.g.
    GET _ilm/one,two - currently you can PUT, but not GET
    a policy named contains,comma as far as I can tell, although
    other special characters work fine)
  4. Cannot contain spaces.

Resolves #34928


For consistency, ILM policy names must now follow the same rules as
index names.

I ended up copying most of the logic, as there was a little bit of index-specific
code in the original, and also it felt weird to call intoMetaDataCreateIndexService
from here. If anyone strongly objects it would be possible to do this without any
duplication, though, with only minor tweaks to the index-name checking code.

For consistency, ILM policy names must now follow the same rules as
index names.
@gwbrown gwbrown added the :Data Management/ILM+SLM Index and Snapshot lifecycle management label Oct 30, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

Copy link
Contributor

@colings86 colings86 left a comment

Choose a reason for hiding this comment

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

@gwbrown I left some comments

Copy link
Member

@jasontedor jasontedor left a comment

Choose a reason for hiding this comment

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

We are still discussing on #34928 whether or not this is the right restriction to apply, if any. Please do not merge this until that discussion is resolved.

@gwbrown gwbrown added the WIP label Nov 1, 2018
@gwbrown
Copy link
Contributor Author

gwbrown commented Nov 1, 2018

Marking this as WIP for now as more review is pointless until we decide on a higher-level direction.

@gwbrown gwbrown changed the base branch from index-lifecycle to master November 2, 2018 13:59
}
int byteCount = 0;
try {
byteCount = policy.getBytes("UTF-8").length;
Copy link
Member

Choose a reason for hiding this comment

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

I think this is cleaner: name.getBytes(StandardCharsets.UTF_8) and then there is no need to catch UnsupportedEncodingException.

Also I think that utf-8 should always be available in a Java runtime.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@gwbrown gwbrown changed the title Enforce index-name rules for ILM policy names Enforce limitations on ILM policy names Nov 5, 2018
@gwbrown gwbrown removed the WIP label Nov 5, 2018
Copy link
Contributor

@colings86 colings86 left a comment

Choose a reason for hiding this comment

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

I left one small comment but otherwise this LGTM

}
if (policy.charAt(0) == '_') {
throw new IllegalArgumentException("invalid policy name [" + policy + "]: must not start with '_', '-', or '+'");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if it would be nicer for the user if we just have a single message here that describes all the characters that we don't allow in a policy name? This might avoid frustration if the user tries something like _foo bar as the policy name since they will be able to fix everything in one step rather than two?

Copy link
Member

Choose a reason for hiding this comment

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

Only if we don't end up with something too complicated. As-is, it's simple to read and validate that it follows the rules when encoded this way. The rules aren't so onerous that I expect any and certainly not multiple to be broken on a routine basis, they will be the exception. We can document the rules in the ILM API guide too, that would help.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking it would be ok as

"invalid policy name [" + policy + "]: must not start with '_', '-', or '+'" and must not contain any spaces or `,`."

But I don't feel too strongly about this, I agree the likelihood of multiple violations is low since there are too many rules here

Copy link
Member

Choose a reason for hiding this comment

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

I would argue that's harder to consume for the case of a single violation (the common case contingent on any violation) as now as a user I am left wondering, wait, which rule did I break?

It's like those awful password dialog boxes. Password doesn't meet the required criteria:

  • must be between 8 and 16 characters on Monday--Friday
  • must be between 7 and 17 characters on weekends
  • contains none of !@*&#
  • contains at least two of ()_+-
  • contains at least four digits
  • contains at least one upper-case letter
  • contains at least two lower-case letters
  • not contain three of the same character
  • not contain any adjacent repeating characters
  • not contain adjacent consecutive digits or letters
  • unless in reverse order

Copy link
Contributor

Choose a reason for hiding this comment

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

ok lets leave it as is then

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. I'm on board with leaving this as separate messages.
  2. This particular message was out of date, I've updated it to only say that policy names cannot start with _ (the other characters are okay).

@colings86
Copy link
Contributor

Now ILM is merged into master and 6.x we should label the PRs with non-issue and the relevant version labels so its easy to see what versions the changes made it into

@jasontedor
Copy link
Member

My understanding, and is how we've been operating in CCR, is that we should also leave the version labels off of these as they show up in the weekly changelog otherwise. We want to continue to not report these individual changes until after the feature is delivered. (They are meaningless until then.)

@colings86
Copy link
Contributor

I am ok with that approach for now given thats how the weekly changelog works but I think we should discuss how this should be for the future as I think its useful to be able to see on PRs what versions a change went into quickly regardless of whether the PR is listed on changelogs/release notes

@jasontedor
Copy link
Member

I am ok with that approach for now given thats how the weekly changelog works but I think we should discuss how this should be for the future as I think its useful to be able to see on PRs what versions a change went into quickly regardless of whether the PR is listed on changelogs/release notes

Let's offline that, that's not germane to this PR.

@gwbrown gwbrown merged commit 67f9e8f into elastic:master Nov 9, 2018
gwbrown added a commit to gwbrown/elasticsearch that referenced this pull request Nov 9, 2018
Enforces restrictions on ILM policy names to ensure we don't accept
policy names the system can't handle, or may reserve for future use.
gwbrown added a commit that referenced this pull request Nov 12, 2018
Enforces restrictions on ILM policy names to ensure we don't accept
policy names the system can't handle, or may reserve for future use.
@gwbrown gwbrown deleted the ilm/enforce-policy-name-restrictions branch December 7, 2018 04:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocker :Data Management/ILM+SLM Index and Snapshot lifecycle management >non-issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants