Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown

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-security owner 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.

Suggested change
.github/actions/container-image-metadata/ @PostHog/team-cloud-platform
.github/actions/container-image-metadata/ @PostHog/team-security

Copy link
Copy Markdown
Author

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. CODEOWNERS itself stays security-owned. If the security reviewers want a security approval kept for this directory, I'll drop the line.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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.

low supply chain (confidence 4/5)

Details

In GitHub CODEOWNERS the last matching pattern wins. That makes .github/actions/container-image-metadata/ @PostHog/team-cloud-platform (line 10) the only owner of that directory and replaces .github/ @PostHog/team-security (line 3) for every file under it. Lines 1-2 of the same file say why .github/ is security-owned: these actions run across the org. This action runs in each caller's build-and-push job, and the README requires that job to be logged in to the target registry first. Every step of the action can therefore read the caller's registry push credential (the docker login config), any cloud credentials an earlier step exported to the job environment, and the caller's GITHUB_TOKEN.

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 @PostHog/team-cloud-platform @PostHog/team-security on one line can still be merged with only a cloud-platform approval.

Impact — A malicious insider, or anyone holding a cloud-platform member's account, can merge a change to action.yml without security review. For example, a new run: step could send the docker config or AWS_* variables off the runner. The change reaches each caller at its next SHA bump. The caller's PR shows only a 40-character SHA change, so nobody re-reviews the action content there. Callers that pin @main would get it at merge. These controls still hold: code-owner approval from a cloud-platform member is still required, CODEOWNERS itself stays security-owned, and the org Semgrep rules (github-actions-curl-shell, github-actions-shell-injection) catch some exfiltration patterns. This diff opens no direct path to loss, so this is graded as a defence-in-depth gap.

Fix — To keep a security approval mandatory, drop line 10 and let the existing .github/ rule cover this directory. Make cloud-platform a requested reviewer by convention or through a ruleset's path-scoped required reviewers. Do not add both teams to the same CODEOWNERS line, because one approval from either team would satisfy it.

Agent-driven security review. I cannot see from the repository whether branch protection or rulesets on main enforce "Require review from Code Owners", or how large @PostHog/team-cloud-platform is and whether it has write access. If that team lacks write access, GitHub treats the owner as unknown and the directory may end up with no effective code owner, which would be worse.

Copy link
Copy Markdown
Author

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 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. CODEOWNERS itself stays security-owned, so changing this line later still needs security.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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

low supply chain (review control) (confidence 4/5)

Details

CODEOWNERS applies the last matching line. So .github/actions/container-image-metadata/ @PostHog/team-cloud-platform (.github/CODEOWNERS:10) replaces .github/ @PostHog/team-security (line 3) for every file in that directory. Security stops being a code owner of action.yml. This is the only path under .github/ that leaves security's ownership. The file's own header (lines 1-2) and AGENTS.md say this repo's actions are security-owned because the whole org runs them.

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 docker buildx imagetools create with that session, and the caller's checkout-persisted GITHUB_TOKEN is also in reach. Its annotations (org.opencontainers.image.revision) are the key for Kargo's promotion gate.

Impact — Once this merges, cloud-platform approval alone can land a change to action.yml. So can anyone holding a cloud-platform member's session or token. Examples: a step that tags an arbitrary digest as the ordered release alias, or one that reads ~/.docker/config.json or AWS credentials from the env. The change reaches callers at their next SHA bump, and the bump PR in the caller repo shows only a new SHA. The PR text frames this as a decision for security. That framing is not a control.

Controls that still hold: callers pin by SHA (the README uses @<sha>), and CODEOWNERS itself stays security-owned. I can't see from the repo whether branch protection enforces code-owner review. If @PostHog/team-cloud-platform lacks write access, GitHub ignores that owner, and line 10 then leaves the directory with no code owner at all.

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 main requires code-owner review, and whether the cloud-platform team has write access, cannot be seen from the repository.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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.

71 changes: 71 additions & 0 deletions .github/actions/container-image-metadata/README.md
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 }}
```
Loading