# Cross-repo IAM review

One repo's scan becomes another repo's review input. The app repo emits a
`cce-access-request.json`; the platform team's IAM/Terraform repo reviews exactly
the operations the code calls — instead of guessing permissions from a ticket.

```mermaid
flowchart LR
  app["app repo<br/>cce access-request"] -->|"artifact / PR"| iam["IAM / Terraform repo<br/>reviews operations"]
  iam -->|"policy PR removes an operation"| check["app repo diff shows<br/>the call is still present"]
```

## The artifact

```bash
cce access-request . --service payments-api -o cce-access-request.json
```

```json
{
  "schema": "cce-access-request/v1",
  "service": "payments-api",
  "commit": "a91c00f…",
  "operations": [
    {"provider": "AWS", "resource": "s3", "operation": "PutObject",
     "file": "internal/upload.go", "line": 71, "sites": 1}
  ],
  "provenance": {"builtin_definition_sha256": "…"},
  "note": "Static code evidence only; no runtime coverage claimed and no resource ARNs inferred. Review operations against policy before granting."
}
```

Operations are deduplicated (`sites` counts occurrences), the commit is
auto-detected from the checkout, and provenance pins the exact rules used.

## App-side workflow

The native reusable workflow checks out the app, emits the versioned request,
and uploads it as `cce-access-request`. It needs no cross-repository token:

```yaml
# .github/workflows/cce-access-request.yml (app repo)
name: CCE access request
on:
  pull_request:
  workflow_dispatch:
permissions:
  contents: read
  packages: read
jobs:
  request:
    uses: stackgenhq/cce-action/.github/workflows/access-request.yml@v1
    with:
      path: .
      service: payments-api
      # Optional custom lens; local files are automatically hashed.
      # lens: .cce/cloud.yaml
```

Download the `cce-access-request` artifact from the run and attach it to the IAM
review. The workflow deliberately does not send `repository_dispatch`: the
default app-repository token should not receive write access to the IAM repo.
If your organization automates that handoff, use a narrowly scoped credential
and send the app PR/run URL; artifact access still requires permission on the
app repository.

For use inside an existing job, the equivalent composite action is
`stackgenhq/cce-action/access-request@v1`.

## IAM-repo side

Review the artifact's operation tuples, evidence, commit, and mapper provenance
against policy. When source access is available, independently re-derive it:

```bash
cce access-request ../payments-api \
  --service payments-api --commit a91c00f... \
  -o reproduced-access-request.json
```

A difference between the submitted and reproduced artifact is a review signal:
confirm the source commit and lens SHA-256 before granting access. Complete
provider/resource/operation rows are evidence to review, not automatically
deployable IAM policy statements.

## Reverse direction: policy PRs check the code

When an IAM PR *removes* `sqs:SendMessage`, scan the consuming service and diff:

```bash
cce access-request ../payments-api -o current.json
# or full scans + markdown diff for the policy PR comment:
cce -folder ../payments-api -language AUTO -filter cloud -format json -output before.json
# apply the policy change, rescan, then:
cce diff before.json after.json --format markdown -o api-diff.md
```

The markdown output is a ready-to-post sticky PR comment (see
[GitHub Actions](github-actions.md#pr-review-cloud-api-diff)).

## Guardrails

- Static evidence only — dynamic/reflection/wrapped calls may be missing.
- No ARNs are inferred; reviewers bind resources, CCE binds operations.
- The default path needs no cross-repository credential; artifacts carry no secrets. Any optional dispatch token must be scoped to the IAM repo only.
