Skip to content

Commit 03804af

Browse files
authored
Misc ReferenceDocs improvements (elastic#113667) (elastic#113861)
- Forbid ephemeral `_auto_gen.html` and `page.html#_auto_gen` links. - Remove dangling/unused `BOOTSTRAP_CHECK_G1GC` link. - Separate test suite into individual tests.
1 parent b2f5878 commit 03804af

File tree

5 files changed

+80
-20
lines changed

5 files changed

+80
-20
lines changed

docs/reference/setup/bootstrap-checks-xes.asciidoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ In addition to the <<bootstrap-checks,{es} bootstrap checks>>, there are
66
checks that are specific to {xpack} features.
77

88
[discrete]
9+
[[bootstrap-checks-xpack-encrypt-sensitive-data]]
910
=== Encrypt sensitive data check
1011
//See EncryptSensitiveDAtaBootstrapCheck.java
1112

@@ -18,6 +19,7 @@ on each node in the cluster. For more information, see
1819
<<encrypting-data,Encrypting sensitive data in Watcher>>.
1920

2021
[discrete]
22+
[[bootstrap-checks-xpack-pki-realm]]
2123
=== PKI realm check
2224
//See PkiRealmBootstrapCheckTests.java
2325

@@ -31,6 +33,7 @@ To pass this bootstrap check, if a PKI realm is enabled, you must configure TLS
3133
and enable client authentication on at least one network communication layer.
3234

3335
[discrete]
36+
[[bootstrap-checks-xpack-role-mappings]]
3437
=== Role mappings check
3538

3639
If you authenticate users with realms other than `native` or `file` realms, you
@@ -65,6 +68,7 @@ To pass this bootstrap check, you must
6568

6669

6770
[discrete]
71+
[[bootstrap-checks-xpack-token-ssl]]
6872
=== Token SSL check
6973
//See TokenSSLBootstrapCheckTests.java
7074

docs/reference/setup/bootstrap-checks.asciidoc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ in the <<set-jvm-options,JVM options>>. We strongly encourage you to do
6060
this if you are in this specific situation. This system property can be used to
6161
force execution of the bootstrap checks independent of the node configuration.
6262

63+
[[bootstrap-checks-heap-size]]
6364
=== Heap size check
6465

6566
By default, {es} automatically sizes JVM heap based on a node's
@@ -71,6 +72,7 @@ size on startup. If the initial heap size is not equal to the maximum heap size,
7172
some JVM heap may not be locked after a resize. To avoid these issues, start the
7273
JVM with an initial heap size equal to the maximum heap size.
7374

75+
[[bootstrap-checks-file-descriptor]]
7476
=== File descriptor check
7577

7678
File descriptors are a Unix construct for tracking open "files". In Unix
@@ -83,6 +85,7 @@ bootstrap check is enforced on OS X and Linux. To pass the file
8385
descriptor check, you might have to configure <<file-descriptors,file
8486
descriptors>>.
8587

88+
[[bootstrap-checks-memory-lock]]
8689
=== Memory lock check
8790

8891
When the JVM does a major garbage collection it touches every page of
@@ -116,6 +119,7 @@ least 4096 threads. This can be done via `/etc/security/limits.conf`
116119
using the `nproc` setting (note that you might have to increase the
117120
limits for the `root` user too).
118121

122+
[[bootstrap-checks-max-file-size]]
119123
=== Max file size check
120124

121125
The segment files that are the components of individual shards and the translog
@@ -144,6 +148,7 @@ address space. This can be done via adding `<user> - as unlimited`
144148
to `/etc/security/limits.conf`. This may require you to increase the limits
145149
for the `root` user too.
146150

151+
[[bootstrap-checks-max-map-count]]
147152
=== Maximum map count check
148153

149154
Continuing from the previous <<max-size-virtual-memory-check,point>>, to
@@ -158,6 +163,7 @@ Alternatively, the maximum map count check is only needed if you are using
158163
indices. If you <<allow-mmap,do not allow>> the use of `mmap` then this
159164
bootstrap check will not be enforced.
160165

166+
[[bootstrap-checks-client-jvm]]
161167
=== Client JVM check
162168

163169
There are two different JVMs provided by OpenJDK-derived JVMs: the
@@ -171,6 +177,7 @@ JVM check, you must start Elasticsearch with the server VM. On modern
171177
systems and operating systems, the server VM is the
172178
default.
173179

180+
[[bootstrap-checks-serial-collector]]
174181
=== Use serial collector check
175182

176183
There are various garbage collectors for the OpenJDK-derived JVMs
@@ -187,6 +194,7 @@ configuration that ships with Elasticsearch configures Elasticsearch to
187194
use the G1GC garbage collector with JDK14 and later versions. For earlier
188195
JDK versions, the configuration defaults to the CMS collector.
189196

197+
[[bootstrap-checks-syscall-filter]]
190198
=== System call filter check
191199
Elasticsearch installs system call filters of various flavors depending
192200
on the operating system (e.g., seccomp on Linux). These system call
@@ -198,6 +206,7 @@ installed. To pass the system call filter check you must fix any
198206
configuration errors on your system that prevented system call filters
199207
from installing (check your logs).
200208

209+
[[bootstrap-checks-onerror]]
201210
=== OnError and OnOutOfMemoryError checks
202211

203212
The JVM options `OnError` and `OnOutOfMemoryError` enable executing
@@ -214,19 +223,22 @@ use the JVM flag `ExitOnOutOfMemoryError`. While this does not have the
214223
full capabilities of `OnError` nor `OnOutOfMemoryError`, arbitrary
215224
forking will not be supported with seccomp enabled.
216225

226+
[[bootstrap-checks-early-access]]
217227
=== Early-access check
218228

219229
The OpenJDK project provides early-access snapshots of upcoming releases. These
220230
releases are not suitable for production. The early-access check detects these
221231
early-access snapshots. To pass this check, you must start Elasticsearch on a
222232
release build of the JVM.
223233

234+
[[bootstrap-checks-all-permission]]
224235
=== All permission check
225236

226237
The all permission check ensures that the security policy used during bootstrap
227238
does not grant the `java.security.AllPermission` to Elasticsearch. Running with
228239
the all permission granted is equivalent to disabling the security manager.
229240

241+
[[bootstrap-checks-discovery-configuration]]
230242
=== Discovery configuration check
231243

232244
By default, when Elasticsearch first starts up it will try and discover other

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ public enum ReferenceDocs {
6161
BOOTSTRAP_CHECK_SYSTEM_CALL_FILTER,
6262
BOOTSTRAP_CHECK_ONERROR_AND_ONOUTOFMEMORYERROR,
6363
BOOTSTRAP_CHECK_EARLY_ACCESS,
64-
BOOTSTRAP_CHECK_G1GC,
6564
BOOTSTRAP_CHECK_ALL_PERMISSION,
6665
BOOTSTRAP_CHECK_DISCOVERY_CONFIGURATION,
6766
BOOTSTRAP_CHECKS,
@@ -120,6 +119,15 @@ static Map<String, String> readLinksBySymbol(InputStream inputStream) throws Exc
120119
if (iterator.hasNext()) {
121120
throw new IllegalStateException("found unexpected extra value: " + iterator.next());
122121
}
122+
123+
// We must only link to anchors with fixed IDs (defined by [[fragment-name]] in the docs) because auto-generated fragment IDs
124+
// depend on the heading text and are too easy to break inadvertently. Auto-generated fragment IDs begin with an underscore.
125+
for (final var entry : result.entrySet()) {
126+
if (entry.getValue().startsWith("_") || entry.getValue().contains("#_")) {
127+
throw new IllegalStateException("found auto-generated fragment ID at " + entry.getKey());
128+
}
129+
}
130+
123131
return result;
124132
}
125133
}

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

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,26 @@
99
"ARCHIVE_INDICES": "archive-indices.html",
1010
"HTTP_TRACER": "modules-network.html#http-rest-request-tracer",
1111
"LOGGING": "logging.html",
12-
"BOOTSTRAP_CHECK_HEAP_SIZE": "_heap_size_check.html",
13-
"BOOTSTRAP_CHECK_FILE_DESCRIPTOR": "_file_descriptor_check.html",
14-
"BOOTSTRAP_CHECK_MEMORY_LOCK": "_memory_lock_check.html",
12+
"BOOTSTRAP_CHECK_HEAP_SIZE": "bootstrap-checks-heap-size.html",
13+
"BOOTSTRAP_CHECK_FILE_DESCRIPTOR": "bootstrap-checks-file-descriptor.html",
14+
"BOOTSTRAP_CHECK_MEMORY_LOCK": "bootstrap-checks-memory-lock.html",
1515
"BOOTSTRAP_CHECK_MAX_NUMBER_THREADS": "max-number-threads-check.html",
16-
"BOOTSTRAP_CHECK_MAX_FILE_SIZE": "_max_file_size_check.html",
16+
"BOOTSTRAP_CHECK_MAX_FILE_SIZE": "bootstrap-checks-max-file-size.html",
1717
"BOOTSTRAP_CHECK_MAX_SIZE_VIRTUAL_MEMORY": "max-size-virtual-memory-check.html",
18-
"BOOTSTRAP_CHECK_MAXIMUM_MAP_COUNT": "_maximum_map_count_check.html",
19-
"BOOTSTRAP_CHECK_CLIENT_JVM": "_client_jvm_check.html",
20-
"BOOTSTRAP_CHECK_USE_SERIAL_COLLECTOR": "_use_serial_collector_check.html",
21-
"BOOTSTRAP_CHECK_SYSTEM_CALL_FILTER": "_system_call_filter_check.html",
22-
"BOOTSTRAP_CHECK_ONERROR_AND_ONOUTOFMEMORYERROR": "_onerror_and_onoutofmemoryerror_checks.html",
23-
"BOOTSTRAP_CHECK_EARLY_ACCESS": "_early_access_check.html",
24-
"BOOTSTRAP_CHECK_G1GC": "_g1gc_check.html",
25-
"BOOTSTRAP_CHECK_ALL_PERMISSION": "_all_permission_check.html",
26-
"BOOTSTRAP_CHECK_DISCOVERY_CONFIGURATION": "_discovery_configuration_check.html",
18+
"BOOTSTRAP_CHECK_MAXIMUM_MAP_COUNT": "bootstrap-checks-max-map-count.html",
19+
"BOOTSTRAP_CHECK_CLIENT_JVM": "bootstrap-checks-client-jvm.html",
20+
"BOOTSTRAP_CHECK_USE_SERIAL_COLLECTOR": "bootstrap-checks-serial-collector.html",
21+
"BOOTSTRAP_CHECK_SYSTEM_CALL_FILTER": "bootstrap-checks-syscall-filter.html",
22+
"BOOTSTRAP_CHECK_ONERROR_AND_ONOUTOFMEMORYERROR": "bootstrap-checks-onerror.html",
23+
"BOOTSTRAP_CHECK_EARLY_ACCESS": "bootstrap-checks-early-access.html",
24+
"BOOTSTRAP_CHECK_ALL_PERMISSION": "bootstrap-checks-all-permission.html",
25+
"BOOTSTRAP_CHECK_DISCOVERY_CONFIGURATION": "bootstrap-checks-discovery-configuration.html",
2726
"BOOTSTRAP_CHECKS": "bootstrap-checks.html",
28-
"BOOTSTRAP_CHECK_ENCRYPT_SENSITIVE_DATA": "bootstrap-checks-xpack.html#_encrypt_sensitive_data_check",
29-
"BOOTSTRAP_CHECK_PKI_REALM": "bootstrap-checks-xpack.html#_pki_realm_check",
30-
"BOOTSTRAP_CHECK_ROLE_MAPPINGS": "bootstrap-checks-xpack.html#_role_mappings_check",
27+
"BOOTSTRAP_CHECK_ENCRYPT_SENSITIVE_DATA": "bootstrap-checks-xpack.html#bootstrap-checks-xpack-encrypt-sensitive-data",
28+
"BOOTSTRAP_CHECK_PKI_REALM": "bootstrap-checks-xpack.html#bootstrap-checks-xpack-pki-realm",
29+
"BOOTSTRAP_CHECK_ROLE_MAPPINGS": "bootstrap-checks-xpack.html#bootstrap-checks-xpack-role-mappings",
3130
"BOOTSTRAP_CHECK_TLS": "bootstrap-checks-xpack.html#bootstrap-checks-tls",
32-
"BOOTSTRAP_CHECK_TOKEN_SSL": "bootstrap-checks-xpack.html#_token_ssl_check",
31+
"BOOTSTRAP_CHECK_TOKEN_SSL": "bootstrap-checks-xpack.html#bootstrap-checks-xpack-token-ssl",
3332
"BOOTSTRAP_CHECK_SECURITY_MINIMAL_SETUP": "security-minimal-setup.html",
3433
"CONTACT_SUPPORT": "troubleshooting.html#troubleshooting-contact-support",
3534
"UNASSIGNED_SHARDS": "red-yellow-cluster-status.html",

server/src/test/java/org/elasticsearch/common/ReferenceDocsTests.java

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ public void testVersionComponent() {
3939
assertEquals("master", getVersionComponent("ABCDEF", true));
4040
}
4141

42-
public void testResourceValidation() throws Exception {
43-
42+
public void testReadsValidLinkDefinitions() throws Exception {
4443
try (var builder = XContentFactory.jsonBuilder()) {
4544
builder.startObject();
4645
for (ReferenceDocs link : ReferenceDocs.values()) {
@@ -54,11 +53,15 @@ public void testResourceValidation() throws Exception {
5453
assertEquals("TEST", map.get(link.name()));
5554
}
5655
}
56+
}
5757

58+
public void testRejectsInvalidJSON() throws Exception {
5859
try (var stream = new ByteArrayInputStream("{\"invalid\":".getBytes(StandardCharsets.UTF_8))) {
5960
expectThrows(XContentParseException.class, () -> ReferenceDocs.readLinksBySymbol(stream));
6061
}
62+
}
6163

64+
public void testRejectsBadStructure() throws Exception {
6265
try (var builder = XContentFactory.jsonBuilder()) {
6366
builder.startObject();
6467
for (ReferenceDocs link : ReferenceDocs.values()) {
@@ -70,7 +73,9 @@ public void testResourceValidation() throws Exception {
7073
expectThrows(IllegalArgumentException.class, () -> ReferenceDocs.readLinksBySymbol(stream));
7174
}
7275
}
76+
}
7377

78+
public void testRejectsExtraSymbol() throws Exception {
7479
try (var builder = XContentFactory.jsonBuilder()) {
7580
builder.startObject();
7681
for (ReferenceDocs link : ReferenceDocs.values()) {
@@ -82,7 +87,9 @@ public void testResourceValidation() throws Exception {
8287
expectThrows(IllegalStateException.class, () -> ReferenceDocs.readLinksBySymbol(stream));
8388
}
8489
}
90+
}
8591

92+
public void testRejectsMissingSymbol() throws Exception {
8693
try (var builder = XContentFactory.jsonBuilder()) {
8794
builder.startObject();
8895
var skipped = randomFrom(ReferenceDocs.values());
@@ -97,7 +104,9 @@ public void testResourceValidation() throws Exception {
97104
expectThrows(IllegalStateException.class, () -> ReferenceDocs.readLinksBySymbol(stream));
98105
}
99106
}
107+
}
100108

109+
public void testRejectsIncorrectOrder() throws Exception {
101110
try (var builder = XContentFactory.jsonBuilder()) {
102111
var shuffled = Arrays.copyOf(ReferenceDocs.values(), ReferenceDocs.values().length);
103112
var i = between(0, ReferenceDocs.values().length - 1);
@@ -117,4 +126,32 @@ public void testResourceValidation() throws Exception {
117126
}
118127
}
119128
}
129+
130+
public void testRejectsAutoGeneratedFragment() throws Exception {
131+
try (var builder = XContentFactory.jsonBuilder()) {
132+
builder.startObject();
133+
for (ReferenceDocs link : ReferenceDocs.values()) {
134+
builder.field(link.name(), "test.html#_auto_generated_fragment");
135+
}
136+
builder.endObject();
137+
138+
try (var stream = BytesReference.bytes(builder).streamInput()) {
139+
expectThrows(IllegalStateException.class, () -> ReferenceDocs.readLinksBySymbol(stream));
140+
}
141+
}
142+
}
143+
144+
public void testRejectsAutoGeneratedPageName() throws Exception {
145+
try (var builder = XContentFactory.jsonBuilder()) {
146+
builder.startObject();
147+
for (ReferenceDocs link : ReferenceDocs.values()) {
148+
builder.field(link.name(), "_auto_generated_page.html");
149+
}
150+
builder.endObject();
151+
152+
try (var stream = BytesReference.bytes(builder).streamInput()) {
153+
expectThrows(IllegalStateException.class, () -> ReferenceDocs.readLinksBySymbol(stream));
154+
}
155+
}
156+
}
120157
}

0 commit comments

Comments
 (0)