RousselTMLEARNING

DevOps

Delivering with GitHub Actions: GHCR, environments, OIDC and attestations

Building and deploying with GitHub Actions: publishing an image to GitHub Container Registry with GITHUB_TOKEN, environments and protection rules, approvals, OIDC to AWS, Azure and Google Cloud, provenance attestations and releases.

1. Building and publishing #

An image traced back to its commit.

The workflow #

From build to production
jobs:
  image:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write
      attestations: write
      id-token: write
    steps:
      - uses: actions/checkout@v7
      - uses: docker/login-action@v4
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - id: meta
        uses: docker/metadata-action@v6
        with:
          images: ghcr.io/${{ github.repository }}
          tags: type=sha
      - id: push
        uses: docker/build-push-action@v7
        with:
          push: true
          tags: ${{ steps.meta.outputs.tags }}
      - uses: actions/attest-build-provenance@v4
        with:
          subject-name: ghcr.io/${{ github.repository }}
          subject-digest: ${{ steps.push.outputs.digest }}
          push-to-registry: true
  production:
    needs: image
    runs-on: ubuntu-latest
    environment:
      name: production
      url: https://boutique.exemple.fr
    permissions:
      id-token: write
      contents: read
    steps:
      - uses: aws-actions/configure-aws-credentials@v5
        with:
          role-to-assume: arn:aws:iam::123456789012:role/shop-deployment
          aws-region: eu-west-3
      - run: ./deploy.sh ${{ needs.image.outputs.tag }}
  • GITHUB_TOKEN is a temporary token created for each run; its rights are set with permissions (here, writing packages).
  • A signed provenance attestation proves which workflow, on which commit, produced the image; it is verified with gh attestation verify.

2. Environments and OIDC #

Controlling who deploys and with which rights.

Environments #

Protection ruleEffect
Required reviewersthe job waits for approval from a designated person or team
Wait timerpause before deployment (1 to 43,200 minutes)
Deployment branchesonly some branches or tags can target the environment
Environment secretsonly available to jobs of that environment, after approval

With id-token: write, the job gets a GitHub-signed OIDC token that the cloud exchanges for temporary rights. The trust relationship specifies the repository and environment (repo:org/repo:environment:production): no key to store.

Best practice : Put production secrets in the production environment, never at repository level: they are then only exposed after approval.

Commands to know #

Commands to know
  • gh attestation verify oci://ghcr.io/org/boutique:sha-abc1234 --owner org : verify an image's provenance
  • gh run list --workflow deploy.yml : deployment history
  • gh release create v1.2.0 --generate-notes : create a release

Sources #

Checked in November 2026: CI/CD platforms change every month, check versions and plans in the vendor's documentation.

Related articles

GitHub Actions: concepts and how it works

Discover GitHub Actions: events, workflows, jobs, steps and actions, the Marketplace, hosted runners, minute …

Writing GitHub Actions workflows

Mastering workflow syntax: triggers and filters, jobs and needs, matrices, if conditions, contexts and expres…

GitHub Actions runners: hosted, self-hosted and ARC

Choosing where workflows run: hosted runners and images, larger runners, self-hosted runners (installation, l…

Keep learning

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!