Skip to content

Commit 0fd4fc9

Browse files
committed
Setup release workflow
Signed-off-by: Sergio Castaño Arteaga <[email protected]>
1 parent 9d8769d commit 0fd4fc9

File tree

8 files changed

+308
-14
lines changed

8 files changed

+308
-14
lines changed

.ct.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
helm-extra-args: --timeout 180s
2+
chart-repos:
3+
- stable=https://charts.helm.sh/stable

.github/workflows/chart.yml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Helm CI
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- "charts/**"
7+
8+
permissions: read-all
9+
10+
jobs:
11+
lint-and-test:
12+
runs-on: ubuntu-20.04
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
- name: Set up Helm
19+
uses: azure/setup-helm@v4
20+
with:
21+
version: v3.9.2
22+
- name: Set up Python
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: 3.7
26+
- name: Set up chart-testing
27+
uses: helm/[email protected]
28+
- name: Run chart-testing (list-changed)
29+
id: list-changed
30+
run: |
31+
changed=$(ct --config .ct.yaml list-changed --target-branch ${{ github.event.repository.default_branch }})
32+
if [[ -n "$changed" ]]; then
33+
echo "changed=true" >> $GITHUB_OUTPUT
34+
fi
35+
- name: Run chart-testing (lint)
36+
run: ct lint --config .ct.yaml --target-branch ${{ github.event.repository.default_branch }}
37+
- name: Create kind cluster
38+
uses: helm/[email protected]
39+
if: steps.list-changed.outputs.changed == 'true'
40+
- name: Run chart-testing (install)
41+
run: ct install --config .ct.yaml --target-branch ${{ github.event.repository.default_branch }}

.github/workflows/release.yml

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
permissions: read-all
9+
10+
jobs:
11+
build-and-publish-images:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
- name: Login to AWS Public ECR
17+
uses: docker/login-action@v3
18+
with:
19+
registry: public.ecr.aws
20+
username: ${{ secrets.AWS_ACCESS_KEY_ID }}
21+
password: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
22+
- name: Extract tag name
23+
id: extract_tag_name
24+
run: echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
25+
- name: Build and push clowarden-dbmigrator image
26+
run: |
27+
docker build \
28+
-f database/migrations/Dockerfile \
29+
-t public.ecr.aws/g6m3a0y9/clowarden-dbmigrator:${{steps.extract_tag_name.outputs.tag}} \
30+
-t public.ecr.aws/g6m3a0y9/clowarden-dbmigrator:latest \
31+
.
32+
docker push --all-tags public.ecr.aws/g6m3a0y9/clowarden-dbmigrator
33+
- name: Build and push clowarden-server image
34+
run: |
35+
docker build \
36+
-t public.ecr.aws/g6m3a0y9/clowarden-server:${{steps.extract_tag_name.outputs.tag}} \
37+
-t public.ecr.aws/g6m3a0y9/clowarden-server:latest \
38+
.
39+
docker push --all-tags public.ecr.aws/g6m3a0y9/clowarden-server
40+
41+
package-and-publish-helm-chart:
42+
needs:
43+
- build-and-publish-images
44+
permissions:
45+
contents: write
46+
runs-on: ubuntu-latest
47+
steps:
48+
- name: Checkout
49+
uses: actions/checkout@v4
50+
with:
51+
fetch-depth: 0
52+
- name: Configure Git
53+
run: |
54+
git config user.name "$GITHUB_ACTOR"
55+
git config user.email "[email protected]"
56+
- name: Install Helm
57+
uses: azure/setup-helm@v4
58+
- name: Run chart-releaser
59+
run: |
60+
# From: https://github.com/metallb/metallb/blob/293f43c1f78ab1b5fa8879a76746b094bd9dd3ca/.github/workflows/publish.yaml#L134-L163
61+
# Ref: https://github.com/helm/chart-releaser-action/issues/60
62+
curl -sSLo cr.tar.gz "https://github.com/helm/chart-releaser/releases/download/v1.6.1/chart-releaser_1.6.1_linux_amd64.tar.gz"
63+
tar -xzf cr.tar.gz
64+
rm -f cr.tar.gz
65+
repo=$(basename "$GITHUB_REPOSITORY")
66+
owner=$(dirname "$GITHUB_REPOSITORY")
67+
tag="${GITHUB_REF_NAME:1}"
68+
exists=$(curl -s -H "Accept: application/vnd.github.v3+json" https://github.com/$GITHUB_REPOSITORY/releases/tag/$repo-chart-$tag -w %{http_code} -o /dev/null)
69+
if [[ $exists != "200" ]]; then
70+
echo "Creating release..."
71+
# package chart
72+
./cr package charts/$repo
73+
# upload chart to github releases
74+
./cr upload \
75+
--owner "$owner" \
76+
--git-repo "$repo" \
77+
--release-name-template "{{ .Name }}-chart-{{ .Version }}" \
78+
--token "${{ secrets.GITHUB_TOKEN }}"
79+
# Update index and push to github pages
80+
./cr index \
81+
--owner "$owner" \
82+
--git-repo "$repo" \
83+
--index-path index.yaml \
84+
--release-name-template "{{ .Name }}-chart-{{ .Version }}" \
85+
--push
86+
else
87+
echo "Release already exists"
88+
fi

README.md

+51-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
# CLOWarden
22

3+
[![Artifact Hub](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/clowarden)](https://artifacthub.io/packages/helm/clowarden/clowarden)
4+
35
**CLOWarden** is a tool that manages the access to resources across multiple services with the initial focus on repositories in a GitHub organization.
4-
CLOWarden allows you to grant access to an individual user or a defined team of users by submitting a PR to a file that defines access rules.
56

67
The CNCF initially used [Sheriff](https://github.com/cncf/sheriff) to manage access to resources. CLOWarden has replaced Sheriff with a system that suits better the needs of the CNCF.
78

8-
CLOWarden supports a legacy configuration mode that allows using [a subset of the Sheriff's permissions configuration file](#configuration) and the [CNCF's people file](https://github.com/cncf/people/blob/main/people.json) to define users, teams and GitHub repositories (the same files currently used by CNCF at <https://github.com/cncf/people>).
9-
109
## How it works
1110

1211
CLOWarden's main goal is to ensure that the resources' **desired state**, as defined in the configuration files, matches the **actual state** in the corresponding services. This is achieved by running *reconciliation* jobs, that can be triggered *on-demand* or *periodically*. These reconciliation jobs are in charge of applying the necessary changes to address the differences between the desired and actual state on each service, which is done by delegating some work on specialized *service handlers*.
@@ -31,9 +30,10 @@ Let's go through a full example to see how this would work in practice.
3130

3231
Our goal in this example will be to create a new team (named `team1`) with one maintainer and one member, as well as a new repository (named `repo1`). We want to give `team1` write permissions on `repo1`, and we'd also like to add a external collaborator, named `collaborator1`, with read permissions.
3332

34-
The first step will be to create a pull request to add the entries below to the configuration files
33+
The first step will be to create a pull request to add the entries below to the configuration files:
3534

36-
(*This configuration intentionally introduces a typo so we can describe CLOWarden's PR validation checks -team1 is misspelled-*):
35+
> [!WARNING]
36+
> This configuration intentionally introduces a typo so we can describe CLOWarden's PR validation checks (team1 is misspelled).
3737
3838
```yaml
3939
teams:
@@ -76,8 +76,6 @@ Now CLOWarden is happy with the changes proposed! This time, it also tried to he
7676

7777
Sometimes this may be easy to spot by just looking at a the diff on the PR. But on other occasions, depending on the changes applied, it can get trickier and be error prone, as just a single extra space or tabulation can have unintented consequences. So CLOWarden simplifies this by analyzing the changes itself and displaying them in an easy to read way as a comment on the PR.
7878

79-
Outside of the context of a PR it is possible to view an autdit log of the changes made see the [#Audit tool](Audit tool) below
80-
8179
![valid-config-check-run](docs/screenshots/valid-config-check-run.png)
8280

8381
Now that the changes are valid, the check has been updated to reflect the new status and the PR can be merged safely once the maintainers are ready. As soon as this happens, CLOWarden will create a reconciliation job and will apply the necessary changes so that the actual state in the services matches the new desired state defined in the configuration. Once the job is executed, a new comment will be posted on the PR with more details:
@@ -180,6 +178,8 @@ repositories:
180178
visibility: public
181179
```
182180

181+
### Some tips to avoid problems
182+
183183
It's important to keep in mind that..
184184

185185
- GitHub usernames are case sensitive
@@ -189,10 +189,53 @@ It's important to keep in mind that..
189189
- It is possible to use the formation field in teams and at the same time explicitly define some team maintainers and members
190190
- Teams formation is not recursive. If a subteam is also using formation, its subteams will be ignored
191191
- GitHub repositories permissions granted using teams won't be effective until the team member has accepted the invitation to the organization
192+
- Before renaming a GitHub username, make sure it's not used as a team maintainer in the configuration file
192193

193194
## Using CLOWarden in your organization
194195

195-
Although has been deployed for use in the CNCF GitHub org, CLOWarden is still in an experimental phase and breaking changes are expected, so we do not recommend its use in other production enviroments yet. Once it stabilizes, we'll publish some additional documentation to make it easier to run your own CLOWarden instance.
196+
You can deploy your own CLOWarden instance by using [the Helm chart provided](https://artifacthub.io/packages/helm/clowarden/clowarden).
197+
198+
## CLI tool
199+
200+
CLOWarden includes a CLI tool that can be handy when adding new organizations to your CLOWarden deployment.
201+
202+
You can use it to:
203+
204+
- Validate the configuration in the repository provided
205+
- Display changes between the actual state and the desired state
206+
- Generate a configuration file from the actual state
207+
208+
> [!NOTE]
209+
> This tool uses the GitHub API, which requires authentication. Please make sure you provide a GitHub token (with repo and read:org scopes) by setting the GITHUB_TOKEN environment variable.
210+
211+
### Building from source
212+
213+
You can build the CLOWarden CLI tool from the source by using [Cargo](https://rustup.rs), the Rust package manager.
214+
215+
```text
216+
cargo install --git https://github.com/cncf/clowarden clowarden-cli
217+
```
218+
219+
```text
220+
% clowarden-cli --help
221+
CLOWarden CLI tool
222+
223+
This tool uses the GitHub API, which requires authentication. Please make sure
224+
you provide a GitHub token (with repo and read:org scopes) by setting the
225+
GITHUB_TOKEN environment variable.
226+
227+
Usage: clowarden-cli <COMMAND>
228+
229+
Commands:
230+
diff Display changes between the actual state (as defined in the services) and the desired state (as defined in the configuration)
231+
generate Generate configuration file from the actual state (experimental)
232+
validate Validate the configuration in the repository provided
233+
help Print this message or the help of the given subcommand(s)
234+
235+
Options:
236+
-h, --help Print help
237+
-V, --version Print version
238+
```
196239

197240
## Contributing
198241

charts/clowarden/Chart.yaml

+15
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,18 @@ dependencies:
1919
version: 8.2.1
2020
repository: https://charts.helm.sh/stable
2121
condition: postgresql.enabled
22+
annotations:
23+
artifacthub.io/category: skip-prediction
24+
artifacthub.io/changes: |
25+
- kind: added
26+
description: Initial release
27+
artifacthub.io/images: |
28+
- name: dbmigrator
29+
image: public.ecr.aws/g6m3a0y9/clowarden-dbmigrator
30+
- name: server
31+
image: public.ecr.aws/g6m3a0y9/clowarden-server
32+
artifacthub.io/links: |
33+
- name: source
34+
url: https://github.com/cncf/clowarden
35+
- name: support
36+
url: https://github.com/cncf/clowarden/issues

charts/clowarden/README.md

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# CLOWarden
2+
3+
[CLOWarden](https://clowarden.io) is a tool that automatically manages organizations users, teams and other resources across multiple services.
4+
5+
## Introduction
6+
7+
This chart bootstraps a CLOWarden deployment on a [Kubernetes](http://kubernetes.io) cluster using the [Helm](https://helm.sh) package manager.
8+
9+
## Prerequisites
10+
11+
Before installing this chart, you need to [setup a GitHub application](https://docs.github.com/en/apps/creating-github-apps/creating-github-apps/creating-a-github-app). The application requires the following permissions [to be set](https://docs.github.com/en/apps/maintaining-github-apps/editing-a-github-apps-permissions):
12+
13+
Repository:
14+
15+
- **Administration**: *read/write*
16+
- **Checks**: *read/write*
17+
- **Contents**: *read*
18+
- **Metadata**: *read*
19+
- **Pull requests**: *read/write*
20+
21+
Organization:
22+
23+
- **Administration**: *read/write*
24+
- **Members**: *read/write*
25+
26+
In addition to those permissions, it must also be subscribed to the following events:
27+
28+
- *Pull Request*
29+
30+
CLOWarden expects GitHub events to be sent to the `/webhook/github` endpoint. In the GitHub application, please enable `webhook` and set the target URL to your exposed endpoint (ie: <https://your-clowarden-deployment/webhook/github>). You will need to define a random secret for the webhook (you can use the following command to do it: `openssl rand -hex 32`). Please note your webhook secret, as well as the GitHub application ID and private key, as you'll need them in the next step when installing the chart.
31+
32+
Once your GitHub application is ready you can install it in the organizations you need.
33+
34+
## Installing the chart
35+
36+
Create a values file (`my-values.yaml`) that includes the configuration values required for your GitHub application:
37+
38+
```yaml
39+
server:
40+
githubApp:
41+
# GitHub application ID
42+
appId: 123456 # Replace with your GitHub app ID
43+
44+
# GitHub application private key
45+
privateKey: |-
46+
-----BEGIN RSA PRIVATE KEY-----
47+
...
48+
YOUR_APP_PRIVATE_KEY
49+
...
50+
-----END RSA PRIVATE KEY-----
51+
52+
# GitHub application webhook secret
53+
webhookSecret: "your-webhook-secret"
54+
```
55+
56+
In addition to the GitHub application configuration, you can also add the organizations you'd like to use CLOWarden with at this point:
57+
58+
```yaml
59+
organizations:
60+
- # Name of the GitHub organization
61+
name: org-name
62+
63+
# CLOWarden's GitHub application installation id
64+
installationId: 12345678
65+
66+
# Repository where the configuration files are located
67+
repository: .clowarden
68+
69+
# Branch to use in the configuration repository
70+
branch: main
71+
72+
# Legacy mode configuration
73+
legacy:
74+
# Whether legacy mode is enabled or not (must be at the moment)
75+
enabled: true
76+
77+
# Path of the Sheriff's permissions file
78+
sheriffPermissionsPath: config.yaml
79+
```
80+
81+
CLOWarden includes a CLI tool that can be handy when adding new organizations to your CLOWarden deployment. For more information please see the [repository's README file](https://github.com/cncf/clowarden?#cli-tool).
82+
83+
To install the chart with the release name `my-clowarden` run:
84+
85+
```bash
86+
$ helm repo add clowarden https://cncf.github.io/clowarden/
87+
$ helm install --values my-values.yaml my-clowarden clowarden/clowarden
88+
```
89+
90+
The command above deploys CLOWarden on the Kubernetes cluster using the default configuration values and the GitHub application configuration provided. Please see the [chart's default values file](https://github.com/cncf/clowarden/blob/main/charts/clowarden/values.yaml) for a list of all the configurable parameters of the chart and their default values.
91+
92+
## Uninstalling the chart
93+
94+
To uninstall the `my-clowarden` deployment run:
95+
96+
```bash
97+
$ helm uninstall my-clowarden
98+
```
99+
100+
This command removes all the Kubernetes components associated with the chart and deletes the release.
101+
102+
## How CLOWarden works
103+
104+
For more information about how CLOWarden works from a user's perspective please see the [repository's README file](https://github.com/cncf/clowarden#readme).

charts/clowarden/values.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ dbmigrator:
3636
job:
3737
image:
3838
# Database migrator image repository (without the tag)
39-
repository: clowarden-dbmigrator
39+
repository: public.ecr.aws/g6m3a0y9/clowarden-dbmigrator
4040

4141
# CLOWarden server configuration
4242
server:
@@ -59,7 +59,7 @@ server:
5959
githubApp:
6060
# GitHub application ID
6161
appId: null
62-
# GitHub application private key path
62+
# GitHub application private key
6363
privateKey: null
6464
# GitHub application webhook secret
6565
webhookSecret: null
@@ -79,9 +79,9 @@ server:
7979

8080
# Deployment configuration
8181
deploy:
82-
replicaCount: 1
82+
replicaCount: 1 # Do not increase
8383
image:
84-
repository: clowarden-server
84+
repository: public.ecr.aws/g6m3a0y9/clowarden-server
8585
resources: {}
8686

8787
# Services CLOWarden will manage
@@ -102,7 +102,7 @@ organizations:
102102
# branch: main
103103
# # Legacy mode configuration
104104
# legacy:
105-
# # Whether legacy mode is enabled or not
105+
# # Whether legacy mode is enabled or not (must be at the moment)
106106
# enabled: true
107107
# # Path of the Sheriff's permissions file
108108
# sheriffPermissionsPath: config.yaml

0 commit comments

Comments
 (0)