Skip to content

Commit a8e616f

Browse files
authored
Improve message about insecure S3 settings (#116955)
Clarifies that insecure settings are stored in plaintext and must not be used. Also removes the mention of the (wrong) system property from the error message if insecure settings are not permitted. Backport of #116915 to `8.16`
1 parent dab09e2 commit a8e616f

File tree

6 files changed

+19
-15
lines changed

6 files changed

+19
-15
lines changed

docs/changelog/116915.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 116915
2+
summary: Improve message about insecure S3 settings
3+
area: Snapshot/Restore
4+
type: enhancement
5+
issues: []

modules/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3Repository.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,7 @@ class S3Repository extends MeteredBlobStoreRepository {
288288
deprecationLogger.critical(
289289
DeprecationCategory.SECURITY,
290290
"s3_repository_secret_settings",
291-
"Using s3 access/secret key from repository settings. Instead "
292-
+ "store these in named clients and the elasticsearch keystore for secure settings."
291+
INSECURE_CREDENTIALS_DEPRECATION_WARNING
293292
);
294293
}
295294

@@ -306,6 +305,11 @@ class S3Repository extends MeteredBlobStoreRepository {
306305
);
307306
}
308307

308+
static final String INSECURE_CREDENTIALS_DEPRECATION_WARNING = Strings.format("""
309+
This repository's settings include a S3 access key and secret key, but repository settings are stored in plaintext and must not be \
310+
used for security-sensitive information. Instead, store all secure settings in the keystore. See [%s] for more information.\
311+
""", ReferenceDocs.SECURE_SETTINGS);
312+
309313
private static Map<String, String> buildLocation(RepositoryMetadata metadata) {
310314
return Map.of("base_path", BASE_PATH_SETTING.get(metadata.settings()), "bucket", BUCKET_SETTING.get(metadata.settings()));
311315
}

modules/repository-s3/src/test/java/org/elasticsearch/repositories/s3/RepositoryCredentialsTests.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,9 @@ public void testRepositoryCredentialsOverrideSecureCredentials() {
107107
assertThat(credentials.getAWSSecretKey(), is("insecure_aws_secret"));
108108

109109
assertCriticalWarnings(
110+
"[access_key] setting was deprecated in Elasticsearch and will be removed in a future release.",
110111
"[secret_key] setting was deprecated in Elasticsearch and will be removed in a future release.",
111-
"Using s3 access/secret key from repository settings. Instead store these in named clients and"
112-
+ " the elasticsearch keystore for secure settings.",
113-
"[access_key] setting was deprecated in Elasticsearch and will be removed in a future release."
112+
S3Repository.INSECURE_CREDENTIALS_DEPRECATION_WARNING
114113
);
115114
}
116115

@@ -194,10 +193,9 @@ public void testReinitSecureCredentials() {
194193

195194
if (hasInsecureSettings) {
196195
assertCriticalWarnings(
196+
"[access_key] setting was deprecated in Elasticsearch and will be removed in a future release.",
197197
"[secret_key] setting was deprecated in Elasticsearch and will be removed in a future release.",
198-
"Using s3 access/secret key from repository settings. Instead store these in named clients and"
199-
+ " the elasticsearch keystore for secure settings.",
200-
"[access_key] setting was deprecated in Elasticsearch and will be removed in a future release."
198+
S3Repository.INSECURE_CREDENTIALS_DEPRECATION_WARNING
201199
);
202200
}
203201
}
@@ -238,10 +236,7 @@ public void sendResponse(RestResponse response) {
238236
throw error.get();
239237
}
240238

241-
assertWarnings(
242-
"Using s3 access/secret key from repository settings. Instead store these in named clients and"
243-
+ " the elasticsearch keystore for secure settings."
244-
);
239+
assertWarnings(S3Repository.INSECURE_CREDENTIALS_DEPRECATION_WARNING);
245240
}
246241

247242
private void createRepository(final String name, final Settings repositorySettings) {

server/src/main/java/org/elasticsearch/common/ReferenceDocs.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public enum ReferenceDocs {
8181
X_OPAQUE_ID,
8282
FORMING_SINGLE_NODE_CLUSTERS,
8383
JDK_LOCALE_DIFFERENCES,
84+
SECURE_SETTINGS,
8485
// this comment keeps the ';' on the next line so every entry above has a trailing ',' which makes the diff for adding new links cleaner
8586
;
8687

server/src/main/java/org/elasticsearch/common/settings/SecureSetting.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,7 @@ private InsecureStringSetting(String name) {
192192
@Override
193193
public SecureString get(Settings settings) {
194194
if (ALLOW_INSECURE_SETTINGS == false && exists(settings)) {
195-
throw new IllegalArgumentException(
196-
"Setting [" + name + "] is insecure, " + "but property [allow_insecure_settings] is not set"
197-
);
195+
throw new IllegalArgumentException("Setting [" + name + "] is insecure, use the elasticsearch keystore instead");
198196
}
199197
return super.get(settings);
200198
}

server/src/main/resources/org/elasticsearch/common/reference-docs-links.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,4 @@ FLOOD_STAGE_WATERMARK fix-watermark-er
4343
X_OPAQUE_ID api-conventions.html#x-opaque-id
4444
FORMING_SINGLE_NODE_CLUSTERS modules-discovery-bootstrap-cluster.html#modules-discovery-bootstrap-cluster-joining
4545
JDK_LOCALE_DIFFERENCES mapping-date-format.html#custom-date-format-locales
46+
SECURE_SETTINGS secure-settings.html

0 commit comments

Comments
 (0)