Skip to content

Commit 58c1184

Browse files
authored
Merge pull request #1 from imjasonh/initial
initial commit
2 parents 03b1ea9 + cb9c4ae commit 58c1184

File tree

2 files changed

+142
-0
lines changed

2 files changed

+142
-0
lines changed

README.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Setup `chainctl`
2+
3+
This action installs the latest `chainctl` binary for a particular environment
4+
and authenticates with it using identity tokens.
5+
6+
## Usage
7+
8+
```yaml
9+
- uses: chainguard-dev/setup-chainctl@main
10+
with:
11+
# the ID of the identity this workload should assume when speaking to Chainguard APIs.
12+
identity: "..."
13+
```
14+
15+
## Scenarios
16+
17+
```yaml
18+
permissions:
19+
id-token: write
20+
21+
steps:
22+
- uses: chainguard-dev/setup-chainctl@main
23+
with:
24+
identity: "deadbeef/badf00d"
25+
```
26+
27+
See [Authenticating to Chainguard Registry](https://edu.chainguard.dev/chainguard/chainguard-images/registry/authenticating/#authenticating-with-github-actions) for more information about creating an identity to pull images from cgr.dev from GitHub Actions, using `setup-chainctl`.

action.yaml

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Copyright 2022 Chainguard, Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
name: 'Setup chainctl'
5+
description: |
6+
This action sets up the Chainguard chainctl CLI and authenticates
7+
it against the target environment.
8+
9+
inputs:
10+
environment:
11+
description: |
12+
Determines the environment from which to download the chainctl
13+
binary from.
14+
required: true
15+
default: enforce.dev
16+
17+
identity:
18+
description: |
19+
The id of the identity that this workflow should assume for
20+
performing actions with chainctl.
21+
required: false
22+
23+
audience:
24+
description: |
25+
Specifies the identity token audience to use when creating an
26+
identity token to authenticate with Chainguard.
27+
Defaults to issuer.${environment}
28+
29+
This field is DEPRECATED, use identity instead.
30+
required: false
31+
32+
invite-code:
33+
description: |
34+
Optionally specifies an invite code that allows this workflow
35+
register itself when run for the first time.
36+
37+
Use of invite codes is DEPRECATED, use identity instead.
38+
required: false
39+
40+
runs:
41+
using: "composite"
42+
43+
steps:
44+
- name: Install chainctl
45+
shell: bash
46+
run: |
47+
cd $(mktemp -d)
48+
wget --quiet -U "GitHub setup-chainctl" -O chainctl "https://dl.${{ inputs.environment }}/chainctl/latest/chainctl_linux_$(uname -m)"
49+
CHAINCTL_INSTALL_PATH="${HOME}/.local/bin"
50+
# Ensure install directory is on the PATH for future steps
51+
echo "${CHAINCTL_INSTALL_PATH}" >> "${GITHUB_PATH}"
52+
install -D --mode 0555 ./chainctl --target-directory "${CHAINCTL_INSTALL_PATH}"
53+
54+
- name: Authenticate with Chainguard (assumed identity)
55+
shell: bash
56+
if: ${{ inputs.identity != '' }}
57+
env:
58+
CHAINCTL_DEBUG: "true"
59+
run: |
60+
if chainctl auth login --identity "${{ inputs.identity }}"; then
61+
echo Logged in as ${{ inputs.identity }}!
62+
else
63+
echo Unable to assume the identity ${{ inputs.identity }}.
64+
exit 1
65+
fi
66+
if ! chainctl auth configure-docker --identity "${{ inputs.identity }}"; then
67+
echo Unable to register credential helper as ${{ inputs.identity }}.
68+
exit 1
69+
fi
70+
71+
- name: Authenticate with Chainguard (DEPRECATED invite-code)
72+
shell: bash
73+
if: ${{ inputs.invite-code != '' }}
74+
env:
75+
CHAINGUARD_INVITE_CODE: ${{ inputs.invite-code }}
76+
CHAINCTL_DEBUG: "true"
77+
run: |
78+
echo "::warning::The use of invite codes with Github actions is deprecated, use assumed identities instead."
79+
80+
AUDIENCE="${{ inputs.audience }}"
81+
if [[ -z "${AUDIENCE}" ]]; then
82+
AUDIENCE=issuer.${{ inputs.environment }}
83+
fi
84+
IDTOKEN=$(curl -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=${AUDIENCE}" | jq -r '.value')
85+
86+
# This will start failing once the invite code expires, which is why we have the login guard.
87+
if chainctl auth login --create-group=false --identity-token "${IDTOKEN}" --invite-code="${CHAINGUARD_INVITE_CODE}"; then
88+
echo Logged in!
89+
else
90+
echo Failed to log in with invite code
91+
exit 1
92+
fi
93+
94+
- name: Authenticate with Chainguard (DEPRECATED registered identity)
95+
shell: bash
96+
if: ${{ inputs.identity == '' && inputs.invite-code == '' }}
97+
env:
98+
CHAINGUARD_INVITE_CODE: ${{ inputs.invite-code }}
99+
CHAINCTL_DEBUG: "true"
100+
run: |
101+
echo "::warning::The use of registered Github actions identities is deprecated, use assumed identities instead."
102+
103+
AUDIENCE="${{ inputs.audience }}"
104+
if [[ -z "${AUDIENCE}" ]]; then
105+
AUDIENCE=issuer.${{ inputs.environment }}
106+
fi
107+
IDTOKEN=$(curl -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=${AUDIENCE}" | jq -r '.value')
108+
109+
if chainctl auth login --identity-token "${IDTOKEN}"; then
110+
echo Logged in!
111+
else
112+
echo No invite code is present! Failing since registration will not do any good.
113+
echo Configure a secret named CHAINGUARD_INVITE_CODE to have this workload register itself.
114+
exit 1
115+
fi

0 commit comments

Comments
 (0)