Skip to content
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

Refactor to support Glue protocol (separate PR) #168

Merged
merged 5 commits into from
Jan 27, 2025
Merged

Conversation

Randgalt
Copy link
Member

Introduce RemoteUriFacade

Abstract RemoteS3Facade's remoteUri() into a new interface
that can be used/injected independently of S3 implementations.

Give Request logger its own config

Move the Request logging config into separate config class

Abstract some common bindings of

Abstract new static methods so portions of module can be used in other contexts

@cla-bot cla-bot bot added the cla-signed label Jan 26, 2025
@Randgalt Randgalt requested review from mosiac1 and vagaerg January 26, 2025 12:47
@Randgalt Randgalt changed the title Refactor a bit to support Glue protocol (separate PR) Refactor to support Glue protocol (separate PR) Jan 26, 2025
@Randgalt Randgalt mentioned this pull request Jan 26, 2025
2 tasks
@Randgalt Randgalt requested a review from mosiac1 January 27, 2025 13:17
@Randgalt
Copy link
Member Author

@mosiac1 I've added another commit with the change to AccessType we discussed. PTAL

@Randgalt Randgalt requested a review from mosiac1 January 27, 2025 17:21
@@ -29,32 +29,65 @@
@Target({TYPE, METHOD})
public @interface ResourceSecurity
{
enum AccessType
sealed interface Access
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't we want Access and/or AccessType to be public scoped?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of this approach? It removes the need for 1 intermediary class

Pasting a diff, I don't have a good way of explaining it in a comment

Index: trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/rest/ResourceSecurityDynamicFeature.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/rest/ResourceSecurityDynamicFeature.java b/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/rest/ResourceSecurityDynamicFeature.java
--- a/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/rest/ResourceSecurityDynamicFeature.java	(revision 03c68f8ac6880af08e00422aaea199bc0addc3a6)
+++ b/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/rest/ResourceSecurityDynamicFeature.java	(date 1737999508310)
@@ -14,11 +14,10 @@
 package io.trino.aws.proxy.server.rest;
 
 import com.google.inject.Inject;
-import io.trino.aws.proxy.server.rest.ResourceSecurity.Access.PublicAccess;
-import io.trino.aws.proxy.server.rest.ResourceSecurity.Access.SigV4Access;
 import io.trino.aws.proxy.server.rest.ResourceSecurity.AccessType;
+import io.trino.aws.proxy.server.rest.ResourceSecurity.AccessType.PublicAccessType;
+import io.trino.aws.proxy.server.rest.ResourceSecurity.AccessType.SigV4AccessType;
 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;
@@ -46,10 +45,10 @@
     {
         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));
+            switch (accessType) {
+                case PublicAccessType _ -> {}
+                case SigV4AccessType sigV4 ->
+                        context.register(new SecurityFilter(signingController, sigV4.getSigningServiceType(), requestLoggerController));
             }
         }
     }
Index: trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/rest/ResourceSecurity.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/rest/ResourceSecurity.java b/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/rest/ResourceSecurity.java
--- a/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/rest/ResourceSecurity.java	(revision 03c68f8ac6880af08e00422aaea199bc0addc3a6)
+++ b/trino-aws-proxy/src/main/java/io/trino/aws/proxy/server/rest/ResourceSecurity.java	(date 1737999578942)
@@ -13,8 +13,8 @@
  */
 package io.trino.aws.proxy.server.rest;
 
-import io.trino.aws.proxy.server.rest.ResourceSecurity.Access.PublicAccess;
-import io.trino.aws.proxy.server.rest.ResourceSecurity.Access.SigV4Access;
+import io.trino.aws.proxy.server.rest.ResourceSecurity.AccessType.PublicAccessType;
+import io.trino.aws.proxy.server.rest.ResourceSecurity.AccessType.SigV4AccessType;
 import io.trino.aws.proxy.spi.signing.SigningServiceType;
 
 import java.lang.annotation.Retention;
@@ -23,69 +23,56 @@
 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
 {
-    sealed interface Access
-    {
-        record PublicAccess()
-                implements Access {}
-
-        record SigV4Access(SigningServiceType signingServiceType)
-                implements Access {}
-    }
-
-    abstract class AccessType
+    sealed interface AccessType
     {
-        private final Access access;
-
-        public Access access()
-        {
-            return access;
-        }
-
-        protected AccessType(Access access)
-        {
-            this.access = requireNonNull(access, "access is null");
-        }
-    }
-
-    class Public
-            extends AccessType
-    {
-        public Public()
-        {
-            super(new PublicAccess());
-        }
-    }
-
-    class S3
-            extends AccessType
-    {
-        public S3()
-        {
-            super(new SigV4Access(SigningServiceType.S3));
-        }
-    }
+        sealed interface PublicAccessType
+                extends AccessType
+                permits Public
+        {}
 
-    class Sts
-            extends AccessType
+        non-sealed interface SigV4AccessType
+                extends AccessType
+        {
+            SigningServiceType getSigningServiceType();
+        }
+    }
+
+    final class Public
+            implements PublicAccessType
+    { }
+
+    final class S3
+            implements SigV4AccessType
     {
-        public Sts()
+        @Override
+        public SigningServiceType getSigningServiceType()
         {
-            super(new SigV4Access(SigningServiceType.STS));
+            return SigningServiceType.S3;
         }
     }
 
-    class Logs
-            extends AccessType
+    final class Sts
+            implements SigV4AccessType
     {
-        public Logs()
+        @Override
+        public SigningServiceType getSigningServiceType()
         {
-            super(new SigV4Access(SigningServiceType.LOGS));
+            return SigningServiceType.STS;
+        }
+    }
+
+    final class Logs
+            implements SigV4AccessType
+    {
+        @Override
+        public SigningServiceType getSigningServiceType()
+        {
+            return SigningServiceType.LOGS;
         }
     }
 

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't we want Access and/or AccessType to be public scoped

It's public by default in annotations

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of this approach

sure - we can do that

import java.util.Optional;

class Signers
{
static final String OVERRIDE_CONTENT_HASH = "__TRINO__OVERRIDE_CONTENT_HASH__";

static final SigningApi aws4Signer = new InternalAwsS3V4Signer();
static final SigningApi aws4Signer = new InternalAwsV4Signer();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use awsV4Signer to be consistent with the AWS names?

awsS34Signer is also quite confusing so awsS3V4Signer it slightly nicer

@Randgalt
Copy link
Member Author

Changes made

@Randgalt Randgalt requested a review from mosiac1 January 27, 2025 18:02
Changes to allow general AWS V4 signing and not just S3 signing.

- Added `SigningTrait` to make signing configurable
- Add traits to `SigningServiceType`
Abstract RemoteS3Facade's `remoteUri()` into a new interface
that can be used/injected independently of S3 implementations.
Move the Request logging config into separate config class
Abstract new static methods so portions of module can be used
in other contexts
This will allow new AccessTypes to be created outside of this
project by third parties. Uses a technique where by the `ResourceSecurity`
instantiates the AccessType assuming a no-arg constructor.
@Randgalt Randgalt merged commit 2a8e05b into main Jan 27, 2025
2 checks passed
@Randgalt Randgalt deleted the jordanz/refactor branch January 27, 2025 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants