Skip to content
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

Cloudfront distribution ID not known when creating secret #71

Open
jvarghese01 opened this issue Oct 2, 2024 · 1 comment
Open

Cloudfront distribution ID not known when creating secret #71

jvarghese01 opened this issue Oct 2, 2024 · 1 comment

Comments

@jvarghese01
Copy link

One of the initials steps is to create a secret with a placeholder value. However, the secret name is:
"cloudfront/DISTRIBUTION_ID"
with DISTRIBUTION_ID to be substituted with the actual cloudfront distribution ID
doc: https://github.com/aws-samples/lambdaedge-openidconnect-samples/blob/master/docs/baseconfiguration.md

Previously the secret name was to be placed in a sm-key.txt file. Looks like this has changed and the secret is simply
"cloudfront/DISTRIBUTION_ID"

The code has been updated to look for this value. https://github.com/aws-samples/lambdaedge-openidconnect-samples/blob/master/src/js/auth.js#L241

However, the distribution_ID is not know when the secret is created. And, the secret ARN must be provided to deploy the stack (circular dependency).

Am I missing something?

@Gribbs
Copy link

Gribbs commented Nov 7, 2024

I'm using CDK and creating the secret and distribution in the same stack, so you can do something like this:

 this.websiteCFDistribution = new cloudfront.Distribution(
      this,
      "WebsiteCFDistribution",
      {
        defaultBehavior: {
          origin: new s3Origins.S3Origin(websiteBucket),
          viewerProtocolPolicy:
            cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
          cachePolicy: cloudfront.CachePolicy.CACHING_DISABLED,
          allowedMethods: cloudfront.AllowedMethods.ALLOW_GET_HEAD_OPTIONS,
          edgeLambdas: [
            {
              functionVersion: this.authFunction.currentVersion,
              eventType: cloudfront.LambdaEdgeEventType.VIEWER_REQUEST,
            },
          ],
        },
        certificate: props.certificate,
        defaultRootObject: "index.html",
        domainNames: [domains.webDomain, domains.wwwDomain],
      },
    );

    this.oidcSecret = new secretsmanager.Secret(this, "OidcSecret", {
      secretName: `cloudfront/${this.websiteCFDistribution.distributionId}`,
      secretStringValue: cdk.SecretValue.unsafePlainText(
        JSON.stringify({ config: "placeholder" }),
      ),
      description:
        "A secret containing the OIDC configuration. Please see https://github.com/aws-samples/lambdaedge-openidconnect-samples/blob/master/docs/baseconfiguration.md for further details",
    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants