Skip to content

Update and Improve the CDN Publishing Workflow#80

Open
cabutlermit wants to merge 4 commits into
mainfrom
update-cdn-publish
Open

Update and Improve the CDN Publishing Workflow#80
cabutlermit wants to merge 4 commits into
mainfrom
update-cdn-publish

Conversation

@cabutlermit
Copy link
Copy Markdown
Contributor

@cabutlermit cabutlermit commented Jun 1, 2026

Purpose and background context

Overview

  1. Update third party Actions dependencies to the latest versions.
  2. Address security concerns with the use of input values (mostly related to preventing injection attacks)
  3. Add validation steps to ensure that acceptable values are being passed to this shared workflow and fail early if there are problems
  4. Expand the capabilities of the workflow to support future repositories that might need to publish content to the CDN

The end result is a shared workflow that is backward compatible with the existing caller workflows from our "static site" repositories AND is ready to use for any future repositories that need to publish objects to paths in our CDN. It fails fast on invalid input values, has flexibility for both source paths (in the caller repository) and target paths (in the S3 bucket backing the CDN), waits until the cache invalidation is complete before finishing the workflow run, and has cleaner output to the Action summary page.

For more details about the CloudFront Distributions, see the Reference: CDN, CloudFront, Web Content document in Confluence.

Details

The actions/checkout and aws-actions/configure-aws-credentials are updated to the latest versions and their parameters are updated for clarity and security (e.g., no persisting git credentials after the initial checkout).

The whole workflow received a number of updates, from cleaning up and expanding the caller workflow inputs, to a new step to run through validation on a number of the inputs to ensure that the values are usable and if they are not, the workflow will fail fast. At the same time, the logic of the workflow was completely revamped to DRY out the code and move input & variable expansion from the run: blocks into env: blocks (this prevents injection attacks). Polling was added to the cache invalidation step to only let the workflow finish after the cache invalidation step is complete.

Knowing that this workflow will be used by future repositories to push content into the CDN, the whole concept of source & target for the aws s3 sync ... command was reworked from the old assumption that the source was always the root of the repository. Moving forward, this shared workflow expects SOURCE_PATH and TARGET_PATH input variables instead.

Finally, extra bits were added to the workflow to ensure that our existing caller workflows that still pass just the S3_URI value will still work as expected. Those caller workflows will eventually need to be updated, but for now, they will still work properly.

How can a reviewer manually see the effects of these changes?

During the development of these changes, the caller workflows from future-of-libraries-static and web-images-static were run to verify compatibility. Each of those repositories has a feature branch named test-publish-workflow that updates the dev-cdn-publish.yml workflow to point to this feature branch for the shared workflow.

A review can visit one of those two repositories, select the Actions tab, select the DEV Publish workflow, and manually run that workflow from the test-publish-workflow branch. That will call the shared workflow from this branch.

Includes new or updated dependencies?

YES: New versions of third-party Actions

Changes expectations for external applications?

NO: This is 100% backwards compatible for existing caller workflows

Code review

  • Code review best practices are documented here and you are encouraged to have a constructive dialogue with your reviewers about their preferences and expectations.

@qltysh
Copy link
Copy Markdown

qltysh Bot commented Jun 1, 2026

❌ 1 blocking issue (1 total)

Tool Category Rule Count
zizmor Vulnerability unpinned action reference 1

Comment thread .github/workflows/cdn-shared-publish.yml
Comment thread .github/workflows/cdn-shared-publish.yml

- name: Configure AWS Credentials
id: aws_credentials
uses: aws-actions/configure-aws-credentials@v6
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unpinned action reference [zizmor:zizmor/unpinned-uses]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't pin to SHAs, just to major versions.

Why these changes are being made:
This started as just a simple "update the version of third party
actions" and then turned into a refactor. The refactor cleans up the
logic and DRYs the code a bit and requires NO changes from any caller
workflow.

How this addresses that need:
* Update actions/checkout and aws-actions/configure-aws-credentials to
the most recent versions
* Clean up usage of environment variables in the various bash commands
throughout the workflow
* Add a "polling" step (using the `aws cloudfront wait` command) to
ensure that the cache invalidation completes before the workflow
finishes
Why these changes are being introduced:
The previous commit was a simple cleanup of the shared CDN publishing
workflow. This commit extends that work with a full refactor of the
workflow that remains compatible with our existing caller workflows
and sets the stage for future repositories that might need to publish
content to the CDN (in particular, the future work to publish the
NDE-tacos content to the CDN).

How this addresses that need:
* Create additional inputs to allow for more options for the the source
and target of the `aws s3 sync` command
* Update existing inputs with corrected "required" versus "optional"
and default values
* Update all the inputs with descriptions
* Add a "validation" step to ensure that some of the freeform inputs
are valid and fail the job quickly if they are not
* Refine the "environment" and "domain" verifications and set
environment variables with the correct combination of environment,
domain, S3 bucket name, and CloudFront domain name (this also allows
future caller workflows to not have to pass the bucket name when
calling this workflow)
* Using the new envrionment variables, simplify both the `aws s3 sync`
command and the cache invalidation command

Side effects of this change:
None

Relevant ticket(s):
* https://mitlibraries.atlassian.net/browse/NDE-96
Why these changes are being made:
Eventually, we will update the caller workflows, but for now we want
to ensure that the old caller workflows still work even with all the
changes to this shared workflow.

How these changes are implemented:
* Add a block to the validation step to parse the deprecated S3_URI
input to set "legacy" environment variables for later steps and set
a boolean to indicate if this workflow has been called by a legacy
caller workflow
* Update later steps with a conditional for the SOURCE_PATH variable
to set it correctly for legacy and non-legacy workflows

Side effects:
None.
@cabutlermit cabutlermit force-pushed the update-cdn-publish branch from adb854d to a14748c Compare June 1, 2026 14:35
Why these changes are being introduced:
First, we want to ensure that the only additional parameters supplied
by the caller workflow are `--include` and `--exclude` parameters.
Second, since we pass the parameters via an `env:` block, we have to
be extra careful with double-quotes (which are required by the
`aws s3 sync` command, but typically get stripped when expanded in a
bash script).

How these changes are implemented:
* Add a block to the validation step to throw an error if there is
any other parameter in the SYNC_PARAMS input outside of `--include` and
`--exclude`
* If the SYNC_PARAMS is valid, merge it together with the other stock
`--exclude` parameters and set one string in the GITHUB_ENV with the
full list of inclues and excludes
* Add the `eval` command to properly expand the `aws s3 sync` command
and preserve the double-quotes where they are required

Side effects:
None.
@cabutlermit cabutlermit force-pushed the update-cdn-publish branch from a14748c to 2a4e2ba Compare June 1, 2026 15:12
@cabutlermit cabutlermit marked this pull request as ready for review June 5, 2026 14:57
@cabutlermit cabutlermit requested review from a team as code owners June 5, 2026 14:57
Copy link
Copy Markdown

@tim-rix tim-rix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks OK to me

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

Successfully merging this pull request may close these issues.

2 participants