Skip to content

Commit 3b7e05b

Browse files
authored
Merge pull request #22 from arnica-ext/checkin-real-code
Checkin real code
2 parents d551aaa + 6a63d6d commit 3b7e05b

13 files changed

Lines changed: 449 additions & 191 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#
22
local_repos/
3+
public_repos/
34

45
# Byte-compiled / optimized / DLL files
56
__pycache__/

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"cSpell.words": [
3+
"gitgoat"
4+
]
5+
}

config.yaml

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,55 @@ base_headers:
1212
## Organization names to run GitGoat on.
1313
org_names:
1414
- GitGoat-Demo
15-
16-
15+
16+
1717
## Repo names to generate
1818
repo_names:
1919
- Echinacea
20-
- Lavender
20+
- Acai
21+
- Peppermint
22+
- Lavender
2123
- Chamomile
2224
- Calendula
2325
- Tarragon
2426
- Ginger
2527
- Wasabi
26-
- Peppermint
27-
- Acai
28+
29+
## Public repo name mapping to private repo names.
30+
## This setting is used to generate as much as realistic commits as in other repos based on the "days_since_last_commit" setting in the members section below.
31+
repo_names_mapping_to_public_repos:
32+
Acai:
33+
org: hardik05
34+
repo: Damn_Vulnerable_C_Program
35+
Echinacea:
36+
org: arnica-ext
37+
repo: GitGoat
38+
Chamomile:
39+
org: bridgecrewio
40+
repo: terragoat
41+
Calendula:
42+
org: WebGoat
43+
repo: WebGoat
44+
Tarragon:
45+
org: appsecco
46+
repo: dvna
47+
Ginger:
48+
org: madhuakula
49+
repo: kubernetes-goat
50+
Wasabi:
51+
org: cider-security-research
52+
repo: cicd-goat
53+
Peppermint:
54+
org: deepfence
55+
repo: SecretScanner
56+
Lavender:
57+
org: OWASP
58+
repo: railsgoat
2859

2960
## Specific configurations per repo (optional).
3061
### "branch_protection" means the policy is enabled in the main branch
3162
### "branch_protection_restirctions" define who can push to the protected branch. A team name is specified by the prefix, e.g. the team "Lavender-push" should be included as "push".
32-
### "codeowners" configure the codeowners file definitions. The possible paths are '' (root), './github'. or '/docs'. The patterns and users/teams associations are in the codeowners documentations on GitHub, but the name of the teams should include only the postfixes (as explained above).
63+
### "codeowners" configure the codeowners file definitions. The possible paths are '' (root), '.github/' or 'docs/'. The patterns and users/teams associations are in the codeowners documentations on GitHub, but the name of the teams should include only the postfixes (as explained above).
3364
### "actions_enabled" means that the repo has GitHub Action enabled
3465
### "allowed_actions" defines the scope of the allowed actions. The options are "all", "selected" or "local_only". It is applicable only if "actions_enabled" is true.
3566
### "verified_allowed_actions" defined if verified actions (not neccesarily owned by GitHub) are allowed. It is applicable only if "actions_enabled" is true.
@@ -219,7 +250,6 @@ members:
219250
login: miker-gg
220251
email: miker@@gitgoat.tools
221252
token: xA6DOQRPkmo6wuP5GUfSJCl6u7H3si2a6AFc
222-
gitgoat_repo_permission: push
223253
member_of_groups:
224254
- Lavender-push
225255
- Calendula-triage
@@ -236,7 +266,6 @@ members:
236266
login: archiet-gg
237267
email: archiet@gitgoat.tools
238268
token: EbcLokhBwUKnN5WmJz6eOwiXN0sFC04UxDIs
239-
gitgoat_repo_permission: admin
240269
member_of_groups:
241270
- Echinacea-admin
242271
- Echinacea-push
@@ -271,7 +300,7 @@ members:
271300
- repo: Ginger
272301
days: 100
273302
branch: feature_G01
274-
create_pr: True
303+
create_pr: False
275304
- repo: Wasabi
276305
days: 25
277306
branch: feature_W01
@@ -289,7 +318,6 @@ members:
289318
login: billdp-gg
290319
email: billdp@gitgoat.tools
291320
token: Nk6u8zQjI5o1CX9QWNuY4VOpmGIo452GEq2T
292-
gitgoat_repo_permission: maintain
293321
member_of_groups:
294322
- Echinacea-push
295323
- Echinacea-pull
@@ -340,7 +368,7 @@ members:
340368
login: codeyf-gg
341369
email: codeyf@gitgoat.tools
342370
token: B81U7smn2ScvPp7nfDXj7RNpTBZvk90tYwiN
343-
gitgoat_repo_permission: push
371+
344372
member_of_groups:
345373
- Echinacea-pull
346374
- Lavender-push
@@ -354,7 +382,7 @@ members:
354382
- Peppermint-push
355383
days_since_last_commit:
356384
- repo: Lavender
357-
days: 101
385+
days: 10
358386
branch: feature_L03
359387
create_pr: True
360388
- repo: Chamomile
@@ -368,13 +396,13 @@ members:
368396
- repo: Calendula
369397
days: 95
370398
branch: feature_C03
371-
create_pr: True
399+
create_pr: False
372400
- repo: Tarragon
373401
days: 93
374402
branch: main
375403
create_pr: False
376404
- repo: Ginger
377-
days: 100
405+
days: 10
378406
branch: feature_G03
379407
create_pr: True
380408
- repo: Wasabi
@@ -391,7 +419,6 @@ members:
391419
login: debu-gg
392420
email: debu@gitgoat.tools
393421
token: NSWR5qmC4g9Cx8Y8yXzQE4kzUmBYWf16ZTsF
394-
gitgoat_repo_permission: triage
395422
member_of_groups:
396423
- Echinacea-pull
397424
- Chamomile-pull
@@ -402,4 +429,4 @@ members:
402429
- repo: Acai
403430
days: 100
404431
branch: feature_A03
405-
create_pr: True
432+
create_pr: False

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ Faker
33
requests
44
pyyaml
55
coloredlogs
6-
tqdm
6+
tqdm
7+
pygit2

run.py

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from src.commit import Commit
88
from src.members import Membership
99
from src.pull_request import PullRequest
10-
from src.direct_permissions import DirectPermission
1110
from src.branch import Branch
1211
from src.codeowners import CodeOwners
1312
from src.secrets import Secrets
@@ -28,26 +27,28 @@ async def mock(config_file: str, orgs: list = []):
2827
await accept_invitations(config, org)
2928
logging.info('----- Creating Teams -----')
3029
await create_teams(config, org)
31-
logging.info('----- Granting Direct Permissions -----')
32-
await add_direct_permissions(config, org)
3330
logging.info('----- Creating Commits and Pull Requests -----')
3431
await create_commits(config, org, secrets)
3532
logging.info('----- Reviewing Pull Requests -----')
3633
await review_pull_requests(config, org)
3734
logging.info('----- Merging Pull Requests -----')
3835
await merge_pull_requests(config, org)
39-
logging.info('----- Configuring Branch Protection -----')
40-
await configure_branch_protection(config, org)
4136
logging.info('----- Configuring CODEOWNERS -----')
4237
await configure_codeowners(config, org)
38+
logging.info('----- Configuring Branch Protection -----')
39+
await configure_branch_protection(config, org)
4340

4441
async def create_repos(config, org):
4542
r = Repository(org, config.filename)
4643
await r.delete_existing_repos()
4744
for repo_name in tqdm(config.repo_names, desc='Repos'):
48-
await r.create(repo_name)
49-
logging.info(f'Cloning GitGoat and pushing to org {org}.')
50-
await r.clone_gitgoat()
45+
if repo_name in config.repo_names_mapping_to_public_repos:
46+
await r.create(repo_name, auto_init = False)
47+
await r.clone_public_repo(config.repo_names_mapping_to_public_repos[repo_name]['org'], config.repo_names_mapping_to_public_repos[repo_name]['repo'])
48+
logging.debug(f'Cloned {config.repo_names_mapping_to_public_repos[repo_name]["repo"]} to org {org} and repo {repo_name}.')
49+
else:
50+
await r.create(repo_name, auto_init = True)
51+
logging.debug(f'Created {repo_name} in org {org}.')
5152

5253
async def create_teams(config, org):
5354
t = Team(org, config.filename)
@@ -84,12 +85,6 @@ async def accept_invitations(config, org):
8485
token = member['token'] if 'ghp_' in member['token'] else 'ghp_' + member['token']
8586
await m.accept_invitation_to_org(token)
8687

87-
async def add_direct_permissions(config, org):
88-
dp = DirectPermission(org, config.filename)
89-
for member in tqdm(config.members, desc='Direct Permission'):
90-
if 'gitgoat_repo_permission' in member:
91-
await dp.add_repository_permission('GitGoat',member['login'],member['gitgoat_repo_permission'])
92-
9388
async def setup_actions(config, org):
9489
a = Actions(org, config.filename)
9590
await a.enable_selected_repositories_in_org()
@@ -111,12 +106,9 @@ async def setup_actions(config, org):
111106
await a.enable_selected_actions_in_repo(actions_enabled_repo, verified_allowed=config.repo_configs[actions_enabled_repo]['verified_allowed_actions'])
112107

113108
async def configure_codeowners(config, org):
114-
r = Repository(org, config.filename)
115109
for repo_name in tqdm(config.repo_names, desc='CODEOWNERS'):
116-
repo = await r.clone(repo_name, 'GitGoat', Config.get_pat(), 'GitGoat@gitgoat.tools')
117-
co = CodeOwners(org,repo_name, repo, config.filename)
118-
filename = await co.generate_file()
119-
await co.push_file(filename)
110+
co = CodeOwners(org,repo_name, config.filename)
111+
await co.generate_codeowners()
120112

121113
async def configure_branch_protection(config, org):
122114
b = Branch(org, config.filename)
@@ -136,13 +128,13 @@ async def create_commits(config, org, secrets):
136128
for member in config.members:
137129
token = member['token'] if 'ghp_' in member['token'] else 'ghp_' + member['token']
138130
for commit_details in tqdm(member['days_since_last_commit'], desc=f'Commits for {member["login"]}'):
139-
repo = await r.clone(commit_details['repo'], member['login'], token, member['email'], commit_details['branch'])
140-
c = Commit(repo, secrets)
131+
c = Commit(secrets, token, config.filename)
132+
sha = await c.get_branch_hash(org, commit_details['repo'], commit_details['branch'])
141133
add_secret = False
142134
if 'commit_secrets_in_repositories' in member and commit_details['repo'] in member['commit_secrets_in_repositories']:
143135
add_secret = True
144-
c.generate_commits(25, commit_details['days'], commit_secret = add_secret)
145-
if commit_details['create_pr']:
136+
await c.generate_random_commits(org, commit_details['repo'], commit_details['branch'], sha, 15, commit_details['days'], add_secret)
137+
if commit_details['create_pr'] and commit_details['branch'] != 'main':
146138
await pr.create_pull_request(token, commit_details['repo'], commit_details['branch'])
147139

148140
async def review_pull_requests(config, org):
@@ -225,7 +217,25 @@ def is_member_allowed_to_merge(config, member, repo):
225217
return True
226218
return False
227219

220+
def print_banner():
221+
print('''
222+
_____ _ _ _____ _ _
223+
| __ \(_)| | | __ \ | | | |
224+
| | \/ _ | |_ | | \/ ___ __ _ | |_ | |__ _ _
225+
| | __ | || __|| | __ / _ \ / _` || __| | '_ \ | | | |
226+
| |_\ \| || |_ | |_\ \| (_) || (_| || |_ | |_) || |_| |
227+
\____/|_| \__| \____/ \___/ \__,_| \__| |_.__/ \__, |
228+
___ _ ___ __/ |
229+
| _| (_) |_ | |___/
230+
| | __ _ _ __ _ __ _ ___ __ _ | |
231+
| | / _` || '__|| '_ \ | | / __| / _` | | |
232+
| | | (_| || | | | | || || (__ | (_| | | |
233+
| |_ \__,_||_| |_| |_||_| \___| \__,_| _| |
234+
|___| |___|
235+
''')
236+
228237
if __name__ == '__main__':
238+
print_banner()
229239
try:
230240
if sys.argv[sys.argv.index("--config")+1].startswith('--'):
231241
raise

0 commit comments

Comments
 (0)