-
Notifications
You must be signed in to change notification settings - Fork 562
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
Support VPC Lattice as an event source #845
base: main
Are you sure you want to change the base?
Changes from 10 commits
30b161f
38946e4
b9d9ad4
229ddbc
0679c1d
2de6093
5117dfb
a71535b
7a645ec
679016f
2f3fad3
66a0fc8
6c57dde
0108f30
07a5aba
4ce1ae6
b587da7
6ca3d07
6f2b629
5bc26a3
389f834
eb1b7a4
47e8fc9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.amazonaws.serverless.proxy; | ||
|
||
import com.amazonaws.serverless.proxy.internal.jaxrs.AwsVpcLatticeV2SecurityContext; | ||
import com.amazonaws.serverless.proxy.model.VPCLatticeV2RequestEvent; | ||
import com.amazonaws.services.lambda.runtime.Context; | ||
import jakarta.ws.rs.core.SecurityContext; | ||
|
||
public class AwsVPCLatticeV2SecurityContextWriter implements SecurityContextWriter<VPCLatticeV2RequestEvent>{ | ||
@Override | ||
public SecurityContext writeSecurityContext(VPCLatticeV2RequestEvent event, Context lambdaContext) { | ||
return new AwsVpcLatticeV2SecurityContext(lambdaContext, event); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.amazonaws.serverless.proxy.internal.jaxrs; | ||
|
||
import com.amazonaws.serverless.proxy.model.VPCLatticeV2RequestEvent; | ||
import com.amazonaws.services.lambda.runtime.Context; | ||
import jakarta.ws.rs.core.SecurityContext; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
import java.security.Principal; | ||
import java.util.Objects; | ||
|
||
/** | ||
* default implementation of the <code>SecurityContext</code> object. This class supports 1 VPC Lattice authentication type: | ||
* AWS_IAM. | ||
*/ | ||
@Getter | ||
@AllArgsConstructor | ||
public class AwsVpcLatticeV2SecurityContext implements SecurityContext { | ||
|
||
static final String AUTH_SCHEME_AWS_IAM = "AWS_IAM"; | ||
|
||
|
||
private final Context lambdaContext; | ||
private final VPCLatticeV2RequestEvent event; | ||
|
||
//------------------------------------------------------------- | ||
// Implementation - SecurityContext | ||
//------------------------------------------------------------- | ||
@Override | ||
public Principal getUserPrincipal() { | ||
if (Objects.equals(getAuthenticationScheme(), AUTH_SCHEME_AWS_IAM)) { | ||
return () -> getEvent().getRequestContext().getIdentity().getPrincipal(); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean isUserInRole(String role) { | ||
return role.equals(event.getRequestContext().getIdentity().getPrincipal()); | ||
} | ||
|
||
@Override | ||
public boolean isSecure() { | ||
return getAuthenticationScheme() != null; | ||
} | ||
|
||
@Override | ||
public String getAuthenticationScheme() { | ||
if (Objects.equals(getEvent().getRequestContext().getIdentity().getType(), AUTH_SCHEME_AWS_IAM)) { | ||
return AUTH_SCHEME_AWS_IAM; | ||
} else { | ||
return null; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,7 +125,7 @@ public String format(ContainerRequestType servletRequest, ContainerResponseType | |
logLineBuilder.append(" "); | ||
logLineBuilder.append(servletRequest.getRequestURI()); | ||
logLineBuilder.append(" "); | ||
logLineBuilder.append(servletRequest.getProtocol()); | ||
//logLineBuilder.append(servletRequest.getProtocol()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is the reason for this change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no way to get the protocol from the lattice payload (confirmed with the VPC Lattice team), so I returned an UnsupportedOperationException which throws a nullpointerException on that line. Is it the right thing to return? or should we default to "HTTP/1.1" ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd default to HTTP as this is the only protocol supported anyway. |
||
logLineBuilder.append("\" "); | ||
|
||
// %>s | ||
|
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 know where it's coming from, but can we please not introduce Lombok to this project?
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.
Sure. Thanks