Skip to content

Conversation

@jaymode
Copy link
Member

@jaymode jaymode commented Sep 13, 2018

In versions prior to 6.3, x-pack configuration files were kept within a
x-pack subdirectory. In 6.3 these files were moved to the config
directory with a backwards compatibilty layer to look for the files in
the old location if file does not exist in the new location. This works
for files that are not pre-created for the user, but in the case of
security there are several files created by default. This change
updates the security code to check if the file in the new location is
a default file that has not been modified. If it is a default file, the
code will also see if a file exists in the pre 6.3 location and use it
instead.

Closes #33464

In versions prior to 6.3, x-pack configuration files were kept within a
x-pack subdirectory. In 6.3 these files were moved to the config
directory with a backwards compatibilty layer to look for the files in
the old location if file does not exist in the new location. This works
for files that are not pre-created for the user, but in the case of
security there are several files created by default. This change
updates the security code to check if the file in the new location is
a default file that has not been modified. If it is a default file, the
code will also see if a file exists in the pre 6.3 location and use it
instead.

Closes elastic#33464
@jaymode jaymode added >bug v7.0.0 :Security/Security Security issues without another label v6.5.0 v6.4.1 labels Sep 13, 2018
@jaymode jaymode requested a review from rjernst September 13, 2018 20:21
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-security

Copy link
Member

@rjernst rjernst left a comment

Choose a reason for hiding this comment

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

LGTM, a couple minor suggestions

}

sourceSets.main.resources {
srcDir 'src/main/config'
Copy link
Member

Choose a reason for hiding this comment

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

Maybe place this in a subdir under resources, so we don't pollute the top level?

try {
in = XPackPlugin.class.getResourceAsStream("/" + name);
if (in != null) {
List<String> defaultLines = Streams.readAllLines(in);
Copy link
Member

Choose a reason for hiding this comment

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

Why not just compare bytes, instead of interpreting into character strings?

@tvernum
Copy link
Contributor

tvernum commented Sep 14, 2018

My concern (but I don't have a fantastic suggestion instead) is that this puts users at risk of accidentally modifying the wrong file and having behaviours change on them.

Specifically:

  • there's a default "role_mapping.yml" file in config/
  • there's a legacy "role_mapping.yml" file in config/x-pack
  • the system uses the config/x-pack/role_mapping.yml
  • user sees role_mapping.yml in config/, and edits it (incorrectly)
  • at that point, nothing happens (because we'd only be monitoring the legacy file for changes)
  • next time the node starts, we detect that config/role_mapping.yml is not in the default state, so we use it, silently, without any warning.
  • all the mappings in the config/x-pack/role_mapping.yml are ignored.

I don't particularly like that behaviour, but as I said I don't have much else to suggest except maybe we can fix the "silently" bit.
Can we consider having a deprecation warning anytime a file exists in both locations (config/ and config/x-pack/) ?
That's always a bad idea, and telling people "you've got two copies of this file, and we've pick xyz" seems like it would be helpful.

@tvernum
Copy link
Contributor

tvernum commented Sep 14, 2018

I'd be happy with adding that logging in a separate PR if we agree it's the best mitigation for that sort of scenario.

@rjernst
Copy link
Member

rjernst commented Sep 14, 2018

@tvernum You have some good points.

Can we consider having a deprecation warning anytime a file exists in both locations (config/ and config/x-pack/) ?

This sounds like a good solution.

@jaymode jaymode added v6.4.2 and removed v6.4.1 labels Sep 25, 2018
@jaymode
Copy link
Member Author

jaymode commented Sep 27, 2018

@rjernst do you mind taking another look? I've updated to address the new log message and your feedback.

Copy link
Member

@rjernst rjernst left a comment

Choose a reason for hiding this comment

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

LGTM


private static final Logger logger = Loggers.getLogger(Security.class);
private static final Logger logger = LogManager.getLogger(Security.class);
private static DeprecationLogger deprecationLogger = new DeprecationLogger(logger);
Copy link
Member

Choose a reason for hiding this comment

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

nit: these are statics, so they should be named with all caps?

throw new UncheckedIOException(e);
} finally {
if (in != null) {
IOUtils.closeWhileHandlingException(in);
Copy link
Member

Choose a reason for hiding this comment

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

What's the reason try-with-resources can't be used?

Copy link
Member Author

Choose a reason for hiding this comment

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

I forgot that try-with-resources can handle nulls. Switched.

@jaymode jaymode merged commit fa28d1c into elastic:6.x Sep 28, 2018
@jaymode jaymode deleted the read_sec_files branch September 28, 2018 14:38
jaymode added a commit that referenced this pull request Sep 28, 2018
In versions prior to 6.3, x-pack configuration files were kept within a
x-pack subdirectory. In 6.3 these files were moved to the config
directory with a backwards compatibilty layer to look for the files in
the old location if file does not exist in the new location. This works
for files that are not pre-created for the user, but in the case of
security there are several files created by default. This change
updates the security code to check if the file in the new location is
a default file that has not been modified. If it is a default file, the
code will also see if a file exists in the pre 6.3 location and use it
instead.

Closes #33464
@jaymode jaymode added v6.4.3 and removed v6.4.2 labels Sep 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants