Skip to content

Commit b13b4ff

Browse files
Merge pull request #30 from jitsecurity/sc-29172-jit-customer-scripts-generate-script-to-onboard
Add GitLab Team Resource Manager script for automated asset coverage updates
2 parents 67bcc0d + bbc60a5 commit b13b4ff

6 files changed

Lines changed: 816 additions & 1 deletion

File tree

.gitlab-ci.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
image: python:3.9-slim
2+
3+
variables:
4+
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.pip-cache"
5+
6+
cache:
7+
paths:
8+
- .pip-cache/
9+
10+
stages:
11+
- sync-teams
12+
13+
sync-teams:
14+
stage: sync-teams
15+
script:
16+
- pip install -r src/scripts/gitlab_team_resource_manager/requirements.txt
17+
- |
18+
if [ ! -f $STATE_FILE ]; then
19+
echo '{"current_team_index": 0}' > $STATE_FILE
20+
fi
21+
- python src/scripts/gitlab_team_resource_manager/gitlab_team_resource_manager.py
22+
variables:
23+
JIT_CLIENT_ID: ${JIT_CLIENT_ID}
24+
JIT_CLIENT_SECRET: ${JIT_CLIENT_SECRET}
25+
TEAM_METADATA_FILE: "team_metadata.json"
26+
TEAM_STATE_FILE: ${STATE_FILE}
27+
environment:
28+
name: production
29+
rules:
30+
- if: $CI_PIPELINE_SOURCE == "schedule"
31+
when: always
32+
- if: $CI_PIPELINE_SOURCE == "web"
33+
when: always
34+
- when: never
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# GitLab Team Resource Manager
2+
3+
This tool manages team resources in GitLab by automatically updating asset coverage based on team metadata configuration.
4+
5+
## Important Notes
6+
7+
- This script is designed to be run on a daily schedule.
8+
- The script will only update assets that are not currently covered by a team resource.
9+
- The script will update the coverage ordered alphabetically by the json file name.
10+
11+
## Configuration
12+
1. Clone the repository:
13+
```bash
14+
git clone https://github.com/jitsecurity/jit-customer-scripts.git
15+
cd jit-customer-scripts
16+
```
17+
18+
2. Push to your own GitLab registry:
19+
```bash
20+
# Remove the original remote
21+
git remote remove origin
22+
23+
# Add your GitLab repository as the new remote
24+
git remote add origin https://gitlab.com/your-organization/jit-customer-scripts.git
25+
26+
# Push to your GitLab repository
27+
git push -u origin main
28+
```
29+
30+
3. Navigate to [Jit platform](https://platform.jit.io/) => Settings => User and Permissions => API Tokens => Generate Token
31+
![image](https://github.com/user-attachments/assets/897cdc35-fb01-48b0-9ffa-6ed65f3b62de)
32+
![image](https://github.com/user-attachments/assets/7ba48c2f-01dc-43fa-ad12-0d33bb8789eb)
33+
34+
35+
4. Copy the `JIT_CLIENT_ID` and `JIT_CLIENT_SECRET`
36+
5. Add the environment variables in GitLab:
37+
- Go to Project > Build > Pipeline Schedules > New schedule
38+
- Select Description, Timezone, Interval Pattern: everyday, branch: main, Variables: JIT_CLIENT_ID and JIT_CLIENT_SECRET
39+
- Click on Create pipeline schedule make sure cron set to 0 12 * * *
40+
![image](https://github.com/user-attachments/assets/c5b25d63-d2be-44fc-a0bf-1f7089df4794)
41+
42+
43+
1. Copy you teams json files to the `src/scripts/gitlab_team_resource_manager` folder.
44+
45+
```json
46+
{
47+
"teams": [
48+
{
49+
"name": "Team Name",
50+
"members": ["member1", "member2"],
51+
"resources": [
52+
{
53+
"type": "repository",
54+
"name": "repo-name",
55+
"vendor": "gitlab"
56+
}
57+
]
58+
}
59+
]
60+
}
61+
```
62+
63+
### Monitor execution:
64+
- View pipeline status in CI/CD > Pipelines
65+
- Check job logs for detailed execution information
66+
- ![image](https://github.com/user-attachments/assets/7490f280-7716-4157-b2ad-9eaef7f4c68b)
67+
68+
69+
70+
71+
## Script Behavior
72+
73+
1. Authentication:
74+
- Authenticates with JIT API using provided credentials
75+
- Exits if authentication fails
76+
77+
2. Asset Processing:
78+
- Fetches uncovered assets from JIT API
79+
- Matches assets with team resources
80+
- Updates coverage status for matching assets
81+
82+
3. Team Selection:
83+
- Processes the first team that has resources matching uncovered assets
84+
- Logs matching resources and team information
85+
86+
## Troubleshooting
87+
88+
1. Authentication Issues:
89+
- Verify JIT_CLIENT_ID and JIT_CLIENT_SECRET are correct
90+
- Check API endpoint accessibility
91+
92+
2. No Assets Found:
93+
- Verify API endpoint configuration
94+
- Check if there are uncovered assets
95+
96+
3. No Matching Resources:
97+
- Verify team_metadata.json structure
98+
- Ensure resource names match asset names
99+
100+
101+
The GitLab Team Resource Manager script:
102+
1. Fetches uncovered assets from JIT API
103+
2. Matches assets with team resources defined in metadata
104+
3. Updates coverage status for matching assets

0 commit comments

Comments
 (0)