Skip to content

Commit 8c44558

Browse files
committed
Add TEP for scoping token to a repositories
1 parent 5d72237 commit 8c44558

File tree

1 file changed

+142
-0
lines changed

1 file changed

+142
-0
lines changed
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
---
2+
title: Scoping token to a list of provided repositories in the same namespaces
3+
authors:
4+
- "@savita"
5+
creation-date: 2023-04-17
6+
status: implementable
7+
---
8+
9+
# Scoping token to a list of provided repositories in the same namespaces
10+
11+
## Summary
12+
13+
This proposal helps user to scope token to multiple repositries in the same namespace.
14+
15+
## Motivation/UseCase
16+
17+
Their is a use case where CI Repos Differ from CD Repos, and the teams would like the generated GitHub Token from Pipelines As Code to allow control over these secondary repos, even if they were not the one triggering the pipeline.
18+
19+
Note: Repos would be assigned to the same Kuberentes Namespace.
20+
21+
story :
22+
23+
<https://issues.redhat.com/browse/SRVKP-2911>
24+
25+
## Proposal
26+
27+
1. Scoping token a list of Repos by global configuration
28+
2. Scoping token a list of Repos by local configuration
29+
30+
### Scoping token a list of Repos by global configuration
31+
32+
* When list of Repos provided by global configuration then scope all those Repos by a temporary Github Token irrespective of the namespaces.
33+
34+
* The configuration exist in `pipelines-as-code` configmap.
35+
36+
* The key which used to have list of Repos is `secret-github-app-scope-extra-repos`
37+
38+
### Scoping token a list of Repos by local configuration
39+
40+
* Scope token to a list of Repos provided by `repo_list_to_scope_token` spec configuration within the Repository custom resource
41+
```
42+
apiVersion: "pipelinesascode.tekton.dev/v1alpha1"
43+
kind: Repository
44+
metadata:
45+
name: test
46+
namespace: test-repo
47+
spec:
48+
url: "https://github.com/linda/project"
49+
repo_list_to_scope_token:
50+
- "owner/project"
51+
- "owner1/project1"
52+
```
53+
54+
Now PAC will read `test` Repository custom resource and scope token to `owner/project`, `owner1/project1` and `linda/project` as well
55+
56+
**Note:**
57+
58+
1. Both `owner/project` and `owner1/project1` Repository should be in same namespace where `test` Repository exist.
59+
60+
2. If any one of the `owner/project` or `owner1/project1` doesn't exist then scoping token will fail
61+
62+
ex: `owner1/project1` does not exist in the namespace
63+
64+
Then below error will be displayed
65+
```
66+
repo owner1/project1 does not exist in namespace test-repo
67+
```
68+
### Scenarios when both global and local configurations provided
69+
70+
1. When Repos are provided by both `secret-github-app-scope-extra-repos` and `repo_list_to_scope_token` then token will be scoped to all the Repos from both configuration
71+
72+
Ex:
73+
74+
* List of Repos provided by `secret-github-app-scope-extra-repos` in cm
75+
76+
```
77+
apiVersion: v1
78+
data:
79+
secret-github-app-scope-extra-repos: "owner2/project2, owner3/project3"
80+
kind: ConfigMap
81+
metadata:
82+
name: pipelines-as-code
83+
namespace: pipelines-as-code
84+
```
85+
86+
* List of Repos provided by `repo_list_to_scope_token` in Repository spec
87+
```
88+
apiVersion: "pipelinesascode.tekton.dev/v1alpha1"
89+
kind: Repository
90+
metadata:
91+
name: test
92+
namespace: test-repo
93+
spec:
94+
url: "https://github.com/linda/project"
95+
repo_list_to_scope_token:
96+
- "owner/project"
97+
- "owner1/project1"
98+
```
99+
100+
Now the token will be scoped to `owner/project`, `owner1/project1`, `owner2/project2`, `owner3/project3`, `linda/project`
101+
102+
2. If only Global `secret-github-app-scope-extra-repos` set then token will be scoped to all the provided repos
103+
104+
3. If only repos are provided by Repository spec using `repo_list_to_scope_token` then token will be scoped to all provided repos only when all repos exist in the same namespace where Repository created.
105+
106+
4. If no Github App is installed for the provided Repos in both global and local configuration then scoping token will fail with below error
107+
```
108+
failed to scope token to repositories in namespace article-pipelines with error : could not refresh installation id 36523992's token: received non 2xx response status \"422 Unprocessable Entity\" when fetching https://api.github.com/app/installations/36523992/access_tokens: Post \"https://api.github.com/repos/savitaashture/article/check-runs\
109+
```
110+
111+
5. If repos are given by `repo_list_to_scope_token` or `secret-github-app-scope-extra-repos` failed to scope token for any reason then CI will not run.
112+
113+
6. repo `owner5/project5` is given globally as well as locally using `secret-github-app-scope-extra-repos` and `repo_list_to_scope_token`
114+
115+
Ex:
116+
```
117+
apiVersion: v1
118+
data:
119+
secret-github-app-scope-extra-repos: "owner5/project5"
120+
kind: ConfigMap
121+
metadata:
122+
name: pipelines-as-code
123+
namespace: pipelines-as-code
124+
```
125+
126+
```
127+
apiVersion: "pipelinesascode.tekton.dev/v1alpha1"
128+
kind: Repository
129+
metadata:
130+
name: test
131+
namespace: test-repo
132+
spec:
133+
url: "https://github.com/linda/project"
134+
repo_list_to_scope_token:
135+
- "owner5/project5"
136+
```
137+
138+
still failed to scope token with below error
139+
```
140+
repo owner5/project5 does not exist in namespace test-repo
141+
```
142+
because `owner5/project5` doesn't exist in namespace `test-repo`.

0 commit comments

Comments
 (0)