-
Notifications
You must be signed in to change notification settings - Fork 25.8k
Security: use x-pack config files when present #33688
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
bb040ea
Security: use x-pack config files when present
jaymode 646b713
remove unused import
jaymode 4b0710f
compare bytes
jaymode 5053b2c
move files out of jar root
jaymode 83f5538
Merge branch '6.x' into read_sec_files
jaymode c6af92a
more detailed deprecation logging
jaymode ce33cb3
Merge branch '6.x' into read_sec_files
jaymode d390a41
Merge branch '6.x' into read_sec_files
jaymode 56edfd8
unused imports
jaymode d3c15c3
Merge branch '6.x' into read_sec_files
jaymode e115792
address feedback
jaymode 24e63ab
Merge branch '6.x' into read_sec_files
jaymode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| */ | ||
| package org.elasticsearch.xpack.security; | ||
|
|
||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
| import org.apache.lucene.util.SetOnce; | ||
| import org.elasticsearch.Version; | ||
|
|
@@ -27,8 +28,8 @@ | |
| import org.elasticsearch.common.inject.Module; | ||
| import org.elasticsearch.common.inject.util.Providers; | ||
| import org.elasticsearch.common.io.stream.NamedWriteableRegistry; | ||
| import org.elasticsearch.common.logging.DeprecationLogger; | ||
| import org.elasticsearch.common.logging.LoggerMessageFormat; | ||
| import org.elasticsearch.common.logging.Loggers; | ||
| import org.elasticsearch.common.network.NetworkModule; | ||
| import org.elasticsearch.common.network.NetworkService; | ||
| import org.elasticsearch.common.regex.Regex; | ||
|
|
@@ -49,6 +50,7 @@ | |
| import org.elasticsearch.common.xcontent.XContentFactory; | ||
| import org.elasticsearch.common.xcontent.XContentParser; | ||
| import org.elasticsearch.common.xcontent.XContentType; | ||
| import org.elasticsearch.core.internal.io.IOUtils; | ||
| import org.elasticsearch.discovery.DiscoveryModule; | ||
| import org.elasticsearch.env.Environment; | ||
| import org.elasticsearch.env.NodeEnvironment; | ||
|
|
@@ -221,7 +223,10 @@ | |
| import org.joda.time.DateTimeZone; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.io.UncheckedIOException; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.time.Clock; | ||
| import java.util.ArrayList; | ||
|
|
@@ -253,7 +258,8 @@ | |
| public class Security extends Plugin implements ActionPlugin, IngestPlugin, NetworkPlugin, ClusterPlugin, DiscoveryPlugin, MapperPlugin, | ||
| ExtensiblePlugin { | ||
|
|
||
| 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); | ||
|
|
||
| public static final String NAME4 = XPackField.SECURITY + "4"; | ||
| public static final Setting<Optional<String>> USER_SETTING = | ||
|
|
@@ -1167,4 +1173,61 @@ public void accept(DiscoveryNode node, ClusterState state) { | |
| public void reloadSPI(ClassLoader loader) { | ||
| securityExtensions.addAll(SecurityExtension.loadExtensions(loader)); | ||
| } | ||
|
|
||
| public static Path resolveConfigFile(Environment env, String name) { | ||
| final Path config = env.configFile().resolve(name); | ||
| final Path legacyConfig = env.configFile().resolve("x-pack").resolve(name); | ||
| // config and legacy config can be the same path if name is an absolute path | ||
| if (config.equals(legacyConfig) == false) { | ||
| final boolean configFileExists = Files.exists(config); | ||
| final boolean legacyConfigExists = Files.exists(legacyConfig); | ||
| if (configFileExists == false) { | ||
| if (legacyConfigExists) { | ||
| deprecationLogger.deprecated("Config file [" + name + "] is in a deprecated location. Move from " + | ||
| legacyConfig.toString() + " to " + config.toString()); | ||
| return legacyConfig; | ||
| } | ||
| } else if (legacyConfigExists) { | ||
| // there is a file in both locations | ||
| if (isDefaultFile(name, config)) { | ||
| // use the legacy file as the new file is the default but warn user | ||
| deprecationLogger.deprecated("Config file [" + name + "] exists in a deprecated location and non-deprecated location." + | ||
| " The file in the non-deprecated location is the default file. Using file found in the deprecated location. Move " + | ||
| legacyConfig.toString() + " to " + config.toString()); | ||
| return legacyConfig; | ||
| } else { | ||
| // the regular file has been modified, but the old still exists, warn the user | ||
| deprecationLogger.deprecated("Config file [" + name + "] exists in a deprecated location and non-deprecated location." + | ||
| " Using file found in the non-deprecated location [" + config.toString() + "]. Determine which file should be" + | ||
| " kept and move it to " + config.toString() + ", then remove " + legacyConfig.toString()); | ||
| } | ||
| } | ||
| } | ||
| return config; | ||
| } | ||
|
|
||
| static boolean isDefaultFile(String name, Path file) { | ||
| InputStream in = null; | ||
| try { | ||
| in = XPackPlugin.class.getResourceAsStream("/config/" + name); | ||
| if (in != null) { | ||
| try (InputStream fin = Files.newInputStream(file)) { | ||
| int inValue = in.read(); | ||
| int finValue = fin.read(); | ||
| while (inValue != -1 && finValue != -1 && inValue == finValue) { | ||
| inValue = in.read(); | ||
| finValue = fin.read(); | ||
| } | ||
| return inValue == finValue; | ||
| } | ||
| } | ||
| } catch (IOException e) { | ||
| throw new UncheckedIOException(e); | ||
| } finally { | ||
| if (in != null) { | ||
| IOUtils.closeWhileHandlingException(in); | ||
|
||
| } | ||
| } | ||
| return false; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?