Skip to content

Commit 9cfaf43

Browse files
committed
chore: use cosign for binaries and docker #262
1 parent 9c75e3c commit 9cfaf43

9 files changed

Lines changed: 70 additions & 216 deletions

File tree

.gcloudignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,5 @@ docs/
1616
test/
1717

1818
README.md
19-
third-party-licenses.md
20-
LICENSE.txt
2119
CONTRIBUTING.md
2220
downloadLatest.sh

.github/workflows/docker-cloudbuild.yml

Lines changed: 0 additions & 103 deletions
This file was deleted.

.github/workflows/docker-publish.yml

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
name: Docker
15+
name: Cloud Builder Docker
1616

1717
# This workflow uses actions that are not certified by GitHub.
1818
# They are provided by a third-party and are governed by
@@ -22,15 +22,13 @@ name: Docker
2222
on:
2323
push:
2424
# Publish semver tags as releases.
25-
tags:
26-
- v1.[0-9]+
27-
- v1.[0-9]+.[0-9]+-beta
25+
tags:
26+
- v[0-1].[0-9]+
27+
- v[0-1].[0-9]+.[0-9]+-beta
2828

2929
env:
30-
# Use docker.io for Docker Hub if empty
3130
REGISTRY: ghcr.io
32-
# github.repository as <account>/<repo>
33-
IMAGE_NAME: ${{ github.repository }}
31+
IMAGE_NAME: apigee/apigeecli
3432

3533

3634
jobs:
@@ -52,9 +50,8 @@ jobs:
5250
# https://github.com/sigstore/cosign-installer
5351
- name: Install cosign
5452
if: github.event_name != 'pull_request'
55-
uses: sigstore/cosign-installer@main
56-
with:
57-
cosign-release: "v1.13.1"
53+
uses: sigstore/cosign-installer@v3.1.1
54+
5855

5956
# Workaround: https://github.com/docker/build-push-action/issues/461
6057
- name: Setup Docker buildx
@@ -82,22 +79,20 @@ jobs:
8279
# https://github.com/docker/build-push-action
8380
- name: Build and push Docker image
8481
id: build-and-push
85-
uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
82+
uses: docker/build-push-action@v4.0.0
8683
with:
8784
context: .
85+
file: Dockerfile.builder
8886
push: ${{ github.event_name != 'pull_request' }}
8987
tags: ${{ steps.meta.outputs.tags }}
9088
labels: ${{ steps.meta.outputs.labels }}
9189

92-
# Sign the resulting Docker image digest except on PRs.
93-
# This will only write to the public Rekor transparency log when the Docker
94-
# repository is public to avoid leaking data. If you would like to publish
95-
# transparency data even for private images, pass --force to cosign below.
96-
# https://github.com/sigstore/cosign
97-
- name: Sign the published Docker image
98-
if: ${{ github.event_name != 'pull_request' }}
90+
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
91+
- name: Sign image with a key
92+
run: |
93+
cosign sign --yes --key env://COSIGN_PRIVATE_KEY "${TAGS}@${DIGEST}"
9994
env:
100-
COSIGN_EXPERIMENTAL: "true"
101-
# This step uses the identity token to provision an ephemeral certificate
102-
# against the sigstore community Fulcio instance.
103-
run: echo "${{ steps.meta.outputs.tags }}" | xargs -I {} cosign sign {}@${{ steps.build-and-push.outputs.digest }}
95+
TAGS: ${{ steps.docker_meta.outputs.tags }}
96+
COSIGN_PRIVATE_KEY: ${{ secrets.COSIGN_PRIVATE_KEY }}
97+
COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }}
98+
DIGEST: ${{ steps.build-and-push.outputs.digest }}

.github/workflows/gorelease-action.yml

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ name: apigeecli-release
1717
on:
1818
push:
1919
# Publish semver tags as releases.
20-
tags:
20+
tags:
2121
- v1.[0-9]+
2222
- v1.[0-9]+.[0-9]+-beta
2323

@@ -32,34 +32,26 @@ jobs:
3232
#go-version: '>=1.18.0'
3333
go-version-file: './go.mod'
3434
check-latest: true
35-
35+
3636
- name: Reviewdog Lint
3737
uses: reviewdog/action-golangci-lint@v1
3838
with:
39-
reporter: github-check
39+
reporter: github-check
4040

41-
- name: 'Install upx'
42-
run: |
43-
sudo apt-get update -y
44-
sudo apt-get install -y upx
45-
export GPG_TTY=$(tty)
41+
- name: Write private key to disk
42+
run: echo "${{ secrets.COSIGN_PRIVATE_KEY }}" > /tmp/cosign.key
4643

47-
- name: Import GPG key
48-
id: import_gpg
49-
uses: crazy-max/ghaction-import-gpg@v5
50-
with:
51-
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
52-
passphrase: ${{ secrets.PASSPHRASE }}
44+
- uses: sigstore/cosign-installer@main
5345

5446
- name: Run GoReleaser
5547
uses: goreleaser/goreleaser-action@v3
5648
with:
5749
distribution: goreleaser
5850
version: latest
59-
args: release --rm-dist
51+
args: release --clean
6052
env:
53+
COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }}
6154
GITHUB_TOKEN: ${{ secrets.TOKEN }}
62-
GPG_FINGERPRINT: ${{ secrets.FINGERPRINT }}
6355

6456
- name: Upload assets
6557
uses: actions/upload-artifact@v3

Dockerfile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ RUN go mod download
3131
RUN date +%FT%H:%I:%M+%Z > /tmp/date
3232
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -buildvcs=true -a -gcflags='all="-l"' -ldflags='-s -w -extldflags "-static" -X main.version='${TAG}' -X main.commit='${COMMIT}' -X main.date='$(cat /tmp/date) -o /go/bin/apigeecli /go/src/apigeecli/main.go
3333

34-
FROM gcr.io/distroless/static-debian11
35-
COPY --from=builder /go/bin/apigeecli /
34+
FROM ghcr.io/jqlang/jq:latest as jq
35+
36+
# use debug because it includes busybox
37+
FROM gcr.io/distroless/static-debian11:debug
38+
COPY --from=builder /go/bin/apigeecli /usr/local/bin/apigeecli
3639
COPY LICENSE.txt /
3740
COPY third-party-licenses.txt /
38-
CMD ["/apigeecli"]
41+
COPY --from=jq /jq /usr/local/bin/jq

Dockerfile.builder

Lines changed: 0 additions & 37 deletions
This file was deleted.

README.md

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,6 @@ This is a tool to interact with [Apigee APIs](https://cloud.google.com/apigee/do
1414
curl -L https://raw.githubusercontent.com/apigee/apigeecli/main/downloadLatest.sh | sh -
1515
```
1616

17-
NOTE: The signature is not verified and the original zip is not preserved.
18-
19-
<details>
20-
<summary>Signature Verification</summary>
21-
22-
### Signature Verification
23-
To test the signature of the binary, import the gpg public key:
24-
25-
```sh
26-
gpg --recv-keys --keyserver keyserver.ubuntu.com A714872F32F34390
27-
gpg: key A714872F32F34390: public key "apigeecli (apigeecli) <13950006+srinandan@users.noreply.github.com>" imported
28-
gpg: Total number processed: 1
29-
gpg: imported: 1
30-
```
31-
32-
Use curl or wget to download the zip and sig files. Verify using:
33-
34-
```sh
35-
gpg --verify apigeecli_<signature-file>.sig apigeecli_<original-file>.zip
36-
gpg: Signature made Thu 05 May 2022 05:58:11 PM UTC
37-
gpg: using RSA key 72D11E3A3B1E9FE22110EC45A714872F32F34390
38-
gpg: issuer "13950006+srinandan@users.noreply.github.com"
39-
gpg: Good signature from "apigeecli (apigeecli) <13950006+srinandan@users.noreply.github.com>" [unknown]
40-
gpg: WARNING: This key is not certified with a trusted signature!
41-
gpg: There is no indication that the signature belongs to the owner.
42-
Primary key fingerprint: 72D1 1E3A 3B1E 9FE2 2110 EC45 A714 872F 32F3 4390
43-
```
44-
45-
</details>
46-
4717
## Getting Started
4818

4919
### User Tokens
@@ -339,6 +309,38 @@ x-google-jwt-locations:
339309
```
340310
341311
query parameters are ignored. By default, if no location is specified, the JWT location is the `Authorization` header and value_prefix is `Bearer <token>`
312+
313+
## How do I verify the binary?
314+
315+
All artifacts are signed by [cosign](https://github.com/sigstore/cosign). We recommend verifying any artifact before using them.
316+
317+
You can use the following public key to verify any `apigeecli` binary with:
318+
319+
```sh
320+
cat cosign.pub
321+
-----BEGIN PUBLIC KEY-----
322+
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEgjcKEyPi18vd6Zk5/ggAkH6CLSy3
323+
C8gzi5q3xsycjI7if5FABk7bfciR4+g32H8xTl4mVHhHuz6I6FBG24/nuQ==
324+
-----END PUBLIC KEY-----
325+
326+
cosign verify-blob --key=cosign.pub --signature apigeecli_<platform>_<arch>.zip.sig apigeecli_<platform>_<arch>.zip
327+
```
328+
329+
Where `platform` can be one of `Darwin`, `Linux` or `Windows` and arch (architecture) can be one of `arm64` or `x86_64`
330+
331+
## How do I verify the apigeecli containers?
332+
333+
All images are signed by [cosign](https://github.com/sigstore/cosign). We recommend verifying any container before using them.
334+
335+
```sh
336+
cat cosign.pub
337+
-----BEGIN PUBLIC KEY-----
338+
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEgjcKEyPi18vd6Zk5/ggAkH6CLSy3
339+
C8gzi5q3xsycjI7if5FABk7bfciR4+g32H8xTl4mVHhHuz6I6FBG24/nuQ==
340+
-----END PUBLIC KEY-----
341+
342+
cosign verify --key=cosign.pub ghcr.io/apigee/apigeecli:latest
343+
```
342344
___
343345

344346
## Support

cloud-builder.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
# gcloud builds submit --config=cloud-builder.yaml --project=project-name
14+
# gcloud builds submit --config=cloud-builder.yaml --project=project-name
1515
steps:
1616
# Build the container image
1717
- name: 'gcr.io/cloud-builders/docker'
18-
args: ['build', '-t', 'gcr.io/$PROJECT_ID/apigeecli-builder', '-f', 'Dockerfile.builder', '.']
18+
args: ['build', '-t', 'gcr.io/$PROJECT_ID/apigeecli', '-f', 'Dockerfile', '.']
1919
# Push the container image to Container Registry
2020
- name: 'gcr.io/cloud-builders/docker'
2121
args: ['push', 'gcr.io/$PROJECT_ID/apigeecli-builder']
2222
options:
2323
env: ["DEBUG=true"]
2424
machineType: N1_HIGHCPU_8
25-
logging: CLOUD_LOGGING_ONLY
25+
logging: CLOUD_LOGGING_ONLY

cosign.pub

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-----BEGIN PUBLIC KEY-----
2+
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEgjcKEyPi18vd6Zk5/ggAkH6CLSy3
3+
C8gzi5q3xsycjI7if5FABk7bfciR4+g32H8xTl4mVHhHuz6I6FBG24/nuQ==
4+
-----END PUBLIC KEY-----

0 commit comments

Comments
 (0)