-
Notifications
You must be signed in to change notification settings - Fork 876
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
CloudFrontUtilities : cannot specify wildcard (*) resource url for a custom policy #5577
Comments
Hello @catherinegrogan, Thank you for reporting the issue. After analyzing the scenario, I believe this to be more of a feature request than a bug in the Java SDK V2.
Code snippetpackage org.example;
import software.amazon.awssdk.services.cloudfront.CloudFrontUtilities;
import software.amazon.awssdk.services.cloudfront.model.CustomSignerRequest;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
public class Main {
public static void main(String[] args) throws Exception {
Path privateKeyPath = Paths.get("/Users/***/private_key.pem");
String keyPairId = "****";
String resourceUrl = "https://****.cloudfront.net";
Instant expirationDate = Instant.now().plus(7, ChronoUnit.DAYS);
CustomSignerRequest customSignerRequest = CustomSignerRequest.builder()
.privateKey(privateKeyPath)
.keyPairId(keyPairId)
.resourceUrl(null)
.expirationDate(expirationDate)
.build();
try {
String signedUrl = CloudFrontUtilities.create()
.getSignedUrlWithCustomPolicy(customSignerRequest)
.url();
System.out.println("Signed URL: " + signedUrl);
} catch (Exception e) {
System.out.println("Exception occurred: " + e.getMessage());
}
}
} By setting the I will further review this request with the Java SDK team and keep you posted. Regards, |
This issue is now closed. Comments on closed issues are hard for our team to see. |
Hi @catherinegrogan, I added support for configuring the Thanks, |
Describe the bug
When using the new CloudFrontUtilities class to sign resource urls, it is not possible to specify a wildcard resource URL policy ('*') as the
CustomSignerRequest.resourceUrl
is used for both the policy and the URL to be signed.The
SigningUtils.buildCustomPolicyForSignedUrl(...)
method which is called from theCloudFrontUtilities.getSignedUrlWithCustomPolicy(CustomSignerRequest request)
method does appear to cater for this by defaulting to the wildcard if the resourceUrl isNULL
BUT it is not possible to specify a null CustomSignerRequest.resourceUrl as this is also used for the URL to be signed.Expected Behavior
Should be able to specify a custom policy resourceUrl as the 'wildcard' (or any other policy required) whilst also specify the resourceUrl to be signed.
Current Behavior
Currently cannot specify a 'wildcard' resourceUrl for a custom policy separate to the URL to be signed.
Example:
When use a signed URL with primefaces '<p:graphicImage ... cache=false>' on a client page primefaces adds a '&pfdrid_c' paramter to the URL. Without the ability to specify a wildcard policy for the resource url then this enforces the primefaces parameter to be present in the URL when signing.
Reproduction Steps
For example:
As indicate above, the code does try to set the default wildcard for the custom policy if a NULL resourceUrl is specified.
However if try to do this then will get a NPE as this value is also used as the URL to be signed.
i.e. if you try this in a test then you will get a NPE exception.
So the code as it stands forces the URL to be signed to always be specified & does not enable a custom resource URL policy to be specified which is different to the URL to be signed.
Possible Solution
CustomSignedResource
parameter to enable the policy resource url to be specified in addition to the URL to be signed.OR
CustomSignedResource.resourceUrl
be specific to the custom policy & then add a new/separate parameter to theCloudFrontUtilities.create()
API callAdditional Information/Context
No response
AWS Java SDK version used
2.27.19
JDK version used
openjdk version "17.0.8" 2023-07-18 LTS
Operating System and version
macOS Sonoma
The text was updated successfully, but these errors were encountered: