Skip to content

Commit 3926275

Browse files
authored
fix: check alts if we return permission denied for pingandwarm (#2860)
1 parent 787e513 commit 3926275

2 files changed

Lines changed: 28 additions & 10 deletions

File tree

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/dp/ClassicDirectAccessChecker.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import io.grpc.Channel;
2626
import io.grpc.ClientInterceptors;
2727
import io.grpc.ManagedChannel;
28+
import io.grpc.Status.Code;
29+
import io.grpc.StatusRuntimeException;
2830
import java.util.Optional;
2931
import java.util.concurrent.ScheduledExecutorService;
3032
import java.util.logging.Level;
@@ -76,15 +78,22 @@ public boolean check(Channel channel) {
7678
private boolean evaluateEligibility(Channel channel) {
7779
MetadataExtractorInterceptor interceptor = createInterceptor();
7880
Channel interceptedChannel = ClientInterceptors.intercept(channel, interceptor);
79-
channelPrimer.primeChannel(interceptedChannel);
8081
MetadataExtractorInterceptor.SidebandData sidebandData = interceptor.getSidebandData();
81-
82-
boolean isEligible =
83-
Optional.ofNullable(sidebandData)
84-
.map(MetadataExtractorInterceptor.SidebandData::getPeerInfo)
85-
.map(PeerInfo::getTransportType)
86-
.map(type -> type == PeerInfo.TransportType.TRANSPORT_TYPE_DIRECT_ACCESS)
87-
.orElse(false);
82+
boolean isEligible = false;
83+
try {
84+
channelPrimer.primeChannel(interceptedChannel);
85+
isEligible =
86+
Optional.ofNullable(sidebandData.getPeerInfo())
87+
.map(PeerInfo::getTransportType)
88+
.map(type -> type == PeerInfo.TransportType.TRANSPORT_TYPE_DIRECT_ACCESS)
89+
.orElse(false);
90+
} catch (StatusRuntimeException e) {
91+
if (e.getStatus().getCode() != Code.PERMISSION_DENIED) {
92+
throw e;
93+
}
94+
// Failed with permission error, resorting to ALTS check.
95+
isEligible = sidebandData.isAlts();
96+
}
8897

8998
if (isEligible) {
9099
// getIp should be non-null as isEligible is true

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/MetadataExtractorInterceptor.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public void onHeaders(Metadata headers) {
7777

7878
@Override
7979
public void onClose(Status status, Metadata trailers) {
80-
sidebandData.onClose(status, trailers);
80+
sidebandData.onClose(status, trailers, getAttributes());
8181
super.onClose(status, trailers);
8282
}
8383
},
@@ -112,6 +112,7 @@ public static SidebandData from(CallOptions callOptions) {
112112
@Nullable private volatile PeerInfo peerInfo;
113113
@Nullable private volatile Duration gfeTiming;
114114
@Nullable private volatile Util.IpProtocol ipProtocol;
115+
private boolean isAlts = false;
115116

116117
@Nullable
117118
public ResponseParams getResponseParams() {
@@ -133,6 +134,10 @@ public Util.IpProtocol getIpProtocol() {
133134
return ipProtocol;
134135
}
135136

137+
public boolean isAlts() {
138+
return isAlts;
139+
}
140+
136141
private void reset() {
137142
responseParams = null;
138143
peerInfo = null;
@@ -147,7 +152,11 @@ void onResponseHeaders(Metadata md, Attributes attributes) {
147152
ipProtocol = extractIpProtocol(attributes);
148153
}
149154

150-
void onClose(Status status, Metadata trailers) {
155+
void onClose(Status status, Metadata trailers, Attributes attributes) {
156+
isAlts = AltsContextUtil.check(attributes);
157+
if (ipProtocol == null) {
158+
ipProtocol = extractIpProtocol(attributes);
159+
}
151160
if (responseParams == null) {
152161
responseParams = extractResponseParams(trailers);
153162
}

0 commit comments

Comments
 (0)