-
Notifications
You must be signed in to change notification settings - Fork 25.6k
add user authentication test for ILM #32826
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
add user authentication test for ILM #32826
Conversation
|
Pinging @elastic/es-core-infra |
a75c831 to
a3414eb
Compare
a3414eb to
b58b30e
Compare
| pollIntervalEntity.startObject("transient"); | ||
| { | ||
| pollIntervalEntity.field(LifecycleSettings.LIFECYCLE_POLL_INTERVAL, "1s"); | ||
| }pollIntervalEntity.endObject(); |
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.
I think the newline is messed up here?
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.
I was trying out a new formatting, I am missing a space there. but no like? I am happy to push it down a line
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.
I'm not a fan of this style of formatting, I think it looks confusing and somewhat ugly since it does not fit in with the code style of the rest of the code. I don't mind the style we have elsewhere sometimes of indenting lines which are inside objects but since here the JSON we are building is quite straight forward I also think its easy to follow formatted normally
| assertThat(indexExplain.get("managed"), equalTo(true)); | ||
| assertThat(indexExplain.get("step"), equalTo("error")); | ||
| assertThat(indexExplain.get("failed_step"), equalTo("readonly")); | ||
| assertThat(indexExplain.get("step_info"), equalTo("permissionsss!")); |
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.
wat?
Do we really assert that the explanation for the step is "permissionsss!" 🐍 ?
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.
haha, yes!
This is technically WIP since the test does not pass... but I have no idea why. I was hoping to at least get early feedback on the types of tests... as to why things are stuck on readonly. still a mystery to me and I am debugging it
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.
I can help look into this tomorrow if you are still having trouble finding the cause of the failure
| pollIntervalEntity.startObject("transient"); | ||
| { | ||
| pollIntervalEntity.field(LifecycleSettings.LIFECYCLE_POLL_INTERVAL, "1s"); | ||
| }pollIntervalEntity.endObject(); |
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.
I'm not a fan of this style of formatting, I think it looks confusing and somewhat ugly since it does not fit in with the code style of the rest of the code. I don't mind the style we have elsewhere sometimes of indenting lines which are inside objects but since here the JSON we are building is quite straight forward I also think its easy to follow formatted normally
| import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue; | ||
| import static org.hamcrest.Matchers.equalTo; | ||
|
|
||
| public class PermissionsIT extends ESRestTestCase { |
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.
Could you add a JavaDoc here explaining what this test class aims to test?
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.
yes
| public void testCanManageIndexAndPolicyDifferentUsers() throws Exception { | ||
| String index = "ilm-00001"; | ||
| createIndexAsAdmin(index, indexSettingsWithPolicy, ""); | ||
| assertBusy(() -> assertFalse(indexExists(index))); |
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.
Is this actually testing anything ILM related? I think we need to test that the policy actually progresses here to ensure the ILM side is doing the permissions correctly?
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.
the index is deleted by ILM?
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.
theoretically. plan to continue debugging the lack of progress in the system today
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.
Could you add a javadoc for this test to explain what its doing? At first glance it looks a bit confusing because it just creates an index and then checks it doesn't exist.
| assertThat(indexExplain.get("managed"), equalTo(true)); | ||
| assertThat(indexExplain.get("step"), equalTo("error")); | ||
| assertThat(indexExplain.get("failed_step"), equalTo("readonly")); | ||
| assertThat(indexExplain.get("step_info"), equalTo("permissionsss!")); |
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.
I can help look into this tomorrow if you are still having trouble finding the cause of the failure
|
Took a while to track down but it seems that the problem with the policy not progressing is due to the update settings request in the read only step being dropped by the Additionally I think there is a bug in the |
|
I am not seeing what you're seeing @colings86. Current master looks like this: Lines 94 to 118 in a883e7d
The whole block is wrapped in a elasticsearch/server/src/main/java/org/elasticsearch/action/support/TransportAction.java Lines 136 to 153 in a883e7d
|
|
@jasontedor hmm good point with the surrounding try-catches. I'm not sure why the request was getting dropped then but I added log lines to all the |
|
@colings86 I think that you're running with assertions enabled? That would lead to the assertion tripping, throwing an |
|
@jasontedor ah yes you are right, since I'm running in a test from gradle It is a bit unfortunately that the asserts don't really show up clearly in the logs though, this made this bug quite difficult to track down without digging into it. I wonder if the assertion is actually worth it here since if the |
That is the right fix for getting the user added to the request. |
I am not arguing against the fix, the fix is clearly correct. I am arguing that there is not any problem with |
The problem here is that the assertion error was getting caught by the JDK, set as the outcome on a future task, and lost. We need to ensure that errors thrown from triggered listeners do not get lost. I opened #32998. |
|
thanks for the assistance here everyone. I think I caught up with changes necessary to make these tests fly! that being said, the qa:with-security tests passed without the adding of the INDEX_LIFECYCLE_ORIGIN |
colings86
left a comment
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.
I left a couple of comments but I think this is close now
| String token = basicAuthHeaderValue("test_admin", new SecureString("x-pack-test-password".toCharArray())); | ||
| return Settings.builder() | ||
| .put(ThreadContext.PREFIX + ".Authorization", token) | ||
| .build(); |
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.
Is this going to be safe? As I understand it, the rest test case uses the admin settings to reset the cluster to a clean state between tests, but here this admin user only has access to the ilm-* indices so I'm not sure if it will be able to clean up the the not-ilm index?
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.
test_admin has full administrator authority. the client() is running as the ILM-specific, test_ilm, user. This is why wipeCluster() has not been throwing an exception and failing the tests when running as adminClient().
| public void testCanManageIndexAndPolicyDifferentUsers() throws Exception { | ||
| String index = "ilm-00001"; | ||
| createIndexAsAdmin(index, indexSettingsWithPolicy, ""); | ||
| assertBusy(() -> assertFalse(indexExists(index))); |
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.
Could you add a javadoc for this test to explain what its doing? At first glance it looks a bit confusing because it just creates an index and then checks it doesn't exist.
| protected void masterOperation(Request request, ClusterState state, ActionListener<Response> listener) { | ||
| Map<String, String> filteredHeaders = threadPool.getThreadContext().getHeaders().entrySet().stream() | ||
| .filter(e -> ClientHelper.SECURITY_HEADER_FILTERS.contains(e.getKey())) | ||
| .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); |
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 might be worth a comment explaining why this needs to be here and not in the task so someone doesn't move it into the task without realising it will break things?
colings86
left a comment
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.
LGTM
These are some user-auth scenarios I think may be worth testing. For some reason, the tests hang on the read-only action. Still not sure why.