Repository navigation
feat(ci): add container image metadata action #87
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
base: main
Are you sure you want to change the base?
Changes from all commits
0a9a9ec
b8d8a9b
de7e165
9a79a34
296d247
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,3 +5,6 @@ workflows/ @PostHog/team-security | |
|
|
||
| # we explicitly want this Action to be owned by security, even if the above rules are removed | ||
| .github/workflows/ci-security.yaml @PostHog/team-security | ||
|
|
||
| # the cloud platform team maintains the container image metadata action | ||
| .github/actions/container-image-metadata/ @PostHog/team-cloud-platform | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new CODEOWNERS line removes @PostHog/team-security as a required reviewer for an org-wide action that runs inside service image-push jobs.DetailsIn GitHub CODEOWNERS the last matching pattern wins. That makes The PR offers to "add the team to the line" if security wants to co-own the directory. That would not restore the requirement. When one line lists several owners, an approval from any one of them satisfies code-owner review, so Impact — A malicious insider, or anyone holding a cloud-platform member's account, can merge a change to Fix — To keep a security approval mandatory, drop line 10 and let the existing Agent-driven security review. I cannot see from the repository whether branch protection or rulesets on
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is intended. The cloud platform team maintains this action and should be able to change it without a security approval. Giving the directory to that team is the one decision this PR asks the security reviewers to make, and the description calls it out. You're right that listing both teams on one line would not keep a security approval required, since either team's approval would satisfy it. I've corrected the description, which had offered that. If the security reviewers want the requirement kept, I'll drop the line. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new CODEOWNERS rule removes @PostHog/team-security as code owner of an org-wide composite action that callers run after their registry login
DetailsCODEOWNERS applies the last matching line. So This action is built to run in each service's image build and publish job. Its README requires the job to be logged in to the registry. The second invocation runs Impact — Once this merges, cloud-platform approval alone can land a change to Controls that still hold: callers pin by SHA (the README uses Fix — Drop line 10. Security stays the required owner, and cloud-platform can still be requested as reviewers. As the PR notes, listing both teams on one line lets either team approve alone, so that does not restore the control. If shared ownership is wanted, require a security approval for this path some other way, for example a ruleset with a path-scoped required reviewer. Agent-driven security review. Whether the branch protection or ruleset on
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same finding as the earlier thread on this line, see my reply there: this is intended, and it is the decision this PR asks the security reviewers to make. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| # Container image metadata | ||
|
|
||
| Tags, labels and OCI provenance annotations for a service container build: the deploy-pipeline contract consumed by Kargo. Every service that promotes through Kargo stamps identical provenance: the standard `org.opencontainers.image.*` set plus commit author, committer, subject and committer timestamp, emitted as **index-level** OCI annotations. ASCII control characters in the commit subject, author and committer are replaced with spaces, each `{{` is separated into `{ {`, and a space is put between a comma and a double quote that directly follows it, so in those cases the annotation values and the `commit-subject`, `commit-author` and `commit-committer` outputs differ from the commit. Kargo's freight discovery reads only OCI annotations (image labels are invisible to it), and without a platform constraint it surfaces only the index level. Kargo warehouses key their commit-order freight gate on `org.opencontainers.image.revision`, so the annotation keys are a contract: don't fork this per repo. | ||
|
|
||
| ## Usage | ||
|
|
||
| Run after `actions/checkout`. The job must be logged in to the target registry, with a login step or equivalent, before the build and push in both examples below. Feed all three outputs to `docker/build-push-action`. Forgetting `annotations` silently drops the provenance. | ||
|
|
||
| The annotations are index-level, so the pushed image must be an OCI image index. Multi-platform builds with BuildKit's default provenance attestations already produce one. | ||
|
|
||
| ```yaml | ||
| steps: | ||
| - uses: actions/checkout@<sha> | ||
| - name: Image metadata | ||
| id: meta | ||
| uses: PostHog/.github/.github/actions/container-image-metadata@<sha> | ||
| with: | ||
| images: registry.example.com/my-service | ||
| # The contract tag (immutable sha-<gitsha>) is fixed; anything else is | ||
| # opt-in and additive. No latest by default: it fails on immutable | ||
| # ECR repos and nothing in the deploy pipeline reads it. | ||
| # extra-tags: type=raw,value=latest,enable={{is_default_branch}} | ||
| - name: Build and push | ||
| uses: docker/build-push-action@<sha> | ||
| with: | ||
| push: true | ||
| tags: ${{ steps.meta.outputs.tags }} | ||
| labels: ${{ steps.meta.outputs.labels }} | ||
| annotations: ${{ steps.meta.outputs.annotations }} | ||
| ``` | ||
|
|
||
| ## Ordered release alias | ||
|
|
||
| Ordered release aliases require two invocations of the action. The first invocation computes the ordered tag before the image build. The second invocation publishes that tag after the build returns its digest. | ||
|
|
||
| Ordered tag generation and publication need: | ||
|
|
||
| - A `push` or `workflow_dispatch` event on the repository's default branch. The ref must match the default branch exactly, letter case included. On any other event or ref, schedules included, generation and publication are skipped: `ordered-release-tag` is empty and no alias is published. The standard tags, labels and annotations are still produced. | ||
| - A checkout of the triggering revision (`GITHUB_SHA`) before the action. If another revision is checked out, no ordered tag is generated. | ||
| - A runner whose `timeout` supports `--kill-after`, as GNU coreutils and uutils coreutils on Ubuntu GitHub-hosted runners do. | ||
|
|
||
| Today a failure in generation or publication does not fail the job. Generation logs a warning and leaves `ordered-release-tag` empty. Publication reports a warning or an error annotation. Read the second invocation's `ordered-release-result` output (`steps.alias.outputs.ordered-release-result` in the example) for the outcome: `present-at-expected-digest`, `absent`, `integrity-mismatch` or `unknown`. It is empty when publication did not run, for example because no ordered tag was generated. When an ordered tag is passed, invalid publication inputs do fail the job: an `images` value that is not exactly one repository in registry/name form, a malformed tag, a missing or malformed digest, or a tag that does not match the revision. | ||
|
|
||
| ```yaml | ||
| env: | ||
| IMAGE_REPOSITORY: registry.example.com/my-service | ||
| steps: | ||
| - uses: actions/checkout@<sha> | ||
| - name: Image metadata and ordered release tag | ||
| id: meta | ||
| uses: PostHog/.github/.github/actions/container-image-metadata@<sha> | ||
| with: | ||
| images: ${{ env.IMAGE_REPOSITORY }} | ||
| generate-ordered-release-tag: "true" | ||
| - name: Build and push | ||
| id: image | ||
| uses: docker/build-push-action@<sha> | ||
| with: | ||
| push: true | ||
| tags: ${{ steps.meta.outputs.tags }} | ||
| labels: ${{ steps.meta.outputs.labels }} | ||
| annotations: ${{ steps.meta.outputs.annotations }} | ||
| - name: Publish ordered release alias | ||
| id: alias | ||
| uses: PostHog/.github/.github/actions/container-image-metadata@<sha> | ||
| with: | ||
| images: ${{ env.IMAGE_REPOSITORY }} | ||
| publish-ordered-release-tag: "true" | ||
| ordered-release-tag: ${{ steps.meta.outputs.ordered-release-tag }} | ||
| ordered-release-digest: ${{ steps.image.outputs.digest }} | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Medium: Security ownership is overridden
CODEOWNERS applies only the last matching pattern, so this replaces the broader
team-securityowner rather than adding maintenance ownership, allowing future changes to executable shared CI code without security-owner approval. Retain security ownership and request cloud-platform review separately; listing both teams here would still permit either team's approval.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is intended: the cloud platform team maintains this action, and giving it the directory is the decision this PR asks the security reviewers to make.
CODEOWNERSitself stays security-owned. If the security reviewers want a security approval kept for this directory, I'll drop the line.