The proxy's two secrets — SESSION_SECRET (HMAC key for the session cookie) and
IMS_CLIENT_SECRET (the confidential DA service credential) — must not live
in the Lambda's plaintext environment (Adobe AWS Security Standard §3.5.8.5).
Instead, the target's env file — env.json for prod, env.stage.json for stage
(matching deploy.sh) — carries only non-secret ids, and the function
resolves the values at runtime from AWS Secrets Manager:
| Plain name | Env var (the id) | Secret it points at |
|---|---|---|
SESSION_SECRET |
SESSION_SECRET_ID |
spectrum-hub/<target>/session-secret |
IMS_CLIENT_SECRET |
IMS_CLIENT_SECRET_ID |
spectrum-hub/<target>/ims-client-secret |
ORIGIN_AUTHENTICATION |
ORIGIN_AUTHENTICATION_ID |
spectrum-hub/<target>/origin-auth |
ORIGIN_AUTHENTICATION is the AEM origin token (hlx_…) for token-based Site
Authentication; it is only set on targets whose origin is locked (stage/aem.page
today). formatRequest in index.js sends it upstream as
Authorization: token <value>. Create/rotate it with
TARGET=stage ORIGIN_ONLY=1 ./set-secrets.sh. Media (*/media_*) bypasses the
Lambda, so the same token must also be set as an Authorization origin header on
the media CloudFront behavior — see README.md and
add-media-behavior.sh (ORIGIN_AUTHENTICATION=…).
On the first request on a cold container, lib/secrets.js
resolveSecrets() fetches each configured id (via the execution role) and
assigns the value onto process.env under the plain name, so the rest of the
code reads env.SESSION_SECRET / env.IMS_CLIENT_SECRET unchanged. It caches
for 10 minutes (rotation without redeploy), fails closed if a value can't be
resolved (anonymous / 500, never open), and is migration-safe: if a
*_SECRET_ID is unset it leaves any existing plaintext env[name] in place.
<target> is stage or prod, matching deploy.sh.
set-secrets.sh creates or rotates the secrets (and can
grant the IAM read permission). Values are passed to the AWS CLI via a private
temp file, never on the command line. It reads AWS_PROFILE / AWS_REGION from
deploy.env.
# Create/rotate BOTH secrets for stage: generates a new SESSION_SECRET,
# prompts (hidden) for the IMS client secret, and grants the role read access.
TARGET=stage GRANT_ROLE=1 ./set-secrets.shOther forms:
TARGET=stage SESSION_ONLY=1 ./set-secrets.sh # rotate only the session secret
TARGET=stage IMS_ONLY=1 ./set-secrets.sh # rotate only the IMS client secretTo supply values non-interactively (e.g. from your own secret store), set
SESSION_SECRET_VALUE / IMS_CLIENT_SECRET_VALUE in the environment first.
The script prints the exact *_SECRET_ID lines to add to that env file (env.json
for prod, env.stage.json for stage). Then wire them up and deploy (Option C below).
IAM changes are account-wide, so
GRANT_ROLE=1is opt-in. If you can't change IAM, run the script without it and have someone attach the policy from Option B.
- AWS Console → Secrets Manager → Store a new secret.
- Secret type: Other type of secret.
- Choose Plaintext and paste the raw value — just the value itself, not
JSON. For
SESSION_SECRET, generate a fresh 32-byte key locally, e.g.openssl rand -base64 32. ForIMS_CLIENT_SECRET, use the value from the Adobe Developer Console. - Encryption key: the default
aws/secretsmanageris fine. - Next → Secret name: use exactly
spectrum-hub/stage/session-secretandspectrum-hub/stage/ims-client-secret(stage), orspectrum-hub/prod/session-secretandspectrum-hub/prod/ims-client-secret(prod).
- Leave rotation disabled (the app re-reads on a 10-min TTL; rotate by storing a new value here). Next → Store.
To rotate later: open the secret → Retrieve secret value → Edit → paste the new value → Save. No redeploy needed; it propagates within ~10 min. For an immediate cutover (compromise), redeploy to force fresh cold starts.
-
Lambda → Functions →
spectrum-<target>-lambda-proxy→ Configuration → Permissions → open the Execution role link (opens IAM). -
Add permissions → Create inline policy → JSON, and paste (replace
<account>, andstage/prodto match):{ "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Action": "secretsmanager:GetSecretValue", "Resource": "arn:aws:secretsmanager:us-east-2:<account>:secret:spectrum-hub/stage/*" }] } -
Name it
website-lambda-secrets-read-<target>→ Create policy.
-
Edit the target's env file (
env.jsonfor prod,env.stage.jsonfor stage): remove the plaintextSESSION_SECRETandIMS_CLIENT_SECRETentries and add the ids:"SESSION_SECRET_ID": "spectrum-hub/stage/session-secret", "IMS_CLIENT_SECRET_ID": "spectrum-hub/stage/ims-client-secret",
Keep
IMS_CLIENT_ID,IMS_SCOPE,AEM_*,ALLOWED_ORIGINS,PUBLIC_HOST, etc.AWS_REGIONis provided by the Lambda runtime — do not add it. -
Deploy:
TARGET=stage ./deploy.sh
-
Verify: sign in on the site and confirm
POST /auth/sessionreturns 200 withSet-Cookie: spectrum_session, and private content shows. If a secret can't be resolved, the function's CloudWatch logs showwebsite-lambda: cannot resolve …and requests fall back to anonymous / 500 (never serving private content open).
- Store the new value (script:
TARGET=<t> SESSION_ONLY=1 ./set-secrets.shorIMS_ONLY=1; or Console → Edit). - Wait up to ~10 min (
SECRET_TTL_MS) — or redeploy for an immediate cutover. - Rotating
SESSION_SECRETinvalidates all existing session cookies (users must sign in again). RotatingIMS_CLIENT_SECRETrequires the new value to also be active in the Adobe Developer Console.