|
| 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 | +  |
| 32 | +  |
| 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 | +  |
| 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 | + -  |
| 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