-
Notifications
You must be signed in to change notification settings - Fork 5
feat(scanning): audit GitHub Actions workflows across repositories #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nakberli841-bot
wants to merge
25
commits into
main
Choose a base branch
from
feat/10-github-actions-workflow-audit
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
db5a09b
feat(scanning): audit GitHub Actions workflows across repositories
nakberli841-bot 664e589
Merge branch 'main' into feat/10-github-actions-workflow-audit
nakberli841-bot 3fdd3f4
fix(backend): merge conflict
nakberli841-bot 86e40b7
Update WorkflowScanRepositoryTest.java
nakberli841-bot 7b87695
Update WorkflowScanRepositoryTest.java
nakberli841-bot 300d4d0
Update WorkflowScanRepositoryTest.java
nakberli841-bot a2bcfed
fix(worker): add githubclient package to component scan in CleatWorke…
nakberli841-bot b4786e8
fix: resolve missing repository imports in tests
nakberli841-bot af8216c
feat: add installationId to AccountEntity and fix migration versioning
nakberli841-bot 1748dc5
feat: add installationId to Account entity and update database schema
nakberli841-bot a0cbe57
fix: resolve checkstyle violations
nakberli841-bot 7787e1f
fix: resolve CI build failures in test modules
nakberli841-bot 622e666
fix(worker): narrow EntityScan and EnableJpaRepositories to specific …
nakberli841-bot 48c3564
fix(scanning): replace invalid SHA in WorkflowParserTest with valid h…
nakberli841-bot 428728a
fix(github-client): mark redisTemplate bean as @Primary to resolve No…
nakberli841-bot eca70f6
fix(worker): add test application.yml with required GitHub and scan p…
nakberli841-bot 035e1e2
fix(worker): fix YAML syntax in test application.yml
nakberli841-bot d4d489b
fix: resolve LazyInitializationException by enabling @Transactional f…
nakberli841-bot ba5ba02
fix: retrieve workflow content from base64 field to avoid host mismatch
nakberli841-bot 8b59d84
fix: delete old scan records before checking for empty workflow files
nakberli841-bot 269ac17
refactor(scanning): improve permission and OIDC audit logic
nakberli841-bot e431f7a
refactor(scanning): align test expectations with new OIDC logic
nakberli841-bot 5850c2f
refactor(test): replace Testcontainers with H2 in-memory database for…
nakberli841-bot 5f68b27
fix(scanning): exclude id-token from broad permissions check in Workf…
nakberli841-bot 59df10d
fix: fetch workflow file contents individually
nakberli841-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
backend/apps/api/src/main/java/dev/cleat/api/controller/WorkflowScanController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package dev.cleat.api.controller; | ||
|
|
||
| import dev.cleat.persistence.entity.WorkflowScanEntity; | ||
| import dev.cleat.persistence.repository.WorkflowScanRepository; | ||
| import java.time.OffsetDateTime; | ||
| import java.util.List; | ||
| import java.util.UUID; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/api/repos") | ||
| public class WorkflowScanController { | ||
|
|
||
| private final WorkflowScanRepository workflowScanRepository; | ||
|
|
||
| public WorkflowScanController(WorkflowScanRepository workflowScanRepository) { | ||
| this.workflowScanRepository = workflowScanRepository; | ||
| } | ||
|
|
||
| @GetMapping("/{repoId}/workflow-scans") | ||
| public List<WorkflowScanResponse> getWorkflowScans(@PathVariable UUID repoId) { | ||
| return workflowScanRepository.findByRepoIdOrderByScannedAtDesc(repoId).stream() | ||
| .map(WorkflowScanResponse::from) | ||
| .toList(); | ||
| } | ||
|
|
||
| public record WorkflowScanResponse( | ||
| UUID id, | ||
| String workflowPath, | ||
| int unpinnedActions, | ||
| boolean broadPermissions, | ||
| boolean missingOidc, | ||
| int riskScore, | ||
| OffsetDateTime scannedAt) { | ||
|
|
||
| public static WorkflowScanResponse from(WorkflowScanEntity entity) { | ||
| return new WorkflowScanResponse( | ||
| entity.getId(), | ||
| entity.getWorkflowPath(), | ||
| entity.getUnpinnedActions(), | ||
| entity.getBroadPermissions(), | ||
| entity.getMissingOidc(), | ||
| entity.getRiskScore(), | ||
| entity.getScannedAt()); | ||
| } | ||
| } | ||
| } |
19 changes: 2 additions & 17 deletions
19
backend/apps/api/src/test/java/dev/cleat/api/AbstractIntegrationTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,6 @@ | ||
| package dev.cleat.api; | ||
|
|
||
| import org.springframework.boot.test.context.SpringBootTest; | ||
| import org.springframework.boot.testcontainers.service.connection.ServiceConnection; | ||
| import org.testcontainers.containers.GenericContainer; | ||
| import org.testcontainers.containers.PostgreSQLContainer; | ||
| import org.testcontainers.junit.jupiter.Container; | ||
| import org.testcontainers.junit.jupiter.Testcontainers; | ||
|
|
||
| @Testcontainers | ||
| @SpringBootTest | ||
| public abstract class AbstractIntegrationTest { | ||
|
|
||
| @Container | ||
| @ServiceConnection | ||
| static PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres:16-alpine"); | ||
|
|
||
| @Container | ||
| @ServiceConnection | ||
| static GenericContainer<?> redis = new GenericContainer<>("redis:7-alpine").withExposedPorts(6379); | ||
| } | ||
| @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
| public abstract class AbstractIntegrationTest {} |
81 changes: 81 additions & 0 deletions
81
backend/apps/api/src/test/java/dev/cleat/api/WorkflowScanControllerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| package dev.cleat.api; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import dev.cleat.common.enums.AccountType; | ||
| import dev.cleat.persistence.entity.AccountEntity; | ||
| import dev.cleat.persistence.entity.RepoEntity; | ||
| import dev.cleat.persistence.entity.WorkflowScanEntity; | ||
| import dev.cleat.persistence.repository.AccountRepository; | ||
| import dev.cleat.persistence.repository.RepoRepository; | ||
| import dev.cleat.persistence.repository.WorkflowScanRepository; | ||
| import java.time.OffsetDateTime; | ||
| import java.util.List; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.test.web.client.TestRestTemplate; | ||
|
|
||
| class WorkflowScanControllerTest extends AbstractIntegrationTest { | ||
|
|
||
| @Autowired | ||
| private AccountRepository accountRepository; | ||
|
|
||
| @Autowired | ||
| private RepoRepository repoRepository; | ||
|
|
||
| @Autowired | ||
| private WorkflowScanRepository workflowScanRepository; | ||
|
|
||
| @Autowired | ||
| private TestRestTemplate restTemplate; | ||
|
|
||
| @Test | ||
| void returnsWorkflowScansForRepo() { | ||
| AccountEntity account = new AccountEntity() | ||
| .setLogin("octocat") | ||
| .setName("Octocat") | ||
| .setType(AccountType.USER) | ||
| .setInstallationId("inst-123"); | ||
| accountRepository.saveAndFlush(account); | ||
|
|
||
| RepoEntity repo = new RepoEntity().setAccount(account).setName("hello-world"); | ||
| repoRepository.saveAndFlush(repo); | ||
|
|
||
| workflowScanRepository.saveAndFlush(new WorkflowScanEntity() | ||
| .setRepo(repo) | ||
| .setWorkflowPath(".github/workflows/ci.yml") | ||
| .setUnpinnedActions(2) | ||
| .setBroadPermissions(false) | ||
| .setMissingOidc(true) | ||
| .setRiskScore(80) | ||
| .setScannedAt(OffsetDateTime.now())); | ||
|
|
||
| var response = restTemplate | ||
| .withBasicAuth("test", "test") | ||
| .getForEntity("/api/repos/" + repo.getId() + "/workflow-scans", List.class); | ||
|
|
||
| // Assert | ||
| assertThat(response.getStatusCode().is2xxSuccessful()).isTrue(); | ||
| assertThat(response.getBody()).hasSize(1); | ||
| } | ||
|
|
||
| @Test | ||
| void returnsEmptyListWhenNoScans() { | ||
| AccountEntity account = new AccountEntity() | ||
| .setLogin("octocat3") | ||
| .setName("Octocat3") | ||
| .setType(AccountType.USER) | ||
| .setInstallationId("inst-456"); | ||
| accountRepository.saveAndFlush(account); | ||
|
|
||
| RepoEntity repo = new RepoEntity().setAccount(account).setName("empty-repo"); | ||
| repoRepository.saveAndFlush(repo); | ||
|
|
||
| var response = restTemplate | ||
| .withBasicAuth("test", "test") | ||
| .getForEntity("/api/repos/" + repo.getId() + "/workflow-scans", List.class); | ||
|
|
||
| assertThat(response.getStatusCode().is2xxSuccessful()).isTrue(); | ||
| assertThat(response.getBody()).isEmpty(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| spring: | ||
| datasource: | ||
| url: jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;MODE=PostgreSQL | ||
| username: sa | ||
| password: | ||
| driver-class-name: org.h2.Driver | ||
| jpa: | ||
| hibernate: | ||
| ddl-auto: none | ||
| data: | ||
| redis: | ||
| host: localhost | ||
| port: 6379 | ||
| security: | ||
| user: | ||
| name: test | ||
| password: test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
backend/apps/worker/src/main/java/dev/cleat/worker/WorkflowScanJob.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package dev.cleat.worker; | ||
|
|
||
| import dev.cleat.persistence.entity.RepoEntity; | ||
| import dev.cleat.persistence.repository.AccountRepository; | ||
| import dev.cleat.scanning.WorkflowScanService; | ||
| import jakarta.transaction.Transactional; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.springframework.scheduling.annotation.Scheduled; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Component | ||
| public class WorkflowScanJob { | ||
|
|
||
| private static final Logger LOG = LoggerFactory.getLogger(WorkflowScanJob.class); | ||
|
|
||
| private final AccountRepository accountRepository; | ||
| private final WorkflowScanService workflowScanService; | ||
|
|
||
| public WorkflowScanJob(AccountRepository accountRepository, WorkflowScanService workflowScanService) { | ||
| this.accountRepository = accountRepository; | ||
| this.workflowScanService = workflowScanService; | ||
| } | ||
|
|
||
| @Scheduled(fixedDelayString = "${cleat.workflow-scan.interval-ms:3600000}") | ||
| @Transactional | ||
| public void run() { | ||
| LOG.info("Starting workflow scan job"); | ||
|
|
||
| accountRepository.findAll().forEach(account -> { | ||
| String installationId = account.getInstallationId(); | ||
|
|
||
| for (RepoEntity repo : account.getRepos()) { | ||
| try { | ||
| workflowScanService.scanRepo(repo, installationId); | ||
| } catch (Exception e) { | ||
| LOG.error("Failed to scan workflows for repo {}/{}", account.getLogin(), repo.getName(), e); | ||
| } | ||
| } | ||
| }); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| LOG.info("Workflow scan job completed"); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,4 +28,7 @@ management: | |
| db: | ||
| enabled: true | ||
| redis: | ||
| enabled: true | ||
| enabled: true | ||
| cleat: | ||
| workflow-scan: | ||
| interval-ms: 3600000 | ||
17 changes: 1 addition & 16 deletions
17
backend/apps/worker/src/test/java/dev/cleat/worker/AbstractIntegrationTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,6 @@ | ||
| package dev.cleat.worker; | ||
|
|
||
| import org.springframework.boot.test.context.SpringBootTest; | ||
| import org.springframework.boot.testcontainers.service.connection.ServiceConnection; | ||
| import org.testcontainers.containers.GenericContainer; | ||
| import org.testcontainers.containers.PostgreSQLContainer; | ||
| import org.testcontainers.junit.jupiter.Container; | ||
| import org.testcontainers.junit.jupiter.Testcontainers; | ||
|
|
||
| @Testcontainers | ||
| @SpringBootTest | ||
| public abstract class AbstractIntegrationTest { | ||
|
|
||
| @Container | ||
| @ServiceConnection | ||
| static PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres:16-alpine"); | ||
|
|
||
| @Container | ||
| @ServiceConnection | ||
| static GenericContainer<?> redis = new GenericContainer<>("redis:7-alpine").withExposedPorts(6379); | ||
| } | ||
| public abstract class AbstractIntegrationTest {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| spring: | ||
| datasource: | ||
| url: jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;MODE=PostgreSQL | ||
| username: sa | ||
| password: | ||
| driver-class-name: org.h2.Driver | ||
| jpa: | ||
| hibernate: | ||
| ddl-auto: none | ||
| data: | ||
| redis: | ||
| host: localhost | ||
| port: 6379 | ||
|
|
||
| github: | ||
| app-id: "test-app-id" | ||
| private-key-path: "/tmp/test-key.pem" | ||
|
|
||
| cleat: | ||
| workflow-scan: | ||
| interval-ms: 3600000 | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.