-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Reprocess operator file settings on service start #114295
Changes from 27 commits
0c193cd
1cc6175
4e243c4
4fab8f6
80036ee
7242520
2fd6eef
4319bb6
574ba67
fd4d20c
75a255d
55f5399
d790a5e
5f41735
28938d5
d6d9c43
fa65684
77421c7
16db4ed
1fae6be
8d3539b
7a02f9b
ff796cf
e478134
74ab91a
9a44ebf
89b0957
dda0723
8dc3709
496ab5c
ae00eaa
99e2b0e
b7608cb
6ba1336
035e8c0
7e2720d
051f3c6
7af83cb
e1a1de2
c0540bf
cf8002a
a5d1bc8
d20b1d3
1409c89
fbf0691
afef613
cb84cfb
997ac7a
a09b505
8548c93
4205feb
65d05b4
dbbf948
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pr: 114295 | ||
summary: "Reprocess operator file settings when settings service starts, due to node restart or master node change" | ||
area: Infra/Settings | ||
type: enhancement | ||
issues: [ ] |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,111 @@ | ||||
/* | ||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||||
* or more contributor license agreements. Licensed under the "Elastic License | ||||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||||
* Public License v 1"; you may not use this file except in compliance with, at | ||||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||||
* License v3.0 only", or the "Server Side Public License, v 1". | ||||
*/ | ||||
|
||||
package org.elasticsearch.upgrades; | ||||
|
||||
import com.carrotsearch.randomizedtesting.annotations.Name; | ||||
|
||||
import org.elasticsearch.client.Request; | ||||
import org.elasticsearch.core.SuppressForbidden; | ||||
import org.elasticsearch.test.XContentTestUtils; | ||||
import org.elasticsearch.test.cluster.ElasticsearchCluster; | ||||
import org.elasticsearch.test.cluster.local.distribution.DistributionType; | ||||
import org.elasticsearch.test.cluster.util.Version; | ||||
import org.elasticsearch.test.cluster.util.resource.Resource; | ||||
import org.elasticsearch.test.junit.RunnableTestRuleAdapter; | ||||
import org.junit.ClassRule; | ||||
import org.junit.rules.RuleChain; | ||||
import org.junit.rules.TemporaryFolder; | ||||
import org.junit.rules.TestRule; | ||||
|
||||
import java.io.IOException; | ||||
import java.util.List; | ||||
import java.util.function.Supplier; | ||||
|
||||
import static org.hamcrest.Matchers.equalTo; | ||||
import static org.hamcrest.Matchers.is; | ||||
import static org.hamcrest.Matchers.not; | ||||
import static org.hamcrest.Matchers.nullValue; | ||||
|
||||
public class FileSettingsRoleMappingUpgradeIT extends ParameterizedRollingUpgradeTestCase { | ||||
|
||||
private static final RunnableTestRuleAdapter versionLimit = new RunnableTestRuleAdapter( | ||||
() -> assumeTrue( | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Could you use something like this here instead to tie it to transport version instead of stack version? The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is kind of related to the comment here, that was removed in 9.0.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like a case for a test-only feature @thecoop wdyt? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, thats a good idea. You could also use synthetic version features to reference specific release versions There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm up for any approach here -- I copied the version check from the existing What I need to check for is that we have a cluster that understands file settings ( @thecoop do you have a pointer for how I could best capture this with synthetic version features/a test only feature? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh wow that's neat. I'll do that 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One note on this is that Line 46 in 075cd24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eh, yes, in that case you can define a historical feature for 8.4.0, and a test feature for 8.15.0, and check between the two There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I reworked it to not use a |
||||
"Only relevant when upgrading from a version before role mappings were stored in cluster state", | ||||
getOldClusterTestVersion().after(new Version(8, 4, 0)) && getOldClusterTestVersion().before(new Version(8, 15, 0)) | ||||
) | ||||
); | ||||
|
||||
private static final String settingsJSON = """ | ||||
{ | ||||
"metadata": { | ||||
"version": "1", | ||||
"compatibility": "8.4.0" | ||||
}, | ||||
"state": { | ||||
"role_mappings": { | ||||
"everyone_kibana": { | ||||
"enabled": true, | ||||
"roles": [ "kibana_user" ], | ||||
"rules": { "field": { "username": "*" } } | ||||
} | ||||
} | ||||
} | ||||
}"""; | ||||
|
||||
private static final TemporaryFolder repoDirectory = new TemporaryFolder(); | ||||
|
||||
private static final ElasticsearchCluster cluster = ElasticsearchCluster.local() | ||||
.distribution(DistributionType.DEFAULT) | ||||
.version(getOldClusterTestVersion()) | ||||
.nodes(NODE_NUM) | ||||
.setting("path.repo", new Supplier<>() { | ||||
@Override | ||||
@SuppressForbidden(reason = "TemporaryFolder only has io.File methods, not nio.File") | ||||
public String get() { | ||||
return repoDirectory.getRoot().getPath(); | ||||
} | ||||
}) | ||||
.setting("xpack.security.enabled", "true") | ||||
// workaround to avoid having to set up clients and authorization headers | ||||
.setting("xpack.security.authc.anonymous.roles", "superuser") | ||||
.configFile("operator/settings.json", Resource.fromString(settingsJSON)) | ||||
.build(); | ||||
|
||||
@ClassRule | ||||
public static TestRule ruleChain = RuleChain.outerRule(versionLimit).around(repoDirectory).around(cluster); | ||||
|
||||
public FileSettingsRoleMappingUpgradeIT(@Name("upgradedNodes") int upgradedNodes) { | ||||
super(upgradedNodes); | ||||
} | ||||
|
||||
@Override | ||||
protected ElasticsearchCluster getUpgradeCluster() { | ||||
return cluster; | ||||
} | ||||
|
||||
public void testRoleMappingsAppliedOnUpgrade() throws IOException { | ||||
if (isOldCluster()) { | ||||
Request clusterStateRequest = new Request("GET", "/_cluster/state/metadata"); | ||||
List<Object> roleMappings = new XContentTestUtils.JsonMapView(entityAsMap(client().performRequest(clusterStateRequest))).get( | ||||
"metadata.role_mappings.role_mappings" | ||||
); | ||||
assertThat(roleMappings, is(nullValue())); | ||||
} else if (isUpgradedCluster()) { | ||||
// the nodes have all been upgraded. Check they re-processed the role mappings in the settings file on | ||||
// upgrade | ||||
Request clusterStateRequest = new Request("GET", "/_cluster/state/metadata"); | ||||
List<Object> roleMappings = new XContentTestUtils.JsonMapView(entityAsMap(client().performRequest(clusterStateRequest))).get( | ||||
"metadata.role_mappings.role_mappings" | ||||
); | ||||
assertThat(roleMappings, is(not(nullValue()))); | ||||
assertThat(roleMappings.size(), equalTo(1)); | ||||
} | ||||
} | ||||
} |
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.
This won't actually run on 9.0, only once these changes are backported to 8.x -- I have a PR open to give this some CI time (also checked that it passes locally).