Skip to content

Commit a1597d0

Browse files
authored
Revert "Remove 7.1 and 7.2 transport version constants (#136038)" (#136573)
This reverts commit 1a3a006. elastic/elasticsearch-serverless#4688
1 parent c01ac24 commit a1597d0

File tree

6 files changed

+428
-67
lines changed

6 files changed

+428
-67
lines changed

server/src/main/java/org/elasticsearch/TransportVersions.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ static TransportVersion def(int id) {
5353
}
5454

5555
// TODO: ES-10337 we can remove all transport versions earlier than 8.18
56+
public static final TransportVersion V_7_1_0 = def(7_01_00_99);
57+
public static final TransportVersion V_7_2_0 = def(7_02_00_99);
5658
public static final TransportVersion V_7_3_0 = def(7_03_00_99);
5759
public static final TransportVersion V_7_3_2 = def(7_03_02_99);
5860
public static final TransportVersion V_7_4_0 = def(7_04_00_99);

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/SecurityFeatureSetUsage.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ public SecurityFeatureSetUsage(StreamInput in) throws IOException {
5555
realmsUsage = in.readGenericMap();
5656
rolesStoreUsage = in.readGenericMap();
5757
sslUsage = in.readGenericMap();
58-
tokenServiceUsage = in.readGenericMap();
59-
apiKeyServiceUsage = in.readGenericMap();
58+
if (in.getTransportVersion().onOrAfter(TransportVersions.V_7_2_0)) {
59+
tokenServiceUsage = in.readGenericMap();
60+
apiKeyServiceUsage = in.readGenericMap();
61+
}
6062
auditUsage = in.readGenericMap();
6163
ipFilterUsage = in.readGenericMap();
6264
anonymousUsage = in.readGenericMap();
@@ -119,8 +121,10 @@ public void writeTo(StreamOutput out) throws IOException {
119121
out.writeGenericMap(realmsUsage);
120122
out.writeGenericMap(rolesStoreUsage);
121123
out.writeGenericMap(sslUsage);
122-
out.writeGenericMap(tokenServiceUsage);
123-
out.writeGenericMap(apiKeyServiceUsage);
124+
if (out.getTransportVersion().onOrAfter(TransportVersions.V_7_2_0)) {
125+
out.writeGenericMap(tokenServiceUsage);
126+
out.writeGenericMap(apiKeyServiceUsage);
127+
}
124128
out.writeGenericMap(auditUsage);
125129
out.writeGenericMap(ipFilterUsage);
126130
out.writeGenericMap(anonymousUsage);

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/TokensInvalidationResult.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
package org.elasticsearch.xpack.core.security.authc.support;
99

1010
import org.elasticsearch.ElasticsearchException;
11+
import org.elasticsearch.TransportVersions;
1112
import org.elasticsearch.common.io.stream.StreamInput;
1213
import org.elasticsearch.common.io.stream.StreamOutput;
1314
import org.elasticsearch.common.io.stream.Writeable;
@@ -58,6 +59,9 @@ public TokensInvalidationResult(StreamInput in) throws IOException {
5859
this.invalidatedTokens = in.readStringCollectionAsList();
5960
this.previouslyInvalidatedTokens = in.readStringCollectionAsList();
6061
this.errors = in.readCollectionAsList(StreamInput::readException);
62+
if (in.getTransportVersion().before(TransportVersions.V_7_2_0)) {
63+
in.readVInt();
64+
}
6165
this.restStatus = RestStatus.readFrom(in);
6266
}
6367

@@ -105,6 +109,9 @@ public void writeTo(StreamOutput out) throws IOException {
105109
out.writeStringCollection(invalidatedTokens);
106110
out.writeStringCollection(previouslyInvalidatedTokens);
107111
out.writeCollection(errors, StreamOutput::writeException);
112+
if (out.getTransportVersion().before(TransportVersions.V_7_2_0)) {
113+
out.writeVInt(5);
114+
}
108115
RestStatus.writeTo(out, restStatus);
109116
}
110117
}

x-pack/plugin/security/src/internalClusterTest/java/org/elasticsearch/xpack/security/authc/TokenAuthIntegTests.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,37 @@ public void testClientCredentialsGrant() throws Exception {
750750
assertUnauthorizedToken(createTokenResponse.accessToken());
751751
}
752752

753+
public void testAuthenticateWithWrongToken() throws Exception {
754+
final TokenService tokenService = internalCluster().getInstance(TokenService.class);
755+
OAuth2Token response = createToken(TEST_USER_NAME, SecuritySettingsSourceField.TEST_PASSWORD_SECURE_STRING);
756+
assertNotNull(response.getRefreshToken());
757+
// Assert that we can authenticate with the access token
758+
assertAuthenticateWithToken(response.accessToken(), TEST_USER_NAME);
759+
// Now attempt to authenticate with an invalid access token string
760+
assertUnauthorizedToken(randomAlphaOfLengthBetween(0, 128));
761+
// Now attempt to authenticate with an invalid access token with valid structure (pre 7.2)
762+
assertUnauthorizedToken(
763+
tokenService.prependVersionAndEncodeAccessToken(
764+
TransportVersions.V_7_1_0,
765+
tokenService.getRandomTokenBytes(TransportVersions.V_7_1_0, randomBoolean()).v1()
766+
)
767+
);
768+
// Now attempt to authenticate with an invalid access token with valid structure (after 7.2 pre 8.10)
769+
assertUnauthorizedToken(
770+
tokenService.prependVersionAndEncodeAccessToken(
771+
TransportVersions.V_7_4_0,
772+
tokenService.getRandomTokenBytes(TransportVersions.V_7_4_0, randomBoolean()).v1()
773+
)
774+
);
775+
// Now attempt to authenticate with an invalid access token with valid structure (current version)
776+
assertUnauthorizedToken(
777+
tokenService.prependVersionAndEncodeAccessToken(
778+
TransportVersion.current(),
779+
tokenService.getRandomTokenBytes(TransportVersion.current(), randomBoolean()).v1()
780+
)
781+
);
782+
}
783+
753784
@Before
754785
public void waitForSecurityIndexWritable() throws Exception {
755786
createSecurityIndexWithWaitForActiveShards();

0 commit comments

Comments
 (0)