Skip to content

Auto-generate cloud provider permissions manifest#6978

Merged
vjeffrey merged 6 commits intomainfrom
feature/auto-generate-permissions-manifest
Mar 18, 2026
Merged

Auto-generate cloud provider permissions manifest#6978
vjeffrey merged 6 commits intomainfrom
feature/auto-generate-permissions-manifest

Conversation

@vjeffrey
Copy link
Copy Markdown
Contributor

@vjeffrey vjeffrey commented Mar 18, 2026

Summary

  • Adds a new Go tool (providers-sdk/v1/util/permissions/permissions.go) that uses Go AST parsing to statically analyze provider resource files and extract every cloud API call, mapping them to IAM/RBAC permissions
  • Supports AWS (370 permissions), GCP (110 permissions), and Azure (75 permissions)
  • Integrates into the buildProvider and buildProviderDist Makefile macros so permission manifests are automatically regenerated whenever a provider is built
  • Adds make providers/permissions as a standalone convenience target
  • Outputs <provider>.permissions.json in each provider's dist/ directory

Output format

{
  "provider": "aws",
  "version": "13.2.4",
  "generated_at": "2026-03-18T17:28:20Z",
  "permissions": ["ec2:DescribeInstances", "s3:ListBuckets", ...],
  "details": [{"permission": "ec2:DescribeInstances", "service": "ec2", "action": "DescribeInstances", "source_file": "aws_ec2.go"}, ...]
}

How it works

  • AWS: Tracks conn.<Service>(region) variable assignments and their method calls (e.g., svc.DescribeInstances) + paginator constructors (ec2.NewDescribeInstancesPaginator). Maps SDK method names 1:1 to IAM actions.
  • GCP: Detects both REST-style chained calls (computeSvc.Regions.List) and gRPC client method calls (client.ListKeyRings). Maps to service.resource.verb format.
  • Azure: Identifies ARM SDK client constructors (compute.NewVirtualMachinesClient) and their pager/get calls. Maps to Microsoft.Provider/resourceType/read format.

Closes #6977

Test plan

  • go vet passes on the new tool
  • make providers/permissions generates correct JSON for all 3 providers
  • AWS output includes expected permissions (ec2:DescribeInstances, s3:ListBuckets, iam:GetAccountPasswordPolicy, etc.)
  • GCP output uses correct service names (compute, cloudkms, iam, etc.)
  • Azure output uses correct ARM provider paths (Microsoft.Compute/virtualMachines/read, etc.)
  • Full make providers build works with permissions extraction integrated

🤖 Generated with Claude Code

sample generated aws permissions file:
aws.permissions.json

Add a Go tool that statically analyzes provider resource source files to extract
all cloud API calls and maps them to IAM/RBAC permissions. The tool produces a
JSON manifest per provider listing every permission required for a full scan.

Integrated into the Makefile build pipeline so manifests are regenerated
automatically when providers are built. Also adds `make providers/permissions`
as a standalone convenience target.

Closes #6977

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@mondoo-code-review mondoo-code-review bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New build-time tool generates cloud provider permission manifests; has a timestamp-based non-determinism issue and a potential panic on empty strings.

- Use deterministic timestamp (SOURCE_DATE_EPOCH or git commit time)
  instead of time.Now() for reproducible builds
- Guard against empty resource string in gcpRESTToPermission to prevent
  index-out-of-range panic
- Guard against empty service string in azureServiceToARM
- Move AggregatedList check before List check in gcpMethodToPermission
  to correctly parse methods like AggregatedListInstances
- Use filepath.WalkDir to recurse into subdirectories when scanning
  for Go source files

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mondoo-code-review mondoo-code-review bot dismissed their stale review March 18, 2026 17:47

Superseded by new review

Copy link
Copy Markdown

@mondoo-code-review mondoo-code-review bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous panic risks on empty strings are fixed; timestamp format is now inconsistent between the two fallback paths.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@mondoo-code-review mondoo-code-review bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Timestamp format is now consistently RFC 3339 across all code paths.

vjeffrey and others added 2 commits March 18, 2026 11:55
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@mondoo-code-review mondoo-code-review bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Silences errcheck linter warning but discards WalkDir errors that could cause silent data loss.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 18, 2026

Test Results

5 504 tests  ±0   5 500 ✅ ±0   2m 14s ⏱️ -1s
  411 suites +1       4 💤 ±0 
   31 files   ±0       0 ❌ ±0 

Results for commit e6c275b. ± Comparison against base commit a0a64af.

♻️ This comment has been updated with latest results.

Output permissions JSON to providers/<name>/resources/ instead of
providers/<name>/dist/ so the files are tracked in git and always
available to users without requiring a build.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@mondoo-code-review mondoo-code-review bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generated permission manifests checked into repo; default output path changed from dist/ to resources/.

// listGoFiles returns all non-test, non-generated .go files in a directory tree.
func listGoFiles(dir string) []string {
var files []string
_ = filepath.WalkDir(dir, func(path string, d os.DirEntry, err error) error {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 suggestion — Previous finding still unresolved: _ = filepath.WalkDir(dir, ...) silently swallows errors. If dir doesn't exist or is unreadable, the caller gets an empty slice with no indication of failure. Consider returning ([]string, error) and propagating the WalkDir error, so main() can log a meaningful message instead of producing an empty manifest.

@vjeffrey vjeffrey merged commit 70b85e8 into main Mar 18, 2026
22 checks passed
@vjeffrey vjeffrey deleted the feature/auto-generate-permissions-manifest branch March 18, 2026 19:25
@github-actions github-actions bot locked and limited conversation to collaborators Mar 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auto-generate cloud provider permissions manifest (AWS, GCP, Azure)

1 participant