I have had a difficult time determining what needs to be done with my CloudFront setup to be able to get my signed cookie setup working. I have carefully followed the steps and using a module with NodeJS to handle the cookie generation (https://github.com/jasonsims/aws-cloudfront-sign). With my current setup, cookies are being set for my application located at
beta.my-site.com
files.my-site.com
curl
localhost
Distribution Status: Deployed
Alternate Domain Names (CNAMEs): files.my-site.com, beta.my-site.com, *.my-site.com
SSL Certification: *.my-site.com (bjdsofjwpefsd4235)
Domain Name: uhr82459shfngbc.cloudfront.net
Custom SSL Client Support: SNI
Origin Domain Name: files-beta.s3.amazonaws.com
Restrict Bucket Access: Yes
Your Identities: access-identity-files-beta.s3.amazonaws.com
Viewer Protocol Policy: HTTPS Only
Allows HTTP Methods: GET, HEAD
Restrict Viewer Access: Yes
Trusted Signers: Self
beta.my-site.com CNAME server-beta.elasticbeanstalk.com
file.my-site.com A ALIAS uhr82459shfngbc.cloudfront.net
beta.my-site.com
files.my-site.com
var express = require('express');
var router = express.Router();
var passport = require('passport');
var crypto = require('crypto');
var moment = require('moment');
var path = require('path');
var fs = require('fs');
var cf = require('aws-cloudfront-sign');
var metaTags = require('./meta-routes');
var cfPK = fs.readFileSync(path.join(__dirname + /config/pk-UHANFBYH54248.pem));
var cfOptions = {
keypairId: 'E5YGBKNfsdfds472',
privateKeyString: cfPK
}
var signedCookies = cf.getSignedCookies('https://files.my-site.com/*', cfOptions);
function isLoggedIn(req, res, next) {
if (req.isAuthenticated())
for(var cookieId in signedCookies) {
res.cookie(cookieId, signedCookies[cookieId]);
}
return next();
res.redirect('/login');
}
The biggest issue has to do with the N/A
value in the domain attribute of my Cloudfront Request Cookies. In order to pass the cookies from the parent domain to the subdomain, this attribute needs to have the value of the hostname.