-
Notifications
You must be signed in to change notification settings - Fork 6
[ENG-3808] Add aws auth login #9
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
Conversation
87576eb
to
c4b2f44
Compare
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.
Greptile Overview
Summary
This PR implements AWS authentication support for the Infisical Java SDK, allowing users to authenticate using AWS credentials (explicit credentials or instance profile) through IAM-based authentication mechanisms. The implementation follows AWS SigV4 signing protocols to create properly signed STS GetCallerIdentity requests that can be verified by Infisical's backend.The changes introduce several key components:
- AwsAuthProvider - The core authentication provider that handles AWS credential signing using AWS SDK v2, creates signed STS requests, and properly encodes request parameters with Base64 encoding
- AwsAuthParameters - A data transfer object that wraps the AWS authentication parameters and provides conversion to the API input model
- AwsAuthLoginInput - The API input model containing the signed IAM request components (method, headers, body) along with identity validation
- AuthClient extension - Adds the new
AwsAuthLogin
method following the same pattern as existing LDAP authentication
The implementation maintains consistency with existing authentication methods in the codebase, using the same validation patterns, error handling approaches, and architectural design. New dependencies were added including AWS SDK auth, Jackson core for JSON processing, and upgraded Lombok version. The code includes comprehensive test coverage with deterministic testing capabilities through timestamp overrides.
Important Files Changed
Changed Files
Filename | Score | Overview |
---|---|---|
pom.xml |
2/5 | Added AWS SDK dependencies and upgraded Lombok but has version conflicts and duplicate SLF4J dependencies |
src/main/java/com/infisical/sdk/auth/AwsAuthProvider.java |
4/5 | Core AWS authentication provider implementing SigV4 signing with proper security practices |
src/main/java/com/infisical/sdk/models/AwsAuthParameters.java |
5/5 | Simple data transfer object for AWS auth parameters with clean conversion method |
src/main/java/com/infisical/sdk/resources/AuthClient.java |
4/5 | Added AWS authentication method following existing patterns consistently |
src/test/java/com/infisical/sdk/auth/AwsAuthProviderTest.java |
4/5 | Comprehensive test coverage for AWS authentication with deterministic validation |
src/main/java/com/infisical/sdk/models/AwsAuthLoginInput.java |
5/5 | API input model with proper validation following established patterns |
Confidence score: 3/5
- This PR introduces substantial new functionality with minimal risk to existing code but has dependency management issues that need resolution
- Score reflects well-structured AWS authentication implementation following established patterns, but lowered due to Maven dependency conflicts that could cause runtime issues
- Pay close attention to
pom.xml
for version conflicts and duplicate dependencies that need to be resolved before merge
Sequence Diagram
sequenceDiagram
participant User
participant AwsAuthProvider
participant AwsV4HttpSigner
participant InstanceProfileCredentialsProvider
participant AuthClient
participant ApiClient
participant InfisicalAPI as "Infisical API"
User->>AwsAuthProvider: "fromCredentials(region, credentials, sessionToken)"
AwsAuthProvider->>AwsV4HttpSigner: "create()"
AwsAuthProvider->>AwsAuthProvider: "encodeParameters(params)"
AwsAuthProvider->>AwsV4HttpSigner: "sign(signingRequest)"
AwsV4HttpSigner-->>AwsAuthProvider: "signedRequest"
AwsAuthProvider->>AwsAuthProvider: "Base64.encode(requestHeaders)"
AwsAuthProvider->>AwsAuthProvider: "Base64.encode(requestBody)"
AwsAuthProvider-->>User: "AwsAuthParameters"
alt Instance Profile Authentication
User->>AwsAuthProvider: "fromInstanceProfile()"
AwsAuthProvider->>InstanceProfileCredentialsProvider: "create()"
AwsAuthProvider->>InstanceProfileCredentialsProvider: "resolveCredentials()"
InstanceProfileCredentialsProvider-->>AwsAuthProvider: "AwsSessionCredentials"
AwsAuthProvider->>AwsAuthProvider: "fromCredentials(region, credentials, sessionToken)"
AwsAuthProvider-->>User: "AwsAuthParameters"
end
User->>AwsAuthParameters: "toLoginInput(identityId)"
AwsAuthParameters-->>User: "AwsAuthLoginInput"
User->>AuthClient: "AwsAuthLogin(AwsAuthLoginInput)"
AuthClient->>AwsAuthLoginInput: "validate()"
AwsAuthLoginInput-->>AuthClient: "validation result"
AuthClient->>ApiClient: "post(url, input, MachineIdentityCredential.class)"
ApiClient->>InfisicalAPI: "POST /api/v1/auth/aws-auth/login"
InfisicalAPI-->>ApiClient: "MachineIdentityCredential"
ApiClient-->>AuthClient: "credential"
AuthClient->>AuthClient: "onAuthenticate.accept(accessToken)"
AuthClient-->>User: "authentication complete"
Additional Comments (1)
-
pom.xml
, line 166 (link)syntax: Lombok version mismatch - annotation processor uses 1.18.30 but dependency uses 1.18.42. This could cause compilation issues.
6 files reviewed, 5 comments
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.
sdk.Auth()
.AwsAuthLogin(
AwsAuthProvider.builder()
.build()
.fromInstanceProfile()
.toLoginInput("361bda71-9a9b-4634-9206-0cbaab646799"));
I'm thinking if we may want to simplify this even further? For the Go, Node.js, Python, and other SDK's we just accept a plain identity ID without the need for specifying if you want to get the credentials from the instance profile.
Is it because we may want to add plain secret access key support in the future? If so, we could create an overloaded function for that if we have to in the future.
Curious what you think!
@DanielHougaard Yeah, I think an overload method with just one string parameter makes sense. Then it would be much easier, like this sdk.Auth().AwsAuthLogin("361bda71-9a9b-4634-9206-0cbaab646799") In most cases, credentials can be retrieved automatically in the AWS environment, so taking in just the identity id and let the default credential finding mechanism to do its job sounds like a reasonable design. The user still has a choice to feed manually crafted credentials if they choose to or need to. I can make a quick modification to make it works like that, just let me know. |
That would be great @fangpenlin! |
okay, done. let me update the doc to reflect that as well |
Trying it out! |
ref: https://linear.app/infisical/issue/ENG-3808/aws-auth-method-support-in-java-sdk
Steps to test it:
ssh -R 8080:localhost:8080 ec2-user@EC2HOSTNAME
java -jar sdk-3.0.0.jar -cp com.infisical.sdk.RetrieveEC2Credentials