-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add status resource with public access
Address #157. Default to path `/api/v1/s3Proxy/status`, returns aws-proxy status. Refactor `SigningServiceType` binding to used annotation.
- Loading branch information
Showing
12 changed files
with
400 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/rest/NodeStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.trino.aws.proxy.server.rest; | ||
|
||
import io.airlift.units.Duration; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
public record NodeStatus( | ||
String nodeId, | ||
String environment, | ||
Duration uptime, | ||
String externalAddress, | ||
String internalAddress, | ||
int processors, | ||
double processCpuLoad, | ||
double systemCpuLoad, | ||
long heapUsed, | ||
long heapAvailable, | ||
long nonHeapUsed) | ||
{ | ||
public NodeStatus | ||
{ | ||
requireNonNull(nodeId, "nodeId is null"); | ||
requireNonNull(environment, "environment is null"); | ||
requireNonNull(uptime, "uptime is null"); | ||
requireNonNull(externalAddress, "externalAddress is null"); | ||
requireNonNull(internalAddress, "internalAddress is null"); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/rest/ParamProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.trino.aws.proxy.server.rest; | ||
|
||
import io.trino.aws.proxy.spi.rest.Request; | ||
import io.trino.aws.proxy.spi.signing.SigningMetadata; | ||
import org.glassfish.jersey.server.ContainerRequest; | ||
import org.glassfish.jersey.server.model.Parameter; | ||
import org.glassfish.jersey.server.spi.internal.ValueParamProvider; | ||
|
||
import java.util.function.Function; | ||
|
||
import static io.trino.aws.proxy.server.rest.SecurityFilter.unwrap; | ||
import static org.glassfish.jersey.server.spi.internal.ValueParamProvider.Priority.HIGH; | ||
|
||
public class ParamProvider | ||
implements ValueParamProvider | ||
{ | ||
@Override | ||
public Function<ContainerRequest, ?> getValueProvider(Parameter parameter) | ||
{ | ||
if (Request.class.isAssignableFrom(parameter.getRawType()) || SigningMetadata.class.isAssignableFrom(parameter.getRawType()) || RequestLoggingSession.class.isAssignableFrom(parameter.getRawType())) { | ||
return containerRequest -> unwrap(containerRequest, parameter.getRawType()); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public PriorityType getPriority() | ||
{ | ||
return HIGH; | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/rest/ResourceSecurity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.trino.aws.proxy.server.rest; | ||
|
||
import io.trino.aws.proxy.server.rest.ResourceSecurity.AccessType.Access.PublicAccess; | ||
import io.trino.aws.proxy.server.rest.ResourceSecurity.AccessType.Access.SigV4Access; | ||
import io.trino.aws.proxy.spi.signing.SigningServiceType; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
@Retention(RUNTIME) | ||
@Target({TYPE, METHOD}) | ||
public @interface ResourceSecurity | ||
{ | ||
enum AccessType | ||
{ | ||
PUBLIC(new PublicAccess()), | ||
S3(new SigV4Access(SigningServiceType.S3)), | ||
STS(new SigV4Access(SigningServiceType.STS)), | ||
LOGS(new SigV4Access(SigningServiceType.LOGS)); | ||
|
||
public sealed interface Access | ||
{ | ||
record PublicAccess() implements Access {} | ||
|
||
record SigV4Access(SigningServiceType signingServiceType) implements Access {} | ||
} | ||
|
||
private final Access access; | ||
|
||
AccessType(Access access) | ||
{ | ||
this.access = requireNonNull(access, "access is null"); | ||
} | ||
|
||
public Access access() | ||
{ | ||
return access; | ||
} | ||
} | ||
|
||
AccessType value(); | ||
} |
69 changes: 69 additions & 0 deletions
69
...ws-proxy/src/main/java/io/trino/aws/proxy/server/rest/ResourceSecurityDynamicFeature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.trino.aws.proxy.server.rest; | ||
|
||
import com.google.inject.Inject; | ||
import io.trino.aws.proxy.server.rest.ResourceSecurity.AccessType; | ||
import io.trino.aws.proxy.server.rest.ResourceSecurity.AccessType.Access.PublicAccess; | ||
import io.trino.aws.proxy.server.rest.ResourceSecurity.AccessType.Access.SigV4Access; | ||
import io.trino.aws.proxy.spi.signing.SigningController; | ||
import io.trino.aws.proxy.spi.signing.SigningServiceType; | ||
import jakarta.ws.rs.container.DynamicFeature; | ||
import jakarta.ws.rs.container.ResourceInfo; | ||
import jakarta.ws.rs.core.FeatureContext; | ||
|
||
import java.lang.reflect.AnnotatedElement; | ||
import java.util.Optional; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
public class ResourceSecurityDynamicFeature | ||
implements DynamicFeature | ||
{ | ||
private final SigningController signingController; | ||
private final RequestLoggerController requestLoggerController; | ||
|
||
@Inject | ||
public ResourceSecurityDynamicFeature(SigningController signingController, RequestLoggerController requestLoggerController) | ||
{ | ||
this.signingController = requireNonNull(signingController); | ||
this.requestLoggerController = requireNonNull(requestLoggerController); | ||
} | ||
|
||
@Override | ||
public void configure(ResourceInfo resourceInfo, FeatureContext context) | ||
{ | ||
if (resourceInfo.getResourceClass().getPackageName().startsWith("io.trino.aws")) { | ||
AccessType accessType = getAccessType(resourceInfo); | ||
switch (accessType.access()) { | ||
case PublicAccess _ -> {} | ||
case SigV4Access(SigningServiceType signingServiceType) -> | ||
context.register(new SecurityFilter(signingController, signingServiceType, requestLoggerController)); | ||
} | ||
} | ||
} | ||
|
||
private static AccessType getAccessType(ResourceInfo resourceInfo) | ||
{ | ||
return getAccessTypeFromAnnotation(resourceInfo.getResourceMethod()) | ||
.or(() -> getAccessTypeFromAnnotation(resourceInfo.getResourceClass())) | ||
.orElseThrow(() -> new IllegalArgumentException("Proxy resource is not annotated with @" + ResourceSecurity.class.getSimpleName() + ": " + resourceInfo.getResourceMethod())); | ||
} | ||
|
||
private static Optional<AccessType> getAccessTypeFromAnnotation(AnnotatedElement annotatedElement) | ||
{ | ||
return Optional.ofNullable(annotatedElement.getAnnotation(ResourceSecurity.class)) | ||
.map(ResourceSecurity::value); | ||
} | ||
} |
Oops, something went wrong.