├── .chainguard
└── source.yaml
├── .github
├── chainguard
│ └── verify-prod.sts.yaml
├── dependabot.yaml
├── testdata
│ └── backend_override.tf
└── workflows
│ ├── actionlint.yaml
│ ├── boilerplate.yaml
│ ├── deploy.yaml
│ ├── donotsubmit.yaml
│ ├── go-test.yaml
│ ├── style.yaml
│ └── terraform.yaml
├── .gitignore
├── .golangci.yml
├── LICENSE
├── README.md
├── cmd
├── app
│ └── main.go
├── negative-prober
│ └── main.go
├── prober
│ └── main.go
└── webhook
│ └── main.go
├── go.mod
├── go.sum
├── hack
└── boilerplate
│ ├── boilerplate.go.txt
│ ├── boilerplate.sh.txt
│ └── boilerplate.yaml.txt
├── iac
├── backend.tf
├── bootstrap
│ ├── backend.tf
│ ├── main.tf
│ ├── output.tf
│ ├── terraform.tfvars
│ └── variables.tf
├── broker.tf
├── gclb.tf
├── github_verify.tf
├── main.tf
├── prober.tf
├── sts_exchange.schema.json
├── terraform.tfvars
└── variables.tf
├── modules
└── app
│ ├── main.tf
│ ├── outputs.tf
│ ├── variables.tf
│ └── webhook.tf
└── pkg
├── envconfig
├── envconfig.go
└── envconfig_test.go
├── gcpkms
├── gcpkms.go
└── gcpkms_test.go
├── ghtransport
├── ghtransport.go
└── ghtransport_test.go
├── maxsize
├── maxsize.go
└── maxsize_test.go
├── octosts
├── event.go
├── octosts.go
├── octosts_test.go
├── revoke.go
├── testdata
│ └── org
│ │ ├── .github
│ │ ├── foo.sts.yaml
│ │ └── org-delegation.sts.yaml
│ │ └── repo
│ │ └── foo.sts.yaml
├── trust_policy.go
└── trust_policy_test.go
├── prober
└── prober.go
├── provider
└── provider.go
└── webhook
├── testdata
├── api
│ └── v3
│ │ └── repos
│ │ └── foo
│ │ └── bar
│ │ ├── compare
│ │ ├── 1234...5678
│ │ └── 9876...4321
│ │ └── contents
│ │ └── .github
│ │ └── chainguard
│ │ ├── test.sts.yaml
│ │ └── test2.sts.yaml
└── app
│ └── installations
│ └── 1111
│ └── access_tokens
├── webhook.go
└── webhook_test.go
/.chainguard/source.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2024 Chainguard, Inc
2 | # SPDX-License-Identifier: Apache-2.0
3 |
4 | spec:
5 | authorities:
6 | - keyless:
7 | url: https://fulcio.sigstore.dev
8 | identities:
9 | - subjectRegExp: .+@chainguard.dev$
10 | issuer: https://accounts.google.com
11 | ctlog:
12 | url: https://rekor.sigstore.dev
13 | - key:
14 | # Allow commits signed by Github (merge commits)
15 | kms: https://github.com/web-flow.gpg
16 |
--------------------------------------------------------------------------------
/.github/chainguard/verify-prod.sts.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2024 Chainguard, Inc.
2 | # SPDX-License-Identifier: Apache-2.0
3 |
4 | issuer: https://token.actions.githubusercontent.com
5 | subject: repo:octo-sts/app:pull_request
6 | claim_pattern:
7 | workflow_ref: octo-sts/app/.github/workflows/verify-prod.yaml@.*
8 |
9 | permissions:
10 | pull_requests: write
11 |
--------------------------------------------------------------------------------
/.github/dependabot.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2024 Chainguard, Inc.
2 | # SPDX-License-Identifier: Apache-2.0
3 |
4 | version: 2
5 | updates:
6 | - package-ecosystem: github-actions
7 | directory: "/"
8 | schedule:
9 | interval: "daily"
10 | groups:
11 | all:
12 | update-types:
13 | - "minor"
14 | - "patch"
15 |
16 | - package-ecosystem: gomod
17 | directory: "./"
18 | schedule:
19 | interval: "daily"
20 | groups:
21 | all:
22 | update-types:
23 | - "patch"
24 |
25 | - package-ecosystem: terraform
26 | directories:
27 | - "/iac"
28 | - "/iac/bootstrap"
29 | - "/modules/app"
30 | schedule:
31 | interval: "daily"
32 | groups:
33 | all:
34 | update-types:
35 | - "patch"
36 |
--------------------------------------------------------------------------------
/.github/testdata/backend_override.tf:
--------------------------------------------------------------------------------
1 | terraform {
2 | backend "local" {
3 | path = "./.local-state"
4 | }
5 | required_providers {
6 | ko = { source = "ko-build/ko" }
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/.github/workflows/actionlint.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2024 Chainguard, Inc.
2 | # SPDX-License-Identifier: Apache-2.0
3 |
4 | name: Action Lint
5 |
6 | on:
7 | pull_request:
8 | branches:
9 | - 'main'
10 |
11 | permissions: {}
12 |
13 | jobs:
14 |
15 | action-lint:
16 | name: Action lint
17 | runs-on: ubuntu-latest
18 |
19 | permissions:
20 | contents: read
21 |
22 | steps:
23 | - name: Check out code
24 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
25 | with:
26 | persist-credentials: false
27 |
28 | - name: Find yamls
29 | id: get_yamls
30 | run: |
31 | yamls="$(find .github/workflows -name "*.y*ml" | grep -v dependabot. | xargs echo)"
32 | echo "files=${yamls}" >> "$GITHUB_OUTPUT"
33 |
34 | - name: Action lint
35 | uses: reviewdog/action-actionlint@a5524e1c19e62881d79c1f1b9b6f09f16356e281 # v1.65.2
36 | with:
37 | actionlint_flags: ${{ steps.get_yamls.outputs.files }}
38 |
--------------------------------------------------------------------------------
/.github/workflows/boilerplate.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2024 Chainguard, Inc.
2 | # SPDX-License-Identifier: Apache-2.0
3 |
4 | name: Boilerplate
5 |
6 | on:
7 | pull_request:
8 | branches:
9 | - 'main'
10 |
11 | permissions: {}
12 |
13 | jobs:
14 |
15 | check:
16 | permissions:
17 | contents: read
18 |
19 | name: Boilerplate Check
20 | runs-on: ubuntu-latest
21 | strategy:
22 | fail-fast: false # Keep running if one leg fails.
23 | matrix:
24 | extension:
25 | - go
26 | - sh
27 | - yaml
28 |
29 | # Map between extension and human-readable name.
30 | include:
31 | - extension: go
32 | language: Go
33 | - extension: sh
34 | language: Bash
35 | - extension: yaml
36 | language: YAML
37 |
38 | steps:
39 | - name: Check out code
40 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
41 | with:
42 | persist-credentials: false
43 |
44 | - uses: chainguard-dev/actions/boilerplate@ce51233d303aed2394a9976e7f5642fd2158f693 # v1.1.1
45 | with:
46 | extension: ${{ matrix.extension }}
47 | language: ${{ matrix.language }}
48 | exclude: pkg/webhook/testdata
49 |
--------------------------------------------------------------------------------
/.github/workflows/deploy.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2024 Chainguard, Inc.
2 | # SPDX-License-Identifier: Apache-2.0
3 |
4 | name: Deploy to Cloud Run
5 |
6 | on:
7 | push:
8 | branches:
9 | - "main"
10 | workflow_dispatch:
11 |
12 | concurrency: deploy
13 |
14 | permissions: {}
15 |
16 | jobs:
17 | deploy:
18 | runs-on: ubuntu-latest
19 |
20 | if: github.repository == 'octo-sts/app'
21 |
22 | permissions:
23 | contents: read # clone the repository contents
24 | id-token: write # federates with GCP
25 |
26 | steps:
27 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
28 | with:
29 | persist-credentials: false
30 |
31 | - uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
32 | with:
33 | go-version-file: './go.mod'
34 | check-latest: true
35 |
36 | - uses: google-github-actions/auth@ba79af03959ebeac9769e648f473a284504d9193 # v2.1.10
37 | id: auth
38 | with:
39 | token_format: 'access_token'
40 | project_id: 'octo-sts'
41 | workload_identity_provider: 'projects/96355665038/locations/global/workloadIdentityPools/github-pool/providers/github-provider'
42 | service_account: 'github-identity@octo-sts.iam.gserviceaccount.com'
43 |
44 | - uses: 'docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772' # v2
45 | with:
46 | username: 'oauth2accesstoken'
47 | password: '${{ steps.auth.outputs.access_token }}'
48 | registry: 'gcr.io'
49 |
50 | # Attempt to deploy the terraform configuration
51 | - uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v2.0.0
52 | with:
53 | terraform_version: 1.9
54 |
55 | - working-directory: ./iac
56 | run: |
57 | terraform init
58 |
59 | terraform plan
60 |
61 | terraform apply -auto-approve
62 |
63 | - uses: rtCamp/action-slack-notify@e31e87e03dd19038e411e38ae27cbad084a90661 # v2.3.3
64 | if: ${{ failure() }}
65 | env:
66 | SLACK_ICON: http://github.com/chainguard-dev.png?size=48
67 | SLACK_USERNAME: guardian
68 | SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
69 | SLACK_CHANNEL: 'octo-sts-alerts' # Use a channel
70 | SLACK_COLOR: '#8E1600'
71 | MSG_MINIMAL: 'true'
72 | SLACK_TITLE: Deploying OctoSTS to Cloud Run failed
73 | SLACK_MESSAGE: |
74 | For detailed logs: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
75 |
--------------------------------------------------------------------------------
/.github/workflows/donotsubmit.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2024 Chainguard, Inc.
2 | # SPDX-License-Identifier: Apache-2.0
3 |
4 | name: Do Not Submit
5 |
6 | on:
7 | pull_request:
8 | branches:
9 | - 'main'
10 |
11 | permissions: {}
12 |
13 | jobs:
14 |
15 | donotsubmit:
16 | name: Do Not Submit
17 | runs-on: ubuntu-latest
18 |
19 | permissions:
20 | contents: read
21 |
22 | steps:
23 | - name: Check out code
24 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
25 | with:
26 | persist-credentials: false
27 |
28 | - name: Do Not Submit
29 | uses: chainguard-dev/actions/donotsubmit@ce51233d303aed2394a9976e7f5642fd2158f693 # v1.1.1
30 |
--------------------------------------------------------------------------------
/.github/workflows/go-test.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2024 Chainguard, Inc.
2 | # SPDX-License-Identifier: Apache-2.0
3 |
4 | name: go-build-test
5 |
6 | on:
7 | pull_request:
8 | branches:
9 | - 'main'
10 | push:
11 | branches:
12 | - 'main'
13 |
14 | permissions: {}
15 |
16 | jobs:
17 |
18 | go-build-test:
19 | runs-on: ubuntu-latest
20 |
21 | permissions:
22 | contents: read
23 |
24 | steps:
25 | - name: Check out code onto GOPATH
26 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
27 | with:
28 | persist-credentials: false
29 |
30 | - name: Set up Go
31 | uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
32 | with:
33 | go-version-file: './go.mod'
34 | check-latest: true
35 |
36 | - name: build
37 | run: |
38 | go build -o octo-sts ./cmd/app
39 |
40 | - name: test
41 | run: |
42 | # Exclude running unit tests against third_party repos.
43 | go test -v -race ./...
44 |
--------------------------------------------------------------------------------
/.github/workflows/style.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2024 Chainguard, Inc.
2 | # SPDX-License-Identifier: Apache-2.0
3 |
4 | name: Code Style
5 |
6 | on:
7 | pull_request:
8 | branches:
9 | - 'main'
10 | push:
11 | branches:
12 | - 'main'
13 |
14 | permissions: {}
15 |
16 | jobs:
17 |
18 | gofmt:
19 | name: check gofmt
20 | runs-on: ubuntu-latest
21 |
22 | permissions:
23 | contents: read
24 |
25 | steps:
26 | - name: Check out code
27 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
28 | with:
29 | persist-credentials: false
30 |
31 | - name: Set up Go
32 | uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
33 | with:
34 | go-version-file: './go.mod'
35 | check-latest: true
36 |
37 | - uses: chainguard-dev/actions/gofmt@main
38 | with:
39 | args: -s
40 |
41 | goimports:
42 | name: check goimports
43 | runs-on: ubuntu-latest
44 |
45 | permissions:
46 | contents: read
47 |
48 | steps:
49 | - name: Check out code
50 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
51 | with:
52 | persist-credentials: false
53 |
54 | - name: Set up Go
55 | uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
56 | with:
57 | go-version-file: './go.mod'
58 | check-latest: true
59 |
60 | - uses: chainguard-dev/actions/goimports@ce51233d303aed2394a9976e7f5642fd2158f693 # v1.1.1
61 |
62 | golangci-lint:
63 | name: golangci-lint
64 | runs-on: ubuntu-latest
65 |
66 | permissions:
67 | contents: read
68 |
69 | steps:
70 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
71 | with:
72 | persist-credentials: false
73 |
74 | - name: Set up Go
75 | uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
76 | with:
77 | go-version-file: './go.mod'
78 | check-latest: true
79 |
80 | - name: golangci-lint
81 | uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
82 | with:
83 | version: v2.1
84 |
85 | lint:
86 | name: Lint
87 | runs-on: ubuntu-latest
88 |
89 | permissions:
90 | contents: read
91 |
92 | steps:
93 | - name: Check out code
94 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
95 | with:
96 | persist-credentials: false
97 |
98 | - name: Set up Go
99 | uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
100 | with:
101 | go-version-file: './go.mod'
102 | check-latest: true
103 |
104 | - uses: chainguard-dev/actions/trailing-space@ce51233d303aed2394a9976e7f5642fd2158f693 # v1.1.1
105 | if: ${{ always() }}
106 |
107 | - uses: chainguard-dev/actions/eof-newline@ce51233d303aed2394a9976e7f5642fd2158f693 # v1.1.1
108 | if: ${{ always() }}
109 |
110 | - uses: reviewdog/action-tflint@92ecd5bdf3d31ada4ac26a702666986f67385fda # master
111 | if: ${{ always() }}
112 | with:
113 | github_token: ${{ secrets.github_token }}
114 | fail_level: warning
115 |
116 | - uses: reviewdog/action-misspell@9daa94af4357dddb6fd3775de806bc0a8e98d3e4 # v1.26.3
117 | if: ${{ always() }}
118 | with:
119 | github_token: ${{ secrets.github_token }}
120 | fail_level: warning
121 | locale: "US"
122 | exclude: |
123 | **/go.sum
124 | **/third_party/**
125 | ./*.yml
126 |
127 | - uses: get-woke/woke-action-reviewdog@d71fd0115146a01c3181439ce714e21a69d75e31 # v0
128 | if: ${{ always() }}
129 | with:
130 | github-token: ${{ secrets.github_token }}
131 | reporter: github-pr-check
132 | level: error
133 | fail-on-error: true
134 |
--------------------------------------------------------------------------------
/.github/workflows/terraform.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2024 Chainguard, Inc.
2 | # SPDX-License-Identifier: Apache-2.0
3 |
4 | name: terraform-lint-validate
5 |
6 | on:
7 | push:
8 | branches:
9 | - main
10 | pull_request:
11 | branches:
12 | - main
13 |
14 | permissions: {}
15 |
16 | jobs:
17 | terraform-lint-validate:
18 | runs-on: ubuntu-latest
19 |
20 | permissions:
21 | contents: read
22 |
23 | strategy:
24 | matrix:
25 | terraform-dir:
26 | - ./iac/bootstrap
27 | - ./iac
28 |
29 | steps:
30 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
31 | with:
32 | persist-credentials: false
33 |
34 | - uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
35 | with:
36 | terraform_version: 1.9
37 |
38 | - run: terraform fmt -check
39 |
40 | - run: cp "$GITHUB_WORKSPACE/.github/testdata/backend_override.tf" "$GITHUB_WORKSPACE/${{ matrix.terraform-dir }}"
41 | - working-directory: ${{ matrix.terraform-dir }}
42 | run: |
43 | terraform init
44 | terraform validate
45 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # If you prefer the allow list template instead of the deny list, see community template:
2 | # https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
3 | #
4 | # Binaries for programs and plugins
5 | *.exe
6 | *.exe~
7 | *.dll
8 | *.so
9 | *.dylib
10 |
11 | # Test binary, built with `go test -c`
12 | *.test
13 |
14 | # Output of the go coverage tool, specifically when used with LiteIDE
15 | *.out
16 |
17 | # Dependency directories (remove the comment below to include it)
18 | # vendor/
19 |
20 | # Go workspace file
21 | go.work
22 |
23 | # Terraform generated
24 | .terraform/
25 | terraform.tfstate
26 | terraform.tfstate.backup
27 | terraform.tfstate.*.backup
28 | .terraform.tfstate.lock.*
29 | .terraform.lock.hcl
30 | /octo-sts
31 |
--------------------------------------------------------------------------------
/.golangci.yml:
--------------------------------------------------------------------------------
1 | version: "2"
2 | run:
3 | issues-exit-code: 1
4 | linters:
5 | enable:
6 | - asciicheck
7 | - errorlint
8 | - gocritic
9 | - gosec
10 | - importas
11 | - misspell
12 | - prealloc
13 | - revive
14 | - staticcheck
15 | - tparallel
16 | - unconvert
17 | - unparam
18 | - whitespace
19 | settings:
20 | revive:
21 | rules:
22 | - name: dot-imports
23 | disabled: true
24 | exclusions:
25 | generated: lax
26 | presets:
27 | - comments
28 | - common-false-positives
29 | - legacy
30 | - std-error-handling
31 | rules:
32 | - linters:
33 | - errcheck
34 | - gosec
35 | path: _test\.go
36 | paths:
37 | - third_party$
38 | - builtin$
39 | - examples$
40 | issues:
41 | max-issues-per-linter: 0
42 | max-same-issues: 0
43 | uniq-by-line: false
44 | formatters:
45 | enable:
46 | - gofmt
47 | - goimports
48 | exclusions:
49 | generated: lax
50 | paths:
51 | - third_party$
52 | - builtin$
53 | - examples$
54 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # `octo-sts`: an STS for GitHub
2 |
3 | This repository holds a GitHub App called `octo-sts` that acts like a Security
4 | Token Service (STS) for the GitHub API. Using this App, workloads running
5 | essentially anywhere that can produce OIDC tokens can federate with this App's
6 | STS API in order to produce short-lived tokens for interacting with GitHub.
7 |
8 | **_The ultimate goal of this App is to wholly eliminate the need for GitHub
9 | Personal Access Tokens (aka PATs)._**
10 |
11 | The original [blog post](https://www.chainguard.dev/unchained/the-end-of-github-pats-you-cant-leak-what-you-dont-have).
12 |
13 | ## Setting up workload trust
14 |
15 | For the App to produce credentials that work with resources in your organization
16 | it must be installed into the organization and have access to any repositories
17 | that you will want workloads to be able to interact with. Unfortunately due to
18 | limitations with GitHub Apps, the App must ask for a superset of the permissions
19 | needed for federation, so the full set of permissions the App requests will be
20 | large, but with one exception (`contents: read` reading policy files) the App
21 | only creates tokens with these scopes based on the "trust policies" you have
22 | configured.
23 |
24 | ### The Trust Policy
25 |
26 | Trust policies are checked into `.github/chainguard/{name}.sts.yaml`, and
27 | consist of a few key parts:
28 |
29 | 1. The claim matching criteria for federation,
30 | 2. The permissions to grant the identity, and
31 | 3. (for Org-level policies) The list of repositories to grant access.
32 |
33 | Here is a simple example that allows the GitHub actions workflows in
34 | `chainguard-dev/foo` running on the `main` branch to read the repo contents and
35 | interact with issues:
36 |
37 | ```yaml
38 | issuer: https://token.actions.githubusercontent.com
39 | subject: repo:chainguard-dev/foo:ref:refs/heads/main
40 |
41 | permissions:
42 | contents: read
43 | issues: write
44 | ```
45 |
46 | The Trust Policy can also match the issuer, subject, and even custom claims with
47 | regular expressions. For example:
48 |
49 | ```yaml
50 | issuer: https://accounts.google.com
51 | subject_pattern: '[0-9]+'
52 | claim_pattern:
53 | email: '.*@chainguard.dev'
54 |
55 | permissions:
56 | contents: read
57 | ```
58 |
59 | This policy will allow OIDC tokens from Google accounts of folks with a
60 | Chainguard email address to federate and read the repo contents.
61 |
62 | ### Federating a token
63 |
64 | The GitHub App implements the Chainguard `SecurityTokenService` GRPC service
65 | definition [here](https://github.com/chainguard-dev/sdk/blob/main/proto/platform/oidc/v1/oidc.platform.proto#L13-L28).
66 |
67 | If a `${TOKEN}` suitable for federation is sent like so:
68 |
69 | ```
70 | curl -H "Authorization: Bearer ${TOKEN}" \
71 | "https://octo-sts.dev/sts/exchange?scope=${REPO}&identity=${NAME}"
72 | ```
73 |
74 | The App will attempt to load the trust policy from
75 | `.github/chainguard/${NAME}.sts.yaml` from `${REPO}` and if the provided `${TOKEN}`
76 | satisfies those rules, it will return a token with the permissions in the trust
77 | policy.
78 |
79 | ### Release cadence
80 |
81 | Our release cadence at this moment is set to when is needed, meaning if we have a bug fix or a new feature
82 | we will might make a new release.
83 |
84 | ### Best Practices
85 |
86 | To ensure secure and effective use of octo-sts, follow these recommended practices:
87 |
88 | #### Repository Security
89 |
90 | - **Enable branch protection**: Configure branch protection rules on your main/default branch to prevent direct commits and require pull request reviews before merging changes. This prevents OctoSTS clients from bypassing security controls by directly merging changes to main without review.
91 |
92 | - **Restrict who can approve pull requests**: Limit pull request approval permissions to trusted team members or repository administrators.
93 |
94 | ### Trust Policy Management
95 |
96 | - **Principle of least privilege**: Grant only the minimum permissions necessary for your workloads to function. Start with read-only permissions and add write permissions only when required.
97 |
98 | - **Scope policies narrowly**: Create specific trust policies for different workloads rather than using broad, catch-all policies.
99 |
100 | - **Regular policy reviews**: Periodically review and audit your trust policies (`.github/chainguard/*.sts.yaml`) to ensure they still align with your security requirements.
101 |
102 | - **Use specific subject matching**: Prefer exact subject matches over broad patterns when possible. For example, use `repo:org/repo:ref:refs/heads/main` instead of `repo:org/repo:.*`.
103 |
104 | #### Token Management
105 |
106 | - **Rotate regularly**: While octo-sts tokens are short-lived, ensure your OIDC token sources (like GitHub Actions) are properly configured and rotated according to best practices.
107 |
108 | - **Secure OIDC token handling**: Ensure your workloads properly secure and handle OIDC tokens before exchanging them with octo-sts.
109 |
110 | ### Permission updates
111 |
112 | Sometimes we need to add or remove a GitHub Permission in order to add/remove permissions that will be include in the
113 | octo-sts token for the users. Due to the nature of GitHub Apps, OctoSTS must request all permissions it might need to use, even if you don't want to use them for your particular installation or policy.
114 |
115 | To avoid disruptions for the users, making them to review and approve the changes in the installed GitHub App we
116 | will apply permissions changes for the `octo-sts app` quarterly at any day during the quarter.
117 |
118 | An issue will be created to explain what permissions is being added or removed.
119 |
120 | Special cases will be discussed in a GitHub issue in https://github.com/octo-sts/app/issues and we might apply more than
121 | one change during the quarter.
122 |
123 | ### Octo-STS GitHub Permissions
124 |
125 | The following permissions are the currently enabled in octo-Sts and will be available when installing the GitHub APP
126 |
127 | #### Repository Permissions
128 |
129 | - **Actions**: `Read/Write`
130 | - **Administration** : `Read-only`
131 | - **Attestations**: `No Access`
132 | - **Checks**: `Read/Write`
133 | - **Code Scanning Alerts**: `Read/Write`
134 | - **Codespaces**: `No Access`
135 | - **Codespaces lifecycle admin**: `No Access`
136 | - **Codespaces metadata**: `No Access`
137 | - **Codespaces secrets**: `No Access`
138 | - **Commit statuses**: `Read/Write`
139 | - **Contents**: `Read/Write`
140 | - **Custom properties**: `No Access`
141 | - **Dependabot alerts**: `No Access`
142 | - **Dependabot secrets**: `No Access`
143 | - **Deployments**: `Read/Write`
144 | - **Discussions**: `Read/Write`
145 | - **Environments**: `Read/Write`
146 | - **Issues**: `Read/Write`
147 | - **Merge queues**: `No Access`
148 | - **Metadata (Mandatory)**: `Read-only`
149 | - **Packages**: `Read/Write`
150 | - **Pages**: `No Access`
151 | - **Projects**: `Read/Write`
152 | - **Pull requests**: `Read/Write`
153 | - **Repository security advisories**: `No Access`
154 | - **Secret scanning alerts**: `No Access`
155 | - **Secrets**: `No Access`
156 | - **Single file**: `No Access`
157 | - **Variables**: `No Access`
158 | - **Webhooks**: `No Access`
159 | - **Workflows**: `Read/Write`
160 |
161 | #### Organization Permissions
162 |
163 | - **API Insights**: `No Access`
164 | - **Administration**: `Read-only`
165 | - **Blocking users**: `No Access`
166 | - **Custom organizations roles**: `No Access`
167 | - **Custom properties**: `No Access`
168 | - **Custom repository roles**: `No Access`
169 | - **Events**: `Read-only`
170 | - **GitHub Copilot Business**: `No Access`
171 | - **Knowledge bases**: `No Access`
172 | - **Members**: `Read/Write`
173 | - **Organization codespaces**: `No Access`
174 | - **Organization codespaces secrets**: `No Access`
175 | - **Organization codespaces settings**: `No Access`
176 | - **Organization dependabot secrets**: `No Access`
177 | - **Personal access token requests**: `No Access`
178 | - **Personal access tokens**: `No Access`
179 | - **Plan**: `No Access`
180 | - **Projects**: `Read/Write`
181 | - **Secrets**: `No Access`
182 | - **Self-hosted runners**: `No Access`
183 | - **Team discussions**: `No Access`
184 | - **Variables**: `No Access`
185 | - **Webhooks**: `No Access`
186 |
187 | #### Account Permissions:
188 |
189 | - **Block another user**: `No Access`
190 | - **Codespaces user secrets**: `No Access`
191 | - **Copilot Chat**: `No Access`
192 | - **Email addresses**: `No Access`
193 | - **Events**: `No Access`
194 | - **Followers**: `No Access`
195 | - **GPG keys**: `No Access`
196 | - **Gists**: `No Access`
197 | - **Git SSH keys**: `No Access`
198 | - **Interaction limits**: `No Access`
199 | - **Plan**: `No Access`
200 | - **Profile**: `No Access`
201 | - **SSH signing keys**: `No Access`
202 | - **Starring**: `No Access`
203 | - **Watching**: `No Access`
204 |
--------------------------------------------------------------------------------
/cmd/app/main.go:
--------------------------------------------------------------------------------
1 | // Copyright 2024 Chainguard, Inc.
2 | // SPDX-License-Identifier: Apache-2.0
3 |
4 | package main
5 |
6 | import (
7 | "context"
8 | "log"
9 | "log/slog"
10 | "net/http"
11 | "os"
12 | "os/signal"
13 |
14 | "chainguard.dev/go-grpc-kit/pkg/duplex"
15 | pboidc "chainguard.dev/sdk/proto/platform/oidc/v1"
16 | kms "cloud.google.com/go/kms/apiv1"
17 | "github.com/chainguard-dev/clog"
18 | metrics "github.com/chainguard-dev/terraform-infra-common/pkg/httpmetrics"
19 | mce "github.com/chainguard-dev/terraform-infra-common/pkg/httpmetrics/cloudevents"
20 | envConfig "github.com/octo-sts/app/pkg/envconfig"
21 | "github.com/octo-sts/app/pkg/ghtransport"
22 | "github.com/octo-sts/app/pkg/octosts"
23 | "google.golang.org/grpc"
24 | "google.golang.org/grpc/credentials/insecure"
25 | )
26 |
27 | func main() {
28 | ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
29 | defer cancel()
30 | ctx = clog.WithLogger(ctx, clog.New(slog.Default().Handler()))
31 |
32 | baseCfg, err := envConfig.BaseConfig()
33 | if err != nil {
34 | log.Panicf("failed to process env var: %s", err)
35 | }
36 | appConfig, err := envConfig.AppConfig()
37 | if err != nil {
38 | log.Panicf("failed to process env var: %s", err)
39 | }
40 |
41 | if baseCfg.Metrics {
42 | go metrics.ServeMetrics()
43 |
44 | // Setup tracing.
45 | defer metrics.SetupTracer(ctx)()
46 | }
47 |
48 | var client *kms.KeyManagementClient
49 |
50 | if baseCfg.KMSKey != "" {
51 | client, err = kms.NewKeyManagementClient(ctx)
52 | if err != nil {
53 | log.Panicf("could not create kms client: %v", err)
54 | }
55 | }
56 |
57 | atr, err := ghtransport.New(ctx, baseCfg, client)
58 | if err != nil {
59 | log.Panicf("error creating GitHub App transport: %v", err)
60 | }
61 |
62 | d := duplex.New(
63 | baseCfg.Port,
64 | // grpc.StatsHandler(otelgrpc.NewServerHandler()),
65 | // grpc.ChainStreamInterceptor(grpc_prometheus.StreamServerInterceptor),
66 | // grpc.ChainUnaryInterceptor(grpc_prometheus.UnaryServerInterceptor, interceptors.ServerErrorInterceptor),
67 | grpc.WithTransportCredentials(insecure.NewCredentials()),
68 | )
69 |
70 | ceclient, err := mce.NewClientHTTP("octo-sts", mce.WithTarget(ctx, appConfig.EventingIngress)...)
71 | if err != nil {
72 | log.Panicf("failed to create cloudevents client: %v", err)
73 | }
74 |
75 | pboidc.RegisterSecurityTokenServiceServer(d.Server, octosts.NewSecurityTokenServiceServer(atr, ceclient, appConfig.Domain, baseCfg.Metrics))
76 | if err := d.RegisterHandler(ctx, pboidc.RegisterSecurityTokenServiceHandlerFromEndpoint); err != nil {
77 | log.Panicf("failed to register gateway endpoint: %v", err)
78 | }
79 |
80 | if err := d.MUX.HandlePath(http.MethodGet, "/", func(w http.ResponseWriter, r *http.Request, _ map[string]string) {
81 | w.Header().Set("Content-Type", "application/json")
82 | s := `{"msg": "please check documentation for usage: https://github.com/octo-sts/app"}`
83 | if _, err := w.Write([]byte(s)); err != nil {
84 | log.Printf("Failed to write bytes back to client: %v", err)
85 | http.Error(w, err.Error(), http.StatusInternalServerError)
86 | }
87 | }); err != nil {
88 | log.Panicf("failed to register root GET handler: %v", err)
89 | }
90 |
91 | if err := d.ListenAndServe(ctx); err != nil {
92 | log.Panicf("ListenAndServe() = %v", err)
93 | }
94 |
95 | // This will block until a signal arrives.
96 | <-ctx.Done()
97 | }
98 |
--------------------------------------------------------------------------------
/cmd/negative-prober/main.go:
--------------------------------------------------------------------------------
1 | // Copyright 2024 Chainguard, Inc.
2 | // SPDX-License-Identifier: Apache-2.0
3 |
4 | package main
5 |
6 | import (
7 | "context"
8 |
9 | "github.com/chainguard-dev/terraform-infra-common/pkg/prober"
10 |
11 | octoprober "github.com/octo-sts/app/pkg/prober"
12 | )
13 |
14 | func main() {
15 | ctx := context.Background()
16 | prober.Go(ctx, prober.Func(octoprober.Negative))
17 | }
18 |
--------------------------------------------------------------------------------
/cmd/prober/main.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2024 Chainguard, Inc.
3 | SPDX-License-Identifier: Apache-2.0
4 | */
5 |
6 | package main
7 |
8 | import (
9 | "context"
10 |
11 | "github.com/chainguard-dev/terraform-infra-common/pkg/prober"
12 |
13 | octoprober "github.com/octo-sts/app/pkg/prober"
14 | )
15 |
16 | func main() {
17 | ctx := context.Background()
18 | prober.Go(ctx, prober.Func(octoprober.Func))
19 | }
20 |
--------------------------------------------------------------------------------
/cmd/webhook/main.go:
--------------------------------------------------------------------------------
1 | // Copyright 2024 Chainguard, Inc.
2 | // SPDX-License-Identifier: Apache-2.0
3 |
4 | package main
5 |
6 | import (
7 | "context"
8 | "fmt"
9 | "log"
10 | "log/slog"
11 | "net/http"
12 | "os"
13 | "os/signal"
14 | "strings"
15 | "time"
16 |
17 | kms "cloud.google.com/go/kms/apiv1"
18 | secretmanager "cloud.google.com/go/secretmanager/apiv1"
19 | "cloud.google.com/go/secretmanager/apiv1/secretmanagerpb"
20 | "github.com/chainguard-dev/clog"
21 | metrics "github.com/chainguard-dev/terraform-infra-common/pkg/httpmetrics"
22 | envConfig "github.com/octo-sts/app/pkg/envconfig"
23 | "github.com/octo-sts/app/pkg/ghtransport"
24 | "github.com/octo-sts/app/pkg/webhook"
25 | )
26 |
27 | func main() {
28 | ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
29 | defer cancel()
30 | ctx = clog.WithLogger(ctx, clog.New(slog.Default().Handler()))
31 |
32 | baseCfg, err := envConfig.BaseConfig()
33 | if err != nil {
34 | log.Panicf("failed to process env var: %s", err)
35 | }
36 | webhookConfig, err := envConfig.WebhookConfig()
37 | if err != nil {
38 | log.Panicf("failed to process env var: %s", err)
39 | }
40 |
41 | if baseCfg.Metrics {
42 | go metrics.ServeMetrics()
43 |
44 | // Setup tracing.
45 | defer metrics.SetupTracer(ctx)()
46 | }
47 |
48 | var client *kms.KeyManagementClient
49 |
50 | if baseCfg.KMSKey != "" {
51 | client, err = kms.NewKeyManagementClient(ctx)
52 | if err != nil {
53 | log.Panicf("could not create kms client: %v", err)
54 | }
55 | }
56 |
57 | atr, err := ghtransport.New(ctx, baseCfg, client)
58 | if err != nil {
59 | log.Panicf("error creating GitHub App transport: %v", err)
60 | }
61 |
62 | // Fetch webhook secrets from secret manager
63 | // or allow webhook secret to be defined by env var.
64 | // Not everyone is using Google KMS, so we need to support other methods
65 | webhookSecrets := [][]byte{}
66 | if baseCfg.KMSKey != "" {
67 | secretmanager, err := secretmanager.NewClient(ctx)
68 | if err != nil {
69 | log.Panicf("could not create secret manager client: %v", err)
70 | }
71 | for _, name := range strings.Split(webhookConfig.WebhookSecret, ",") {
72 | resp, err := secretmanager.AccessSecretVersion(ctx, &secretmanagerpb.AccessSecretVersionRequest{
73 | Name: name,
74 | })
75 | if err != nil {
76 | log.Panicf("error fetching webhook secret %s: %v", name, err)
77 | }
78 | webhookSecrets = append(webhookSecrets, resp.GetPayload().GetData())
79 | }
80 | } else {
81 | webhookSecrets = [][]byte{[]byte(webhookConfig.WebhookSecret)}
82 | }
83 |
84 | var orgs []string
85 | for _, s := range strings.Split(webhookConfig.OrganizationFilter, ",") {
86 | if o := strings.TrimSpace(s); o != "" {
87 | orgs = append(orgs, o)
88 | }
89 | }
90 |
91 | mux := http.NewServeMux()
92 | mux.Handle("/", &webhook.Validator{
93 | Transport: atr,
94 | WebhookSecret: webhookSecrets,
95 | Organizations: orgs,
96 | })
97 | srv := &http.Server{
98 | Addr: fmt.Sprintf(":%d", baseCfg.Port),
99 | ReadHeaderTimeout: 10 * time.Second,
100 | Handler: mux,
101 | }
102 | log.Panic(srv.ListenAndServe())
103 | }
104 |
--------------------------------------------------------------------------------
/go.mod:
--------------------------------------------------------------------------------
1 | module github.com/octo-sts/app
2 |
3 | go 1.24.2
4 |
5 | require (
6 | chainguard.dev/go-grpc-kit v0.17.10
7 | chainguard.dev/sdk v0.1.33
8 | cloud.google.com/go/kms v1.22.0
9 | cloud.google.com/go/secretmanager v1.14.7
10 | github.com/bradleyfalzon/ghinstallation/v2 v2.15.0
11 | github.com/chainguard-dev/clog v1.7.0
12 | github.com/chainguard-dev/terraform-infra-common v0.6.149
13 | github.com/cloudevents/sdk-go/v2 v2.16.0
14 | github.com/coreos/go-oidc/v3 v3.14.1
15 | github.com/golang-jwt/jwt/v4 v4.5.2
16 | github.com/google/go-cmp v0.7.0
17 | github.com/google/go-github/v71 v71.0.0
18 | github.com/hashicorp/go-multierror v1.1.1
19 | github.com/hashicorp/golang-lru/v2 v2.0.7
20 | github.com/kelseyhightower/envconfig v1.4.0
21 | golang.org/x/oauth2 v0.30.0
22 | google.golang.org/api v0.235.0
23 | google.golang.org/grpc v1.72.2
24 | k8s.io/apimachinery v0.33.1
25 | sigs.k8s.io/yaml v1.4.0
26 | )
27 |
28 | require (
29 | cloud.google.com/go v0.121.0 // indirect
30 | cloud.google.com/go/longrunning v0.6.7 // indirect
31 | cloud.google.com/go/trace v1.11.6 // indirect
32 | github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.27.0 // indirect
33 | github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace v1.27.0 // indirect
34 | github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.51.0 // indirect
35 | github.com/cenkalti/backoff/v5 v5.0.2 // indirect
36 | github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
37 | github.com/ebitengine/purego v0.8.2 // indirect
38 | github.com/go-ole/go-ole v1.3.0 // indirect
39 | github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
40 | github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
41 | github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
42 | github.com/sethvargo/go-envconfig v1.3.0 // indirect
43 | github.com/shirou/gopsutil/v4 v4.25.4 // indirect
44 | github.com/yusufpapurcu/wmi v1.2.4 // indirect
45 | go.opentelemetry.io/auto/sdk v1.1.0 // indirect
46 | go.opentelemetry.io/contrib/detectors/gcp v1.36.0 // indirect
47 | gopkg.in/yaml.v3 v3.0.1 // indirect
48 | )
49 |
50 | require (
51 | cloud.google.com/go/auth v0.16.1 // indirect
52 | cloud.google.com/go/auth/oauth2adapt v0.2.8 // indirect
53 | cloud.google.com/go/compute/metadata v0.7.0 // indirect
54 | cloud.google.com/go/iam v1.5.2 // indirect
55 | github.com/beorn7/perks v1.0.1 // indirect
56 | github.com/cenkalti/backoff/v4 v4.3.0 // indirect
57 | github.com/cespare/xxhash/v2 v2.3.0 // indirect
58 | github.com/felixge/httpsnoop v1.0.4 // indirect
59 | github.com/go-jose/go-jose/v4 v4.1.0
60 | github.com/go-logr/logr v1.4.2 // indirect
61 | github.com/go-logr/stdr v1.2.2 // indirect
62 | github.com/google/go-querystring v1.1.0 // indirect
63 | github.com/google/s2a-go v0.1.9 // indirect
64 | github.com/google/uuid v1.6.0 // indirect
65 | github.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirect
66 | github.com/googleapis/gax-go/v2 v2.14.2 // indirect
67 | github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
68 | github.com/grpc-ecosystem/go-grpc-prometheus v1.2.1-0.20210315223345-82c243799c99 // indirect
69 | github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.3 // indirect
70 | github.com/hashicorp/errwrap v1.1.0 // indirect
71 | github.com/json-iterator/go v1.1.12 // indirect
72 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
73 | github.com/modern-go/reflect2 v1.0.2 // indirect
74 | github.com/prometheus/client_golang v1.22.0 // indirect
75 | github.com/prometheus/client_model v0.6.2 // indirect
76 | github.com/prometheus/common v0.63.0 // indirect
77 | github.com/prometheus/procfs v0.16.0 // indirect
78 | github.com/stretchr/testify v1.10.0
79 | go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.60.0 // indirect
80 | go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0 // indirect
81 | go.opentelemetry.io/otel v1.36.0 // indirect
82 | go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.36.0 // indirect
83 | go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.35.0 // indirect
84 | go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.36.0 // indirect
85 | go.opentelemetry.io/otel/metric v1.36.0 // indirect
86 | go.opentelemetry.io/otel/sdk v1.36.0 // indirect
87 | go.opentelemetry.io/otel/trace v1.36.0 // indirect
88 | go.opentelemetry.io/proto/otlp v1.6.0 // indirect
89 | go.uber.org/multierr v1.11.0 // indirect
90 | go.uber.org/zap v1.27.0 // indirect
91 | golang.org/x/crypto v0.38.0 // indirect
92 | golang.org/x/net v0.40.0 // indirect
93 | golang.org/x/sync v0.14.0 // indirect
94 | golang.org/x/sys v0.33.0 // indirect
95 | golang.org/x/text v0.25.0 // indirect
96 | golang.org/x/time v0.11.0 // indirect
97 | google.golang.org/genproto v0.0.0-20250505200425-f936aa4a68b2 // indirect
98 | google.golang.org/genproto/googleapis/api v0.0.0-20250519155744-55703ea1f237 // indirect
99 | google.golang.org/genproto/googleapis/rpc v0.0.0-20250519155744-55703ea1f237 // indirect
100 | google.golang.org/protobuf v1.36.6 // indirect
101 | )
102 |
--------------------------------------------------------------------------------
/hack/boilerplate/boilerplate.go.txt:
--------------------------------------------------------------------------------
1 | // Copyright 2024 Chainguard, Inc.
2 | // SPDX-License-Identifier: Apache-2.0
3 |
--------------------------------------------------------------------------------
/hack/boilerplate/boilerplate.sh.txt:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | # Copyright 2024 Chainguard, Inc.
4 | # SPDX-License-Identifier: Apache-2.0
5 |
--------------------------------------------------------------------------------
/hack/boilerplate/boilerplate.yaml.txt:
--------------------------------------------------------------------------------
1 | # Copyright 2024 Chainguard, Inc.
2 | # SPDX-License-Identifier: Apache-2.0
3 |
--------------------------------------------------------------------------------
/iac/backend.tf:
--------------------------------------------------------------------------------
1 | terraform {
2 | backend "gcs" {
3 | bucket = "octo-sts-terraform-state"
4 | prefix = "/octo-sts"
5 | }
6 | required_providers {
7 | ko = { source = "ko-build/ko" }
8 | cosign = { source = "chainguard-dev/cosign" }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/iac/bootstrap/backend.tf:
--------------------------------------------------------------------------------
1 | terraform {
2 | backend "gcs" {
3 | bucket = "octo-sts-terraform-state"
4 | prefix = "/bootstrap"
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/iac/bootstrap/main.tf:
--------------------------------------------------------------------------------
1 | provider "google" { project = var.project_id }
2 | provider "google-beta" { project = var.project_id }
3 |
4 | resource "google_project_service" "iamcredentials-api" {
5 | project = var.project_id
6 | service = "iamcredentials.googleapis.com"
7 | disable_dependent_services = false
8 | disable_on_destroy = false
9 | }
10 |
11 | data "google_monitoring_notification_channel" "notify-chainguard-slack" {
12 | display_name = "Slack Octo STS Notification"
13 | }
14 |
15 | locals {
16 | notification_channels = [
17 | data.google_monitoring_notification_channel.notify-chainguard-slack.name,
18 | ]
19 | }
20 |
21 | module "github-wif" {
22 | source = "chainguard-dev/common/infra//modules/github-wif-provider"
23 | version = "0.6.149"
24 |
25 | project_id = var.project_id
26 | name = "github-pool"
27 | github_org = "octo-sts"
28 |
29 | notification_channels = local.notification_channels
30 | }
31 |
32 | moved {
33 | from = google_iam_workload_identity_pool.github_pool
34 | to = module.github-wif.google_iam_workload_identity_pool.this
35 | }
36 |
37 | moved {
38 | from = google_iam_workload_identity_pool_provider.github_provider
39 | to = module.github-wif.google_iam_workload_identity_pool_provider.this
40 | }
41 |
42 | module "github_identity" {
43 | source = "chainguard-dev/common/infra//modules/github-gsa"
44 | version = "0.6.149"
45 |
46 | project_id = var.project_id
47 | name = "github-identity"
48 | wif-pool = module.github-wif.pool_name
49 |
50 | repository = "octo-sts/app"
51 | refspec = "refs/heads/main"
52 | workflow_ref = ".github/workflows/deploy.yaml"
53 |
54 | notification_channels = local.notification_channels
55 | }
56 |
57 | moved {
58 | from = google_service_account.github_identity
59 | to = module.github_identity.google_service_account.this
60 | }
61 |
62 |
63 | resource "google_project_iam_member" "github_owner" {
64 | project = var.project_id
65 | role = "roles/owner"
66 | member = "serviceAccount:${module.github_identity.email}"
67 | }
68 |
69 | module "github_pull_requests" {
70 | source = "chainguard-dev/common/infra//modules/github-gsa"
71 | version = "0.6.149"
72 |
73 | project_id = var.project_id
74 | name = "github-pull-requests"
75 | wif-pool = module.github-wif.pool_name
76 |
77 | repository = "octo-sts/app"
78 | refspec = "pull_request"
79 | workflow_ref = ".github/workflows/verify-prod.yaml"
80 |
81 | notification_channels = local.notification_channels
82 | }
83 |
84 | moved {
85 | from = google_service_account.github_pull_requests
86 | to = module.github_pull_requests.google_service_account.this
87 | }
88 |
89 | resource "google_project_iam_member" "github_viewer" {
90 | project = var.project_id
91 | role = "roles/viewer"
92 | member = "serviceAccount:${module.github_pull_requests.email}"
93 | }
94 |
95 | resource "google_project_iam_member" "github_iam_viewer" {
96 | project = var.project_id
97 | role = "roles/iam.securityReviewer"
98 | member = "serviceAccount:${module.github_pull_requests.email}"
99 | }
100 |
--------------------------------------------------------------------------------
/iac/bootstrap/output.tf:
--------------------------------------------------------------------------------
1 | output "pool" {
2 | value = module.github-wif.pool_name
3 | }
4 |
--------------------------------------------------------------------------------
/iac/bootstrap/terraform.tfvars:
--------------------------------------------------------------------------------
1 | project_id = "octo-sts"
2 |
--------------------------------------------------------------------------------
/iac/bootstrap/variables.tf:
--------------------------------------------------------------------------------
1 | variable "project_id" {
2 | description = "The project ID where all resources created will reside."
3 | }
4 |
--------------------------------------------------------------------------------
/iac/broker.tf:
--------------------------------------------------------------------------------
1 | // Create the Broker abstraction.
2 | module "cloudevent-broker" {
3 | source = "chainguard-dev/common/infra//modules/cloudevent-broker"
4 | version = "0.6.149"
5 |
6 | name = "octo-sts-broker"
7 | project_id = var.project_id
8 | regions = module.networking.regional-networks
9 |
10 | notification_channels = local.notification_channels
11 | }
12 |
13 | data "google_client_openid_userinfo" "me" {}
14 |
15 | module "cloudevent-recorder" {
16 | source = "chainguard-dev/common/infra//modules/cloudevent-recorder"
17 | version = "0.6.149"
18 |
19 | name = "octo-sts-recorder"
20 | project_id = var.project_id
21 | regions = module.networking.regional-networks
22 | broker = module.cloudevent-broker.broker
23 |
24 | retention-period = 90
25 |
26 | provisioner = "serviceAccount:${data.google_client_openid_userinfo.me.email}"
27 |
28 | notification_channels = local.notification_channels
29 |
30 | types = {
31 | "dev.octo-sts.exchange" : {
32 | schema = file("${path.module}/sts_exchange.schema.json")
33 | notification_channels = local.notification_channels
34 | }
35 | }
36 | }
37 |
38 | resource "google_bigquery_table" "errors-by-installations" {
39 | dataset_id = module.cloudevent-recorder.dataset_id
40 | table_id = "errors_by_installations"
41 |
42 | view {
43 | query = <\n
\n\n
\n\n