You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: gracefully handle rate-limits and ephemeral errors (#48)
* Gracefully handle rate-limits through `github.com/isometry/ghait` and its use of `github.com/gofri/go-github-ratelimit`.
* Gracefully handle ephemeral 504 errors from GitHub's backend; add `.spec.retryInteval` field on both `Token` and `ClusterToken` to override the default `5m` retry interval.
* Increase default `.spec.refreshInterval` from `10m` to `30m`.
* Expand usage guidance in `README.md` with more complete configuration and `Token` examples.
Fixes: #47
@@ -18,10 +18,19 @@ This operator functions similarly to cert-manager, but instead of managing certi
18
18
19
19
* A Kubernetes cluster (v1.21+)
20
20
* A [GitHub App](https://docs.github.com/en/apps/creating-github-apps) with permissions and repository assignments sufficient to meet the needs of all anticipated GitHub API interactions. Typically: `metadata: read`, `contents: read`, `statuses: write`.
21
+
* Specifically: App ID, App Installation ID and a Private Key are required.
21
22
22
-
#### Example `gtm-config` secret
23
-
<details>
24
-
<summary><i>expand me! ✨</i></summary>
23
+
### Installation
24
+
25
+
A Helm Chart is provided your for convenience: [deploy/charts/github-token-manager/](deploy/charts/github-token-manager/)
26
+
27
+
Alternatively, a baseline Kustomization is provided under [config/default/](config/default/)
28
+
29
+
### Configuration
30
+
31
+
The operator itself requires configuration via `ConfigMap/gtm-config` in its deployment namespace. This contains the GitHub App ID, Installation ID and Private Key provider details. In addition to embedding the private key file within the secret, AWS Key Management Service (KMS), Google Cloud Key Management, and HashiCorp Vault's Transit Secrets Engine are also supported for secure external handling of keying material.
32
+
33
+
#### Example `gtm-config` with embedded Private Key
25
34
26
35
```yaml
27
36
apiVersion: v1
@@ -31,8 +40,8 @@ metadata:
31
40
namespace: github-token-manager
32
41
stringData:
33
42
gtm.yaml: |
34
-
app_id: <app-id>
35
-
installation_id: <installation-id>
43
+
app_id: 1234
44
+
installation_id: 4567890
36
45
provider: file
37
46
key: /config/private.key
38
47
private.key: |
@@ -41,11 +50,109 @@ stringData:
41
50
-----END RSA PRIVATE KEY-----
42
51
```
43
52
44
-
</details>
53
+
#### Example `gtm-config` with AWS KMS
54
+
55
+
```yaml
56
+
apiVersion: v1
57
+
kind: Secret
58
+
metadata:
59
+
name: gtm-config
60
+
namespace: github-token-manager
61
+
stringData:
62
+
gtm.yaml: |
63
+
app_id: 1234
64
+
installation_id: 45678890
65
+
provider: aws
66
+
key: alias/github-token-manager
67
+
```
68
+
69
+
### `Token` and `ClusterToken`
70
+
71
+
Once the operator is installed and configured, any number of namespaced `Token` and non-namespaced `ClusterToken` may be created, resulting in matching `Secret` resoures being created, containing either `token` or `username` and `password` fields, depending on configuration.
72
+
73
+
The namespaced `Token` resource manages a `Secret` in the same namespace containing a fine-grained [installation access token](https://docs.github.com/en/rest/apps/apps?apiVersion=2022-11-28#create-an-installation-access-token-for-an-app) for the configured GitHub App, appropriate for delegated management by the namespace owner.
74
+
75
+
The non-namespaced `ClusterToken` resource does the same thing, but supports abstracted management where only the managed `Secret` is bound to the configured target namespace via `.spec.secret.namespace`.
76
+
77
+
```yaml
78
+
apiVersion: github.as-code.io/v1
79
+
kind: ClusterToken # or Token
80
+
metadata:
81
+
name: foo
82
+
spec:
83
+
installationID: 321 # (optional) override GitHub App Installation ID configured for the operator
84
+
permissions: {} # (optional) map of token permissions, default: all permissions assigned to the GitHub App
annotations: {} # (optional) map of annotations for managed `Secret`
91
+
basicAuth: true # (optional) create `Secret` with `username` and `password` rather than `token`
92
+
labels: {} # (optional) map of labels for managed `Secret`
93
+
name: bar # (optional) override name for managed `Secret` (default: .metadata.name)
94
+
namespace: default # (required, ClusterToken-only) set the target namespace for managed `Secret`
95
+
```
96
+
97
+
#### Examples
98
+
99
+
Manage a `Secret/github-token` containing HTTP Basic Auth `username` and `password` fields appropriate for use with a Flux' `GitRepository` [Secret Reference](https://fluxcd.io/flux/components/source/gitrepositories/#secret-reference):
100
+
101
+
```yaml
102
+
apiVersion: github.as-code.io/v1
103
+
kind: Token
104
+
metadata:
105
+
name: github-token
106
+
namespace: flux-system
107
+
spec:
108
+
permissions:
109
+
metadata: read
110
+
contents: read
111
+
refreshInterval: 45m
112
+
secret:
113
+
basicAuth: true
114
+
```
115
+
116
+
Manage a `Secret/github-status` containing a plain `token` field appropriate for use with a Flux' `Provider` [GitHub Commit Status Updates](https://fluxcd.io/flux/components/notification/providers/#github):
117
+
118
+
```yaml
119
+
apiVersion: github.as-code.io/v1
120
+
kind: Token
121
+
metadata:
122
+
name: github-status
123
+
namespace: flux-system
124
+
spec:
125
+
permissions:
126
+
metadata: read
127
+
statuses: write
128
+
refreshInterval: 45m
129
+
```
130
+
131
+
Manage `Secret/github` in the `default` namespace containing a plain `token` field, inheriting all permissions assigned to the configured GitHub App:
132
+
133
+
```yaml
134
+
apiVersion: github.as-code.io/v1
135
+
kind: ClusterToken
136
+
metadata:
137
+
name: default-github
138
+
spec:
139
+
secret:
140
+
name: github
141
+
namespace: default
142
+
```
143
+
144
+
## Contributing
145
+
146
+
All contributions from the community are welcome.
147
+
148
+
**NOTE:** Run `make help` for more information on all potential `make` targets
149
+
150
+
More information can be found via the [Kubebuilder Documentation](https://book.kubebuilder.io/introduction.html)
45
151
46
152
### To Deploy on the cluster
47
153
48
-
**Build and push your image to the location specified by `IMG`:**
154
+
155
+
#### Build and push your image to the location specified by `IMG`:
49
156
50
157
```sh
51
158
make ko-build IMG=<some-registry>/github-token-manager:tag
@@ -55,13 +162,13 @@ make ko-build IMG=<some-registry>/github-token-manager:tag
55
162
And it is required to have access to pull the image from the working environment.
56
163
Make sure you have the proper permission to the registry if the above commands don’t work.
57
164
58
-
**Install the CRDs into the cluster:**
165
+
#### Install the CRDs into the cluster:
59
166
60
167
```sh
61
168
make install
62
169
```
63
170
64
-
**Deploy the Manager to the cluster with the image specified by `IMG`:**
171
+
#### Deploy the Manager to the cluster with the image specified by `IMG`:
65
172
66
173
```sh
67
174
make deploy IMG=<some-registry>/github-token-manager:tag
@@ -70,43 +177,26 @@ make deploy IMG=<some-registry>/github-token-manager:tag
70
177
> **NOTE**: If you encounter RBAC errors, you may need to grant yourself cluster-admin
71
178
privileges or be logged in as admin.
72
179
73
-
**Create instances of your solution**
74
-
You can apply the samples (examples) from the config/sample:
75
-
76
-
```sh
77
-
kubectl apply -k config/samples/
78
-
```
79
-
80
-
>**NOTE**: Ensure that the samples has default values to test it out.
81
-
82
180
### To Uninstall
83
181
84
-
**Delete the instances (CRs) from the cluster:**
182
+
#### Delete the instances (CRs) from the cluster
85
183
86
184
```sh
87
185
kubectl delete -k config/samples/
88
186
```
89
187
90
-
**Delete the APIs(CRDs) from the cluster:**
188
+
#### Delete the APIs(CRDs) from the cluster
91
189
92
190
```sh
93
191
make uninstall
94
192
```
95
193
96
-
**UnDeploy the controller from the cluster:**
194
+
#### UnDeploy the controller from the cluster
97
195
98
196
```sh
99
197
make undeploy
100
198
```
101
199
102
-
## Contributing
103
-
104
-
// TODO(user): Add detailed information on how you would like others to contribute to this project
105
-
106
-
**NOTE:** Run `make help` for more information on all potential `make` targets
107
-
108
-
More information can be found via the [Kubebuilder Documentation](https://book.kubebuilder.io/introduction.html)
0 commit comments